Type Definition nalgebra::base::MatrixMN

source ·
pub type MatrixMN<N, R, C> = Matrix<N, R, C, Owned<N, R, C>>;
Expand description

A statically sized column-major matrix with R rows and C columns.

Implementations§

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().

Creates a matrix with all its elements set to elem.

Creates a matrix with all its elements set to elem.

Same as from_element_generic.

Creates a matrix with all its elements set to 0.

Creates a matrix with all its elements filled by an iterator.

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.

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).

Creates a matrix filled with the results of a function applied to each of its component coordinates.

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.

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.

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.

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);

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);

Creates a matrix filled with random values.

Creates a matrix filled with random values from the given distribution.

Creates a new uninitialized matrix or vector.

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);

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);

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);

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);

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(3, &[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);

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(3, &[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);

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);

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);

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);

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);

Creates a matrix or vector filled with random values from the given distribution.

Creates a matrix filled with random values.

Creates a new uninitialized matrix or vector.

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);

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);

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);

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);

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(3, &[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);

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(3, &[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);

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);

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);

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);

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);

Creates a matrix or vector filled with random values from the given distribution.

Creates a matrix filled with random values.

Creates a new uninitialized matrix or vector.

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);

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);

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);

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);

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(3, &[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);

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(3, &[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);

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);

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);

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);

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);

Creates a matrix or vector filled with random values from the given distribution.

Creates a matrix filled with random values.

Creates a new uninitialized matrix or vector.

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);

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);

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);

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);

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(3, &[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);

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(3, &[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);

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);

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);

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);

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);

Creates a matrix or vector filled with random values from the given distribution.

Creates a matrix filled with random values.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Initializes this matrix from its components.

Trait Implementations§

Performs an operation.
Performs specific operation.
The underlying scalar field.
Multiplies an element of the ring with an element of the module.
Returns the largest finite number this type can represent
Returns the smallest finite number this type can represent
Performs the /= operation. Read more
Performs the /= operation. Read more
Orthonormalizes the given family of vectors. The largest free family of vectors is moved at the beginning of the array and its size is returned. Vectors at an indices larger or equal to this length can be modified to an arbitrary value. Read more
Applies the given closure to each element of the orthonormal basis of the subspace orthogonal to free family of vectors vs. If vs is not a free family, the result is unspecified. Read more
The vector space dimension.
The i-the canonical basis element.
The dot product between two vectors.
Same as &self[i] but without bound-checking.
Same as &mut self[i] but without bound-checking.
Applies the given closule to each element of this vector space’s canonical basis. Stops if f returns false. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The identity element.
Specific identity.
The result of inner product (same as the field used by this vector space).
Measures the angle between two vectors.
Computes the inner product of self with other.
Returns the inverse of self, relative to the operator O.
In-place inversin of self.
Returns the join (aka. supremum) of two values.
Returns the infimum and the supremum simultaneously.
Return the minimum of self and other if they are comparable.
Return the maximum of self and other if they are comparable.
Sorts two values in increasing order using a partial ordering.
Clamp value between min and max. Returns None if value is not comparable to min or max. Read more
Returns the meet (aka. infimum) of two values.
The underlying scalar field.
Performs the *= operation. Read more
Performs the *= operation. Read more
The squared norm of this vector.
The norm of this vector.
Returns a normalized version of this vector.
Normalizes this vector in-place and returns its norm.
Returns a normalized version of this vector unless its norm as smaller or equal to eps.
Normalizes this vector in-place or does nothing if its norm is smaller or equal to eps. Read more
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more
Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more
The underlying scalar field.
Returns the additive identity element of Self, 0. Read more
Returns true if self is equal to the additive identity.
Sets self to the additive identity element of Self, 0.