pub struct TensorSliceManager {
pub shape: TensorShape,
pub slices: HashMap<String, TensorSlice>,
}Expand description
Registry that manages named slices of a fixed-shape tensor.
§Semantics
- Bounds checking — every
SliceSpecis validated against the manager’sTensorShapeon creation. - Copy-on-write — each write increments
versionand marks the slicedirty; callingflush_allclears all dirty flags (e.g. after persisting to storage). - Overlap detection —
overlapping_sliceslists every registered slice that overlaps a given query spec.
Fields§
§shape: TensorShapeShape of the underlying tensor.
slices: HashMap<String, TensorSlice>Registered slices, keyed by name.
Implementations§
Source§impl TensorSliceManager
impl TensorSliceManager
Sourcepub fn new(shape: TensorShape) -> Self
pub fn new(shape: TensorShape) -> Self
Creates a new, empty manager for a tensor of the given shape.
Sourcepub fn create_slice(
&mut self,
name: String,
spec: SliceSpec,
data: Vec<f32>,
) -> Result<(), String>
pub fn create_slice( &mut self, name: String, spec: SliceSpec, data: Vec<f32>, ) -> Result<(), String>
Registers a new named slice.
§Errors
Returns Err with a descriptive message when:
- a slice with the same
namealready exists, spec.end[i] > shape.dims[i]for any dimension, ordata.len() != spec.element_count().
Sourcepub fn write_slice(&mut self, name: &str, data: Vec<f32>) -> bool
pub fn write_slice(&mut self, name: &str, data: Vec<f32>) -> bool
Overwrites the data of an existing slice.
On success the slice’s version is incremented and dirty is set to
true. Returns false when the slice does not exist or data has the
wrong length.
Sourcepub fn read_slice(&self, name: &str) -> Option<&TensorSlice>
pub fn read_slice(&self, name: &str) -> Option<&TensorSlice>
Returns an immutable reference to the named slice, or None.
Sourcepub fn flush_all(&mut self)
pub fn flush_all(&mut self)
Clears the dirty flag on every registered slice.
Intended to be called after all dirty slices have been flushed to persistent storage.
Sourcepub fn overlapping_slices<'a>(&'a self, spec: &SliceSpec) -> Vec<&'a str>
pub fn overlapping_slices<'a>(&'a self, spec: &SliceSpec) -> Vec<&'a str>
Returns the names of all registered slices that overlap spec.
The order of the returned names is unspecified (depends on the
HashMap iteration order).
Sourcepub fn remove_slice(&mut self, name: &str) -> bool
pub fn remove_slice(&mut self, name: &str) -> bool
Removes the named slice from the registry.
Returns true if the slice existed and was removed, false otherwise.
Sourcepub fn stats(&self) -> SliceManagerStats
pub fn stats(&self) -> SliceManagerStats
Computes aggregate statistics over all registered slices.
Auto Trait Implementations§
impl Freeze for TensorSliceManager
impl RefUnwindSafe for TensorSliceManager
impl Send for TensorSliceManager
impl Sync for TensorSliceManager
impl Unpin for TensorSliceManager
impl UnsafeUnpin for TensorSliceManager
impl UnwindSafe for TensorSliceManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more