Struct Row

Source
pub struct Row<const M: usize, const N: usize, T> { /* private fields */ }
Expand description

A row in a Matrix.

Implementations§

Source§

impl<T, const M: usize, const N: usize> Row<M, N, T>

Source

pub fn dot<const P: usize>(&self, other: &Column<N, P, T>) -> T
where T: Copy + Mul<Output = T> + Sum,

Source

pub fn dot_partial<const P: usize>( &self, other: &Column<N, P, T>, range: Range<usize>, ) -> T
where T: Copy + Mul<Output = T> + Sum,

Compute the dot product, but only with elements specified by the range

Methods from Deref<Target = Stride<T, M>>§

Source

pub fn len(&self) -> usize

Returns the number of elements in the strided slice.

This is equivalent to the ceiling division of the underlying slice length by S.

§Examples
let data = &[1, 2, 3, 4, 5, 6];
assert_eq!(Stride::<_, 1>::new(data).len(), 6);
assert_eq!(Stride::<_, 2>::new(data).len(), 3);
assert_eq!(Stride::<_, 3>::new(data).len(), 2);
Source

pub fn is_empty(&self) -> bool

Returns true if the strided slice has a length of 0.

§Examples
let stride = Stride::<_, 3>::new(&[1, 2, 3, 4, 5, 6]);
assert!(!stride.is_empty());
Source

pub fn as_ptr(&self) -> *const T

Returns a raw pointer to the underlying slice’s buffer.

See slice::as_ptr().

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Returns an unsafe mutable pointer to the underlying slice’s buffer.

See slice::as_mut_ptr().

Source

pub fn get<I>( &self, index: I, ) -> Option<&<I as StrideIndex<Stride<T, S>>>::Output>
where I: StrideIndex<Stride<T, S>>,

Returns a reference to an element or substride depending on the type of index.

  • If given a position, returns a reference to the element at that position or None if out of bounds.
  • If given a range, returns the substride corresponding to that range, or None if out of bounds.
§Examples
let stride = Stride::<_, 2>::new(&[1, 2, 3, 4, 5, 6]);
assert_eq!(stride.get(1), Some(&3));
assert_eq!(stride.get(0..2), Some(Stride::<_, 2>::new(&[1, 2, 3, 4])));
assert_eq!(stride.get(3), None);
assert_eq!(stride.get(0..4), None);
Source

pub fn get_mut<I>( &mut self, index: I, ) -> Option<&mut <I as StrideIndex<Stride<T, S>>>::Output>
where I: StrideIndex<Stride<T, S>>,

Returns a mutable reference to an element or substride depending on the type of index (see get) or None if the index is out of bounds.

§Examples
let data = &mut [0, 1, 2, 3];
let stride = Stride::<_, 2>::new_mut(data);

if let Some(elem) = stride.get_mut(1) {
    *elem = 42;
}
assert_eq!(stride, Stride::<_, 2>::new(&[0, 1, 42, 3]));
Source

pub unsafe fn get_unchecked<I>( &self, index: I, ) -> &<I as StrideIndex<Stride<T, S>>>::Output
where I: StrideIndex<Stride<T, S>>,

Returns a reference to an element or substride, without doing bounds checking.

For a safe alternative see get.

§Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.

Source

pub unsafe fn get_unchecked_mut<I>( &mut self, index: I, ) -> &mut <I as StrideIndex<Stride<T, S>>>::Output
where I: StrideIndex<Stride<T, S>>,

Returns a mutable reference to an element or substride, without doing bounds checking.

For a safe alternative see get_mut.

§Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.

Source

pub fn first(&self) -> Option<&T>

Returns a reference to the first element of the strided slice, or None if it is empty.

Source

pub fn first_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the first element of the strided slice, or None if it is empty.

Source

pub fn last(&self) -> Option<&T>

Returns a reference to the last element of the strided slice, or None if it is empty.

Source

pub fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the last element of the strided slice, or None if it is empty.

Source

