Type Definition ndarray::RawArrayViewMut

source ·
pub type RawArrayViewMut<A, D> = ArrayBase<RawViewRepr<*mut A>, D>;
Expand description

A mutable array view without a lifetime.

This is similar to ArrayViewMut but does not carry any lifetime or ownership information, and its data cannot be read/written without an unsafe conversion into an ArrayViewMut. The relationship between RawArrayViewMut and ArrayViewMut is somewhat analogous to the relationship between *mut T and &mut T, but RawArrayViewMut has additional requirements that *mut T does not, such as non-nullness.

The RawArrayViewMut<A, D> is parameterized by A for the element type and D for the dimensionality.

Raw array views have all the methods of an array (see ArrayBase).

See also RawArrayView.

Warning

You can’t use this type with an arbitrary raw pointer; see from_shape_ptr for details.

Implementations§

source§

impl<A, D> RawArrayViewMut<A, D>where D: Dimension,

source

pub unsafe fn from_shape_ptr<Sh>(shape: Sh, ptr: *mut A) -> Selfwhere Sh: Into<StrideShape<D>>,

Create an RawArrayViewMut<A, D> from shape information and a raw pointer to the elements.

Safety

The caller is responsible for ensuring all of the following:

  • ptr must be non-null, and it must be safe to .offset() ptr by zero.

  • It must be safe to .offset() the pointer repeatedly along all axes and calculate the counts for the .offset() calls without overflow, even if the array is empty or the elements are zero-sized.

    In other words,

    • All possible pointers generated by moving along all axes must be in bounds or one byte past the end of a single allocation with element type A. The only exceptions are if the array is empty or the element type is zero-sized. In these cases, ptr may be dangling, but it must still be safe to .offset() the pointer along the axes.

    • The offset in units of bytes between the least address and greatest address by moving along all axes must not exceed isize::MAX. This constraint prevents the computed offset, in bytes, from overflowing isize regardless of the starting point due to past offsets.

    • The offset in units of A between the least address and greatest address by moving along all axes must not exceed isize::MAX. This constraint prevents overflow when calculating the count parameter to .offset() regardless of the starting point due to past offsets.

  • The product of non-zero axis lengths must not exceed isize::MAX.

  • Strides must be non-negative.

This function can use debug assertions to check some of these requirements, but it’s not a complete check.

source

pub unsafe fn deref_into_view<'a>(self) -> ArrayView<'a, A, D>

Converts to a read-only view of the array.

Safety

From a safety standpoint, this is equivalent to dereferencing a raw pointer for every element in the array. You must ensure that all of the data is valid, ensure that the pointer is aligned, and choose the correct lifetime.

source

pub unsafe fn deref_into_view_mut<'a>(self) -> ArrayViewMut<'a, A, D>

Converts to a mutable view of the array.

Safety

From a safety standpoint, this is equivalent to dereferencing a raw pointer for every element in the array. You must ensure that all of the data is valid, ensure that the pointer is aligned, and choose the correct lifetime.

source

pub fn split_at(self, axis: Axis, index: Ix) -> (Self, Self)

Split the array view along axis and return one array pointer strictly before the split and one array pointer after the split.

Panics if axis or index is out of bounds.

source

pub fn cast<B>(self) -> RawArrayViewMut<B, D>

Cast the raw pointer of the raw array view to a different type

Panics if element size is not compatible.

Lack of panic does not imply it is a valid cast. The cast works the same way as regular raw pointer casts.

While this method is safe, for the same reason as regular raw pointer casts are safe, access through the produced raw view is only possible in an unsafe block or function.

source§

impl<T, D> RawArrayViewMut<Complex<T>, D>where D: Dimension,

source

pub fn split_complex(self) -> Complex<RawArrayViewMut<T, D>>

Splits the view into views of the real and imaginary components of the elements.

Trait Implementations§

source§

impl<A, D: Dimension> NdProducer for RawArrayViewMut<A, D>

§

type Item = *mut A

The element produced per iteration.
§

type Dim = D

Dimension type
source§

fn raw_dim(&self) -> Self::Dim

Return the shape of the producer.