Commit 1feabb0d by Eric Junyuan Xie Committed by Tianqi Chen

create symbol from nodeattr (#116)

parent 61df4ec5
......@@ -21,7 +21,7 @@
namespace nnvm {
/*!
* \brief Symbol is help class used to represent the operator node in Graph.
*
*
* Symbol acts as an interface for building graphs from different components
* like Variable, Functor and Group. Symbol is also exported to python front-end
* (while Graph is not) to enable quick test and deployment. Conceptually,
......@@ -193,6 +193,12 @@ class Symbol {
static Symbol CreateFunctor(const Op* op,
std::unordered_map<std::string, std::string> attrs);
/*!
* \brief Create symbolic functor(AtomicSymbol) by given node attributes.
* \param attrs pre-initialized Node attributes.
* \return Symbol that can be used to call compose further.
*/
static Symbol CreateFunctor(const NodeAttrs& attrs);
/*!
* \brief Create symbol node representing variable.
* \param name Name of the variable.
* \return The symbol.
......
......@@ -527,6 +527,22 @@ Symbol Symbol::CreateFunctor(const Op* op,
return s;
}
Symbol Symbol::CreateFunctor(const NodeAttrs& attrs) {
static auto& fnum_vis_output = Op::GetAttr<FNumVisibleOutputs>("FNumVisibleOutputs");
Symbol s;
NodePtr n = Node::Create();
n->attrs = attrs;
uint32_t nout = n->num_outputs();
if (fnum_vis_output.count(n->op())) {
nout = fnum_vis_output[n->op()](n->attrs);
}
for (uint32_t i = 0; i < nout; ++i) {
s.outputs.emplace_back(NodeEntry{n, i, 0});
}
return s;
}
Symbol Symbol::CreateGroup(const std::vector<Symbol> &symbols) {
Symbol ret;
for (const auto &s : symbols) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment