mxnet
Public Member Functions | Static Public Member Functions | List of all members
mxnet::cpp::Symbol Class Reference

Symbol interface. More...

#include <symbol.h>

Collaboration diagram for mxnet::cpp::Symbol:
Collaboration graph

Public Member Functions

 Symbol ()
 
 Symbol (SymbolHandle handle)
 construct a Symbol with SymbolHandle More...
 
 Symbol (const char *name)
 construct a variable Symbol More...
 
 Symbol (const std::string &name)
 construct a variable Symbol More...
 
Symbol operator+ (const Symbol &rhs) const
 
Symbol operator- (const Symbol &rhs) const
 
Symbol operator* (const Symbol &rhs) const
 
Symbol operator/ (const Symbol &rhs) const
 
Symbol operator% (const Symbol &rhs) const
 
Symbol operator+ (mx_float scalar) const
 
Symbol operator- (mx_float scalar) const
 
Symbol operator* (mx_float scalar) const
 
Symbol operator/ (mx_float scalar) const
 
Symbol operator% (mx_float scalar) const
 
Symbol Copy () const
 
Symbol operator[] (int index)
 
Symbol operator[] (const std::string &index)
 
void Save (const std::string &file_name) const
 save Symbol to a file More...
 
std::string ToJSON () const
 save Symbol into a JSON string More...
 
Symbol GetInternals () const
 save Symbol into a JSON string the symbol whose outputs are all the internals. More...
 
SymbolHandle GetHandle () const
 
 Symbol (const std::string &operator_name, const std::string &name, std::vector< const char *> input_keys, std::vector< SymbolHandle > input_values, std::vector< const char *> config_keys, std::vector< const char *> config_values)
 construct an operator Symbol, with given input Symbol and config More...
 
void InferShape (const std::map< std::string, std::vector< mx_uint > > &arg_shapes, std::vector< std::vector< mx_uint > > *in_shape, std::vector< std::vector< mx_uint > > *aux_shape, std::vector< std::vector< mx_uint > > *out_shape) const
 infer the shapes by providing shapes of known argument shapes. More...
 
std::vector< std::string > ListArguments () const
 List the arguments names. More...
 
std::vector< std::string > ListInputs () const
 
std::vector< std::string > ListOutputs () const
 
std::vector< std::string > ListAuxiliaryStates () const
 
std::map< std::string, std::string > ListAttributes () const
 
void SetAttribute (const std::string &key, const std::string &value)
 set key-value attribute to the symbol More...
 
void SetAttributes (const std::map< std::string, std::string > &attrs)
 set a series of key-value attribute to the symbol More...
 
mx_uint GetNumOutputs () const
 
mxnet::cpp::Symbol GetBackendSymbol (const std::string &backendName) const
 
std::string GetName () const
 
void InferExecutorArrays (const Context &context, std::vector< NDArray > *arg_arrays, std::vector< NDArray > *grad_arrays, std::vector< OpReqType > *grad_reqs, std::vector< NDArray > *aux_arrays, const std::map< std::string, NDArray > &args_map, const std::map< std::string, NDArray > &arg_grad_store=std::map< std::string, NDArray >(), const std::map< std::string, OpReqType > &grad_req_type=std::map< std::string, OpReqType >(), const std::map< std::string, NDArray > &aux_map=std::map< std::string, NDArray >()) const
 infer and construct all the arrays to bind to executor by providing some known arrays. More...
 
void InferArgsMap (const Context &context, std::map< std::string, NDArray > *args_map, const std::map< std::string, NDArray > &known_args) const
 infer and construct all the input arguments arrays to bind to executor by providing some known arguments arrays. More...
 
