Struct tract_core::model::Graph

source ·
pub struct Graph<F, O>where
    F: Fact + Clone + 'static,
    O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,{
    pub nodes: Vec<Node<F, O>>,
    pub inputs: Vec<OutletId>,
    pub outputs: Vec<OutletId>,
    pub outlet_labels: HashMap<OutletId, String>,
    pub properties: HashMap<String, Arc<Tensor>>,
    pub symbol_table: SymbolTable,
}
Expand description

Main model class

Parameterized by a Fact class.

Fields§

§nodes: Vec<Node<F, O>>

all nodes in the model

§inputs: Vec<OutletId>

model inputs

§outputs: Vec<OutletId>

model outputs

§outlet_labels: HashMap<OutletId, String>

outlet labels

§properties: HashMap<String, Arc<Tensor>>

model properties

§symbol_table: SymbolTable

symbol table

Implementations§

source§

impl<F, O> Graph<F, O>where F: Fact + Clone + 'static, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static, Graph<F, O>: SpecialOps<F, O>,

source

pub fn add_source( &mut self, name: impl Into<String>, fact: F ) -> TractResult<OutletId>

source§

impl<F, O> Graph<F, O>where F: Fact + Clone + 'static, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source

pub fn add_node( &mut self, name: impl Into<String>, op: impl Into<O>, output_facts: TVec<F> ) -> TractResult<usize>

source

pub fn add_edge(&mut self, outlet: OutletId, inlet: InletId) -> TractResult<()>

Connect a node outlet to a node inlet.

source

pub fn input_outlets(&self) -> TractResult<&[OutletId]>

Get model inputs.

source

pub fn set_input_outlets(&mut self, inputs: &[OutletId]) -> TractResult<()>

Change model inputs.

source

pub fn with_input_outlets(self, inputs: &[OutletId]) -> TractResult<Self>

Change model inputs and return self.

source

