pub struct Shape {
pub dims: Vec<usize>,
pub strides: Vec<usize>,
}Expand description
Represents the dimensional layout and physical memory strides of a tensor.
By separating dimensions from strides, ETensor can perform zero-copy view manipulations (like transposing or slicing) without moving physical data.
Fields§
§dims: Vec<usize>The mathematical dimensions of the tensor (e.g., [Batch, Channels, Height, Width]).
strides: Vec<usize>The number of physical memory elements to skip to reach the next element in a given dimension.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn new(dims: Vec<usize>) -> Self
pub fn new(dims: Vec<usize>) -> Self
Creates a new, contiguous shape layout.
Automatically calculates the default row-major (C-contiguous) strides required to map multi-dimensional coordinates to a flat 1D memory buffer.
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Transposes the last two dimensions in O(1) time.
This returns a new Shape representation with swapped dimensions and strides,
explicitly avoiding any duplication of the underlying physical buffer.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Returns the total number of mathematical elements contained in the shape.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Verifies if the underlying physical memory layout perfectly matches the mathematical layout.
This is crucial for backend hardware execution, as many optimized CUDA or CPU BLAS kernels require contiguous memory arrays to function correctly.
Trait Implementations§
impl Eq for Shape
impl StructuralPartialEq for Shape
Auto Trait Implementations§
impl Freeze for Shape
impl RefUnwindSafe for Shape
impl Send for Shape
impl Sync for Shape
impl Unpin for Shape
impl UnsafeUnpin for Shape
impl UnwindSafe for Shape
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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