Skip to content

Commit

Permalink
Optimize C++ API
Browse files Browse the repository at this point in the history
Pass parameter with reference instead of value.
Add const as well as it is not changed.
  • Loading branch information
zhaoyao73 committed Nov 30, 2018
1 parent f5d131e commit 523db4f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpp-package/example/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool check_datafiles(const std::vector<std::string> &data_files) {
return true;
}

bool setDataIter(MXDataIter *iter , std::string useType,
bool setDataIter(MXDataIter *iter , const std::string &useType,
const std::vector<std::string> &data_files, int batch_size) {
if (!check_datafiles(data_files))
return false;
Expand Down
4 changes: 2 additions & 2 deletions cpp-package/include/mxnet-cpp/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Operator {
* \param symbol the input symbol
* \return reference of self
*/
Operator &SetInput(const std::string &name, Symbol symbol);
Operator &SetInput(const std::string &name, const Symbol &symbol);
/*!
* \brief add an input symbol
* \param symbol the input symbol
Expand Down Expand Up @@ -133,7 +133,7 @@ class Operator {
* \param ndarray the input ndarray
* \return reference of self
*/
Operator &SetInput(const std::string &name, NDArray ndarray);
Operator &SetInput(const std::string &name, const NDArray &ndarray);
/*!
* \brief add an input ndarray
* \param ndarray the input ndarray
Expand Down
4 changes: 2 additions & 2 deletions cpp-package/include/mxnet-cpp/operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ inline void Operator::Invoke(NDArray &output) {
Invoke(outputs);
}

inline Operator &Operator::SetInput(const std::string &name, Symbol symbol) {
inline Operator &Operator::SetInput(const std::string &name, const Symbol &symbol) {
if (symbol.GetHandle()) {
input_keys_.push_back(name.c_str());
input_symbols_.push_back(symbol.GetHandle());
}
return *this;
}

inline Operator &Operator::SetInput(const std::string &name, NDArray ndarray) {
inline Operator &Operator::SetInput(const std::string &name, const NDArray &ndarray) {
input_keys_.push_back(name.c_str());
input_ndarrays_.push_back(ndarray.GetHandle());
return *this;
Expand Down

0 comments on commit 523db4f

Please sign in to comment.