pub fn set_input_names( &mut self, inputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<()>

Set model inputs by the node name.

source

pub fn with_input_names( self, inputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<Self>

Set model inputs by the node name and return self.

source

pub fn input_fact(&self, ix: usize) -> TractResult<&F>

Get the ix-th input tensor type information.

source

pub fn input_fact_mut(&mut self, ix: usize) -> TractResult<&mut F>

Get the ix-th input tensor type information, mutably.

source

pub fn set_input_fact(&mut self, input: usize, fact: F) -> TractResult<()>

Set the ix-th input tensor type information.

source

pub fn with_input_fact(self, input: usize, fact: F) -> TractResult<Self>

Set the ix-th input tensor type information and return self.

source

pub fn output_outlets(&self) -> TractResult<&[OutletId]>

Get model outputs.

source

pub fn auto_outputs(&mut self) -> TractResult<()>

Guess outputs from the topology: node or nodes with no successors.

source

pub fn set_output_outlets(&mut self, outputs: &[OutletId]) -> TractResult<()>

Change model outputs.

source

pub fn with_output_outlets(self, outputs: &[OutletId]) -> TractResult<Self>

Change model outputs and return self.

source

pub fn set_output_names( &mut self, outputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<()>

Set model outputs by node names.

source

pub fn with_output_names( self, outputs: impl IntoIterator<Item = impl AsRef<str>> ) -> TractResult<Self>

Set model outputs by node names and return self.

source

pub fn output_fact(&self, ix: usize) -> TractResult<&F>

Get the ix-th input tensor type information.

source

pub fn output_fact_mut(&mut self, ix: usize) -> TractResult<&mut F>

Get the ix-th input tensor type information, mutably.

source

pub fn set_output_fact(&mut self, output: usize, fact: F) -> TractResult<()>

Set the ix-th output tensor type information.

source

pub fn with_output_fact(self, output: usize, fact: F) -> TractResult<Self>

Set the ix-th output tensor type information and return self.

source

pub fn node_names(&self) -> impl Iterator<Item = &str>

Iterate over all node names.

source

pub fn node_id_by_name(&self, name: &str) -> TractResult<usize>

source

pub fn node_by_name(&self, name: impl AsRef<str>) -> TractResult<&Node<F, O>>

Find a node by its name.

source

pub fn node_by_name_mut( &mut self, name: impl AsRef<str> ) -> TractResult<&mut Node<F, O>>

Borrow mutably a node by its name.

source

pub fn rename_node(&mut self, id: usize, name: &str) -> TractResult<()>

source

pub fn node(&self, id: usize) -> &Node<F, O>

Find a node by its id.

source

pub fn node_mut(&mut self, id: usize) -> &mut Node<F, O>

Find a node by its id.

source

pub fn nodes(&self) -> &[Node<F, O>]

Access the nodes table.

source

pub fn nodes_mut(&mut self) -> &mut [Node<F, O>]

Access the nodes table.

source

pub fn node_facts(&self, id: usize) -> TractResult<(TVec<&F>, TVec<&F>)>

Get input and output tensor information for a node.

source

pub fn node_input_facts(&self, node_id: usize) -> TractResult<TVec<&F>>

Get input tensor information for a node.

source

pub fn node_output_facts(&self, node_id: usize) -> TractResult<TVec<&F>>

Get output tensor information for a node.

source

pub fn outlet_fact(&self, outlet: OutletId) -> TractResult<&F>

Get tensor information for a single outlet.

source

pub fn outlet_fact_mut(&mut self, outlet: OutletId) -> TractResult<&mut F>

Get tensor information for a single outlet.

source

pub fn outlets_fact_mut( &mut self, outlets: &[OutletId] ) -> TractResult<TVec<&mut F>>

Get multiple mutable tensor information for outlets.

source

pub fn set_outlet_fact(&mut self, outlet: OutletId, fact: F) -> TractResult<()>

Set tensor information for a single outlet.

source

pub fn with_outlet_fact(self, outlet: OutletId, fact: F) -> TractResult<Self>

Set tensor information for a single outlet and return self.

source

pub fn outlet_label(&self, outlet: OutletId) -> Option<&str>

Get label for an outlet.

source

pub fn set_outlet_label( &mut self, outlet: OutletId, label: String ) -> TractResult<()>

Set label for an outlet.

source

pub fn with_outlet_label( self, outlet: OutletId, label: String ) -> TractResult<Self>

Set label for an outlet and return self.

source

pub fn find_outlet_label(&self, label: &str) -> Option<OutletId>

Find outlet by label.

source

pub fn eval_order(&self) -> TractResult<Vec<usize>>

Computes an evalutation order for the graph inputs and outputs

source

pub fn check_edges(&self) -> TractResult<()>

source

pub fn into_runnable(self) -> TractResult<RunnableModel<F, O, Self>>

Converts the model into a RunnableModel which fixes the inputs and outputs and allows passing data through the model.

source

pub fn single_prec(&self, id: usize) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_prec_at( &self, id: usize, count: usize ) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_succ_at( &self, id: usize, count: usize ) -> TractResult<Option<&Node<F, O>>>

source

pub fn single_succ(&self, id: usize) -> TractResult<Option<&Node<F, O>>>

source

pub fn outlet_successors(&self, outlet: OutletId) -> &[InletId]

source§

impl<F, O> Graph<F, O>where F: Fact + Clone + 'static + From<Arc<Tensor>>, O: Debug + Display + From<Const> + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source

pub fn add_const( &mut self, name: impl Into<String>, v: impl IntoArcTensor ) -> TractResult<OutletId>

source§

impl<F, O> Graph<F, O>where F: Fact + Clone + 'static + for<'a> From<&'a F>, O: Display + Debug + Clone + AsRef<dyn Op> + AsMut<dyn Op> + 'static + for<'a> From<&'a O>, Graph<F, O>: SpecialOps<F, O>,

source

pub fn check_compact(&self) -> TractResult<()>

source

pub fn compact(&mut self) -> TractResult<()>

source

pub fn into_compact(self) -> TractResult<Self>

source§

impl Graph<TypedFact, Box<dyn TypedOp + 'static, Global>>

source

pub fn into_optimized(self) -> TractResult<TypedModel>

source

pub fn check_consistency(&self) -> TractResult<()>

source

pub fn into_decluttered(self) -> TractResult<TypedModel>

source

pub fn declutter(&mut self) -> TractResult<()>

Perform declutter passes on the network.

source

pub fn optimize_with_session( &mut self, session: &mut OptimizerSession<'_> ) -> TractResult<()>

Perform optimization passes on the model, using a given optimizer session.

source

pub fn concretize_dims(&self, values: &SymbolValues) -> TractResult<TypedModel>

source

pub fn optimize(&mut self) -> TractResult<()>

Translate the graph to locally optimized operators (LIR or MIR ops).

source

pub fn node_axes_mapping(&self, id: usize) -> TractResult<AxesMapping>

source

pub fn axes_mapping(&self) -> TractResult<AxesMapping>

Trait Implementations§

source§

impl<F, O> Clone for Graph<F, O>where F: Fact + Clone + 'static + Clone, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static + Clone,

source§

fn clone(&self) -> Graph<F, O>

Returns a copy 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<F, O> Debug for Graph<F, O>where F: Fact + Clone + 'static + Debug, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static + Debug,

source§

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

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

impl<F, O> Default for Graph<F, O>where F: Fact + Clone + 'static, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source§

fn default() -> Graph<F, O>

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

impl<F, O> Display for Graph<F, O>where F: Fact + Clone + 'static, O: Debug + Display + AsRef<dyn Op> + AsMut<dyn Op> + Clone + 'static,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, O> RefUnwindSafe for Graph<F, O>where F: RefUnwindSafe, O: RefUnwindSafe,

§

impl<F, O> Send for Graph<F, O>where O: Send,

§

impl<F, O> Sync for Graph<F, O>where O: Sync,

§

impl<F, O> Unpin for Graph<F, O>where F: Unpin, O: Unpin,

§

impl<F, O> UnwindSafe for Graph<F, O>where F: UnwindSafe + RefUnwindSafe, O: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for Twhere T: Any,

source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.