cg_operator: Add Operator

Description Usage Arguments Value Note Author(s) Examples

View source: R/node.R

Description

Add an operation node to the active graph.

Usage

1
cg_operator(fun, inputs, name = NULL)

Arguments

fun

cg_function object, function evaluated by the node.

inputs

list, the nodes that are consumed by the operation.

name

character scalar, name of the node (optional). In case argument name is missing, the node is added to the graph under an automatically generated name.

Value

cg_node object.

Note

Any objects that are supplied to argument inputs that are not cg_node objects are implicitly coerced to cg_constant objects.

The elements of argument input can be named to control how the arguments of the function provided to argument fun are machted when the function is evaluated. In case no names are provided, arguments are matched positionally.

Author(s)

Ron Triepels

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Initialize a computational graph
graph <- cg_graph()

# Create a custom negation function
f <- cg_function(
    def = function(x) -x,
    grads = list(function(x, val, grad) -grad)
)

# Add a an operator with the negation function to the graph.
a <- cg_operator(f, list(10), name = "a")

cgraph documentation built on Feb. 9, 2020, 5:07 p.m.

Related to cg_operator in cgraph...