pub struct Node { /* private fields */ }
Expand description

A structure that stores a pointer to a computation graph node that corresponds to an operation.

Clone trait duplicates the pointer, not the underlying nodes.

PartialEq trait compares pointers, not the related nodes.

Example

let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t).unwrap();
assert!(n1 != n2);
let n3 = n1.clone();
assert!(n1 == n3);

Implementations

Returns the parent graph that contains the node.

Returns

Parent graph of the node

Returns the dependency nodes that are used to compute the value in the current node.

Returns

Vector of nodes used by the node to perform its operation

Returns the dependency graphs that are used to compute the value in the current node.

These dependencies are non-empty only for Call and Iterate operations.

Returns

Vector of graphs used by the node to perform its operation

Returns the operation associated with the node.

Returns

Operation associated with the node

Returns the ID of the node.

A node ID is a serial number of a node between 0 and n-1 where n is the number of nodes in the parent graph. This number is equal to the number of nodes in the parent graph before this node was added to it.

Returns

Node ID

Returns the pair of the parent graph ID and node ID

Returns

(Graph ID, Node ID)

Returns the type of the value computed by the node.

Returns

Output type of the node operation

Applies Context::set_node_name to the parent context and this node. Returns the clone of this.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n = g.input(t).unwrap();
n.set_name("XOR").unwrap();

Applies Context::get_node_name to the parent context and this node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n = g.input(t).unwrap();
n.set_name("XOR").unwrap();
assert_eq!(n.get_name().unwrap(), "XOR".to_owned());

Adds a node to the parent graph that adds elementwise the array or scalar associated with the node to an array or scalar of the same scalar type associated with another node.

Applies Graph::add to the parent graph, this node and the b node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t).unwrap();
let n3 = n1.add(n2).unwrap();

Adds a node to the parent graph that subtracts elementwise the array or scalar of the same scalar type associated with another node from an array or scalar associated with the node.

Applies Graph::subtract to the parent graph, this node and the b node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t).unwrap();
let n3 = n1.subtract(n2).unwrap();

Adds a node to the parent graph that multiplies elementwise the array or scalar associated with the node by an array or scalar of the same scalar type associated with another node.

Applies Graph::multiply to the parent graph, this node and the b node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t).unwrap();
let n3 = n1.multiply(n2).unwrap();

Adds a node to the parent graph that computes the dot product of arrays or scalars associated with the node and another node.

Applies Graph::dot to the parent graph, this node and the b node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![10], INT32);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t).unwrap();
let n3 = n1.dot(n2).unwrap();

Adds a node to the parent graph that computes the matrix product of two arrays associated with the node and another node.

Applies Graph::matmul to the parent graph, this node and the b node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t1 = array_type(vec![2, 3], INT32);
let t2 = array_type(vec![3, 2], INT32);
let n1 = g.input(t1).unwrap();
let n2 = g.input(t2).unwrap();
let n3 = n1.matmul(n2).unwrap();

Adds a node to the parent graph that divides a scalar or each entry of the array associated with the node by a positive constant integer scale.

Applies Graph::add to the parent graph, this node and scale.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![2, 3], INT32);
let n1 = g.input(t).unwrap();
let n2 = n1.truncate(4).unwrap();

Adds a node to the parent graph that computes the sum of entries of the array associated with the node along given axes.

Applies Graph::sum to the parent graph, this node and axes.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let axes = vec![1, 0];
let n1 = g.input(t).unwrap();
let n2 = n1.sum(axes).unwrap();

Adds a node to the parent graph that permutes the array associated with the node along given axes.

Applies Graph::permute_axes to the parent graph, this node and axes.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let axes = vec![1, 0, 2];
let n1 = g.input(t).unwrap();
let n2 = n1.permute_axes(axes).unwrap();

Adds a node to the parent graph that extracts a sub-array with a given index from the array associated with the node.

Applies Graph::get to the parent graph, this node and index.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let index = vec![2];
let n1 = g.input(t).unwrap();
let n2 = n1.get(index).unwrap();

Adds a node that extracts a sub-array corresponding to a given slice from the array associated with the node.

Applies Graph::get_slice to the parent graph, this node and slice.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let slice = vec![SliceElement::Ellipsis, SliceElement::SubArray(None, None, Some(-2))];
let n1 = g.input(t).unwrap();
let n2 = n1.get_slice(slice).unwrap();

