OwnedMatrix

Struct OwnedMatrix 

Source
pub struct OwnedMatrix<T, A: Allocator = Global> { /* private fields */ }
Expand description

A matrix that owns its elements.

To pass it to algorithms, use the .data() and .data_mut() functions.

§Example

#![feature(allocator_api)]
let mut A = OwnedMatrix::identity(2, 2, StaticRing::<i32>::RING);
let mut B = OwnedMatrix::identity(2, 2, StaticRing::<i32>::RING);
let mut C = OwnedMatrix::identity(2, 2, StaticRing::<i32>::RING);
StaticRing::<i32>::RING.get_ring().solve_right(A.data_mut(), B.data_mut(), C.data_mut(), Global).assert_solved();

Implementations§

Source§

impl<T> OwnedMatrix<T>

Source

pub fn from_fn<F>(row_count: usize, col_count: usize, f: F) -> Self
where F: FnMut(usize, usize) -> T,

Creates the row_count x col_count OwnedMatrix whose (i, j)-th entry is the output of the given function on (i, j).

Source

pub fn zero<R: RingStore>(row_count: usize, col_count: usize, ring: R) -> Self
where R::Type: RingBase<Element = T>,

Creates the row_count x col_count zero matrix over the given ring.

Source

pub fn identity<R: RingStore>( row_count: usize, col_count: usize, ring: R, ) -> Self
where R::Type: RingBase<Element = T>,

Creates the row_count x col_count identity matrix over the given ring.

Source§

impl<T, A: Allocator> OwnedMatrix<T, A>

Source

pub fn new(data: Vec<T, A>, col_count: usize) -> Self

Creates the row_count x col_count OwnedMatrix matrix, whose entries are taken from the given vector, interpreted as a row-major matrix. The number of rows is row_count = data.len() / col_count.

If col_count is zero, this will panic. If that can happen, consider using OwnedMatrix::new_with_shape().

Source

pub fn new_with_shape( data: Vec<T, A>, row_count: usize, col_count: usize, ) -> Self

Creates the row_count x col_count OwnedMatrix matrix, whose entries are taken from the given vector, interpreted as a row-major matrix.

§Example
let matrix = OwnedMatrix::new_with_shape(vec![1, 2, 3, 4, 5, 6], 3, 2);
assert_eq!(3, *matrix.at(1, 0));
assert_eq!(6, *matrix.at(2, 1));
Source

pub fn from_fn_in<F>( row_count: usize, col_count: usize, f: F, allocator: A, ) -> Self
where F: FnMut(usize, usize) -> T,

Available on crate feature unstable-enable only.

Creates the row_count x col_count OwnedMatrix whose (i, j)-th entry is the output of the given function on (i, j).

§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn data<'a>(&'a self) -> Submatrix<'a, AsFirstElement<T>, T>

Returns a Submatrix view on the data of this matrix.

Source

pub fn data_mut<'a>(&'a mut self) -> SubmatrixMut<'a, AsFirstElement<T>, T>

Returns a SubmatrixMut view on the data of this matrix.

Source

pub fn at(&self, i: usize, j: usize) -> &T

Returns a reference to the (i, j)-th entry of this matrix.

Source

pub fn at_mut(&mut self, i: usize, j: usize) -> &mut T

Returns a mutable reference to the (i, j)-th entry of this matrix.

Source

pub fn row_count(&self) -> usize

Returns the number of rows of this matrix.

Source

pub fn col_count(&self) -> usize

Returns the number of columns of this matrix.

Source

pub fn zero_in<R: RingStore>( row_count: usize, col_count: usize, ring: R, allocator: A, ) -> Self
where R::Type: RingBase<Element = T>,

Available on crate feature unstable-enable only.

Creates the row_count x col_count zero matrix over the given ring.

§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn identity_in<R: RingStore>( row_count: usize, col_count: usize, ring: R, allocator: A, ) -> Self
where R::Type: RingBase<Element = T>,

Available on crate feature unstable-enable only.

Creates the row_count x col_count identity matrix over the given ring.

§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn clone_matrix<R: RingStore>(&self, ring: R) -> Self
where R::Type: RingBase<Element = T>, A: Clone,

Available on crate feature unstable-enable only.
§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_row_count<F>(&mut self, new_count: usize, new_entries: F)
where F: FnMut() -> T,

Available on crate feature unstable-enable only.
§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Trait Implementations§

Source§

impl<T: Debug, A: Allocator> Debug for OwnedMatrix<T, A>

Source§

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

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

impl<T> MatrixCompare<T> for OwnedMatrix<T>

Source§

fn col_count(&self) -> usize

Returns the number of columns of the matrix.
Source§

fn row_count(&self) -> usize

Returns the number of rows of the matrix.
Source§

fn at(&self, i: usize, j: usize) -> &T

Returns a reference to the element at the given position.

Auto Trait Implementations§

§

impl<T, A> Freeze for OwnedMatrix<T, A>
where A: Freeze,

§

impl<T, A> RefUnwindSafe for OwnedMatrix<T, A>

§

impl<T, A> Send for OwnedMatrix<T, A>
where A: Send, T: Send,

§

impl<T, A> Sync for OwnedMatrix<T, A>
where A: Sync, T: Sync,

§

impl<T, A> Unpin for OwnedMatrix<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnwindSafe for OwnedMatrix<T, A>
where A: UnwindSafe, 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.