cg_operator {cgraph}R Documentation

Add Operator

Description

Add an operation node to the active graph.

Usage

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 converted to cg_constant objects.

Author(s)

Ron Triepels

Examples

# Initialize a computational graph
x <- 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")


[Package cgraph version 4.0.3 Index]