ExecutorSimpleBind (const Context &context, const std::map< std::string, NDArray > &args_map, const std::map< std::string, NDArray > &arg_grad_store=std::map< std::string, NDArray >(), const std::map< std::string, OpReqType > &grad_req_type=std::map< std::string, OpReqType >(), const std::map< std::string, NDArray > &aux_map=std::map< std::string, NDArray >())
 Create an executor by bind symbol with context and arguments. If user do not want to compute the gradients of i-th argument, grad_req_type[i] can be kNullOp. The input arrays in the given maps should have the same name with the input symbol. Only need some of the necessary arrays, and the other arrays can be infered automatically. More...
 
ExecutorBind (const Context &context, const std::vector< NDArray > &arg_arrays, const std::vector< NDArray > &grad_arrays, const std::vector< OpReqType > &grad_reqs, const std::vector< NDArray > &aux_arrays, const std::map< std::string, Context > &group_to_ctx=std::map< std::string, Context >(), Executor *shared_exec=nullptr)
 Create an executor by bind symbol with context and arguments. If user do not want to compute the gradients of i-th argument, grad_req_type[i] can be kNullOp. More...
 

Static Public Member Functions

static Symbol Variable (const std::string &name="")
 construct a variable Symbol More...
 
static Symbol Group (const std::vector< Symbol > &symbols)
 Create a symbol that groups symbols together. More...
 
static Symbol Load (const std::string &file_name)
 load Symbol from a JSON file More...
 
static Symbol LoadJSON (const std::string &json_str)
 load Symbol from a JSON string More...
 

Detailed Description

Symbol interface.

Constructor & Destructor Documentation

◆ Symbol() [1/5]

mxnet::cpp::Symbol::Symbol ( )
inline

◆ Symbol() [2/5]

mxnet::cpp::Symbol::Symbol ( SymbolHandle  handle)
explicit

construct a Symbol with SymbolHandle

Parameters
handlethe given SymbolHandle

◆ Symbol() [3/5]

mxnet::cpp::Symbol::Symbol ( const char *  name)
explicit

construct a variable Symbol

Parameters
namethe name of the variable

◆ Symbol() [4/5]

mxnet::cpp::Symbol::Symbol ( const std::string &  name)
explicit

construct a variable Symbol

Parameters
namethe name of the variable

◆ Symbol() [5/5]

mxnet::cpp::Symbol::Symbol ( const std::string &  operator_name,
const std::string &  name,
std::vector< const char *>  input_keys,
std::vector< SymbolHandle input_values,
std::vector< const char *>  config_keys,
std::vector< const char *>  config_values 
)

construct an operator Symbol, with given input Symbol and config

Parameters
namethe name of the Symbol
input_keysthe vector of keys of the input
input_valuesthe vector of the intput Symbols
config_keysthe vector of keys of the config
config_valuesthe vecotr of values of the config

Member Function Documentation

◆ Bind()

Executor* mxnet::cpp::Symbol::Bind ( const Context context,
const std::vector< NDArray > &  arg_arrays,
const std::vector< NDArray > &  grad_arrays,
const std::vector< OpReqType > &  grad_reqs,
const std::vector< NDArray > &  aux_arrays,
const std::map< std::string, Context > &  group_to_ctx = std::map< std::string, Context >(),
Executor shared_exec = nullptr 
)

Create an executor by bind symbol with context and arguments. If user do not want to compute the gradients of i-th argument, grad_req_type[i] can be kNullOp.

Parameters
contextthe context of binding.
arg_arraysthe NDArray that stores the input arguments to the symbol.
grad_arraysNDArray that is used to store the gradient output of the input arguments.
grad_reqsrequirment type of gradient saving. Can only be in {kNullOp, kAddTo, kWriteTo}.
aux_arraysNDArray that is used as internal state in op
group_to_ctxdict of string to mx.Context
shared_execExecutor to share memory with. This is intended for runtime reshaping, variable length sequencesn etc. The returned executor shares state with shared_exec, and should not be used in parallel with it.
Returns
a new executor, which need to be free manually.

◆ Copy()

Symbol mxnet::cpp::Symbol::Copy ( ) const

◆ GetBackendSymbol()

