pub trait OpState:
Debug
+ DynClone
+ Downcast
+ Send {
// Required methods
fn eval(
&mut self,
ctx: &EvalContext<'_>,
op: &dyn Op,
inputs: TVec<TValue>,
) -> TractResult<TVec<TValue>>;
fn reset_lanes(&mut self, lanes: &[LaneId]) -> TractResult<()>;
// Provided methods
fn load_from(
&mut self,
_: &mut TurnState,
_: &mut dyn Iterator<Item = TValue>,
) -> TractResult<()> { ... }
fn save_to(&self, _: &mut Vec<TValue>) -> TractResult<()> { ... }
fn init_tensor_fact(&self) -> Option<(String, TypedFact)> { ... }
fn has_init_tensor_fact(&self) -> bool { ... }
fn resolve_symbols(&mut self, _: &mut TurnState) -> TractResult<()> { ... }
}Required Methods§
fn eval( &mut self, ctx: &EvalContext<'_>, op: &dyn Op, inputs: TVec<TValue>, ) -> TractResult<TVec<TValue>>
Sourcefn reset_lanes(&mut self, lanes: &[LaneId]) -> TractResult<()>
fn reset_lanes(&mut self, lanes: &[LaneId]) -> TractResult<()>
Discard what this state carries for lanes, so each can be handed to
another stream. Required, with no default: an op holding per-lane state
clears those rows, one holding none says so with Ok(()), and one that
cannot serve several streams at once fails here – which is where a laned
runtime finds out, since it resets every lane before the first turn.
Provided Methods§
fn load_from( &mut self, _: &mut TurnState, _: &mut dyn Iterator<Item = TValue>, ) -> TractResult<()>
fn save_to(&self, _: &mut Vec<TValue>) -> TractResult<()>
fn init_tensor_fact(&self) -> Option<(String, TypedFact)>
Sourcefn has_init_tensor_fact(&self) -> bool
fn has_init_tensor_fact(&self) -> bool
Allocation-free predicate mirroring whether OpState::init_tensor_fact
returns Some. The per-run symbol-resolution path queries this once for
every stateful op on every run, so it must not call init_tensor_fact
(which clones a String and a TypedFact) merely to test for presence.
Any impl that overrides init_tensor_fact to return Some must override
this to return true (and delegate it wherever init_tensor_fact is
delegated), or its resolve_symbols will not run.
fn resolve_symbols(&mut self, _: &mut TurnState) -> TractResult<()>
Implementations§
Source§impl dyn OpState
impl dyn OpState
Sourcepub fn is<__T: OpState>(&self) -> bool
pub fn is<__T: OpState>(&self) -> bool
Returns true if the trait object wraps an object of type __T.
Sourcepub fn downcast<__T: OpState>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: OpState>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
Returns a boxed object from a boxed trait object if the underlying object is of type
__T. Returns the original boxed trait if it isn’t.
Sourcepub fn downcast_rc<__T: OpState>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: OpState>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of
type __T. Returns the original Rc-ed trait if it isn’t.
Sourcepub fn downcast_ref<__T: OpState>(&self) -> Option<&__T>
pub fn downcast_ref<__T: OpState>(&self) -> Option<&__T>
Returns a reference to the object within the trait object if it is of type __T, or
None if it isn’t.
Sourcepub fn downcast_mut<__T: OpState>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: OpState>(&mut self) -> Option<&mut __T>
Returns a mutable reference to the object within the trait object if it is of type
__T, or None if it isn’t.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".