Skip to main content

InferenceContext

Struct InferenceContext 

Source
pub struct InferenceContext<'a> {
    pub node: &'a Node,
    /* private fields */
}
Expand description

The context passed to every op inference rule.

It exposes each input’s inferred type and shape-data, lets a rule mint fresh symbolic dimensions and broadcast shapes, and collects the outputs the rule produces. Rules never touch the Graph directly — they operate purely on this context, which makes them trivially unit testable in isolation.

Fields§

§node: &'a Node

The node being inferred.

Implementations§

Source§

impl<'a> InferenceContext<'a>

Source

pub fn new( node: &'a Node, inputs: Vec<NodeIo>, opset_imports: &'a HashMap<String, u64>, policy: MergePolicy, interner: &'a mut SymbolInterner, ) -> Self

Build a context for node from its resolved inputs (aligned with node.inputs, skipped slots carrying an empty NodeIo).

Source

pub fn op(&self) -> &str

The op type of the node.

Source

pub fn num_inputs(&self) -> usize

The number of input slots (including skipped optional ones).

Source

pub fn num_outputs(&self) -> usize

The number of output slots.

Source

pub fn has_input(&self, i: usize) -> bool

Whether input slot i is present (a value is connected).

Source

pub fn input_type(&self, i: usize) -> Option<&TypeInfo>

The inferred type of input i, if resolved.

Source

pub fn input_shape(&self, i: usize) -> Option<&[DimExpr]>

The inferred shape of input i, if resolved.

Source

pub fn input_dtype(&self, i: usize) -> Option<DataType>

The inferred dtype of input i, if resolved.

Source

pub fn input_rank(&self, i: usize) -> Option<usize>

The inferred rank of input i, if resolved.

Source

pub fn input_shape_data(&self, i: usize) -> Option<&ShapeData>

The propagated shape-data of input i, if any.

Source

pub fn set_output_type(&mut self, i: usize, type_info: TypeInfo)

Set the type of output i.

Source

pub fn set_output(&mut self, i: usize, dtype: DataType, shape: TypedShape)

Set the dtype and shape of output i.

Source

pub fn set_output_shape_data(&mut self, i: usize, data: ShapeData)

Set the propagated shape-data of output i.

Source

pub fn into_outputs(self) -> Vec<NodeIo>

Consume the context, returning the outputs the rule produced.

Source

pub fn policy(&self) -> MergePolicy

The active merge policy.

Source

pub fn opset(&self, domain: &str) -> u64

The imported opset version for domain (the default ""/ai.onnx domain resolves to the canonical "" key, else 1).

Source

pub fn fresh_dim(&mut self) -> DimExpr

Mint a fresh opaque dimension.

Source

pub fn broadcast( &mut self, a: &[DimExpr], b: &[DimExpr], ) -> Result<TypedShape, ShapeInferError>

Broadcast two shapes under NumPy rules. Where two distinct symbolic dims must be unified, keeps a deterministic representative symbol (see broadcast_dim) rather than minting a fresh one. Errors only under MergePolicy::Strict on a concrete incompatibility.

Source

pub fn broadcast_dim( &mut self, a: &DimExpr, b: &DimExpr, ) -> Result<DimExpr, ShapeInferError>

Broadcast a single pair of dimensions.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for InferenceContext<'a>

§

impl<'a> Freeze for InferenceContext<'a>

§

impl<'a> RefUnwindSafe for InferenceContext<'a>

§

impl<'a> Send for InferenceContext<'a>

§

impl<'a> Sync for InferenceContext<'a>

§

impl<'a> Unpin for InferenceContext<'a>

§

impl<'a> UnsafeUnpin for InferenceContext<'a>

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> 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, 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.