mxnet
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
nnvm::Symbol Class Reference

Symbol is help class used to represent the operator node in Graph. More...

#include <symbolic.h>

Collaboration diagram for nnvm::Symbol:
Collaboration graph

Public Types

enum  ListAttrOption { kRecursive = 0, kShallow = 1 }
 option passed to ListAttr More...
 
enum  ListInputOption { kAll = 0, kReadOnlyArgs = 1, kAuxiliaryStates = 2 }
 option passed to ListInputNames More...
 

Public Member Functions

Symbol Copy () const
 Copy the symbol. More...
 
void Print (std::ostream &os) const
 Print the symbol info to output stream. More...
 
Symbol operator[] (size_t index) const
 Get the index-th element from the returned tuple. More...
 
std::vector< ObjectPtrListInputs (ListInputOption option) const
 List the input variable nodes. More...
 
std::vector< std::string > ListInputNames (ListInputOption option) const
 List the input names. More...
 
std::vector< std::string > ListOutputNames () const
 List the names of outputs for this symbol. More...
 
void Compose (const array_view< const Symbol * > &args, const std::unordered_map< std::string, const Symbol * > &kwargs, const std::string &name)
 Compose the symbol with arguments, this changes the current symbol. The kwargs passed in can be in-complete,. More...
 
Symbol operator() (const array_view< const Symbol * > &args, const std::unordered_map< std::string, const Symbol * > &kwargs, const std::string &name) const
 Apply the symbol as a function, compose with arguments. More...
 
void AddControlDeps (const Symbol &src)
 Add control flow dependencies to the operators in symbols. More...
 
Symbol GetInternals () const
 
Symbol GetChildren () const
 
void SetAttrs (const std::vector< std::pair< std::string, std::string > > &attrs)
 Set additional attributes to current node. More...
 
bool GetAttr (const std::string &key, std::string *out) const
 Get attributes from the symbol. More...
 
std::unordered_map< std::string, std::string > ListAttrs (ListAttrOption option) const
 Get attribute dictionary from the symbol. More...
 
std::vector< std::tuple< std::string, std::string, std::string > > ListAttrsRecursive () const
 Get attribute dictionary from the symbol and all children. More...
 

Static Public Member Functions

static Symbol CreateFunctor (const Op *op, std::unordered_map< std::string, std::string > attrs)
 Create symbolic functor(AtomicSymbol) by given operator and attributes. More...
 
static Symbol CreateFunctor (const NodeAttrs &attrs)
 Create symbolic functor(AtomicSymbol) by given node attributes. More...
 
static Symbol CreateVariable (const std::string &name)
 Create symbol node representing variable. More...
 
static Symbol CreateGroup (const std::vector< Symbol > &symbols)
 Create equivalence of symbol by grouping the symbols together. More...
 

Public Attributes

std::vector< NodeEntryoutputs
 output entries contained in the symbol More...
 

Detailed Description

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, symbol is the final operation of a graph and thus including all the information required (the graph) to evaluate its output value.

Member Enumeration Documentation

option passed to ListAttr

Enumerator
kRecursive 

recursively list all attributes

kShallow 

only list attributes in current node

option passed to ListInputNames

Enumerator
kAll 

list all the arguments

kReadOnlyArgs 

list only read only arguments

kAuxiliaryStates 

List auxiliary states that can be mutated by the graph. This excludes the ReadOnly arguments.

Member Function Documentation

void nnvm::Symbol::AddControlDeps ( const Symbol src)

Add control flow dependencies to the operators in symbols.

For grouped symbol, an error will be raised. This mutates current symbolic Node.

Parameters
srcThe symbols to depend on.
void nnvm::Symbol::Compose ( const array_view< const Symbol * > &  args,
const std::unordered_map< std::string, const Symbol * > &  kwargs,
const std::string &  name 
)

Compose the symbol with arguments, this changes the current symbol. The kwargs passed in can be in-complete,.

The rest of the symbols will remain the same name.

Parameters
argsPositional arguments.
kwargsKeyword arguments for the symbol.
nameName of returned symbol.
Symbol nnvm::Symbol::Copy ( ) const

Copy the symbol.

