mxnet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
mxnet::Symbol Class Reference

Symbol is used to represent dynamically generated symbolic computation graph. More...

#include <symbolic.h>

Collaboration diagram for mxnet::Symbol:
Collaboration graph

Classes

struct  DataEntry
 an entry that represents output data from a node 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...
 
std::vector< std::string > ListArguments () const
 List the arguments names. More...
 
std::vector< std::string > ListOutputs () const
 
std::vector< std::string > ListAuxiliaryStates () const
 
Symbol operator[] (size_t index) const
 get the index th element from the returned tuple. More...
 
void Compose (const std::vector< Symbol > &args, const std::string &name)
 Compose the symbol with arguments, this changes current symbol. More...
 
void Compose (const std::unordered_map< std::string, 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...
 
bool GetName (std::string *out)
 Get name from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More...
 
void SetAttr (const std::string &key, const std::string &value)
 set additional attributes of the symbol, This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More...
 
bool GetAttr (const std::string &key, std::string *out)
 Get attributes from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More...
 
std::map< std::string,
std::string > 
ListAttr ()
 Get attribute dictionary from the symbol and all children. Each attribute name is pre-pended with the symbol name. For grouped sybmbol, an error will be raised. More...
 
std::map< std::string,
std::string > 
ListAttrShallow ()
 Get attribute dictionary from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised. More...
 
Symbol operator() (const std::vector< Symbol > &args, const std::string &name) const
 Apply the symbol as a function, compose with arguments. More...
 
Symbol operator() (const std::unordered_map< std::string, Symbol > &kwargs, const std::string &name) const
 compose with named arguments More...
 
Symbol GetInternals () const
 
Symbol Grad (const std::vector< std::string > &wrt) const
 get the gradient graph More...
 
bool InferShape (std::vector< TShape > *arg_shapes, std::vector< TShape > *out_shapes, std::vector< TShape > *aux_shapes, bool partial_infer=false) const
 infer the shapes of outputs and unknown input arguments More...
 
bool InferShape (const std::unordered_map< std::string, TShape > &known_arg_shapes, std::vector< TShape > *arg_shapes, std::vector< TShape > *out_shapes, std::vector< TShape > *aux_shapes, bool partial_infer=false) const
 infer the shapes by providing shapes of known arguments. More...
 
bool InferType (std::vector< int > *arg_types, std::vector< int > *out_types, std::vector< int > *aux_types) const
 infer the types of outputs and unknown input arguments More...
 
bool InferType (const std::unordered_map< std::string, int > &known_arg_types, std::vector< int > *arg_types, std::vector< int > *out_types, std::vector< int > *aux_types) const
 infer the types by providing types of known arguments. More...
 
void Save (dmlc::JSONWriter *writer) const
 interface for json serialization. More...
 
void Load (dmlc::JSONReader *reader)
 interface for json serialization. More...
 
size_t NumOutputs () const
 get number of outputs of this symbol More...
 

Static Public Member Functions

static Symbol Create (OperatorProperty *op)
 create Symbol by wrapping OperatorProperty This function takes the ownership of op More...
 
static Symbol CreateGroup (const std::vector< Symbol > &symbols)
 create equivalence of symbol by grouping the symbols together More...
 
static Symbol CreateVariable (const std::string &name)
 create variable symbol node More...
 

Protected Attributes

std::vector< DataEntryheads_
 the head nodes of Symbols This head is only effective when More...
 

Friends

class StaticGraph
 let static graph know the contents More...
 

Detailed Description

Symbol is used to represent dynamically generated symbolic computation graph.

This class is used as a tool to generate computation graphs(aka. configuration) of the network. Symbol is always composite, the head Node is the output node of the symbol. An atomic symbol can be seen as a special case of the composite symbol with only the head node.

Member Function Documentation

void mxnet::Symbol::Compose ( const std::vector< Symbol > &  args,
const std::string &  name 
)

Compose the symbol with arguments, this changes current symbol.

The positional arguments passed in must be complete(contain all arguments).

Parameters
argspositional arguments for the symbol
namename of returned symbol.
void mxnet::Symbol::Compose ( const std::unordered_map< std::string, 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
kwargskeyword arguments for the symbol
namename of returned symbol.
Symbol mxnet::Symbol::Copy ( ) const

copy the symbol

Returns
a deep copy of the graph
static Symbol mxnet::Symbol::Create ( OperatorProperty op)
static

create Symbol by wrapping OperatorProperty This function takes the ownership of op

Parameters
opthe OperatorProperty of the Operator
Returns
Symbol
See Also
OperatorProperty::Create
static Symbol mxnet::Symbol::CreateGroup ( const std::vector< Symbol > &  symbols)
static

create equivalence of symbol by grouping the symbols together

Parameters
symbolslist of symbols
Returns
the grouped symbol
static Symbol mxnet::Symbol::CreateVariable ( const std::string &  name)
static

create variable symbol node

Parameters
namename of the variable
Returns
the new variable
bool mxnet::Symbol::GetAttr ( const std::string &  key,
std::string *  out 
)

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

Parameters
keyKey of the attribute.
outthe output value of the attribute.
Returns
true if the attribute exists, false if the attribute do not exist.
Symbol mxnet::Symbol::GetInternals ( ) const
bool mxnet::Symbol::GetName ( std::string *  out)

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

Parameters
outthe output value of the name.
Symbol mxnet::Symbol::Grad ( const std::vector< std::string > &  wrt) const

get the gradient graph

Parameters
wrtwith respect to the input
Returns
the new symbol with gradient graph
bool mxnet::Symbol::InferShape ( std::vector< TShape > *  arg_shapes,
std::vector< TShape > *  out_shapes,
std::vector< TShape > *  aux_shapes,
bool  partial_infer = false 
) const

infer the shapes of outputs and unknown input arguments

Parameters
arg_shapesthe shape of input arguments of the operator this should be of same length as the vector returned by ListArguments in_shape allows unknown elements, which are checked by shape.ndim() == 0. For unknown shapes, InferShape will try to fill in the correct Shape in in_shape For known shapes, InferShape will check shape consistency

common practice: set the shape of data input, and usually weight's shape can be inferred

Parameters
out_shapesUse to store the inferred shapes of outputs.
aux_shapesUse to store the inferred shapes of auxiliary states
partial_inferReturn partially inferred results if true.
Returns
true if the shape inference is successful, false if there is not enough information.
Exceptions
dmlc::Errorif the known arg_shapes are inconsistent.
bool mxnet::Symbol::InferShape ( const std::unordered_map< std::string, TShape > &  known_arg_shapes,
std::vector< TShape > *  arg_shapes,
std::vector< TShape > *  out_shapes,
std::vector< TShape > *  aux_shapes,
bool  partial_infer = false 
) const

infer the shapes by providing shapes of known arguments.

Parameters
known_arg_shapesmap of argument name to shape of arguments with known shapes.
arg_shapesused to store inferred shapes of arguments.
out_shapesused to store inferred shapes of outputs.
aux_shapesUse to store the inferred shapes of auxiliary states
partial_inferReturn partially inferred results if true.
Returns
true if the shape inference is successful, false if there is not enough information.
Exceptions
dmlc::Errorif the known arg_shapes are inconsistent.
bool mxnet::Symbol::InferType ( std::vector< int > *  arg_types,
std::vector< int > *  out_types,
std::vector< int > *  aux_types 
) const

infer the types of outputs and unknown input arguments

Parameters
arg_typesthe type of input arguments of the operator this should be of same length as the vector returned by ListArguments in_type allows unknown elements, which are checked by type.ndim() == 0. For unknown types, Infertype will try to fill in the correct type in in_type For known types, Infertype will check type consistency

common practice: set the type of data input, and usually weight's type can be inferred

Parameters
out_typesUse to store the inferred types of outputs.
aux_typesUse to store the inferred types of auxiliary states
Returns
true if the type inference is successful, false if there is not enough information.
Exceptions
dmlc::Errorif the known arg_types are inconsistent.
bool mxnet::Symbol::InferType ( const std::unordered_map< std::string, int > &  known_arg_types,
std::vector< int > *  arg_types,
std::vector< int > *  out_types,
std::vector< int > *  aux_types 
) const

infer the types by providing types of known arguments.

Parameters
known_arg_typesmap of argument name to type of arguments with known types.
arg_typesused to store inferred types of arguments.
out_typesused to store inferred types of outputs.
aux_typesUse to store the inferred types of auxiliary states
Returns
true if the type inference is successful, false if there is not enough information.
Exceptions
dmlc::Errorif the known arg_types are inconsistent.
std::vector<std::string> mxnet::Symbol::ListArguments ( ) const

List the arguments names.

The position of the returned list also corresponds to calling position in operator()

Returns
the arguments list of this symbol, they can be either named or unnamed (empty string).
std::map<std::string, std::string> mxnet::Symbol::ListAttr ( )

Get attribute dictionary from the symbol and all children. Each attribute name is pre-pended with the symbol name. For grouped sybmbol, an error will be raised.

Returns
a dictionary.
std::map<std::string, std::string> mxnet::Symbol::ListAttrShallow ( )

Get attribute dictionary from the symbol. This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.

Returns
a dictionary.
std::vector<std::string> mxnet::Symbol::ListAuxiliaryStates ( ) const
Returns
get the descriptions of auxiliary data for this symbol
std::vector<std::string> mxnet::Symbol::ListOutputs ( ) const
Returns
get the descriptions of outputs for this symbol
void mxnet::Symbol::Load ( dmlc::JSONReader *  reader)

interface for json serialization.

Parameters
readerthe JSON read to read json.
size_t mxnet::Symbol::NumOutputs ( ) const
inline

get number of outputs of this symbol

Returns
number of outputs
Symbol mxnet::Symbol::operator() ( const std::vector< Symbol > &  args,
const std::string &  name 
) const

Apply the symbol as a function, compose with arguments.

Parameters
argspositional arguments for the symbol
namename of returned symbol.
Returns
a new Symbol which is the composition of current symbol with its arguments
Symbol mxnet::Symbol::operator() ( const std::unordered_map< std::string, Symbol > &  kwargs,
const std::string &  name 
) const

compose with named arguments

Parameters
kwargskeyword arguments for the symbol
namename of returned symbol.
Returns
a new symbol which is the composition of current symbol with its arguments
Symbol mxnet::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 mxnet::Symbol::Print ( std::ostream &  os) const

print the symbol info to output stream.

Parameters
osthe output stream we like to print to
void mxnet::Symbol::Save ( dmlc::JSONWriter *  writer) const

interface for json serialization.

Parameters
writerthe JSON writer write json.
void mxnet::Symbol::SetAttr ( const std::string &  key,
const std::string &  value 
)

set additional attributes of the symbol, This only works for symbol with outputs from single operators. For grouped sybmbol, an error will be raised.

Parameters
keythe key of the attribute
valuethe value of the attribute.

Friends And Related Function Documentation

friend class StaticGraph
friend

let static graph know the contents

Member Data Documentation

std::vector<DataEntry> mxnet::Symbol::heads_
protected

the head nodes of Symbols This head is only effective when


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