mxnet::cpp::Symbol mxnet::cpp::Symbol::GetBackendSymbol ( const std::string &  backendName) const
Returns
get the new symbol through subgraph API for this symbol

◆ GetHandle()

SymbolHandle mxnet::cpp::Symbol::GetHandle ( ) const
inline
Returns
the SymbolHandle

◆ GetInternals()

Symbol mxnet::cpp::Symbol::GetInternals ( ) const

save Symbol into a JSON string the symbol whose outputs are all the internals.

◆ GetName()

std::string mxnet::cpp::Symbol::GetName ( ) const
Returns
get the name of the symbol

◆ GetNumOutputs()

mx_uint mxnet::cpp::Symbol::GetNumOutputs ( ) const
Returns
get number of outputs for this symbol

◆ Group()

static Symbol mxnet::cpp::Symbol::Group ( const std::vector< Symbol > &  symbols)
static

Create a symbol that groups symbols together.

Parameters
symbolsList of symbols to be groupe

◆ InferArgsMap()

void mxnet::cpp::Symbol::InferArgsMap ( const Context context,
std::map< std::string, NDArray > *  args_map,
const std::map< std::string, NDArray > &  known_args 
) const

infer and construct all the input arguments arrays to bind to executor by providing some known arguments arrays.

Parameters
contextthe context of all the infered arrays.
args_mapmap of all the infered input arguments arrays.
known_argsmap of some given arguments arrays.

◆ InferExecutorArrays()

void mxnet::cpp::Symbol::InferExecutorArrays ( const Context context,
std::vector< NDArray > *  arg_arrays,
std::vector< NDArray > *  grad_arrays,
std::vector< OpReqType > *  grad_reqs,
std::vector< NDArray > *  aux_arrays,
const std::map< std::string, NDArray > &  args_map,
const std::map< std::string, NDArray > &  arg_grad_store = std::map< std::string, NDArray >(),
const std::map< std::string, OpReqType > &  grad_req_type = std::map< std::string, OpReqType >(),
const std::map< std::string, NDArray > &  aux_map = std::map< std::string, NDArray >() 
) const

infer and construct all the arrays to bind to executor by providing some known arrays.

Parameters
contextthe context of all the infered arrays
arg_arraysinfered input arguments arrays.
arad_arraysinfered arrays to store the gradient output of the input arguments.
aux_arraysinfered arrays that is used as internal state in op.
args_mapmap of some given arguments arrays.
args_grad_storemap of some gradient given store arrays.
args_req_typemap of some given type of gradient saving. Can only be in {kNullOp, kAddTo, kWriteTo}.
aux_mapNDArray that stores the internal state in op

◆ InferShape()

void mxnet::cpp::Symbol::InferShape ( const std::map< std::string, std::vector< mx_uint > > &  arg_shapes,
std::vector< std::vector< mx_uint > > *  in_shape,
std::vector< std::vector< mx_uint > > *  aux_shape,
std::vector< std::vector< mx_uint > > *  out_shape 
) const

infer the shapes by providing shapes of known argument shapes.

Parameters
arg_shapesmap of argument name to shape of arguments with known shapes.
in_shapesused to store infered shapes of input arguments.
out_shapesused to store infered shapes of outputs.
aux_shapesuse to store the infered shapes of auxiliary states

◆ ListArguments()

std::vector<std::string> mxnet::cpp::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).

◆ ListAttributes()

std::map<std::string, std::string> mxnet::cpp::Symbol::ListAttributes ( ) const
Returns
get all attributes for this symbol

◆ ListAuxiliaryStates()

std::vector<std::string> mxnet::cpp::Symbol::ListAuxiliaryStates ( ) const
Returns
get the descriptions of auxiliary data for this symbol

◆ ListInputs()

std::vector<std::string> mxnet::cpp::Symbol::ListInputs ( ) const
Returns
lists all argument names and aux states of the symbol

◆ ListOutputs()

