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§
Source§impl Node
Public methods which supposed to be imported in Python.
impl Node
Public methods which supposed to be imported in Python.
Sourcepub fn get_node_dependencies(&self) -> Vec<Node>
pub fn get_node_dependencies(&self) -> Vec<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
Sourcepub fn get_graph_dependencies(&self) -> Vec<Graph>
pub fn get_graph_dependencies(&self) -> Vec<Graph>
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
Sourcepub fn get_id(&self) -> u64
pub fn get_id(&self) -> u64
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
Sourcepub fn get_global_id(&self) -> (u64, u64)
pub fn get_global_id(&self) -> (u64, u64)
Sourcepub fn get_operation(&self) -> Operation
pub fn get_operation(&self) -> Operation
Sourcepub fn set_name(&self, name: &str) -> Result<Node>
pub fn set_name(&self, name: &str) -> Result<Node>
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();
Sourcepub fn get_name(&self) -> Result<Option<String>>
pub fn get_name(&self) -> Result<Option<String>>
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(), Some("XOR".to_owned()));
Sourcepub fn add(&self, b: Node) -> Result<Node>
pub fn add(&self, b: Node) -> Result<Node>
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();
Sourcepub fn subtract(&self, b: Node) -> Result<Node>
pub fn subtract(&self, b: Node) -> Result<Node>
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();
Sourcepub fn multiply(&self, b: Node) -> Result<Node>
pub fn multiply(&self, b: Node) -> Result<Node>
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();
Sourcepub fn mixed_multiply(&self, b: Node) -> Result<Node>
pub fn mixed_multiply(&self, b: Node) -> Result<Node>
Adds a node to the parent graph that multiplies elementwise the array or scalar associated with the node by a binary array or scalar associated with another node.
Applies Graph::mixed_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(INT32);
let bit_t = scalar_type(BIT);
let n1 = g.input(t).unwrap();
let n2 = g.input(bit_t).unwrap();
let n3 = n1.mixed_multiply(n2).unwrap();
Sourcepub fn dot(&self, b: Node) -> Result<Node>
pub fn dot(&self, b: Node) -> Result<Node>
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();
Sourcepub fn matmul(&self, b: Node) -> Result<Node>
pub fn matmul(&self, b: Node) -> Result<Node>
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();
Sourcepub fn join(
&self,
b: Node,
t: JoinType,
headers: HashMap<String, String>,
) -> Result<Node>
pub fn join( &self, b: Node, t: JoinType, headers: HashMap<String, String>, ) -> Result<Node>
Adds a node that computes a join of a given type on two named tuples along given key headers. More detailed documentation can be found in Graph::join.
Applies Graph::join to the parent graph, this
node and the b
node.
§Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t1n = array_type(vec![100], BIT);
let t11 = array_type(vec![100], INT32);
let t12 = array_type(vec![100, 128], BIT);
let t13 = array_type(vec![100], INT64);
let t2n = array_type(vec![50], BIT);
let t21 = array_type(vec![50], INT32);
let t22 = array_type(vec![50, 128], BIT);
let t23 = array_type(vec![50], UINT8);
let t1 = named_tuple_type(vec![
(NULL_HEADER.to_owned(), t1n),
("ID".to_owned(), t11),
("Occupation".to_owned(), t12),
("Revenue".to_owned(), t13),
]);
let t2 = named_tuple_type(vec![
(NULL_HEADER.to_owned(), t2n),
("ID".to_owned(), t21),
("Job".to_owned(), t22),
("Age".to_owned(), t23),
]);
let n1 = g.input(t1).unwrap();
let n2 = g.input(t2).unwrap();
let n3 = n1.join(n2, JoinType::Inner, HashMap::from([
("ID".to_owned(), "ID".to_owned()),
("Occupation".to_owned(), "Job".to_owned()),
])).unwrap();
Sourcepub fn join_with_column_masks(
&self,
b: Node,
t: JoinType,
headers: HashMap<String, String>,
) -> Result<Node>
pub fn join_with_column_masks( &self, b: Node, t: JoinType, headers: HashMap<String, String>, ) -> Result<Node>
Adds a node that computes a join of a given type on two named tuples along given key headers. More detailed documentation can be found in Graph::join_with_column_masks.
Applies Graph::join_with_column_masks to the parent graph, this
node and the b
node.
§Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t1n = array_type(vec![100], BIT);
let t11 = tuple_type(vec![array_type(vec![100], BIT), array_type(vec![100], INT32)]);
let t12 = tuple_type(vec![array_type(vec![100], BIT), array_type(vec![100, 128], BIT)]);
let t13 = tuple_type(vec![array_type(vec![100], BIT), array_type(vec![100], INT64)]);
let t2n = array_type(vec![50], BIT);
let t21 = tuple_type(vec![array_type(vec![50], BIT), array_type(vec![50], INT32)]);
let t22 = tuple_type(vec![array_type(vec![50], BIT), array_type(vec![50, 128], BIT)]);
let t23 = tuple_type(vec![array_type(vec![50], BIT), array_type(vec![50], UINT8)]);
let t1 = named_tuple_type(vec![
(NULL_HEADER.to_owned(), t1n),
("ID".to_owned(), t11),
("Occupation".to_owned(), t12),
("Revenue".to_owned(), t13),
]);
let t2 = named_tuple_type(vec![
(NULL_HEADER.to_owned(), t2n),
("ID".to_owned(), t21),
("Job".to_owned(), t22),
("Age".to_owned(), t23),
]);
let n1 = g.input(t1).unwrap();
let n2 = g.input(t2).unwrap();
let n3 = n1.join_with_column_masks(n2, JoinType::Inner, HashMap::from([
("ID".to_owned(), "ID".to_owned()),
("Occupation".to_owned(), "Job".to_owned()),
])).unwrap();
Sourcepub fn sort(&self, key: String) -> Result<Node>
pub fn sort(&self, key: String) -> Result<Node>
Adds a node that sorts a table given as named tuple according to the column given by the key argument. The key column must be a 2-d BIT array of shape [n, b], interpreted as bitstrings of length b. Other columns in the named tuple must be arrays of arbitrary type and shape, as long as they share the first dimension: [n, …]. Bitstrings are sorted lexicographically, and the sorting algorithm is stable: preserving relative order of entries in other arrays where the corresponding key entries match.
§Arguments
key
- name of the field to sort on it, this array must be 2-d of type BIT.
§Returns
New sorted node
§Example
let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let v1 = g.input(array_type(vec![20], INT32)).unwrap();
let v2 = g.input(array_type(vec![20, 10, 2], UINT64)).unwrap();
let k = g.input(array_type(vec![20, 32], BIT)).unwrap();
let a = g.create_named_tuple(vec![("key".to_string(), k), ("value1".to_string(), v1), ("value2".to_string(), v2)]).unwrap();
let a = a.sort("key".to_string()).unwrap();
Sourcepub fn truncate(&self, scale: u128) -> Result<Node>
pub fn truncate(&self, scale: u128) -> Result<Node>
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();
Sourcepub fn sum(&self, axes: ArrayShape) -> Result<Node>
pub fn sum(&self, axes: ArrayShape) -> Result<Node>
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();
Sourcepub fn cum_sum(&self, axis: u64) -> Result<Node>
pub fn cum_sum(&self, axis: u64) -> Result<Node>
Adds a node to the parent graph that computes the cumulative sum of elements along a given axis.
Applies Graph::cum_sum to the parent graph, this
node and axis
.
§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.cum_sum(1).unwrap();
Sourcepub fn permute_axes(&self, axes: ArrayShape) -> Result<Node>
pub fn permute_axes(&self, axes: ArrayShape) -> Result<Node>
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();
Sourcepub fn get(&self, index: ArrayShape) -> Result<Node>
pub fn get(&self, index: ArrayShape) -> Result<Node>
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();
Sourcepub fn get_slice(&self, slice: Slice) -> Result<Node>
pub fn get_slice(&self, slice: Slice) -> Result<Node>
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();
Sourcepub fn reshape(&self, new_type: Type) -> Result<Node>
pub fn reshape(&self, new_type: Type) -> Result<Node>
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();
Sourcepub fn a2b(&self) -> Result<Node>
pub fn a2b(&self) -> Result<Node>
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();
Sourcepub fn b2a(&self, scalar_type: ScalarType) -> Result<Node>
pub fn b2a(&self, scalar_type: ScalarType) -> Result<Node>
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();
Sourcepub fn tuple_get(&self, index: u64) -> Result<Node>
pub fn tuple_get(&self, index: u64) -> Result<Node>
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();
Sourcepub fn named_tuple_get(&self, key: String) -> Result<Node>
pub fn named_tuple_get(&self, key: String) -> Result<Node>
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();
Sourcepub fn vector_get(&self, index: Node) -> Result<Node>
pub fn vector_get(&self, index: Node) -> Result<Node>
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();
Sourcepub fn array_to_vector(&self) -> Result<Node>
pub fn array_to_vector(&self) -> Result<Node>
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]);
Sourcepub fn vector_to_array(&self) -> Result<Node>
pub fn vector_to_array(&self) -> Result<Node>
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]);
Sourcepub fn gather(&self, indices: Node, axis: u64) -> Result<Node>
pub fn gather(&self, indices: Node, axis: u64) -> Result<Node>
Adds a node to the parent graph converting a vector associated with the node to an array.
Applies Graph::gather to the parent graph and this
node.
Sourcepub fn repeat(&self, n: u64) -> Result<Node>
pub fn repeat(&self, n: u64) -> Result<Node>
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();
Sourcepub fn print(&self, message: String) -> Result<Node>
pub fn print(&self, message: String) -> Result<Node>
Adds an operation which logs the value of the node at runtime.
Sourcepub fn set_as_output(&self) -> Result<Node>
pub fn set_as_output(&self) -> Result<Node>
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§
Source§impl Hash for Node
impl Hash for Node
impl Eq for Node
Auto Trait Implementations§
impl Freeze for Node
impl !RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl !UnwindSafe for Node
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.