Adds a node to the parent graph that reshapes a value associated with the node to a given compatible type.

Applies Graph::reshape to the parent graph, this node and new_type.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let old_t = array_type(vec![3, 2, 3], INT32);
let new_t = array_type(vec![3,6], INT32);
let n1 = g.input(old_t).unwrap();
let n2 = n1.reshape(new_t).unwrap();

Adds a node to the parent graph converting an integer array or scalar associated with the node to the binary form.

Applies Graph::a2b to the parent graph and this node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2], INT32);
let n1 = g.input(t).unwrap();
let n2 = n1.a2b().unwrap();

Adds a node to the parent graph converting a binary array associated with the node to an array of a given scalar type.

Applies Graph::b2a to the parent graph, this node and scalar_type.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 32], BIT);
let n1 = g.input(t).unwrap();
let n2 = n1.b2a(INT32).unwrap();

Adds a node that extracts an element of a tuple associated with the node.

Applies Graph::tuple_get to the parent graph, this node and index.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t1 = array_type(vec![3, 2, 3], INT32);
let t2 = array_type(vec![2, 3], INT32);
let n1 = g.input(t1).unwrap();
let n2 = g.input(t2).unwrap();
let n3 = g.create_tuple(vec![n1, n2]).unwrap();
let n4 = n3.tuple_get(1).unwrap();

Adds a node to the parent graph that extracts an element of a named tuple associated with the node.

Applies Graph::named_tuple_get to the parent graph, this node and the key string.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t1 = array_type(vec![3, 2, 3], INT32);
let t2 = array_type(vec![2, 3], INT32);
let n1 = g.input(t1).unwrap();
let n2 = g.input(t2).unwrap();
let n3 = g.create_named_tuple(vec![("node1".to_owned(), n1), ("node2".to_owned(), n2)]).unwrap();
let n4 = n3.named_tuple_get("node2".to_owned()).unwrap();

Adds a node to the parent graph that extracts an element of a vector associated with the node.

Applies Graph::vector_get to the parent graph, this node and the index node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let n1 = g.input(t.clone()).unwrap();
let n2 = g.input(t.clone()).unwrap();
let n3 = g.create_vector(t, vec![n1,n2]).unwrap();
let index = g.constant(scalar_type(UINT32), Value::from_scalar(0, UINT32).unwrap()).unwrap();
let n4 = n3.vector_get(index).unwrap();

Adds a node to the parent graph converting an array associated with the node to a vector.

Applies Graph::array_to_vector to the parent graph and this node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![4, 3, 2], INT32);
let n1 = g.input(t).unwrap();
let n2 = g.array_to_vector(n1).unwrap();
let index = g.constant(scalar_type(UINT32), Value::from_scalar(0, UINT32).unwrap()).unwrap();
let n3 = n2.vector_get(index).unwrap();

assert!(n2.get_type().unwrap().is_vector());
assert_eq!(n3.get_type().unwrap().get_shape(), vec![3,2]);

Adds a node to the parent graph converting a vector associated with the node to an array.

Applies Graph::vector_to_array to the parent graph and this node.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2], INT32);
let vec_t = vector_type(4, t);
let n1 = g.input(vec_t).unwrap();
let n2 = n1.vector_to_array().unwrap();

assert!(n2.get_type().unwrap().is_array());
assert_eq!(n2.get_type().unwrap().get_shape(), vec![4, 3, 2]);

Adds a node that creates a vector with n copies of a value of this node.

Applies Graph::repeat to the parent graph, this node and n.

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2, 3], INT32);
let n1 = g.input(t).unwrap();
let n2 = n1.repeat(10).unwrap();

Applies Graph::set_output_node to the parent graph and this node.

Returns

This node

Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = array_type(vec![3, 2], INT32);
let vec_t = vector_type(4, t);
let n1 = g.input(vec_t).unwrap();
let n2 = g.vector_to_array(n1).unwrap();
n2.set_as_output().unwrap();
g.finalize().unwrap();

Trait Implementations

Returns a new Node value with a copy of the pointer to a node.

Performs copy-assignment from source. Read more

Hashes the node pointer.

Arguments

state - state of a hash function that is changed after hashing the node

Feeds a slice of this type into the given Hasher. Read more

Tests whether self and other nodes are equal via comparison of their respective pointers.

Arguments

other - another Node value

Returns

true if self and other are equal, false otherwise

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.