Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 71c5075

Browse files
committed
Addressed Review comments
1 parent 6e8560b commit 71c5075

File tree

7 files changed

+23
-24
lines changed

7 files changed

+23
-24
lines changed

src/brain/tf_session_entity/tf_session_entity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void TFSE_TYPE::ImportGraph(const std::string &filename) {
5151
TF_GraphImportGraphDef(graph_, graph_def, opts, status_);
5252
TF_DeleteImportGraphDefOptions(opts);
5353
TF_DeleteBuffer(graph_def);
54-
assert(IsStatusOk());
54+
PL_ASSERT(IsStatusOk());
5555
}
5656

5757
TFSE_TEMPLATE_ARGUMENTS
@@ -92,8 +92,8 @@ void TFSE_TYPE::Eval(const std::string &opName) {
9292
// Evaluate op with inputs and outputs
9393
TFSE_TEMPLATE_ARGUMENTS
9494
OutputType *TFSE_TYPE::Eval(
95-
std::vector<TfSessionEntityInput<InputType>> helper_inputs,
96-
std::vector<TfSessionEntityOutput<OutputType>> helper_outputs) {
95+
const std::vector<TfSessionEntityInput<InputType>>& helper_inputs,
96+
const std::vector<TfSessionEntityOutput<OutputType>>& helper_outputs) {
9797
std::vector<TF_Tensor *> in_vals, out_vals;
9898
std::vector<TF_Output> ins, outs;
9999
for (auto helperIn : helper_inputs) {
@@ -113,13 +113,13 @@ OutputType *TFSE_TYPE::Eval(
113113
&(outs.at(0)), &(out_vals.at(0)), outs.size(), // Outputs
114114
nullptr, 0, // Operations
115115
nullptr, status_);
116-
assert(TF_GetCode(status_) == TF_OK);
116+
PL_ASSERT(TF_GetCode(status_) == TF_OK);
117117
return static_cast<OutputType *>(TF_TensorData(out_vals.at(0)));
118118
}
119119

120120
// Evaluate op with only inputs(where nothing is output eg. Backprop)
121121
TFSE_TEMPLATE_ARGUMENTS
122-
void TFSE_TYPE::Eval(std::vector<TfSessionEntityInput<InputType>> helper_inputs,
122+
void TFSE_TYPE::Eval(const std::vector<TfSessionEntityInput<InputType>>& helper_inputs,
123123
const std::string &op_name) {
124124
std::vector<TF_Tensor *> in_vals;
125125
std::vector<TF_Output> ins;
@@ -135,7 +135,7 @@ void TFSE_TYPE::Eval(std::vector<TfSessionEntityInput<InputType>> helper_inputs,
135135
nullptr, nullptr, 0, // Outputs
136136
&op, 1, // Operations
137137
nullptr, status_);
138-
assert(TF_GetCode(status_) == TF_OK);
138+
PL_ASSERT(TF_GetCode(status_) == TF_OK);
139139
}
140140

141141
/*

src/brain/tf_session_entity/tf_session_entity_input.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace peloton {
1616
namespace brain {
1717
TFSEIN_TEMPLATE_ARGUMENTS
18-
TFSEIN_TYPE::TfSessionEntityInput(InputType input, const std::string &op) {
18+
TFSEIN_TYPE::TfSessionEntityInput(const InputType& input, const std::string &op) {
1919
this->placeholder_name_ = op;
2020
this->DetermineDataType();
2121
InputType input_for_tf = input;
@@ -27,12 +27,12 @@ TFSEIN_TYPE::TfSessionEntityInput(InputType input, const std::string &op) {
2727

2828
// 1d vector
2929
TFSEIN_TEMPLATE_ARGUMENTS
30-
TFSEIN_TYPE::TfSessionEntityInput(std::vector<InputType> input,
30+
TFSEIN_TYPE::TfSessionEntityInput(const std::vector<InputType> &input,
3131
const std::string &op) {
3232
this->placeholder_name_ = op;
3333
this->DetermineDataType();
3434
int64_t dims[] = {static_cast<int64_t>(input.size())};
35-
InputType *input_for_tf = input.data();
35+
const InputType *input_for_tf = input.data();
3636
this->tensor_ =
3737
TF_AllocateTensor(this->data_type_, dims, 1, dims[0] * sizeof(InputType));
3838
auto buff = (InputType *)TF_TensorData(this->tensor_);
@@ -41,7 +41,7 @@ TFSEIN_TYPE::TfSessionEntityInput(std::vector<InputType> input,
4141

4242
// 2d vector
4343
TFSEIN_TEMPLATE_ARGUMENTS
44-
TFSEIN_TYPE::TfSessionEntityInput(std::vector<std::vector<InputType>> input,
44+
TFSEIN_TYPE::TfSessionEntityInput(const std::vector<std::vector<InputType>>& input,
4545
const std::string &op) {
4646
this->placeholder_name_ = op;
4747
this->DetermineDataType();
@@ -56,7 +56,7 @@ TFSEIN_TYPE::TfSessionEntityInput(std::vector<std::vector<InputType>> input,
5656

5757
// raw flattened input
5858
TFSEIN_TEMPLATE_ARGUMENTS
59-
TFSEIN_TYPE::TfSessionEntityInput(InputType *input, std::vector<int64_t> dims,
59+
TFSEIN_TYPE::TfSessionEntityInput(InputType *input, const std::vector<int64_t>& dims,
6060
const std::string &op) {
6161
this->placeholder_name_ = op;
6262
this->DetermineDataType();
@@ -73,7 +73,7 @@ TFSEIN_TYPE::TfSessionEntityInput(InputType *input, std::vector<int64_t> dims,
7373

7474
// Flattens 2d inputs
7575
TFSEIN_TEMPLATE_ARGUMENTS
76-
InputType *TFSEIN_TYPE::Flatten(std::vector<std::vector<InputType>> elems) {
76+
InputType *TFSEIN_TYPE::Flatten(const std::vector<std::vector<InputType>>& elems) {
7777
std::vector<InputType> flattened;
7878
for (auto row : elems) {
7979
for (float elem : row) {

src/brain/tf_session_entity/tf_session_entity_output.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TFSEOUT_TYPE::TfSessionEntityOutput(const std::string &op) {
2424
}
2525

2626
TFSEOUT_TEMPLATE_ARGUMENTS
27-
TFSEOUT_TYPE::TfSessionEntityOutput(std::vector<int64_t> dims,
27+
TFSEOUT_TYPE::TfSessionEntityOutput(const std::vector<int64_t>& dims,
2828
const std::string &op) {
2929
this->placeholder_name_ = op;
3030
this->DetermineDataType();

src/include/brain/tf_session_entity/tf_session_entity.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ class TfSessionEntity {
5454
* 3. Inputs and Outputs eg. Loss calculation, Predictions.
5555
*/
5656
void Eval(const std::string &opName);
57-
void Eval(std::vector<TfSessionEntityInput<InputType>> helper_inputs,
57+
void Eval(const std::vector<TfSessionEntityInput<InputType>>& helper_inputs,
5858
const std::string &op_name);
5959
OutputType *Eval(
60-
std::vector<TfSessionEntityInput<InputType>> helper_inputs,
61-
std::vector<TfSessionEntityOutput<OutputType>> helper_outputs);
60+
const std::vector<TfSessionEntityInput<InputType>>& helper_inputs,
61+
const std::vector<TfSessionEntityOutput<OutputType>>& helper_outputs);
6262

6363
/** Helpers **/
6464
// Print the name of all operations(`ops`) in this graph
6565
void PrintOperations();
6666
/**
67-
* Checking if the status is ok - Tensorflow C is horrible in showing theres
67+
* Checking if the status is ok - Tensorflow C is horrible in showing there's
6868
* an error
6969
* uptil the eval statement - adding status checks can help find in which step
7070
* the error

src/include/brain/tf_session_entity/tf_session_entity_input.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ TFSEIN_TEMPLATE_ARGUMENTS
3636
class TfSessionEntityInput : public TfSessionEntityIOBase<InputType> {
3737
public:
3838
// Const Input
39-
TfSessionEntityInput(InputType input, const std::string &op);
39+
TfSessionEntityInput(const InputType& input, const std::string& op);
4040
// 1d vector
41-
TfSessionEntityInput(std::vector<InputType> input, const std::string &op);
41+
TfSessionEntityInput(const std::vector<InputType>& input, const std::string& op);
4242
// 2d vector
43-
TfSessionEntityInput(std::vector<std::vector<InputType>> input,
43+
TfSessionEntityInput(const std::vector<std::vector<InputType>> &input,
4444
const std::string &op);
4545
// raw flattened input
46-
TfSessionEntityInput(InputType *input, std::vector<int64_t> dims,
46+
TfSessionEntityInput(InputType *input, const std::vector<int64_t> &dims,
4747
const std::string &op);
4848

4949
private:
5050
// Flattens 2d inputs
51-
InputType *Flatten(std::vector<std::vector<InputType>> elems);
51+
InputType *Flatten(const std::vector<std::vector<InputType>> &elems);
5252
};
5353
} // namespace brain
5454
} // namespace peloton

src/include/brain/tf_session_entity/tf_session_entity_io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#pragma once
1414

1515
#include <tensorflow/c/c_api.h>
16-
#include <cassert>
1716
#include <cstdio>
1817
#include <cstring>
1918
#include <iostream>

src/include/brain/tf_session_entity/tf_session_entity_output.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TfSessionEntityOutput : public TfSessionEntityIOBase<OutputType> {
4646
// const output
4747
explicit TfSessionEntityOutput(const std::string &op);
4848
// n-d output
49-
explicit TfSessionEntityOutput(std::vector<int64_t> dims,
49+
explicit TfSessionEntityOutput(const std::vector<int64_t>& dims,
5050
const std::string &op);
5151
};
5252
} // namespace brain

0 commit comments

Comments
 (0)