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

Add GetName function in Symbol class for cpp package #12076

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cpp-package/include/mxnet-cpp/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class Symbol {
std::vector<std::string> ListOutputs() const;
/*! \return get the descriptions of auxiliary data for this symbol */
std::vector<std::string> ListAuxiliaryStates() const;
/*! \return get the name of the symbol */
std::string GetName() const;
/*!
* \brief infer and construct all the arrays to bind to executor by providing
* some known arrays.
Expand Down
8 changes: 8 additions & 0 deletions cpp-package/include/mxnet-cpp/symbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ inline std::vector<std::string> Symbol::ListAuxiliaryStates() const {
return ret;
}

inline std::string Symbol::GetName() const {
int success;
const char* out_name;
CHECK_EQ(MXSymbolGetName(GetHandle(), &out_name, &success), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if success == 0? Based on the function description, it seems that out_name could be NULL even if the returned value is 0:

/*!
 * \brief Get string attribute from symbol
 * \param symbol the source symbol
 * \param key The key of the symbol.
 * \param out The result attribute, can be NULL if the attribute do not exist.
 * \param success Whether the result is contained in out.
 * \return 0 when success, -1 when failure happens
 */
int NNSymbolGetAttr(SymbolHandle in,
                             const char* key,
                             const char** out,
                             int *out);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

CHECK_EQ(success, 1);
return std::string(out_name);
}

inline void Symbol::InferShape(
const std::map<std::string, std::vector<mx_uint> > &arg_shapes,
std::vector<std::vector<mx_uint> > *in_shape,
Expand Down