Returns
A deep copy of this symbol.
static Symbol nnvm::Symbol::CreateFunctor ( const Op op,
std::unordered_map< std::string, std::string >  attrs 
)
static

Create symbolic functor(AtomicSymbol) by given operator and attributes.

Parameters
opThe operator.
attrsThe additional attributes.
Returns
Symbol that can be used to call compose further.
static Symbol nnvm::Symbol::CreateFunctor ( const NodeAttrs attrs)
static

Create symbolic functor(AtomicSymbol) by given node attributes.

Parameters
attrspre-initialized Node attributes.
Returns
Symbol that can be used to call compose further.
static Symbol nnvm::Symbol::CreateGroup ( const std::vector< Symbol > &  symbols)
static

Create equivalence of symbol by grouping the symbols together.

Parameters
symbolsA list of symbols to be grouped.
Returns
The grouped symbol.
static Symbol nnvm::Symbol::CreateVariable ( const std::string &  name)
static

Create symbol node representing variable.

Parameters
nameName of the variable.
Returns
The symbol.
bool nnvm::Symbol::GetAttr ( const std::string &  key,
std::string *  out 
) const

Get attributes from the symbol.

This only works for symbol with outputs from single operators. For grouped symbol, an error will be raised.

Parameters
keyKey of the attribute. When key == "name", it returns the name attirbute.
outThe output value of the attribute.
Returns
true If the attribute exists, false if the attribute does not exist.
Symbol nnvm::Symbol::GetChildren ( ) const
Symbol nnvm::Symbol::GetInternals ( ) const
std::unordered_map<std::string, std::string> nnvm::Symbol::ListAttrs ( ListAttrOption  option) const

Get attribute dictionary from the symbol.

For grouped symbol, an error will be raised.

Parameters
optionIf recursive flag is set, the attributes of all children are retrieved. The name of symbol will be pre-pended to each key.
Returns
The created attribute.
std::vector<std::tuple<std::string, std::string, std::string> > nnvm::Symbol::ListAttrsRecursive ( ) const

Get attribute dictionary from the symbol and all children.

For grouped symbol, an error will be raised.

Returns
The created attribute in format <operator_name, key, value>.
std::vector<std::string> nnvm::Symbol::ListInputNames ( ListInputOption  option) const

List the input names.

The order of the returned list is the same as the order of the input list to operator().

Parameters
optionThe options to list the arguments.
Returns
The arguments list of this symbol, they can be either named or unnamed (empty string).
See also
ListInputOption
std::vector<ObjectPtr> nnvm::Symbol::ListInputs ( ListInputOption  option) const

List the input variable nodes.

The order of the returned list is the same as the order of the input list to operator().

Parameters
optionThe options to list the arguments.
Returns
The arguments list of this symbol, they can be either named or unnamed (empty string).
See also
ListInputOption
std::vector<std::string> nnvm::Symbol::ListOutputNames ( ) const

List the names of outputs for this symbol.

For normal operators, it is usually symbol node name + "_output".

Returns
get the descriptions of outputs for this symbol.
Symbol nnvm::Symbol::operator() ( const array_view< const Symbol * > &  args,
const std::unordered_map< std::string, const Symbol * > &  kwargs,
const std::string &  name 
) const

Apply the symbol as a function, compose with arguments.

This is equivalent to Copy then Compose.

Parameters
argsPositional arguments for the symbol.
kwargsKeyword arguments for the symbol.
nameName of returned symbol.
Returns
A new Symbol which is the composition of current symbol with its arguments.
Symbol nnvm::Symbol::operator[] ( size_t  index) const

Get the index-th element from the returned tuple.

Parameters
indexIndex of multi output.
Returns
The symbol corresponds to the indexed element.
void nnvm::Symbol::Print ( std::ostream &  os) const

Print the symbol info to output stream.

Parameters
osThe output stream to print to.
void nnvm::Symbol::SetAttrs ( const std::vector< std::pair< std::string, std::string > > &  attrs)

Set additional attributes to current node.

This only works for symbol with outputs from single operators. For grouped symbol, an error will be raised.

This function mutates the node's symbol and is not recommended.

Parameters
attrsThe attributes to set.

Member Data Documentation

std::vector<NodeEntry> nnvm::Symbol::outputs

output entries contained in the symbol


The documentation for this class was generated from the following file: