Public Types | Public Member Functions | Static Public Attributes | Friends
ngraph::Function Class Reference

A user-defined function. More...

#include <function.hpp>

Collaboration diagram for ngraph::Function:
Collaboration graph
[legend]

Public Types

using topological_sort_t = std::function< std::vector< std::shared_ptr< Node > >(const std::vector< std::shared_ptr< Node > > &root_nodes)>
 

Public Member Functions

const DiscreteTypeInfoget_type_info () const
 
 Function (const NodeVector &results, const ParameterVector &parameters, const std::string &name="")
 
 Function (const OutputVector &results, const ParameterVector &parameters, const std::string &name="")
 
 Function (const std::shared_ptr< Node > &result, const ParameterVector &parameters, const std::string &name="")
 
 Function (const ResultVector &results, const ParameterVector &parameters, const std::string &name="")
 
 Function (const ResultVector &results, const SinkVector &sinks, const ParameterVector &parameters, const std::string &name="")
 
 Function (const OutputVector &results, const SinkVector &sinks, const ParameterVector &parameters, const std::string &name="")
 
 Function (const ResultVector &results, const SinkVector &sinks, const ParameterVector &parameters, const VariableVector &variables, const std::string &name="")
 
 Function (const OutputVector &results, const SinkVector &sinks, const ParameterVector &parameters, const VariableVector &variables, const std::string &name="")
 
 Function (const ResultVector &results, const ParameterVector &parameters, const VariableVector &variables, const std::string &name="")
 
 Function (const OutputVector &results, const ParameterVector &parameters, const VariableVector &variables, const std::string &name="")
 
 Function (const OutputVector &results, const std::string &name="")
 
 Function (const OutputVector &results, const SinkVector &sinks, const std::string &name="")
 
size_t get_output_size () const
 Return the number of outputs for this function.
 
std::shared_ptr< Nodeget_output_op (size_t i) const
 Return the op that generates output i.
 
Output< Nodeoutput (size_t i) const
 
const element::Typeget_output_element_type (size_t i) const
 Return the element type of output i.
 
const Shapeget_output_shape (size_t i) const
 Return the shape of element i.
 
const PartialShapeget_output_partial_shape (size_t i) const
 Return the partial shape of element i.
 
std::shared_ptr< Nodeget_result () const
 Check that there is a single result and return it.
 
const std::string & get_name () const
 Get the unique name of the function. More...
 
void set_friendly_name (const std::string &name)
 Sets a friendly name for a function. This does not overwrite the unique name of the function and is retrieved via get_friendly_name(). Used mainly for debugging. More...
 
const std::string & get_friendly_name () const
 Gets the friendly name for a function. If no friendly name has been set via set_friendly_name then the function's unique name is returned. More...
 
std::vector< std::shared_ptr< Node > > get_ops () const
 
std::vector< std::shared_ptr< Node > > get_ordered_ops () const
 
void map_unordered_ops (std::function< void(Node *)> f) const
 
void replace_node (std::shared_ptr< Node > old, std::shared_ptr< Node > repl)
 
void validate_nodes_and_infer_types () const
 
size_t get_graph_size () const
 Returns the sum of the size of all nodes in the graph plus the size of all constant data. This has little value beyond comparing the relative size of graphs and should not be considered the actual memory consumption of a graph.
 
bool is_dynamic () const
 Returns true if any of the op's defined in the function contains partial shape.
 
void replace_parameter (size_t parameter_index, const std::shared_ptr< op::Parameter > &parameter)
 Replace the parameter_indexth parameter of the function with parameter. More...
 
void set_topological_sort (topological_sort_t)
 
virtual bool visit_attributes (AttributeVisitor &visitor)
 
const ParameterVector & get_parameters () const
 Return the function parameters.
 
const ResultVector & get_results () const
 Return a list of function's outputs.
 
int64_t get_parameter_index (const std::shared_ptr< op::Parameter > &parameter) const
 Index for parameter, or -1.
 
int64_t get_result_index (const Output< Node > &value) const
 Index for value or result referencing it, or -1.
 
bool evaluate (const HostTensorVector &output_tensors, const HostTensorVector &input_tensors, EvaluationContext evaluation_context=EvaluationContext()) const
 Evaluate the function on inputs, putting results in outputs. More...
 
const SinkVector & get_sinks () const
 Return a list of function's sinks.
 
void add_sinks (const SinkVector &sinks)
 Add new sink nodes to the list. Method doesn't validate graph, it should be done manually after all changes. More...
 
void remove_sink (const std::shared_ptr< op::Sink > &sink)
 Delete sink node from the list of sinks. Method doesn't delete node from graph. More...
 
void add_results (const ResultVector &results)
 Add new Result nodes to the list. Method doesn't validate graph, it should be done manually after all changes. More...
 
void remove_result (const std::shared_ptr< op::Result > &result)
 Delete Result node from the list of results. Method will not delete node from graph. More...
 
void add_parameters (const ParameterVector &params)
 Add new Parameter nodes to the list. More...
 
void remove_parameter (const std::shared_ptr< op::Parameter > &param)
 Delete Parameter node from the list of parameters. Method will not delete node from graph. You need to replace Parameter with other operation manually. Attention: Indexing of parameters can be changed. More...
 
