2021-04-29 23:06:52 +08:00
|
|
|
use nalgebra_macros::{dmatrix, matrix};
|
|
|
|
use nalgebra::{DMatrix, SMatrix, Matrix3x2, Matrix1x2, Matrix1x3, Matrix1x4, Matrix2x1, Matrix2, Matrix2x3, Matrix2x4, Matrix3x1, Matrix3, Matrix3x4, Matrix4x1, Matrix4x2, Matrix4x3, Matrix4};
|
2021-04-11 14:01:30 +08:00
|
|
|
|
|
|
|
#[test]
|
2021-04-12 14:36:38 +08:00
|
|
|
fn matrix_small_dims_exhaustive() {
|
|
|
|
// 0x0
|
2021-04-14 23:30:52 +08:00
|
|
|
assert_eq!(matrix![], SMatrix::<i32, 0, 0>::zeros());
|
2021-04-12 14:36:38 +08:00
|
|
|
|
|
|
|
// 1xN
|
2021-04-14 23:30:52 +08:00
|
|
|
assert_eq!(matrix![1], SMatrix::<i32, 1, 1>::new(1));
|
2021-04-12 14:36:38 +08:00
|
|
|
assert_eq!(matrix![1, 2], Matrix1x2::new(1, 2));
|
|
|
|
assert_eq!(matrix![1, 2, 3], Matrix1x3::new(1, 2, 3));
|
|
|
|
assert_eq!(matrix![1, 2, 3, 4], Matrix1x4::new(1, 2, 3, 4));
|
|
|
|
|
|
|
|
// 2xN
|
|
|
|
assert_eq!(matrix![1; 2], Matrix2x1::new(1, 2));
|
|
|
|
assert_eq!(matrix![1, 2; 3, 4], Matrix2::new(1, 2, 3, 4));
|
|
|
|
assert_eq!(matrix![1, 2, 3; 4, 5, 6], Matrix2x3::new(1, 2, 3, 4, 5, 6));
|
|
|
|
assert_eq!(matrix![1, 2, 3, 4; 5, 6, 7, 8], Matrix2x4::new(1, 2, 3, 4, 5, 6, 7, 8));
|
|
|
|
|
|
|
|
// 3xN
|
|
|
|
assert_eq!(matrix![1; 2; 3], Matrix3x1::new(1, 2, 3));
|
|
|
|
assert_eq!(matrix![1, 2; 3, 4; 5, 6], Matrix3x2::new(1, 2, 3, 4, 5, 6));
|
|
|
|
assert_eq!(matrix![1, 2, 3; 4, 5, 6; 7, 8, 9], Matrix3::new(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
|
|
|
assert_eq!(matrix![1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12],
|
|
|
|
Matrix3x4::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));
|
|
|
|
|
|
|
|
// 4xN
|
|
|
|
assert_eq!(matrix![1; 2; 3; 4], Matrix4x1::new(1, 2, 3, 4));
|
|
|
|
assert_eq!(matrix![1, 2; 3, 4; 5, 6; 7, 8], Matrix4x2::new(1, 2, 3, 4, 5, 6, 7, 8));
|
|
|
|
assert_eq!(matrix![1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12],
|
|
|
|
Matrix4x3::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));
|
|
|
|
assert_eq!(matrix![1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16],
|
|
|
|
Matrix4::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
|
2021-04-17 15:45:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn matrix_const_fn() {
|
|
|
|
// Ensure that matrix! can be used in const contexts
|
|
|
|
const _: SMatrix<i32, 0, 0> = matrix![];
|
|
|
|
const _: SMatrix<i32, 1, 2> = matrix![1, 2];
|
|
|
|
const _: SMatrix<i32, 2, 3> = matrix![1, 2, 3; 4, 5, 6];
|
2021-04-29 23:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dmatrix_small_dims_exhaustive() {
|
|
|
|
// 0x0
|
|
|
|
assert_eq!(dmatrix![], DMatrix::<i32>::zeros(0, 0));
|
|
|
|
|
|
|
|
// // 1xN
|
|
|
|
assert_eq!(dmatrix![1], SMatrix::<i32, 1, 1>::new(1));
|
|
|
|
assert_eq!(dmatrix![1, 2], Matrix1x2::new(1, 2));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3], Matrix1x3::new(1, 2, 3));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3, 4], Matrix1x4::new(1, 2, 3, 4));
|
|
|
|
|
|
|
|
// 2xN
|
|
|
|
assert_eq!(dmatrix![1; 2], Matrix2x1::new(1, 2));
|
|
|
|
assert_eq!(dmatrix![1, 2; 3, 4], Matrix2::new(1, 2, 3, 4));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3; 4, 5, 6], Matrix2x3::new(1, 2, 3, 4, 5, 6));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3, 4; 5, 6, 7, 8], Matrix2x4::new(1, 2, 3, 4, 5, 6, 7, 8));
|
|
|
|
|
|
|
|
// 3xN
|
|
|
|
assert_eq!(dmatrix![1; 2; 3], Matrix3x1::new(1, 2, 3));
|
|
|
|
assert_eq!(dmatrix![1, 2; 3, 4; 5, 6], Matrix3x2::new(1, 2, 3, 4, 5, 6));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3; 4, 5, 6; 7, 8, 9], Matrix3::new(1, 2, 3, 4, 5, 6, 7, 8, 9));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12],
|
|
|
|
Matrix3x4::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));
|
|
|
|
|
|
|
|
// 4xN
|
|
|
|
assert_eq!(dmatrix![1; 2; 3; 4], Matrix4x1::new(1, 2, 3, 4));
|
|
|
|
assert_eq!(dmatrix![1, 2; 3, 4; 5, 6; 7, 8], Matrix4x2::new(1, 2, 3, 4, 5, 6, 7, 8));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12],
|
|
|
|
Matrix4x3::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));
|
|
|
|
assert_eq!(dmatrix![1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12; 13, 14, 15, 16],
|
|
|
|
Matrix4::new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
|
|
|
|
}
|