Struct Graph

Source
pub struct Graph<TData: Ord, TOp: Ord> { /* private fields */ }
Expand description

Graph

Implementations§

Source§

impl<TData: Clone + Copy + Ord, TOp: Clone + Copy + Ord> Graph<TData, TOp>

Source

pub fn new() -> Graph<TData, TOp>

Create a graph with defaults

Source

pub fn iter_data(&self) -> NodeIterator<'_, TData>

iterator over data node.

Source

pub fn iter_op(&self) -> NodeIterator<'_, TOp>

iterator over op node.

Source

pub fn iter_op_given_input( &self, var: &TData, ) -> Result<NodeIterator<'_, TOp>, &str>

Return the list of ops that the given variable is the input of the func.

Source

pub fn iter_op_given_output( &self, var: &TData, ) -> Result<NodeIterator<'_, TOp>, &str>

Return the list of ops that the given variable is the output.

Source

pub fn iter_input_given_op( &self, func: &TOp, ) -> Result<NodeIterator<'_, TData>, &str>

Return the list of input given the func.

Source

pub fn iter_output_given_op( &self, func: &TOp, ) -> Result<NodeIterator<'_, TData>, &str>

Return a list of data as the output of the op.

Source

pub fn add_data(&mut self, id: &TData) -> Result<TData, &str>

Add a data node.

Source

pub fn drop_data(&mut self, id: &TData) -> Result<TData, &str>

Remove a data node, op node and downstream data/op node are removed.

Source

pub fn add_op(&mut self, id: &TOp) -> Result<TOp, &str>

Add a danglging op node.

Source

pub fn drop_op(&mut self, id: &TOp) -> Result<TOp, &str>

Remvoe an op node, input data node and downstream data/op node are removed.

Source

pub fn decouple_data_func( &mut self, var: &TData, func: &TOp, ) -> Result<(), AutoDiffError>

Decouple input variable and op

Source

pub fn decouple_func_data( &mut self, func: &TOp, var: &TData, ) -> Result<(), AutoDiffError>

Decouple op and output variable

Source

pub fn get_input_edge_data(&self) -> BTreeSet<TData>

list data node without upstream op node in a set.

Source

pub fn get_output_edge_data(&self) -> BTreeSet<TData>

list data node without downstream op node in a set.

Source

pub fn connect( &mut self, dti: &[TData], dto: &[TData], op: &TOp, ) -> Result<TOp, &str>

Connect input data, output data and operation

Source

pub fn connect_aux( &mut self, input_data: &[TData], output_data: &[TData], op: &TOp, ) -> Result<TOp, &str>

Auxilary connect, This allows the graph to support loop.

Source

pub fn walk<F>( &self, start_set: &[TData], forward: bool, closure: F, ) -> Result<(), BTreeSet<TData>>
where F: Fn(&[TData], &[TData], &TOp),

Walk through the graph with a starting set of data nodes. Go through backwards if forward is false. The closure call provides the side-effect.

This Walk() guarantee the input of visiting op is already visited or it’s an input.

Source

pub fn append( &mut self, other: &Self, data_key_map: BTreeMap<TData, TData>, op_key_map: BTreeMap<TOp, TOp>, ) -> Result<(), AutoDiffError>

Trait Implementations§

Source§

impl<TData: Clone + Ord, TOp: Clone + Ord> Clone for Graph<TData, TOp>

Source§

fn clone(&self) -> Graph<TData, TOp>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph<GenKey, GenKey>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TData: Clone + Copy + Ord, TOp: Clone + Copy + Ord> Default for Graph<TData, TOp>

Source§

fn default() -> Graph<TData, TOp>

Returns the “default value” for a type. Read more
Source§

impl<'de, TData, TOp> Deserialize<'de> for Graph<TData, TOp>
where TData: Deserialize<'de> + Ord, TOp: Deserialize<'de> + Ord,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T1: Ord, T2: Ord> PartialEq for Graph<T1, T2>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<TData, TOp> Serialize for Graph<TData, TOp>
where TData: Serialize + Ord, TOp: Serialize + Ord,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T1: Ord, T2: Ord> Eq for Graph<T1, T2>

Auto Trait Implementations§

§

impl<TData, TOp> Freeze for Graph<TData, TOp>

§

impl<TData, TOp> RefUnwindSafe for Graph<TData, TOp>
where TData: RefUnwindSafe, TOp: RefUnwindSafe,

§

impl<TData, TOp> Send for Graph<TData, TOp>
where TData: Send, TOp: Send,

§

impl<TData, TOp> Sync for Graph<TData, TOp>
where TData: Sync, TOp: Sync,

§

impl<TData, TOp> Unpin for Graph<TData, TOp>

§

impl<TData, TOp> UnwindSafe for Graph<TData, TOp>
where TData: RefUnwindSafe, TOp: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,