void add_variables (const VariableVector &variables)
 Add new variables to the list. Method doesn't validate graph, it should be done manually after all changes. More...
 
void remove_variable (const VariablePtr &variable)
 Delete variable from the list of variables. Method doesn't delete nodes that used this variable from the graph. More...
 
const VariableVector & get_variables () const
 Return a list of function's variables.
 
VariablePtr get_variable_by_id (const std::string &variable_id) const
 Return a variable by specified variable_id.
 

Static Public Attributes

static constexpr DiscreteTypeInfo type_info {"Function", 0}
 

Friends

std::ostream & operator<< (std::ostream &, const Function &)
 

Detailed Description

A user-defined function.

Constructor & Destructor Documentation

◆ Function() [1/2]

ngraph::Function::Function ( const OutputVector &  results,
const std::string &  name = "" 
)
explicit

Constructs a Function. Lists of parameters and variables will be generated automatically based on traversing the graph from the results.

◆ Function() [2/2]

ngraph::Function::Function ( const OutputVector &  results,
const SinkVector &  sinks,
const std::string &  name = "" 
)

Constructs a Function. Lists of parameters and variables will be generated automatically based on traversing the graph from the results and the sinks.

Member Function Documentation

◆ add_parameters()

void ngraph::Function::add_parameters ( const ParameterVector &  params)

Add new Parameter nodes to the list.

Method doesn't change or validate graph, it should be done manually. For example, if you want to replace ReadValue node by Parameter, you should do the following steps:

  • replace node ReadValue by Parameter in graph
  • call add_parameter() to add new input to the list
  • call graph validation to check correctness of changes
Parameters
paramsnew Parameter nodes

◆ add_results()

void ngraph::Function::add_results ( const ResultVector &  results)

Add new Result nodes to the list. Method doesn't validate graph, it should be done manually after all changes.

Parameters
resultsnew Result nodes

◆ add_sinks()

void ngraph::Function::add_sinks ( const SinkVector &  sinks)

Add new sink nodes to the list. Method doesn't validate graph, it should be done manually after all changes.

Parameters
sinksnew sink nodes

◆ add_variables()

void ngraph::Function::add_variables ( const VariableVector &  variables)

Add new variables to the list. Method doesn't validate graph, it should be done manually after all changes.

Parameters
variablesnew variables to add

◆ evaluate()

bool ngraph::Function::evaluate ( const HostTensorVector &  output_tensors,
const HostTensorVector &  input_tensors,
EvaluationContext  evaluation_context = EvaluationContext() 
) const

Evaluate the function on inputs, putting results in outputs.

Parameters
output_tensorsTensors for the outputs to compute. One for each result
input_tensorsTensors for the inputs. One for each inputs.
evaluation_contextStorage of additional settings and attributes that can be used when evaluating the function. This additional information can be shared across nodes.

◆ get_friendly_name()

const std::string& ngraph::Function::get_friendly_name ( ) const

Gets the friendly name for a function. If no friendly name has been set via set_friendly_name then the function's unique name is returned.

Returns
A const reference to the function's friendly name.

◆ get_name()

const std::string& ngraph::Function::get_name ( ) const

Get the unique name of the function.

Returns
A const reference to the function's unique name.

◆ remove_parameter()

void ngraph::Function::remove_parameter ( const std::shared_ptr< op::Parameter > &  param)

Delete Parameter node from the list of parameters. Method will not delete node from graph. You need to replace Parameter with other operation manually. Attention: Indexing of parameters can be changed.

Possible use of method is to replace input by variable. For it the following steps should be done:

  • Parameter node should be replaced by ReadValue
  • call remove_parameter(param) to remove input from the list
  • check if any parameter indexes are saved/used somewhere, update it for all inputs because indexes can be changed
  • call graph validation to check all changes
Parameters
paramParameter node to delete

◆ remove_result()

void ngraph::Function::remove_result ( const std::shared_ptr< op::Result > &  result)

Delete Result node from the list of results. Method will not delete node from graph.

Parameters
resultResult node to delete

◆ remove_sink()

void ngraph::Function::remove_sink ( const std::shared_ptr< op::Sink > &  sink)

Delete sink node from the list of sinks. Method doesn't delete node from graph.

Parameters
sinkSink to delete

◆ remove_variable()

void ngraph::Function::remove_variable ( const VariablePtr &  variable)

Delete variable from the list of variables. Method doesn't delete nodes that used this variable from the graph.

Parameters
variableVariable to delete

◆ replace_parameter()

void ngraph::Function::replace_parameter ( size_t  parameter_index,
const std::shared_ptr< op::Parameter > &  parameter 
)

Replace the parameter_indexth parameter of the function with parameter.

All users of the parameter_indexth parameter are redirected to parameter, and the parameter_indexth entry in the function parameter list is replaced with parameter.

Parameters
parameter_indexThe index of the parameter to replace.
parameterThe parameter to substitute for the parameter_indexth parameter.

◆ set_friendly_name()

void ngraph::Function::set_friendly_name ( const std::string &  name)

Sets a friendly name for a function. This does not overwrite the unique name of the function and is retrieved via get_friendly_name(). Used mainly for debugging.

Parameters
nameis the friendly name to set

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