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>
impl<'a> TensorViewMut<'a>
Sourcepub unsafe fn new(
ptr: *mut u8,
shape: &[usize],
strides: &[usize],
dtype: ScalarType,
) -> Result<Self, DiffsolRtError>
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.
Sourcepub fn from_slice_mut<T: Scalar>(values: &'a mut [T], shape: &[usize]) -> Self
pub fn from_slice_mut<T: Scalar>(values: &'a mut [T], shape: &[usize]) -> Self
Sourcepub fn as_view(&self) -> TensorView<'_>
pub fn as_view(&self) -> TensorView<'_>
A view of the same data, which borrows self.
Sourcepub fn strides(&self) -> &[usize]
pub fn strides(&self) -> &[usize]
The stride of each axis, in bytes. The Tensor docs give the data layout.
Sourcepub fn dtype(&self) -> ScalarType
pub fn dtype(&self) -> ScalarType
The scalar type of the values.
Sourcepub fn index<T: Scalar>(
&self,
index: impl AsRef<[usize]>,
) -> Result<&T, DiffsolRtError>
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.
Sourcepub fn column<T: Scalar>(&self, index: &[usize]) -> Result<&[T], DiffsolRtError>
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.
Sourcepub fn index_mut<T: Scalar>(
&mut self,
index: impl AsRef<[usize]>,
) -> Result<&mut T, DiffsolRtError>
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.
Sourcepub fn column_mut<T: Scalar>(
&mut self,
index: &[usize],
) -> Result<&mut [T], DiffsolRtError>
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§
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> 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
impl<T, U> Imply<T> for U
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.