Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Optimize C++ API (#13496)
Browse files Browse the repository at this point in the history
* Optimize C++ API

Pass parameter with reference instead of value.
Add const as well as it is not changed.

* fix docs/architecture/overview.md

Fix BinaryShapeFunction typedef
Add a right brace for SmoothL1Shape_
  • Loading branch information
zhaoyao73 authored and marcoabreu committed Dec 12, 2018
1 parent 9ce7eab commit 002e0bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 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
5 changes: 3 additions & 2 deletions docs/architecture/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ let's check input data shape consistency and provide output shape.
```cpp
typedef TShape (*UnaryShapeFunction)(const TShape& src,
const EnvArguments& env);
typedef TShape (*BinaryShapeFunction)(const TShape& const TShape& rhs,lhs,

typedef TShape (*BinaryShapeFunction)(const TShape& lhs,
const TShape& rhs,
const EnvArguments& env);
```
You can use `mshadow::TShape` to check input data shape and designate output data shape.
Expand Down Expand Up @@ -597,6 +597,7 @@ Written explicitly, it is:
inline TShape SmoothL1Shape_(const TShape& src,
const EnvArguments& env) {
return TShape(src);
}
```
### Define Functions
Expand Down

0 comments on commit 002e0bb

Please sign in to comment.