Expand description
An owned matrix column-major matrix with R
rows and C
columns.
Because this is an alias, not all its methods are listed here. See the Matrix
type too.
Implementations
sourceimpl<T, D: DimName> OMatrix<T, D, D> where
T: Scalar + Zero + One,
DefaultAllocator: Allocator<T, D, D>,
impl<T, D: DimName> OMatrix<T, D, D> where
T: Scalar + Zero + One,
DefaultAllocator: Allocator<T, D, D>,
sourcepub fn new_scaling(scaling: T) -> Self
pub fn new_scaling(scaling: T) -> Self
Creates a new homogeneous matrix that applies the same scaling factor on each dimension.
sourcepub fn new_nonuniform_scaling<SB>(
scaling: &Vector<T, DimNameDiff<D, U1>, SB>
) -> Self where
D: DimNameSub<U1>,
SB: Storage<T, DimNameDiff<D, U1>>,
pub fn new_nonuniform_scaling<SB>(
scaling: &Vector<T, DimNameDiff<D, U1>, SB>
) -> Self where
D: DimNameSub<U1>,
SB: Storage<T, DimNameDiff<D, U1>>,
Creates a new homogeneous matrix that applies a distinct scaling factor for each dimension.
sourcepub fn new_translation<SB>(
translation: &Vector<T, DimNameDiff<D, U1>, SB>
) -> Self where
D: DimNameSub<U1>,
SB: Storage<T, DimNameDiff<D, U1>>,
pub fn new_translation<SB>(
translation: &Vector<T, DimNameDiff<D, U1>, SB>
) -> Self where
D: DimNameSub<U1>,
SB: Storage<T, DimNameDiff<D, U1>>,
Creates a new homogeneous matrix that applies a pure translation.
sourceimpl<T: Scalar, R: Dim, C: Dim> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
impl<T: Scalar, R: Dim, C: Dim> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
Generic constructors
This set of matrix and vector construction functions are all generic with-regard to the matrix dimensions. They all expect to be given the dimension as inputs.
These functions should only be used when working on dimension-generic code.
sourcepub unsafe fn new_uninitialized_generic(nrows: R, ncols: C) -> MaybeUninit<Self>
pub unsafe fn new_uninitialized_generic(nrows: R, ncols: C) -> MaybeUninit<Self>
Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics
if nrows != R::to_usize()
or ncols != C::to_usize()
.
sourcepub fn from_element_generic(nrows: R, ncols: C, elem: T) -> Self
pub fn from_element_generic(nrows: R, ncols: C, elem: T) -> Self
Creates a matrix with all its elements set to elem
.
sourcepub fn repeat_generic(nrows: R, ncols: C, elem: T) -> Self
pub fn repeat_generic(nrows: R, ncols: C, elem: T) -> Self
Creates a matrix with all its elements set to elem
.
Same as from_element_generic
.
sourcepub fn zeros_generic(nrows: R, ncols: C) -> Self where
T: Zero,
pub fn zeros_generic(nrows: R, ncols: C) -> Self where
T: Zero,
Creates a matrix with all its elements set to 0.
sourcepub fn from_iterator_generic<I>(nrows: R, ncols: C, iter: I) -> Self where
I: IntoIterator<Item = T>,
pub fn from_iterator_generic<I>(nrows: R, ncols: C, iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a matrix with all its elements filled by an iterator.
sourcepub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self
pub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in row-major order.
The order of elements in the slice must follow the usual mathematic writing, i.e., row-by-row.
sourcepub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self
pub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice. The components must have the same layout as the matrix data storage (i.e. column-major).
sourcepub fn from_fn_generic<F>(nrows: R, ncols: C, f: F) -> Self where
F: FnMut(usize, usize) -> T,
pub fn from_fn_generic<F>(nrows: R, ncols: C, f: F) -> Self where
F: FnMut(usize, usize) -> T,
Creates a matrix filled with the results of a function applied to each of its component coordinates.
sourcepub fn identity_generic(nrows: R, ncols: C) -> Self where
T: Zero + One,
pub fn identity_generic(nrows: R, ncols: C) -> Self where
T: Zero + One,
Creates a new identity matrix.
If the matrix is not square, the largest square submatrix starting at index (0, 0)
is set
to the identity matrix. All other entries are set to zero.
sourcepub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: T) -> Self where
T: Zero + One,
pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: T) -> Self where
T: Zero + One,
Creates a new matrix with its diagonal filled with copies of elt
.
If the matrix is not square, the largest square submatrix starting at index (0, 0)
is set
to the identity matrix. All other entries are set to zero.
sourcepub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[T]) -> Self where
T: Zero,
pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[T]) -> Self where
T: Zero,
Creates a new matrix that may be rectangular. The first elts.len()
diagonal elements are
filled with the content of elts
. Others are set to 0.
Panics if elts.len()
is larger than the minimum among nrows
and ncols
.
sourcepub fn from_rows<SB>(rows: &[Matrix<T, Const<1>, C, SB>]) -> Self where
SB: Storage<T, Const<1>, C>,
pub fn from_rows<SB>(rows: &[Matrix<T, Const<1>, C, SB>]) -> Self where
SB: Storage<T, Const<1>, C>,
Builds a new matrix from its rows.
Panics if not enough rows are provided (for statically-sized matrices), or if all rows do not have the same dimensions.
Example
let m = Matrix3::from_rows(&[ RowVector3::new(1.0, 2.0, 3.0), RowVector3::new(4.0, 5.0, 6.0), RowVector3::new(7.0, 8.0, 9.0) ]);
assert!(m.m11 == 1.0 && m.m12 == 2.0 && m.m13 == 3.0 &&
m.m21 == 4.0 && m.m22 == 5.0 && m.m23 == 6.0 &&
m.m31 == 7.0 && m.m32 == 8.0 && m.m33 == 9.0);
sourcepub fn from_columns<SB>(columns: &[Vector<T, R, SB>]) -> Self where
SB: Storage<T, R>,
pub fn from_columns<SB>(columns: &[Vector<T, R, SB>]) -> Self where
SB: Storage<T, R>,
Builds a new matrix from its columns.
Panics if not enough columns are provided (for statically-sized matrices), or if all columns do not have the same dimensions.
Example
let m = Matrix3::from_columns(&[ Vector3::new(1.0, 2.0, 3.0), Vector3::new(4.0, 5.0, 6.0), Vector3::new(7.0, 8.0, 9.0) ]);
assert!(m.m11 == 1.0 && m.m12 == 4.0 && m.m13 == 7.0 &&
m.m21 == 2.0 && m.m22 == 5.0 && m.m23 == 8.0 &&
m.m31 == 3.0 && m.m32 == 6.0 && m.m33 == 9.0);
sourcepub fn new_random_generic(nrows: R, ncols: C) -> Self where
Standard: Distribution<T>,
pub fn new_random_generic(nrows: R, ncols: C) -> Self where
Standard: Distribution<T>,
Creates a matrix filled with random values.
sourcepub fn from_distribution_generic<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: R,
ncols: C,
distribution: &Distr,
rng: &mut G
) -> Self
pub fn from_distribution_generic<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: R,
ncols: C,
distribution: &Distr,
rng: &mut G
) -> Self
Creates a matrix filled with random values from the given distribution.
sourcepub fn from_vec_generic(nrows: R, ncols: C, data: Vec<T>) -> Self
pub fn from_vec_generic(nrows: R, ncols: C, data: Vec<T>) -> Self
Creates a matrix backed by a given Vec
.
The output matrix is filled column-by-column.
Example
let vec = vec![0, 1, 2, 3, 4, 5];
let vec_ptr = vec.as_ptr();
let matrix = Matrix::from_vec_generic(Dynamic::new(vec.len()), Const::<1>, vec);
let matrix_storage_ptr = matrix.data.as_vec().as_ptr();
// `matrix` is backed by exactly the same `Vec` as it was constructed from.
assert_eq!(matrix_storage_ptr, vec_ptr);
sourceimpl<T, D: Dim> OMatrix<T, D, D> where
T: Scalar,
DefaultAllocator: Allocator<T, D, D>,
impl<T, D: Dim> OMatrix<T, D, D> where
T: Scalar,
DefaultAllocator: Allocator<T, D, D>,
sourcepub fn from_diagonal<SB: Storage<T, D>>(diag: &Vector<T, D, SB>) -> Self where
T: Zero,
pub fn from_diagonal<SB: Storage<T, D>>(diag: &Vector<T, D, SB>) -> Self where
T: Zero,
Creates a square matrix with its diagonal set to diag
and all other entries set to 0.
Example
let m = Matrix3::from_diagonal(&Vector3::new(1.0, 2.0, 3.0));
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_diagonal(&DVector::from_row_slice(&[1.0, 2.0, 3.0]));
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 2.0 && m.m23 == 0.0 &&
m.m31 == 0.0 && m.m32 == 0.0 && m.m33 == 3.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 0.0 &&
dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 3.0);
sourceimpl<T: Scalar, R: DimName, C: DimName> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
impl<T: Scalar, R: DimName, C: DimName> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
sourcepub unsafe fn new_uninitialized() -> MaybeUninit<Self>
pub unsafe fn new_uninitialized() -> MaybeUninit<Self>
Creates a new uninitialized matrix or vector.
sourcepub fn from_element(elem: T) -> Self
pub fn from_element(elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Example
let v = Vector3::from_element(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::from_element(3, 2.0);
let m = Matrix2x3::from_element(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_element(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn repeat(elem: T) -> Self
pub fn repeat(elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Same as .from_element
.
Example
let v = Vector3::repeat(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::repeat(3, 2.0);
let m = Matrix2x3::repeat(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::repeat(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn zeros() -> Self where
T: Zero,
pub fn zeros() -> Self where
T: Zero,
Creates a matrix or vector with all its elements set to 0
.
Example
let v = Vector3::<f32>::zeros();
// The argument represents the vector dimension.
let dv = DVector::<f32>::zeros(3);
let m = Matrix2x3::<f32>::zeros();
// The two arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::zeros(2, 3);
assert!(v.x == 0.0 && v.y == 0.0 && v.z == 0.0);
assert!(dv[0] == 0.0 && dv[1] == 0.0 && dv[2] == 0.0);
assert!(m.m11 == 0.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 0.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 0.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 0.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_iterator<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
pub fn from_iterator<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a matrix or vector with all its elements filled by an iterator.
The output matrix is filled column-by-column.
Example
let v = Vector3::from_iterator((0..3).into_iter());
// The additional argument represents the vector dimension.
let dv = DVector::from_iterator(3, (0..3).into_iter());
let m = Matrix2x3::from_iterator((0..6).into_iter());
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_iterator(2, 3, (0..6).into_iter());
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_fn<F>(f: F) -> Self where
F: FnMut(usize, usize) -> T,
pub fn from_fn<F>(f: F) -> Self where
F: FnMut(usize, usize) -> T,
Creates a matrix or vector filled with the results of a function applied to each of its component coordinates.
Example
let v = Vector3::from_fn(|i, _| i);
// The additional argument represents the vector dimension.
let dv = DVector::from_fn(3, |i, _| i);
let m = Matrix2x3::from_fn(|i, j| i * 3 + j);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_fn(2, 3, |i, j| i * 3 + j);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn identity() -> Self where
T: Zero + One,
pub fn identity() -> Self where
T: Zero + One,
Creates an identity matrix. If the matrix is not square, the largest square submatrix (starting at the first row and column) is set to the identity while all other entries are set to zero.
Example
let m = Matrix2x3::<f32>::identity();
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::identity(2, 3);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 1.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 1.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_diagonal_element(elt: T) -> Self where
T: Zero + One,
pub fn from_diagonal_element(elt: T) -> Self where
T: Zero + One,
Creates a matrix filled with its diagonal filled with elt
and all other
components set to zero.
Example
let m = Matrix2x3::from_diagonal_element(5.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_diagonal_element(2, 3, 5.0);
assert!(m.m11 == 5.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 5.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 5.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_partial_diagonal(elts: &[T]) -> Self where
T: Zero,
pub fn from_partial_diagonal(elts: &[T]) -> Self where
T: Zero,
Creates a new matrix that may be rectangular. The first elts.len()
diagonal
elements are filled with the content of elts
. Others are set to 0.
Panics if elts.len()
is larger than the minimum among nrows
and ncols
.
Example
let m = Matrix3::from_partial_diagonal(&[1.0, 2.0]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_partial_diagonal(3, 3, &[1.0, 2.0]);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 2.0 && m.m23 == 0.0 &&
m.m31 == 0.0 && m.m32 == 0.0 && m.m33 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 0.0 &&
dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0);
sourcepub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
distribution: &Distr,
rng: &mut G
) -> Self
pub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
distribution: &Distr,
rng: &mut G
) -> Self
Creates a matrix or vector filled with random values from the given distribution.
sourcepub fn new_random() -> Self where
Standard: Distribution<T>,
pub fn new_random() -> Self where
Standard: Distribution<T>,
Creates a matrix filled with random values.
sourceimpl<T: Scalar, R: DimName> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
impl<T: Scalar, R: DimName> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
sourcepub unsafe fn new_uninitialized(ncols: usize) -> MaybeUninit<Self>
pub unsafe fn new_uninitialized(ncols: usize) -> MaybeUninit<Self>
Creates a new uninitialized matrix or vector.
sourcepub fn from_element(ncols: usize, elem: T) -> Self
pub fn from_element(ncols: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Example
let v = Vector3::from_element(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::from_element(3, 2.0);
let m = Matrix2x3::from_element(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_element(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn repeat(ncols: usize, elem: T) -> Self
pub fn repeat(ncols: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Same as .from_element
.
Example
let v = Vector3::repeat(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::repeat(3, 2.0);
let m = Matrix2x3::repeat(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::repeat(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn zeros(ncols: usize) -> Self where
T: Zero,
pub fn zeros(ncols: usize) -> Self where
T: Zero,
Creates a matrix or vector with all its elements set to 0
.
Example
let v = Vector3::<f32>::zeros();
// The argument represents the vector dimension.
let dv = DVector::<f32>::zeros(3);
let m = Matrix2x3::<f32>::zeros();
// The two arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::zeros(2, 3);
assert!(v.x == 0.0 && v.y == 0.0 && v.z == 0.0);
assert!(dv[0] == 0.0 && dv[1] == 0.0 && dv[2] == 0.0);
assert!(m.m11 == 0.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 0.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 0.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 0.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_iterator<I>(ncols: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
pub fn from_iterator<I>(ncols: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a matrix or vector with all its elements filled by an iterator.
The output matrix is filled column-by-column.
Example
let v = Vector3::from_iterator((0..3).into_iter());
// The additional argument represents the vector dimension.
let dv = DVector::from_iterator(3, (0..3).into_iter());
let m = Matrix2x3::from_iterator((0..6).into_iter());
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_iterator(2, 3, (0..6).into_iter());
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_fn<F>(ncols: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
pub fn from_fn<F>(ncols: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
Creates a matrix or vector filled with the results of a function applied to each of its component coordinates.
Example
let v = Vector3::from_fn(|i, _| i);
// The additional argument represents the vector dimension.
let dv = DVector::from_fn(3, |i, _| i);
let m = Matrix2x3::from_fn(|i, j| i * 3 + j);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_fn(2, 3, |i, j| i * 3 + j);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn identity(ncols: usize) -> Self where
T: Zero + One,
pub fn identity(ncols: usize) -> Self where
T: Zero + One,
Creates an identity matrix. If the matrix is not square, the largest square submatrix (starting at the first row and column) is set to the identity while all other entries are set to zero.
Example
let m = Matrix2x3::<f32>::identity();
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::identity(2, 3);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 1.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 1.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_diagonal_element(ncols: usize, elt: T) -> Self where
T: Zero + One,
pub fn from_diagonal_element(ncols: usize, elt: T) -> Self where
T: Zero + One,
Creates a matrix filled with its diagonal filled with elt
and all other
components set to zero.
Example
let m = Matrix2x3::from_diagonal_element(5.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_diagonal_element(2, 3, 5.0);
assert!(m.m11 == 5.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 5.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 5.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_partial_diagonal(ncols: usize, elts: &[T]) -> Self where
T: Zero,
pub fn from_partial_diagonal(ncols: usize, elts: &[T]) -> Self where
T: Zero,
Creates a new matrix that may be rectangular. The first elts.len()
diagonal
elements are filled with the content of elts
. Others are set to 0.
Panics if elts.len()
is larger than the minimum among nrows
and ncols
.
Example
let m = Matrix3::from_partial_diagonal(&[1.0, 2.0]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_partial_diagonal(3, 3, &[1.0, 2.0]);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 2.0 && m.m23 == 0.0 &&
m.m31 == 0.0 && m.m32 == 0.0 && m.m33 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 0.0 &&
dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0);
sourcepub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
ncols: usize,
distribution: &Distr,
rng: &mut G
) -> Self
pub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
ncols: usize,
distribution: &Distr,
rng: &mut G
) -> Self
Creates a matrix or vector filled with random values from the given distribution.
sourcepub fn new_random(ncols: usize) -> Self where
Standard: Distribution<T>,
pub fn new_random(ncols: usize) -> Self where
Standard: Distribution<T>,
Creates a matrix filled with random values.
sourceimpl<T: Scalar, C: DimName> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
impl<T: Scalar, C: DimName> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
sourcepub unsafe fn new_uninitialized(nrows: usize) -> MaybeUninit<Self>
pub unsafe fn new_uninitialized(nrows: usize) -> MaybeUninit<Self>
Creates a new uninitialized matrix or vector.
sourcepub fn from_element(nrows: usize, elem: T) -> Self
pub fn from_element(nrows: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Example
let v = Vector3::from_element(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::from_element(3, 2.0);
let m = Matrix2x3::from_element(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_element(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn repeat(nrows: usize, elem: T) -> Self
pub fn repeat(nrows: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Same as .from_element
.
Example
let v = Vector3::repeat(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::repeat(3, 2.0);
let m = Matrix2x3::repeat(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::repeat(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn zeros(nrows: usize) -> Self where
T: Zero,
pub fn zeros(nrows: usize) -> Self where
T: Zero,
Creates a matrix or vector with all its elements set to 0
.
Example
let v = Vector3::<f32>::zeros();
// The argument represents the vector dimension.
let dv = DVector::<f32>::zeros(3);
let m = Matrix2x3::<f32>::zeros();
// The two arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::zeros(2, 3);
assert!(v.x == 0.0 && v.y == 0.0 && v.z == 0.0);
assert!(dv[0] == 0.0 && dv[1] == 0.0 && dv[2] == 0.0);
assert!(m.m11 == 0.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 0.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 0.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 0.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_iterator<I>(nrows: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
pub fn from_iterator<I>(nrows: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a matrix or vector with all its elements filled by an iterator.
The output matrix is filled column-by-column.
Example
let v = Vector3::from_iterator((0..3).into_iter());
// The additional argument represents the vector dimension.
let dv = DVector::from_iterator(3, (0..3).into_iter());
let m = Matrix2x3::from_iterator((0..6).into_iter());
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_iterator(2, 3, (0..6).into_iter());
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_fn<F>(nrows: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
pub fn from_fn<F>(nrows: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
Creates a matrix or vector filled with the results of a function applied to each of its component coordinates.
Example
let v = Vector3::from_fn(|i, _| i);
// The additional argument represents the vector dimension.
let dv = DVector::from_fn(3, |i, _| i);
let m = Matrix2x3::from_fn(|i, j| i * 3 + j);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_fn(2, 3, |i, j| i * 3 + j);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn identity(nrows: usize) -> Self where
T: Zero + One,
pub fn identity(nrows: usize) -> Self where
T: Zero + One,
Creates an identity matrix. If the matrix is not square, the largest square submatrix (starting at the first row and column) is set to the identity while all other entries are set to zero.
Example
let m = Matrix2x3::<f32>::identity();
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::identity(2, 3);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 1.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 1.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_diagonal_element(nrows: usize, elt: T) -> Self where
T: Zero + One,
pub fn from_diagonal_element(nrows: usize, elt: T) -> Self where
T: Zero + One,
Creates a matrix filled with its diagonal filled with elt
and all other
components set to zero.
Example
let m = Matrix2x3::from_diagonal_element(5.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_diagonal_element(2, 3, 5.0);
assert!(m.m11 == 5.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 5.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 5.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_partial_diagonal(nrows: usize, elts: &[T]) -> Self where
T: Zero,
pub fn from_partial_diagonal(nrows: usize, elts: &[T]) -> Self where
T: Zero,
Creates a new matrix that may be rectangular. The first elts.len()
diagonal
elements are filled with the content of elts
. Others are set to 0.
Panics if elts.len()
is larger than the minimum among nrows
and ncols
.
Example
let m = Matrix3::from_partial_diagonal(&[1.0, 2.0]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_partial_diagonal(3, 3, &[1.0, 2.0]);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 2.0 && m.m23 == 0.0 &&
m.m31 == 0.0 && m.m32 == 0.0 && m.m33 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 0.0 &&
dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0);
sourcepub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: usize,
distribution: &Distr,
rng: &mut G
) -> Self
pub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: usize,
distribution: &Distr,
rng: &mut G
) -> Self
Creates a matrix or vector filled with random values from the given distribution.
sourcepub fn new_random(nrows: usize) -> Self where
Standard: Distribution<T>,
pub fn new_random(nrows: usize) -> Self where
Standard: Distribution<T>,
Creates a matrix filled with random values.
sourceimpl<T: Scalar> OMatrix<T, Dynamic, Dynamic> where
DefaultAllocator: Allocator<T, Dynamic, Dynamic>,
impl<T: Scalar> OMatrix<T, Dynamic, Dynamic> where
DefaultAllocator: Allocator<T, Dynamic, Dynamic>,
sourcepub unsafe fn new_uninitialized(nrows: usize, ncols: usize) -> MaybeUninit<Self>
pub unsafe fn new_uninitialized(nrows: usize, ncols: usize) -> MaybeUninit<Self>
Creates a new uninitialized matrix or vector.
sourcepub fn from_element(nrows: usize, ncols: usize, elem: T) -> Self
pub fn from_element(nrows: usize, ncols: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Example
let v = Vector3::from_element(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::from_element(3, 2.0);
let m = Matrix2x3::from_element(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_element(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn repeat(nrows: usize, ncols: usize, elem: T) -> Self
pub fn repeat(nrows: usize, ncols: usize, elem: T) -> Self
Creates a matrix or vector with all its elements set to elem
.
Same as .from_element
.
Example
let v = Vector3::repeat(2.0);
// The additional argument represents the vector dimension.
let dv = DVector::repeat(3, 2.0);
let m = Matrix2x3::repeat(2.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::repeat(2, 3, 2.0);
assert!(v.x == 2.0 && v.y == 2.0 && v.z == 2.0);
assert!(dv[0] == 2.0 && dv[1] == 2.0 && dv[2] == 2.0);
assert!(m.m11 == 2.0 && m.m12 == 2.0 && m.m13 == 2.0 &&
m.m21 == 2.0 && m.m22 == 2.0 && m.m23 == 2.0);
assert!(dm[(0, 0)] == 2.0 && dm[(0, 1)] == 2.0 && dm[(0, 2)] == 2.0 &&
dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
sourcepub fn zeros(nrows: usize, ncols: usize) -> Self where
T: Zero,
pub fn zeros(nrows: usize, ncols: usize) -> Self where
T: Zero,
Creates a matrix or vector with all its elements set to 0
.
Example
let v = Vector3::<f32>::zeros();
// The argument represents the vector dimension.
let dv = DVector::<f32>::zeros(3);
let m = Matrix2x3::<f32>::zeros();
// The two arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::zeros(2, 3);
assert!(v.x == 0.0 && v.y == 0.0 && v.z == 0.0);
assert!(dv[0] == 0.0 && dv[1] == 0.0 && dv[2] == 0.0);
assert!(m.m11 == 0.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 0.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 0.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 0.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_iterator<I>(nrows: usize, ncols: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
pub fn from_iterator<I>(nrows: usize, ncols: usize, iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a matrix or vector with all its elements filled by an iterator.
The output matrix is filled column-by-column.
Example
let v = Vector3::from_iterator((0..3).into_iter());
// The additional argument represents the vector dimension.
let dv = DVector::from_iterator(3, (0..3).into_iter());
let m = Matrix2x3::from_iterator((0..6).into_iter());
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_iterator(2, 3, (0..6).into_iter());
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_fn<F>(nrows: usize, ncols: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
pub fn from_fn<F>(nrows: usize, ncols: usize, f: F) -> Self where
F: FnMut(usize, usize) -> T,
Creates a matrix or vector filled with the results of a function applied to each of its component coordinates.
Example
let v = Vector3::from_fn(|i, _| i);
// The additional argument represents the vector dimension.
let dv = DVector::from_fn(3, |i, _| i);
let m = Matrix2x3::from_fn(|i, j| i * 3 + j);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_fn(2, 3, |i, j| i * 3 + j);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn identity(nrows: usize, ncols: usize) -> Self where
T: Zero + One,
pub fn identity(nrows: usize, ncols: usize) -> Self where
T: Zero + One,
Creates an identity matrix. If the matrix is not square, the largest square submatrix (starting at the first row and column) is set to the identity while all other entries are set to zero.
Example
let m = Matrix2x3::<f32>::identity();
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::<f32>::identity(2, 3);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 1.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 1.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_diagonal_element(nrows: usize, ncols: usize, elt: T) -> Self where
T: Zero + One,
pub fn from_diagonal_element(nrows: usize, ncols: usize, elt: T) -> Self where
T: Zero + One,
Creates a matrix filled with its diagonal filled with elt
and all other
components set to zero.
Example
let m = Matrix2x3::from_diagonal_element(5.0);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_diagonal_element(2, 3, 5.0);
assert!(m.m11 == 5.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 5.0 && m.m23 == 0.0);
assert!(dm[(0, 0)] == 5.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0);
sourcepub fn from_partial_diagonal(nrows: usize, ncols: usize, elts: &[T]) -> Self where
T: Zero,
pub fn from_partial_diagonal(nrows: usize, ncols: usize, elts: &[T]) -> Self where
T: Zero,
Creates a new matrix that may be rectangular. The first elts.len()
diagonal
elements are filled with the content of elts
. Others are set to 0.
Panics if elts.len()
is larger than the minimum among nrows
and ncols
.
Example
let m = Matrix3::from_partial_diagonal(&[1.0, 2.0]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_partial_diagonal(3, 3, &[1.0, 2.0]);
assert!(m.m11 == 1.0 && m.m12 == 0.0 && m.m13 == 0.0 &&
m.m21 == 0.0 && m.m22 == 2.0 && m.m23 == 0.0 &&
m.m31 == 0.0 && m.m32 == 0.0 && m.m33 == 0.0);
assert!(dm[(0, 0)] == 1.0 && dm[(0, 1)] == 0.0 && dm[(0, 2)] == 0.0 &&
dm[(1, 0)] == 0.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 0.0 &&
dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0);
sourcepub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: usize,
ncols: usize,
distribution: &Distr,
rng: &mut G
) -> Self
pub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: usize,
ncols: usize,
distribution: &Distr,
rng: &mut G
) -> Self
Creates a matrix or vector filled with random values from the given distribution.
sourcepub fn new_random(nrows: usize, ncols: usize) -> Self where
Standard: Distribution<T>,
pub fn new_random(nrows: usize, ncols: usize) -> Self where
Standard: Distribution<T>,
Creates a matrix filled with random values.
sourceimpl<T: Scalar, R: DimName, C: DimName> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
impl<T: Scalar, R: DimName, C: DimName> OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
sourcepub fn from_row_slice(data: &[T]) -> Self
pub fn from_row_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in row-major order.
The order of elements in the slice must follow the usual mathematic writing, i.e., row-by-row.
Example
let v = Vector3::from_row_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_row_slice(&[0, 1, 2]);
let m = Matrix2x3::from_row_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_row_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn from_column_slice(data: &[T]) -> Self
pub fn from_column_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in column-major order.
Example
let v = Vector3::from_column_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_column_slice(&[0, 1, 2]);
let m = Matrix2x3::from_column_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_column_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_vec(data: Vec<T>) -> Self
pub fn from_vec(data: Vec<T>) -> Self
Creates a matrix backed by a given Vec
.
The output matrix is filled column-by-column.
Example
let m = Matrix2x3::from_vec(vec![0, 1, 2, 3, 4, 5]);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_vec(2, 3, vec![0, 1, 2, 3, 4, 5]);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourceimpl<T: Scalar, R: DimName> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
impl<T: Scalar, R: DimName> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
sourcepub fn from_row_slice(data: &[T]) -> Self
pub fn from_row_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in row-major order.
The order of elements in the slice must follow the usual mathematic writing, i.e., row-by-row.
Example
let v = Vector3::from_row_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_row_slice(&[0, 1, 2]);
let m = Matrix2x3::from_row_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_row_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn from_column_slice(data: &[T]) -> Self
pub fn from_column_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in column-major order.
Example
let v = Vector3::from_column_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_column_slice(&[0, 1, 2]);
let m = Matrix2x3::from_column_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_column_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_vec(data: Vec<T>) -> Self
pub fn from_vec(data: Vec<T>) -> Self
Creates a matrix backed by a given Vec
.
The output matrix is filled column-by-column.
Example
let m = Matrix2x3::from_vec(vec![0, 1, 2, 3, 4, 5]);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_vec(2, 3, vec![0, 1, 2, 3, 4, 5]);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourceimpl<T: Scalar, C: DimName> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
impl<T: Scalar, C: DimName> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
sourcepub fn from_row_slice(data: &[T]) -> Self
pub fn from_row_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in row-major order.
The order of elements in the slice must follow the usual mathematic writing, i.e., row-by-row.
Example
let v = Vector3::from_row_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_row_slice(&[0, 1, 2]);
let m = Matrix2x3::from_row_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_row_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn from_column_slice(data: &[T]) -> Self
pub fn from_column_slice(data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in column-major order.
Example
let v = Vector3::from_column_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_column_slice(&[0, 1, 2]);
let m = Matrix2x3::from_column_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_column_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_vec(data: Vec<T>) -> Self
pub fn from_vec(data: Vec<T>) -> Self
Creates a matrix backed by a given Vec
.
The output matrix is filled column-by-column.
Example
let m = Matrix2x3::from_vec(vec![0, 1, 2, 3, 4, 5]);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_vec(2, 3, vec![0, 1, 2, 3, 4, 5]);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourceimpl<T: Scalar> OMatrix<T, Dynamic, Dynamic> where
DefaultAllocator: Allocator<T, Dynamic, Dynamic>,
impl<T: Scalar> OMatrix<T, Dynamic, Dynamic> where
DefaultAllocator: Allocator<T, Dynamic, Dynamic>,
sourcepub fn from_row_slice(nrows: usize, ncols: usize, data: &[T]) -> Self
pub fn from_row_slice(nrows: usize, ncols: usize, data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in row-major order.
The order of elements in the slice must follow the usual mathematic writing, i.e., row-by-row.
Example
let v = Vector3::from_row_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_row_slice(&[0, 1, 2]);
let m = Matrix2x3::from_row_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_row_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 1 && m.m13 == 2 &&
m.m21 == 3 && m.m22 == 4 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 1 && dm[(0, 2)] == 2 &&
dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
sourcepub fn from_column_slice(nrows: usize, ncols: usize, data: &[T]) -> Self
pub fn from_column_slice(nrows: usize, ncols: usize, data: &[T]) -> Self
Creates a matrix with its elements filled with the components provided by a slice in column-major order.
Example
let v = Vector3::from_column_slice(&[0, 1, 2]);
// The additional argument represents the vector dimension.
let dv = DVector::from_column_slice(&[0, 1, 2]);
let m = Matrix2x3::from_column_slice(&[0, 1, 2, 3, 4, 5]);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_column_slice(2, 3, &[0, 1, 2, 3, 4, 5]);
assert!(v.x == 0 && v.y == 1 && v.z == 2);
assert!(dv[0] == 0 && dv[1] == 1 && dv[2] == 2);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourcepub fn from_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
pub fn from_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
Creates a matrix backed by a given Vec
.
The output matrix is filled column-by-column.
Example
let m = Matrix2x3::from_vec(vec![0, 1, 2, 3, 4, 5]);
assert!(m.m11 == 0 && m.m12 == 2 && m.m13 == 4 &&
m.m21 == 1 && m.m22 == 3 && m.m23 == 5);
// The two additional arguments represent the matrix dimensions.
let dm = DMatrix::from_vec(2, 3, vec![0, 1, 2, 3, 4, 5]);
assert!(dm[(0, 0)] == 0 && dm[(0, 1)] == 2 && dm[(0, 2)] == 4 &&
dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
sourceimpl<T: Scalar> OMatrix<T, Dynamic, Dynamic>
impl<T: Scalar> OMatrix<T, Dynamic, Dynamic>
sourcepub fn resize_mut(&mut self, new_nrows: usize, new_ncols: usize, val: T) where
DefaultAllocator: Reallocator<T, Dynamic, Dynamic, Dynamic, Dynamic>,
pub fn resize_mut(&mut self, new_nrows: usize, new_ncols: usize, val: T) where
DefaultAllocator: Reallocator<T, Dynamic, Dynamic, Dynamic, Dynamic>,
Resizes this matrix in-place.
The values are copied such that self[(i, j)] == result[(i, j)]
. If the result has more
rows and/or columns than self
, then the extra rows or columns are filled with val
.
Defined only for owned fully-dynamic matrices, i.e., DMatrix
.
sourceimpl<T: Scalar, C: Dim> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
impl<T: Scalar, C: Dim> OMatrix<T, Dynamic, C> where
DefaultAllocator: Allocator<T, Dynamic, C>,
sourcepub fn resize_vertically_mut(&mut self, new_nrows: usize, val: T) where
DefaultAllocator: Reallocator<T, Dynamic, C, Dynamic, C>,
pub fn resize_vertically_mut(&mut self, new_nrows: usize, val: T) where
DefaultAllocator: Reallocator<T, Dynamic, C, Dynamic, C>,
Changes the number of rows of this matrix in-place.
The values are copied such that self[(i, j)] == result[(i, j)]
. If the result has more
rows than self
, then the extra rows are filled with val
.
Defined only for owned matrices with a dynamic number of rows (for example, DVector
).
sourceimpl<T: Scalar, R: Dim> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
impl<T: Scalar, R: Dim> OMatrix<T, R, Dynamic> where
DefaultAllocator: Allocator<T, R, Dynamic>,
sourcepub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: T) where
DefaultAllocator: Reallocator<T, R, Dynamic, R, Dynamic>,
pub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: T) where
DefaultAllocator: Reallocator<T, R, Dynamic, R, Dynamic>,
Changes the number of column of this matrix in-place.
The values are copied such that self[(i, j)] == result[(i, j)]
. If the result has more
columns than self
, then the extra columns are filled with val
.
Defined only for owned matrices with a dynamic number of columns (for example, DVector
).
sourceimpl<T: ComplexField, D> OMatrix<T, D, D> where
D: DimMin<D, Output = D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<(usize, usize), DimMinimum<D, D>> + Allocator<T, D> + Allocator<T::RealField, D> + Allocator<T::RealField, D, D>,
impl<T: ComplexField, D> OMatrix<T, D, D> where
D: DimMin<D, Output = D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<(usize, usize), DimMinimum<D, D>> + Allocator<T, D> + Allocator<T::RealField, D> + Allocator<T::RealField, D, D>,
Trait Implementations
sourceimpl<T, R: DimName, C: DimName> Bounded for OMatrix<T, R, C> where
T: Scalar + Bounded,
DefaultAllocator: Allocator<T, R, C>,
impl<T, R: DimName, C: DimName> Bounded for OMatrix<T, R, C> where
T: Scalar + Bounded,
DefaultAllocator: Allocator<T, R, C>,
sourceimpl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 16]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 16]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 16]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 16]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
sourceimpl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 2]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 2]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 2]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 2]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
sourceimpl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 4]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 4]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 4]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 4]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
sourceimpl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 8]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 8]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[Matrix<<T as SimdValue>::Element, R, C, <DefaultAllocator as Allocator<<T as SimdValue>::Element, R, C>>::Buffer>; 8]> for OMatrix<T, R, C> where
T: From<[<T as SimdValue>::Element; 8]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
sourceimpl<T: SimdRealField, R, const D: usize> From<Isometry<T, R, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
R: SubsetOf<OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
impl<T: SimdRealField, R, const D: usize> From<Isometry<T, R, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
R: SubsetOf<OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
sourceimpl<T: SimdRealField, R, const D: usize> From<Similarity<T, R, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
R: SubsetOf<OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
impl<T: SimdRealField, R, const D: usize> From<Similarity<T, R, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
R: SubsetOf<OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
sourcefn from(sim: Similarity<T, R, D>) -> Self
fn from(sim: Similarity<T, R, D>) -> Self
Performs the conversion.
sourceimpl<T: RealField, C, const D: usize> From<Transform<T, C, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
C: TCategory,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
impl<T: RealField, C, const D: usize> From<Transform<T, C, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
C: TCategory,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
sourceimpl<T: Scalar + Zero + One, const D: usize> From<Translation<T, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, Const<D>>,
impl<T: Scalar + Zero + One, const D: usize> From<Translation<T, D>> for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> where
Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, Const<D>>,
sourcefn from(t: Translation<T, D>) -> Self
fn from(t: Translation<T, D>) -> Self
Performs the conversion.
sourceimpl<T: SimdComplexField, R: Dim, C: Dim> Normed for OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
impl<T: SimdComplexField, R: Dim, C: Dim> Normed for OMatrix<T, R, C> where
DefaultAllocator: Allocator<T, R, C>,
type Norm = T::SimdRealField
type Norm = T::SimdRealField
The type of the norm.
sourcefn norm(&self) -> T::SimdRealField
fn norm(&self) -> T::SimdRealField
Computes the norm.
sourcefn norm_squared(&self) -> T::SimdRealField
fn norm_squared(&self) -> T::SimdRealField
Computes the squared norm.
sourcefn unscale_mut(&mut self, n: Self::Norm)
fn unscale_mut(&mut self, n: Self::Norm)
Divides self
by n.
sourceimpl<T, D: DimName> One for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
impl<T, D: DimName> One for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
sourceimpl<'a, T, D: DimName> Product<&'a Matrix<T, D, D, <DefaultAllocator as Allocator<T, D, D>>::Buffer>> for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
impl<'a, T, D: DimName> Product<&'a Matrix<T, D, D, <DefaultAllocator as Allocator<T, D, D>>::Buffer>> for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
sourceimpl<T, D: DimName> Product<Matrix<T, D, D, <DefaultAllocator as Allocator<T, D, D>>::Buffer>> for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
impl<T, D: DimName> Product<Matrix<T, D, D, <DefaultAllocator as Allocator<T, D, D>>::Buffer>> for OMatrix<T, D, D> where
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
sourceimpl<T, R, C> SimdValue for OMatrix<T, R, C> where
T: Scalar + SimdValue,
R: Dim,
C: Dim,
T::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
impl<T, R, C> SimdValue for OMatrix<T, R, C> where
T: Scalar + SimdValue,
R: Dim,
C: Dim,
T::Element: Scalar,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
sourceunsafe fn extract_unchecked(&self, i: usize) -> Self::Element
unsafe fn extract_unchecked(&self, i: usize) -> Self::Element
Extracts the i-th lane of self
without bound-checking.
sourcefn replace(&mut self, i: usize, val: Self::Element)
fn replace(&mut self, i: usize, val: Self::Element)
Replaces the i-th lane of self
by val
. Read more
sourceunsafe fn replace_unchecked(&mut self, i: usize, val: Self::Element)
unsafe fn replace_unchecked(&mut self, i: usize, val: Self::Element)
Replaces the i-th lane of self
by val
without bound-checking.
sourcefn select(self, cond: Self::SimdBool, other: Self) -> Self
fn select(self, cond: Self::SimdBool, other: Self) -> Self
Merges self
and other
depending on the lanes of cond
. Read more
sourceimpl<T1, T2, R1, C1, R2, C2> SubsetOf<Matrix<T2, R2, C2, <DefaultAllocator as Allocator<T2, R2, C2>>::Buffer>> for OMatrix<T1, R1, C1> where
R1: Dim,
C1: Dim,
R2: Dim,
C2: Dim,
T1: Scalar,
T2: Scalar + SupersetOf<T1>,
DefaultAllocator: Allocator<T2, R2, C2> + Allocator<T1, R1, C1> + SameShapeAllocator<T1, R1, C1, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
impl<T1, T2, R1, C1, R2, C2> SubsetOf<Matrix<T2, R2, C2, <DefaultAllocator as Allocator<T2, R2, C2>>::Buffer>> for OMatrix<T1, R1, C1> where
R1: Dim,
C1: Dim,
R2: Dim,
C2: Dim,
T1: Scalar,
T2: Scalar + SupersetOf<T1>,
DefaultAllocator: Allocator<T2, R2, C2> + Allocator<T1, R1, C1> + SameShapeAllocator<T1, R1, C1, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
sourcefn to_superset(&self) -> OMatrix<T2, R2, C2>
fn to_superset(&self) -> OMatrix<T2, R2, C2>
The inclusion map: converts self
to the equivalent element of its superset.
sourcefn is_in_subset(m: &OMatrix<T2, R2, C2>) -> bool
fn is_in_subset(m: &OMatrix<T2, R2, C2>) -> bool
Checks if element
is actually part of the subset Self
(and can be converted to it).
sourcefn from_superset_unchecked(m: &OMatrix<T2, R2, C2>) -> Self
fn from_superset_unchecked(m: &OMatrix<T2, R2, C2>) -> Self
Use with care! Same as self.to_superset
but without any property checks. Always succeeds.
sourcefn from_superset(element: &T) -> Option<Self>
fn from_superset(element: &T) -> Option<Self>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
sourceimpl<'a, T, C: Dim> Sum<&'a Matrix<T, Dynamic, C, <DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer>> for OMatrix<T, Dynamic, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, Dynamic, C>,
impl<'a, T, C: Dim> Sum<&'a Matrix<T, Dynamic, C, <DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer>> for OMatrix<T, Dynamic, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, Dynamic, C>,
sourceimpl<'a, T, R: DimName, C: DimName> Sum<&'a Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>> for OMatrix<T, R, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, R, C>,
impl<'a, T, R: DimName, C: DimName> Sum<&'a Matrix<T, R, C, <DefaultAllocator as Allocator<T, R, C>>::Buffer>> for OMatrix<T, R, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, R, C>,
sourceimpl<T, C: Dim> Sum<Matrix<T, Dynamic, C, <DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer>> for OMatrix<T, Dynamic, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, Dynamic, C>,
impl<T, C: Dim> Sum<Matrix<T, Dynamic, C, <DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer>> for OMatrix<T, Dynamic, C> where
T: Scalar + ClosedAdd + Zero,
DefaultAllocator: Allocator<T, Dynamic, C>,
sourcefn sum<I: Iterator<Item = OMatrix<T, Dynamic, C>>>(
iter: I
) -> OMatrix<T, Dynamic, C>
fn sum<I: Iterator<Item = OMatrix<T, Dynamic, C>>>(
iter: I
) -> OMatrix<T, Dynamic, C>
Example
assert_eq!(vec![DVector::repeat(3, 1.0f64),
DVector::repeat(3, 1.0f64),
DVector::repeat(3, 1.0f64)].into_iter().sum::<DVector<f64>>(),
DVector::repeat(3, 1.0f64) + DVector::repeat(3, 1.0f64) + DVector::repeat(3, 1.0f64));
Panics
Panics if the iterator is empty:
iter::empty::<DMatrix<f64>>().sum::<DMatrix<f64>>(); // panics!