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 NodeThe node being inferred.
Implementations§
Source§impl<'a> InferenceContext<'a>
impl<'a> InferenceContext<'a>
Sourcepub fn new(
node: &'a Node,
inputs: Vec<NodeIo>,
opset_imports: &'a HashMap<String, u64>,
policy: MergePolicy,
interner: &'a mut SymbolInterner,
) -> Self
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).
Sourcepub fn num_inputs(&self) -> usize
pub fn num_inputs(&self) -> usize
The number of input slots (including skipped optional ones).
Sourcepub fn num_outputs(&self) -> usize
pub fn num_outputs(&self) -> usize
The number of output slots.
Sourcepub fn has_input(&self, i: usize) -> bool
pub fn has_input(&self, i: usize) -> bool
Whether input slot i is present (a value is connected).
Sourcepub fn input_type(&self, i: usize) -> Option<&TypeInfo>
pub fn input_type(&self, i: usize) -> Option<&TypeInfo>
The inferred type of input i, if resolved.
Sourcepub fn input_shape(&self, i: usize) -> Option<&[DimExpr]>
pub fn input_shape(&self, i: usize) -> Option<&[DimExpr]>
The inferred shape of input i, if resolved.
Sourcepub fn input_dtype(&self, i: usize) -> Option<DataType>
pub fn input_dtype(&self, i: usize) -> Option<DataType>
The inferred dtype of input i, if resolved.
Sourcepub fn input_rank(&self, i: usize) -> Option<usize>
pub fn input_rank(&self, i: usize) -> Option<usize>
The inferred rank of input i, if resolved.
Sourcepub fn input_shape_data(&self, i: usize) -> Option<&ShapeData>
pub fn input_shape_data(&self, i: usize) -> Option<&ShapeData>
The propagated shape-data of input i, if any.
Sourcepub fn set_output_type(&mut self, i: usize, type_info: TypeInfo)
pub fn set_output_type(&mut self, i: usize, type_info: TypeInfo)
Set the type of output i.
Sourcepub fn set_output(&mut self, i: usize, dtype: DataType, shape: TypedShape)
pub fn set_output(&mut self, i: usize, dtype: DataType, shape: TypedShape)
Set the dtype and shape of output i.
Sourcepub fn set_output_shape_data(&mut self, i: usize, data: ShapeData)
pub fn set_output_shape_data(&mut self, i: usize, data: ShapeData)
Set the propagated shape-data of output i.
Sourcepub fn into_outputs(self) -> Vec<NodeIo>
pub fn into_outputs(self) -> Vec<NodeIo>
Consume the context, returning the outputs the rule produced.
Sourcepub fn policy(&self) -> MergePolicy
pub fn policy(&self) -> MergePolicy
The active merge policy.
Sourcepub fn opset(&self, domain: &str) -> u64
pub fn opset(&self, domain: &str) -> u64
The imported opset version for domain (the default ""/ai.onnx
domain falls back to the highest imported ai.onnx version, else 1).
Sourcepub fn broadcast(
&mut self,
a: &[DimExpr],
b: &[DimExpr],
) -> Result<TypedShape, ShapeInferError>
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.
Sourcepub fn broadcast_dim(
&mut self,
a: &DimExpr,
b: &DimExpr,
) -> Result<DimExpr, ShapeInferError>
pub fn broadcast_dim( &mut self, a: &DimExpr, b: &DimExpr, ) -> Result<DimExpr, ShapeInferError>
Broadcast a single pair of dimensions.