pub struct TensorSliceView {
pub data: Vec<f64>,
pub descriptor: ViewDescriptor,
pub stats: SliceViewStats,
}Expand description
Zero-copy logical view manager over a flat f64 data buffer.
All slice/broadcast operations produce new ViewDescriptors that share
the same backing data — no elements are ever duplicated.
§Examples
use ipfrs_tensorlogic::slice_view::{TensorSliceView, SliceRange};
// 2×3 tensor filled with 0..6
let data: Vec<f64> = (0..6).map(|x| x as f64).collect();
let mut view = TensorSliceView::new(data, vec![2, 3]);
assert_eq!(view.get(&[0, 0]), Some(0.0));
assert_eq!(view.get(&[1, 2]), Some(5.0));
// Slice row 1 only
let slice_desc = view.slice(0, SliceRange::contiguous(1, 2)).expect("example: should succeed in docs");
assert_eq!(slice_desc.base_offset, 3);
assert_eq!(slice_desc.shape, vec![1, 3]);Fields§
§data: Vec<f64>Flat backing buffer.
descriptor: ViewDescriptorCurrent logical view descriptor.
stats: SliceViewStatsCumulative statistics (slices, broadcasts, views created).
Implementations§
Source§impl TensorSliceView
impl TensorSliceView
Sourcepub fn new(data: Vec<f64>, shape: Vec<usize>) -> Self
pub fn new(data: Vec<f64>, shape: Vec<usize>) -> Self
Create a new TensorSliceView over data with the given logical shape.
Row-major strides are computed automatically and base_offset is set to 0.
stats.total_views_created is incremented.
Sourcepub fn get(&self, indices: &[usize]) -> Option<f64>
pub fn get(&self, indices: &[usize]) -> Option<f64>
Retrieve a single element by its multi-dimensional index.
Returns None if the index is out of bounds for the logical shape or
if the computed flat index exceeds the backing buffer length.
Sourcepub fn slice(&mut self, dim: usize, range: SliceRange) -> Option<ViewDescriptor>
pub fn slice(&mut self, dim: usize, range: SliceRange) -> Option<ViewDescriptor>
Apply a slice along dim and return the resulting ViewDescriptor.
The data buffer is not modified; the new descriptor adjusts
base_offset and strides[dim] to reflect the slice.
Returns None if:
dim >= self.descriptor.ndim(), orrange.start >= self.descriptor.shape[dim].
stats.total_slices is incremented on success.
Sourcepub fn broadcast_strides(
&mut self,
target_shape: &[usize],
) -> Option<Vec<usize>>
pub fn broadcast_strides( &mut self, target_shape: &[usize], ) -> Option<Vec<usize>>
Compute broadcast strides to view the current logical shape as target_shape.
Uses BroadcastShape internally. Returns None if the shapes are
incompatible. stats.total_broadcasts is incremented on success.
Sourcepub fn stats(&self) -> &SliceViewStats
pub fn stats(&self) -> &SliceViewStats
Return a reference to the cumulative statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TensorSliceView
impl RefUnwindSafe for TensorSliceView
impl Send for TensorSliceView
impl Sync for TensorSliceView
impl Unpin for TensorSliceView
impl UnsafeUnpin for TensorSliceView
impl UnwindSafe for TensorSliceView
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