Skip to content

Commit

Permalink
Add list attr recursive (apache#89)
Browse files Browse the repository at this point in the history
* Add list attr recursive

* fix
  • Loading branch information
piiswrong committed Dec 29, 2016
1 parent f17fea0 commit 472ad59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/nnvm/symbolic.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <string>
#include <vector>
#include <tuple>
#include <utility>

#include "./base.h"
Expand Down Expand Up @@ -168,6 +169,15 @@ class Symbol {
* \return The created attribute.
*/
std::unordered_map<std::string, std::string> ListAttrs(ListAttrOption option) const;
/*!
* \brief Get attribute dictionary from the symbol and all children.
*
* For grouped symbol, an error will be raised.
*
* \return The created attribute in format <operator_name, key, value>.
*/
std::vector<std::tuple<std::string, std::string, std::string> >
ListAttrsRecursive() const;
/*!
* \brief Create symbolic functor(AtomicSymbol) by given operator and attributes.
* \param op The operator.
Expand Down
11 changes: 11 additions & 0 deletions src/core/symbolic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ std::unordered_map<std::string, std::string> Symbol::ListAttrs(ListAttrOption op
}
}

std::vector<std::tuple<std::string, std::string, std::string> >
Symbol::ListAttrsRecursive() const {
std::vector<std::tuple<std::string, std::string, std::string> > ret;
DFSVisit(this->outputs, [&ret](const NodePtr& n) {
for (const auto& it : n->attrs.dict) {
ret.emplace_back(std::make_tuple(n->attrs.name, it.first, it.second));
}
});
return ret;
}

Symbol Symbol::CreateFunctor(const Op* op,
std::unordered_map<std::string, std::string> attrs) {
static auto& fnum_vis_output = Op::GetAttr<FNumVisibleOutputs>("FNumVisibleOutputs");
Expand Down

0 comments on commit 472ad59

Please sign in to comment.