Skip to main content

TensorViewMut

Struct TensorViewMut 

Source
pub struct TensorViewMut<'a> { /* private fields */ }
Expand description

A mutable view of an N-D array of f32 or f64 values that the view does not own.

It has the same data layout and the same layout rules as TensorView. Also, no two indices give the same value (there is no stride of 0 on an axis with more than one value), so each value can be changed through the view. The C callbacks of crate::ode_callbacks write their outputs through a TensorViewMut.

A TensorViewMut has the C layout of RawLayout. The C type of ptr is const uint8_t *: a C callback casts it to double * (or float *) to write the values.

Implementations§

Source§

impl<'a> TensorViewMut<'a>

Source

pub unsafe fn new( ptr: *mut u8, shape: &[usize], strides: &[usize], dtype: ScalarType, ) -> Result<Self, DiffsolRtError>

Make a mutable view of data, with a shape and strides (in bytes) that obey the layout rules, and no two indices that give the same value.

§Errors

If the layout does not obey the rules.

§Safety

For each index in shape, ptr plus the byte offset from strides must point to a valid value of the type dtype. The data must stay valid during 'a, and nothing else can read or change it during 'a.

Source

pub fn from_slice_mut<T: Scalar>(values: &'a mut [T], shape: &[usize]) -> Self

Make a mutable view of values, with the shape shape in column-major (Fortran) order.

§Panics

If the number of values is not the product of shape, or shape does not have 1 to MAX_NDIM axes.

Source

pub fn as_view(&self) -> TensorView<'_>

A view of the same data, which borrows self.

Source

pub fn shape(&self) -> &[usize]

The length of each axis.

Source

pub fn strides(&self) -> &[usize]

The stride of each axis, in bytes. The Tensor docs give the data layout.

Source

pub fn data_ptr(&mut self) -> *mut u8

The pointer to the first value. It is valid during 'a.

Source

pub fn dtype(&self) -> ScalarType

The scalar type of the values.

Source

pub fn index<T: Scalar>( &self, index: impl AsRef<[usize]>, ) -> Result<&T, DiffsolRtError>

A reference to the value at index. TensorView::index gives the details.

§Panics

If index does not have one value for each axis, or a value is out of range.

Source

pub fn column<T: Scalar>(&self, index: &[usize]) -> Result<&[T], DiffsolRtError>

The column at index. Tensor::column gives the details.

§Panics

If index does not have one value for each axis after the first, or a value is out of range.

Source

pub fn index_mut<T: Scalar>( &mut self, index: impl AsRef<[usize]>, ) -> Result<&mut T, DiffsolRtError>

A mutable reference to the value at index, with one value for each axis. The scalar type must be T.

§Panics

If index does not have one value for each axis, or a value is out of range.

Source

pub fn column_mut<T: Scalar>( &mut self, index: &[usize], ) -> Result<&mut [T], DiffsolRtError>

The column at index, as one mutable slice of shape[0] values. Tensor::column gives the details.

§Panics

If index does not have one value for each axis after the first, or a value is out of range.

Trait Implementations§

Source§

impl<'a> Debug for TensorViewMut<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Send for TensorViewMut<'a>

§

impl<'a> !Sync for TensorViewMut<'a>

§

impl<'a> !UnwindSafe for TensorViewMut<'a>

§

impl<'a> Forget for TensorViewMut<'a>

§

impl<'a> Freeze for TensorViewMut<'a>

§

impl<'a> Move for TensorViewMut<'a>

§

impl<'a> RefUnwindSafe for TensorViewMut<'a>

§

impl<'a> Unpin for TensorViewMut<'a>

§

impl<'a> UnsafeUnpin for TensorViewMut<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.