pub struct StridedView<'a, T, Op = Identity> { /* private fields */ }Expand description
Dynamic-rank immutable strided view with lazy element operations.
This is the Julia-equivalent StridedView type with:
- Dynamic rank, with metadata borrowed (
StridedView::new, no allocation) or owned (StridedView::new_owned, for computed metadata) - Lazy element operations via the
Optype parameter - Zero-copy transformations (permute, transpose, adjoint, conj)
§Type Parameters
'a: Lifetime of the underlying data and of borrowed metadataT: Element typeOp: Element operation applied lazily on access (default:Identity)
Implementations§
Source§impl<'a, T, Op> StridedView<'a, T, Op>
impl<'a, T, Op> StridedView<'a, T, Op>
Sourcepub fn new(
data: &'a [T],
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<Self>
pub fn new( data: &'a [T], dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Result<Self>
Create an immutable strided view that borrows the caller’s metadata.
This is the allocation-free constructor: dims and strides must
outlive the view, which every caller that keeps its layouts does.
Sourcepub fn new_owned(
data: &'a [T],
dims: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Result<Self>
pub fn new_owned( data: &'a [T], dims: Vec<usize>, strides: Vec<isize>, offset: isize, ) -> Result<Self>
Create an immutable strided view that owns computed metadata.
For a caller that computes dims/strides next to the view, as a
helper returning a view must. Prefer StridedView::new otherwise.
Sourcepub unsafe fn new_unchecked(
data: &'a [T],
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Self
pub unsafe fn new_unchecked( data: &'a [T], dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Self
Create a view without bounds checking, borrowing the caller’s metadata.
§Safety
The caller must ensure all index combinations stay within bounds.
Sourcepub unsafe fn new_owned_unchecked(
data: &'a [T],
dims: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Self
pub unsafe fn new_owned_unchecked( data: &'a [T], dims: Vec<usize>, strides: Vec<isize>, offset: isize, ) -> Self
Sourcepub fn permute(&self, perm: &[usize]) -> Result<StridedView<'a, T, Op>>
pub fn permute(&self, perm: &[usize]) -> Result<StridedView<'a, T, Op>>
Permute dimensions.
Sourcepub fn diagonal_view(
&self,
axis_pairs: &[(usize, usize)],
) -> Result<StridedView<'a, T, Op>>
pub fn diagonal_view( &self, axis_pairs: &[(usize, usize)], ) -> Result<StridedView<'a, T, Op>>
Create a diagonal view by fusing repeated axis pairs via stride trick (zero-copy).
For each pair (a, b):
- New stride =
strides[a] + strides[b] - New dim =
min(dims[a], dims[b]) - The higher-numbered axis is removed
- Pairs use original axis numbering
§Example
A[i,i,j] shape=[n,n,m] strides=[s0,s1,s2] -> shape=[n,m] strides=[s0+s1, s2]
Sourcepub fn broadcast(&self, target_dims: &[usize]) -> Result<StridedView<'a, T, Op>>
pub fn broadcast(&self, target_dims: &[usize]) -> Result<StridedView<'a, T, Op>>
Broadcast this view to a target shape.
Size-1 dimensions are expanded (stride set to 0) to match target.
Source§impl<'a, T: Copy + ElementOpApply, Op: ComposableElementOp<T>> StridedView<'a, T, Op>
Composition methods: require T: ElementOpApply and Op: ComposableElementOp<T>.
impl<'a, T: Copy + ElementOpApply, Op: ComposableElementOp<T>> StridedView<'a, T, Op>
Composition methods: require T: ElementOpApply and Op: ComposableElementOp<T>.
Sourcepub fn transpose_2d(&self) -> Result<StridedView<'a, T, Op::ComposeTranspose>>
pub fn transpose_2d(&self) -> Result<StridedView<'a, T, Op::ComposeTranspose>>
Transpose a 2D view: reverses dimensions and composes the Transpose element op.
Julia equivalent: Base.transpose(a::AbstractStridedView{<:Any, 2})
Sourcepub fn adjoint_2d(&self) -> Result<StridedView<'a, T, Op::ComposeAdjoint>>
pub fn adjoint_2d(&self) -> Result<StridedView<'a, T, Op::ComposeAdjoint>>
Adjoint (conjugate transpose) of a 2D view.
Julia equivalent: Base.adjoint(a::AbstractStridedView{<:Any, 2})
Sourcepub fn conj(&self) -> StridedView<'a, T, Op::ComposeConj>
pub fn conj(&self) -> StridedView<'a, T, Op::ComposeConj>
Complex conjugate (compose Conj without changing dims/strides).
Julia equivalent: Base.conj(a::AbstractStridedView)
Source§impl<'a, T: Copy, Op: ElementOp<T>> StridedView<'a, T, Op>
Element access: requires Op: ElementOp<T>.
impl<'a, T: Copy, Op: ElementOp<T>> StridedView<'a, T, Op>
Element access: requires Op: ElementOp<T>.