Struct ciphercore_base::graphs::Node
source · [−]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
sourceimpl Node
impl Node
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_operation(&self) -> Operation
pub fn get_operation(&self) -> 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
sourceimpl Node
impl Node
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<String>
pub fn get_name(&self) -> Result<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(), "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 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 truncate(&self, scale: u64) -> Result<Node>
pub fn truncate(&self, scale: u64) -> 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 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 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 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
impl Eq for Node
Auto Trait Implementations
impl !RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl !UnwindSafe for Node
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more