pub trait TensorStorage:
Send
+ Sync
+ Debug
+ Display
+ DynEq
+ Downcast {
// Required methods
fn byte_len(&self) -> usize;
fn is_empty(&self) -> bool;
fn deep_clone(&self) -> Box<dyn TensorStorage>;
fn as_plain(&self) -> Option<&PlainStorage>;
fn as_plain_mut(&mut self) -> Option<&mut PlainStorage>;
fn into_plain(self: Box<Self>) -> Option<PlainStorage>;
fn dyn_hash(&self, state: &mut dyn Hasher);
fn exotic_fact(
&self,
shape: &[usize],
) -> TractResult<Option<Box<dyn ExoticFact>>>;
}Expand description
Trait abstracting over tensor storage backends.
PlainStorage is the primary implementation backed by a contiguous Blob.
Non-plain backends are held behind StorageKind::Exotic(Box<dyn TensorStorage>).
Required Methods§
fn byte_len(&self) -> usize
fn is_empty(&self) -> bool
fn deep_clone(&self) -> Box<dyn TensorStorage>
fn as_plain(&self) -> Option<&PlainStorage>
fn as_plain_mut(&mut self) -> Option<&mut PlainStorage>
fn into_plain(self: Box<Self>) -> Option<PlainStorage>
fn dyn_hash(&self, state: &mut dyn Hasher)
Sourcefn exotic_fact(
&self,
shape: &[usize],
) -> TractResult<Option<Box<dyn ExoticFact>>>
fn exotic_fact( &self, shape: &[usize], ) -> TractResult<Option<Box<dyn ExoticFact>>>
Build the ExoticFact that describes this storage for use in TypedFact.
Plain storage returns None. Exotic storages should return the
appropriate fact so that From<Arc<Tensor>> for TypedFact preserves
exotic-ness.
Implementations§
Source§impl dyn TensorStorage
impl dyn TensorStorage
Sourcepub fn is<__T: TensorStorage>(&self) -> bool
pub fn is<__T: TensorStorage>(&self) -> bool
Returns true if the trait object wraps an object of type __T.
Sourcepub fn downcast<__T: TensorStorage>(
self: Box<Self>,
) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: TensorStorage>( 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: TensorStorage>(
self: Rc<Self>,
) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: TensorStorage>( 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: TensorStorage>(&self) -> Option<&__T>
pub fn downcast_ref<__T: TensorStorage>(&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: TensorStorage>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: TensorStorage>(&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.