pub struct StridedViewMut<'a, T> { /* private fields */ }Expand description
Dynamic-rank mutable strided view.
Always uses Identity element operation for write simplicity.
Julia typically applies ops on the read side.
Implementations§
Source§impl<'a, T> StridedViewMut<'a, T>
impl<'a, T> StridedViewMut<'a, T>
Sourcepub fn new(
data: &'a mut [T],
dims: &[usize],
strides: &[isize],
offset: isize,
) -> Result<StridedViewMut<'a, T>, StridedError>
pub fn new( data: &'a mut [T], dims: &[usize], strides: &[isize], offset: isize, ) -> Result<StridedViewMut<'a, T>, StridedError>
Create a mutable view, copying the caller’s metadata inline.
The layout is copied, so it does not need to outlive the view and no
heap allocation happens at rank <= INLINE_RANK.
§Examples
use strided_view::StridedViewMut;
let mut data = [0.0f64; 4];
let mut view = StridedViewMut::<f64>::new(&mut data, &[2, 2], &[1, 2], 0).unwrap();
view.set(&[1, 1], 5.0);
assert_eq!(data[3], 5.0);Sourcepub unsafe fn new_unchecked(
data: &'a mut [T],
dims: &[usize],
strides: &[isize],
offset: isize,
) -> StridedViewMut<'a, T>
pub unsafe fn new_unchecked( data: &'a mut [T], dims: &[usize], strides: &[isize], offset: isize, ) -> StridedViewMut<'a, T>
Create without bounds checking, copying the caller’s metadata.
§Safety
Caller must ensure all index combinations stay within bounds.
§Examples
use strided_view::StridedViewMut;
let mut data = [0.0f64; 4];
let view = unsafe { StridedViewMut::<f64>::new_unchecked(&mut data, &[2, 2], &[1, 2], 0) };
assert_eq!(view.ndim(), 2);Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Raw mutable pointer to element at the view’s base offset.
Sourcepub fn permute(
self,
perm: &[usize],
) -> Result<StridedViewMut<'a, T>, StridedError>
pub fn permute( self, perm: &[usize], ) -> Result<StridedViewMut<'a, T>, StridedError>
Permute dimensions, consuming the mutable view.
Returns a new mutable view with reordered dimensions and strides.
Takes self by value to prevent aliasing of mutable views.
Sourcepub fn as_view(&self) -> StridedView<'_, T>
pub fn as_view(&self) -> StridedView<'_, T>
Reborrow as an immutable view.
The reborrow copies this view’s metadata into the immutable view’s
inline storage, which allocates nothing up to INLINE_RANK and
spills above it (the mutable owner always keeps its own copy).
§Examples
use strided_view::StridedViewMut;
let mut data = [1.0f64, 2.0, 3.0];
let view = StridedViewMut::<f64>::new(&mut data, &[3], &[1], 0).unwrap();
let read = view.as_view();
assert_eq!(read.get(&[2]), 3.0);