std::vector<std::string> mxnet::cpp::Symbol::ListOutputs ( ) const
Returns
get the descriptions of outputs for this symbol

◆ Load()

static Symbol mxnet::cpp::Symbol::Load ( const std::string &  file_name)
static

load Symbol from a JSON file

Parameters
file_namethe name of the file

◆ LoadJSON()

static Symbol mxnet::cpp::Symbol::LoadJSON ( const std::string &  json_str)
static

load Symbol from a JSON string

Parameters
json_strthe JSON string

◆ operator%() [1/2]

Symbol mxnet::cpp::Symbol::operator% ( const Symbol rhs) const

◆ operator%() [2/2]

Symbol mxnet::cpp::Symbol::operator% ( mx_float  scalar) const

◆ operator*() [1/2]

Symbol mxnet::cpp::Symbol::operator* ( const Symbol rhs) const

◆ operator*() [2/2]

Symbol mxnet::cpp::Symbol::operator* ( mx_float  scalar) const

◆ operator+() [1/2]

Symbol mxnet::cpp::Symbol::operator+ ( const Symbol rhs) const

◆ operator+() [2/2]

Symbol mxnet::cpp::Symbol::operator+ ( mx_float  scalar) const

◆ operator-() [1/2]

Symbol mxnet::cpp::Symbol::operator- ( const Symbol rhs) const

◆ operator-() [2/2]

Symbol mxnet::cpp::Symbol::operator- ( mx_float  scalar) const

◆ operator/() [1/2]

Symbol mxnet::cpp::Symbol::operator/ ( const Symbol rhs) const

◆ operator/() [2/2]

Symbol mxnet::cpp::Symbol::operator/ ( mx_float  scalar) const

◆ operator[]() [1/2]

Symbol mxnet::cpp::Symbol::operator[] ( int  index)

◆ operator[]() [2/2]

Symbol mxnet::cpp::Symbol::operator[] ( const std::string &  index)

◆ Save()

void mxnet::cpp::Symbol::Save ( const std::string &  file_name) const

save Symbol to a file

Parameters
file_namethe name of the file

◆ SetAttribute()

void mxnet::cpp::Symbol::SetAttribute ( const std::string &  key,
const std::string &  value 
)

set key-value attribute to the symbol

Parameters
keystring represent the key for the attribute
valuestring represent the value for the attribute

◆ SetAttributes()

void mxnet::cpp::Symbol::SetAttributes ( const std::map< std::string, std::string > &  attrs)

set a series of key-value attribute to the symbol

Parameters
attrsstring:string map represent the key value attributes

◆ SimpleBind()

Executor* mxnet::cpp::Symbol::SimpleBind ( const Context context,
const std::map< std::string, NDArray > &  args_map,
const std::map< std::string, NDArray > &  arg_grad_store = std::map< std::string, NDArray >(),
const std::map< std::string, OpReqType > &  grad_req_type = std::map< std::string, OpReqType >(),
const std::map< std::string, NDArray > &  aux_map = std::map< std::string, NDArray >() 
)

Create an executor by bind symbol with context and arguments. If user do not want to compute the gradients of i-th argument, grad_req_type[i] can be kNullOp. The input arrays in the given maps should have the same name with the input symbol. Only need some of the necessary arrays, and the other arrays can be infered automatically.

Parameters
contextthe context of binding.
args_mapthe NDArray that stores the input arguments to the symbol.
arg_grad_storeNDArray that is used to store the gradient output of the input arguments.
grad_req_typerequirment type of gradient saving. Can only be in {kNullOp, kAddTo, kWriteTo}.
aux_mapNDArray that stores the internal state in op
Returns
a new executor, which need to be free manually.

◆ ToJSON()

std::string mxnet::cpp::Symbol::ToJSON ( ) const

save Symbol into a JSON string

◆ Variable()

static Symbol mxnet::cpp::Symbol::Variable ( const std::string &  name = "")
static

construct a variable Symbol

Parameters
namethe name of the variable

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