pub fn swap(&mut self, a: usize, b: usize)

Swaps two elements in the strided slice.

§Arguments
  • a - The index of the first element
  • b - The index of the second element
§Panics

If a or b are out of bounds.

Source

pub fn iter(&self) -> Iter<'_, T, S>

Returns an iterator over the stride.

§Examples
let stride = Stride::<_, 2>::new(&[1, 2, 3, 4, 5, 6]);
let mut iterator = stride.iter();
assert_eq!(iterator.next(), Some(&1));
assert_eq!(iterator.next(), Some(&3));
assert_eq!(iterator.next(), Some(&5));
assert_eq!(iterator.next(), None);
Source

pub fn iter_mut(&mut self) -> IterMut<'_, T, S>

Returns an iterator over the stride that allows modifying each value.

§Examples
let slice = &mut [1, 1, 2, 2, 3, 3];
let stride = Stride::<_, 2>::new_mut(slice);
for elem in stride.iter_mut() {
    *elem *= 2;
}
assert_eq!(slice, &[2, 1, 4, 2, 6, 3]);
Source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire strided slice.

Only available on strided slices with a stride of 1.

§Examples
let slice = &[1, 2, 3];
let stride = Stride::<_, 1>::new(slice);
assert_eq!(stride.as_slice(), slice);
Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice containing the entire strided slice.

Only available on strided slices with a stride of 1.

§Examples
let slice = &mut [1, 2, 7];
let stride = Stride::<_, 1>::new_mut(slice);
stride.as_mut_slice()[2] = 3;
assert_eq!(slice, &[1, 2, 3])

Trait Implementations§

Source§

impl<const M: usize, const N: usize, T: Debug> Debug for Row<M, N, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, const M: usize, const N: usize> Deref for Row<M, N, T>

Source§

type Target = Stride<T, M>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, const M: usize, const N: usize> DerefMut for Row<M, N, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<const M: usize, const N: usize, T: Hash> Hash for Row<M, N, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
Source§

impl<const M: usize, const N: usize, T: Ord> Ord for Row<M, N, T>

Source§

fn cmp(&self, other: &Row<M, N, T>) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl<T, U, const M: usize, const N: usize> PartialEq<[U]> for Row<M, N, T>
where T: PartialEq<U>,

Source§

fn eq(&self, other: &[U]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, U, const M: usize, const N: usize, const P: usize> PartialEq<[U; P]> for Row<M, N, T>
where T: PartialEq<U>,

Source§

fn eq(&self, other: &[U; P]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, U, const M: usize, const N: usize, const S: usize> PartialEq<Stride<U, S>> for Row<M, N, T>
where T: PartialEq<U>,

Source§

fn eq(&self, other: &Stride<U, S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const M: usize, const N: usize, T: PartialEq> PartialEq for Row<M, N, T>

Source§

fn eq(&self, other: &Row<M, N, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const M: usize, const N: usize, T: PartialOrd> PartialOrd for Row<M, N, T>

Source§

fn partial_cmp(&self, other: &Row<M, N, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const M: usize, const N: usize, T: Eq> Eq for Row<M, N, T>

Source§

impl<const M: usize, const N: usize, T> StructuralPartialEq for Row<M, N, T>

Auto Trait Implementations§

§

impl<const M: usize, const N: usize, T> Freeze for Row<M, N, T>
where T: Freeze,

§

impl<const M: usize, const N: usize, T> RefUnwindSafe for Row<M, N, T>
where T: RefUnwindSafe,

§

impl<const M: usize, const N: usize, T> Send for Row<M, N, T>
where T: Send,

§

impl<const M: usize, const N: usize, T> !Sized for Row<M, N, T>

§

impl<const M: usize, const N: usize, T> Sync for Row<M, N, T>
where T: Sync,

§

impl<const M: usize, const N: usize, T> Unpin for Row<M, N, T>
where T: Unpin,

§

impl<const M: usize, const N: usize, T> UnwindSafe for Row<M, N, T>
where T: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.