Skip to content

expressiongraph_node

eaertbel edited this page Nov 25, 2014 · 3 revisions

An expression graph node

An expression graph follows the composite pattern. The root node owns its arguments, and each of the arguments behave as if they were a root themself. The difference between individual nodes and composites is ignored. An expression graph node is also a stateful object, with the states as explained in figure 1.

The following diagram defines the allowable calls to an expression graph node. Input variables are introduced into expression graphs in the following way. Input variables are specified by a series of setInputVar methods. Calls to these methods are passed on to the arguments of each operation, until it reaches an InputType node. InputType are parameterized with a variable number and return a variable value if the call to setInputVar matches its parameter.

state diagram

Fig. 1: The states of an expression graph.

In this figure:

  • setInputVar corresponds to a series of methods that specify the input variables in different ways, such as for each variable separately, for an array of variables, etc.
  • value returns the current value of the expression graph represented by the graph node. If it needs to know the value of the arguments it owns, it first calls value() on its arguments. First all input variables should have been set using one of the setInputVar!
  • derivative(i) computes the value of the i-th (geometric) derivative of the node. value() should always be called before!

A node also has a series of auxiliary methods:

  • cached nodes can have a name.
  • subExpression_... extract a named subexpression of the current node.
  • write_dotfile(ostream& of) write a graphviz .dot file representing the current expression.
  • print(ostream& of) prints the current expression to the output stream.