Learn R Programming

cgraph (version 6.0.1)

cg_operator: 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.

Examples

Run this code
# NOT RUN {
# 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")

# }

Run the code above in your browser using DataLab