Re-enable most tests.
This commit is contained in:
parent
9bd2890875
commit
5a4179c287
@ -1,19 +1,14 @@
|
||||
use num::{Zero, One};
|
||||
use num::{One, Zero};
|
||||
use num::Float;
|
||||
|
||||
use na::{self,
|
||||
DVector, DMatrix,
|
||||
Vector1, Vector2, Vector3, Vector4, Vector5, Vector6,
|
||||
RowVector3, RowVector4, RowVector5,
|
||||
Matrix2, Matrix3, Matrix4, Matrix5, Matrix6,
|
||||
Matrix2x3, Matrix3x2, Matrix3x4, Matrix4x3, Matrix2x4, Matrix4x5,
|
||||
MatrixMN};
|
||||
use na::dimension::{U8, U15};
|
||||
use na::{self, DMatrix, DVector, Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4,
|
||||
Matrix4, Matrix4x3, Matrix4x5, Matrix5, Matrix6, MatrixMN, RowVector3, RowVector4,
|
||||
RowVector5, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6};
|
||||
use na::dimension::{U15, U8};
|
||||
|
||||
#[test]
|
||||
fn iter() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
|
||||
let mut it = a.iter();
|
||||
assert_eq!(*it.next().unwrap(), 1.0);
|
||||
@ -66,35 +61,30 @@ fn iter() {
|
||||
fn debug_output_corresponds_to_data_container() {
|
||||
assert_eq!(
|
||||
format!("{:?}", Matrix2::new(1.0, 2.0, 3.0, 4.0)),
|
||||
"Matrix { data: [1, 3, 2, 4] }"
|
||||
"Matrix { data: [1.0, 3.0, 2.0, 4.0] }"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_column_major() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
|
||||
let expected = &[ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ];
|
||||
let expected = &[1.0, 4.0, 2.0, 5.0, 3.0, 6.0];
|
||||
|
||||
assert_eq!(a.as_slice(), expected);
|
||||
|
||||
let a = Matrix2x3::from_row_slice(&[1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0]);
|
||||
let a = Matrix2x3::from_row_slice(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
|
||||
|
||||
assert_eq!(a.as_slice(), expected);
|
||||
|
||||
let a = Matrix2x3::from_column_slice(&[1.0, 4.0,
|
||||
2.0, 5.0,
|
||||
3.0, 6.0]);
|
||||
let a = Matrix2x3::from_column_slice(&[1.0, 4.0, 2.0, 5.0, 3.0, 6.0]);
|
||||
|
||||
assert_eq!(a.as_slice(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linear_index() {
|
||||
let a = Matrix2x3::new(1, 2, 3,
|
||||
4, 5, 6);
|
||||
let a = Matrix2x3::new(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assert_eq!(a[0], 1);
|
||||
assert_eq!(a[1], 4);
|
||||
@ -121,25 +111,14 @@ fn linear_index() {
|
||||
#[test]
|
||||
fn identity() {
|
||||
let id1 = Matrix3::<f64>::identity();
|
||||
let id2 = Matrix3x4::new(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0);
|
||||
let id2 = Matrix3x4::new(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
|
||||
let id2bis = Matrix3x4::identity();
|
||||
let id3 = Matrix4x3::new(1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0,
|
||||
0.0, 0.0, 0.0);
|
||||
let id3 = Matrix4x3::new(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
|
||||
let id3bis = Matrix4x3::identity();
|
||||
|
||||
|
||||
let not_id1 = Matrix3::identity() * 2.0;
|
||||
let not_id2 = Matrix3x4::new(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 1.0);
|
||||
let not_id3 = Matrix4x3::new(1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0,
|
||||
0.0, 1.0, 0.0);
|
||||
let not_id2 = Matrix3x4::new(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0);
|
||||
let not_id3 = Matrix4x3::new(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0);
|
||||
|
||||
assert_eq!(id2, id2bis);
|
||||
assert_eq!(id3, id3bis);
|
||||
@ -153,9 +132,7 @@ fn identity() {
|
||||
|
||||
#[test]
|
||||
fn coordinates() {
|
||||
let a = Matrix3x4::new(11, 12, 13, 14,
|
||||
21, 22, 23, 24,
|
||||
31, 32, 33, 34);
|
||||
let a = Matrix3x4::new(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34);
|
||||
|
||||
assert_eq!(a.m11, 11);
|
||||
assert_eq!(a.m12, 12);
|
||||
@ -176,10 +153,7 @@ fn coordinates() {
|
||||
#[test]
|
||||
fn from_diagonal() {
|
||||
let diag = Vector3::new(1, 2, 3);
|
||||
let expected = Matrix3::new(
|
||||
1, 0, 0,
|
||||
0, 2, 0,
|
||||
0, 0, 3);
|
||||
let expected = Matrix3::new(1, 0, 0, 0, 2, 0, 0, 0, 3);
|
||||
let a = Matrix3::from_diagonal(&diag);
|
||||
|
||||
assert_eq!(a, expected);
|
||||
@ -190,13 +164,10 @@ fn from_rows() {
|
||||
let rows = &[
|
||||
RowVector4::new(11, 12, 13, 14),
|
||||
RowVector4::new(21, 22, 23, 24),
|
||||
RowVector4::new(31, 32, 33, 34)
|
||||
RowVector4::new(31, 32, 33, 34),
|
||||
];
|
||||
|
||||
let expected = Matrix3x4::new(
|
||||
11, 12, 13, 14,
|
||||
21, 22, 23, 24,
|
||||
31, 32, 33, 34);
|
||||
let expected = Matrix3x4::new(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34);
|
||||
|
||||
let a = Matrix3x4::from_rows(rows);
|
||||
|
||||
@ -209,13 +180,10 @@ fn from_columns() {
|
||||
Vector3::new(11, 21, 31),
|
||||
Vector3::new(12, 22, 32),
|
||||
Vector3::new(13, 23, 33),
|
||||
Vector3::new(14, 24, 34)
|
||||
Vector3::new(14, 24, 34),
|
||||
];
|
||||
|
||||
let expected = Matrix3x4::new(
|
||||
11, 12, 13, 14,
|
||||
21, 22, 23, 24,
|
||||
31, 32, 33, 34);
|
||||
let expected = Matrix3x4::new(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34);
|
||||
|
||||
let a = Matrix3x4::from_columns(columns);
|
||||
|
||||
@ -228,13 +196,10 @@ fn from_columns_dynamic() {
|
||||
DVector::from_row_slice(3, &[11, 21, 31]),
|
||||
DVector::from_row_slice(3, &[12, 22, 32]),
|
||||
DVector::from_row_slice(3, &[13, 23, 33]),
|
||||
DVector::from_row_slice(3, &[14, 24, 34])
|
||||
DVector::from_row_slice(3, &[14, 24, 34]),
|
||||
];
|
||||
|
||||
let expected = DMatrix::from_row_slice(3, 4,
|
||||
&[ 11, 12, 13, 14,
|
||||
21, 22, 23, 24,
|
||||
31, 32, 33, 34 ]);
|
||||
let expected = DMatrix::from_row_slice(3, 4, &[11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34]);
|
||||
|
||||
let a = DMatrix::from_columns(columns);
|
||||
|
||||
@ -248,7 +213,7 @@ fn from_too_many_rows() {
|
||||
RowVector4::new(11, 12, 13, 14),
|
||||
RowVector4::new(21, 22, 23, 24),
|
||||
RowVector4::new(31, 32, 33, 34),
|
||||
RowVector4::new(31, 32, 33, 34)
|
||||
RowVector4::new(31, 32, 33, 34),
|
||||
];
|
||||
|
||||
let _ = Matrix3x4::from_rows(rows);
|
||||
@ -257,10 +222,7 @@ fn from_too_many_rows() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn from_not_enough_columns() {
|
||||
let columns = &[
|
||||
Vector3::new(11, 21, 31),
|
||||
Vector3::new(14, 24, 34)
|
||||
];
|
||||
let columns = &[Vector3::new(11, 21, 31), Vector3::new(14, 24, 34)];
|
||||
|
||||
let _ = Matrix3x4::from_columns(columns);
|
||||
}
|
||||
@ -269,8 +231,8 @@ fn from_not_enough_columns() {
|
||||
#[should_panic]
|
||||
fn from_rows_with_different_dimensions() {
|
||||
let columns = &[
|
||||
DVector::from_row_slice(3, &[ 11, 21, 31 ]),
|
||||
DVector::from_row_slice(3, &[ 12, 22, 32, 33 ])
|
||||
DVector::from_row_slice(3, &[11, 21, 31]),
|
||||
DVector::from_row_slice(3, &[12, 22, 32, 33]),
|
||||
];
|
||||
|
||||
let _ = DMatrix::from_columns(columns);
|
||||
@ -278,11 +240,11 @@ fn from_rows_with_different_dimensions() {
|
||||
|
||||
#[test]
|
||||
fn to_homogeneous() {
|
||||
let a = Vector3::new(1.0, 2.0, 3.0);
|
||||
let a = Vector3::new(1.0, 2.0, 3.0);
|
||||
let expected_a = Vector4::new(1.0, 2.0, 3.0, 0.0);
|
||||
|
||||
let b = DVector::from_row_slice(3, &[ 1.0, 2.0, 3.0 ]);
|
||||
let expected_b = DVector::from_row_slice(4, &[ 1.0, 2.0, 3.0, 0.0 ]);
|
||||
let b = DVector::from_row_slice(3, &[1.0, 2.0, 3.0]);
|
||||
let expected_b = DVector::from_row_slice(4, &[1.0, 2.0, 3.0, 0.0]);
|
||||
|
||||
assert_eq!(a.to_homogeneous(), expected_a);
|
||||
assert_eq!(b.to_homogeneous(), expected_b);
|
||||
@ -290,39 +252,32 @@ fn to_homogeneous() {
|
||||
|
||||
#[test]
|
||||
fn simple_add() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
|
||||
let b = Matrix2x3::new(10.0, 20.0, 30.0,
|
||||
40.0, 50.0, 60.0);
|
||||
let c = DMatrix::from_row_slice(2, 3, &[ 10.0, 20.0, 30.0,
|
||||
40.0, 50.0, 60.0 ]);
|
||||
let b = Matrix2x3::new(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
|
||||
let c = DMatrix::from_row_slice(2, 3, &[10.0, 20.0, 30.0, 40.0, 50.0, 60.0]);
|
||||
|
||||
let expected = Matrix2x3::new(11.0, 22.0, 33.0,
|
||||
44.0, 55.0, 66.0);
|
||||
let expected = Matrix2x3::new(11.0, 22.0, 33.0, 44.0, 55.0, 66.0);
|
||||
|
||||
assert_eq!(expected, &a + &b);
|
||||
assert_eq!(expected, &a + b);
|
||||
assert_eq!(expected, a + &b);
|
||||
assert_eq!(expected, a + b);
|
||||
assert_eq!(expected, &a + b);
|
||||
assert_eq!(expected, a + &b);
|
||||
assert_eq!(expected, a + b);
|
||||
|
||||
// Sum of a static matrix with a dynamic one.
|
||||
assert_eq!(expected, &a + &c);
|
||||
assert_eq!(expected, a + &c);
|
||||
assert_eq!(expected, a + &c);
|
||||
assert_eq!(expected, &c + &a);
|
||||
assert_eq!(expected, &c + a);
|
||||
assert_eq!(expected, &c + a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_sum() {
|
||||
type M = Matrix2x3<f32>;
|
||||
|
||||
let a = M::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let b = M::new(10.0, 20.0, 30.0,
|
||||
40.0, 50.0, 60.0);
|
||||
let c = M::new(100.0, 200.0, 300.0,
|
||||
400.0, 500.0, 600.0);
|
||||
let a = M::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
let b = M::new(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
|
||||
let c = M::new(100.0, 200.0, 300.0, 400.0, 500.0, 600.0);
|
||||
|
||||
assert_eq!(M::zero(), Vec::<M>::new().iter().sum());
|
||||
assert_eq!(M::zero(), Vec::<M>::new().into_iter().sum());
|
||||
@ -334,49 +289,60 @@ fn simple_sum() {
|
||||
|
||||
#[test]
|
||||
fn simple_scalar_mul() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
|
||||
let expected = Matrix2x3::new(10.0, 20.0, 30.0,
|
||||
40.0, 50.0, 60.0);
|
||||
let expected = Matrix2x3::new(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
|
||||
|
||||
assert_eq!(expected, a * 10.0);
|
||||
assert_eq!(expected, a * 10.0);
|
||||
assert_eq!(expected, &a * 10.0);
|
||||
assert_eq!(expected, 10.0 * a);
|
||||
assert_eq!(expected, 10.0 * a);
|
||||
assert_eq!(expected, 10.0 * &a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_mul() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
|
||||
let b = Matrix3x4::new(10.0, 20.0, 30.0, 40.0,
|
||||
50.0, 60.0, 70.0, 80.0,
|
||||
90.0, 100.0, 110.0, 120.0);
|
||||
let b = Matrix3x4::new(
|
||||
10.0,
|
||||
20.0,
|
||||
30.0,
|
||||
40.0,
|
||||
50.0,
|
||||
60.0,
|
||||
70.0,
|
||||
80.0,
|
||||
90.0,
|
||||
100.0,
|
||||
110.0,
|
||||
120.0,
|
||||
);
|
||||
|
||||
let expected = Matrix2x4::new(380.0, 440.0, 500.0, 560.0,
|
||||
830.0, 980.0, 1130.0, 1280.0);
|
||||
let expected = Matrix2x4::new(380.0, 440.0, 500.0, 560.0, 830.0, 980.0, 1130.0, 1280.0);
|
||||
|
||||
assert_eq!(expected, &a * &b);
|
||||
assert_eq!(expected, a * &b);
|
||||
assert_eq!(expected, &a * b);
|
||||
assert_eq!(expected, a * b);
|
||||
assert_eq!(expected, a * &b);
|
||||
assert_eq!(expected, &a * b);
|
||||
assert_eq!(expected, a * b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_product() {
|
||||
type M = Matrix3<f32>;
|
||||
|
||||
let a = M::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0,
|
||||
7.0, 8.0, 9.0);
|
||||
let b = M::new(10.0, 20.0, 30.0,
|
||||
40.0, 50.0, 60.0,
|
||||
70.0, 80.0, 90.0);
|
||||
let c = M::new(100.0, 200.0, 300.0,
|
||||
400.0, 500.0, 600.0,
|
||||
700.0, 800.0, 900.0);
|
||||
let a = M::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
|
||||
let b = M::new(10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0);
|
||||
let c = M::new(
|
||||
100.0,
|
||||
200.0,
|
||||
300.0,
|
||||
400.0,
|
||||
500.0,
|
||||
600.0,
|
||||
700.0,
|
||||
800.0,
|
||||
900.0,
|
||||
);
|
||||
|
||||
assert_eq!(M::one(), Vec::<M>::new().iter().product());
|
||||
assert_eq!(M::one(), Vec::<M>::new().into_iter().product());
|
||||
@ -399,19 +365,20 @@ fn cross_product_vector_and_row_vector() {
|
||||
assert_eq!(row_cross, RowVector3::new(-1.0, -4.0, 3.0));
|
||||
|
||||
assert_eq!(
|
||||
Vector3::new(1.0, 1.0, 0.0).cross(&Vector3::new(-0.5, 17.0, 0.0)).transpose(),
|
||||
RowVector3::new(1.0, 1.0, 0.0).cross(&RowVector3::new(-0.5, 17.0, 0.0)));
|
||||
Vector3::new(1.0, 1.0, 0.0)
|
||||
.cross(&Vector3::new(-0.5, 17.0, 0.0))
|
||||
.transpose(),
|
||||
RowVector3::new(1.0, 1.0, 0.0).cross(&RowVector3::new(-0.5, 17.0, 0.0))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_scalar_conversion() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let expected = Matrix2x3::new(1, 2, 3,
|
||||
4, 5, 6);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
let expected = Matrix2x3::new(1, 2, 3, 4, 5, 6);
|
||||
|
||||
let a_u32: Matrix2x3<u32> = na::try_convert(a).unwrap(); // f32 -> u32
|
||||
let a_f32: Matrix2x3<f32> = na::convert(a_u32); // u32 -> f32
|
||||
let a_f32: Matrix2x3<f32> = na::convert(a_u32); // u32 -> f32
|
||||
|
||||
assert_eq!(a, a_f32);
|
||||
assert_eq!(expected, a_u32);
|
||||
@ -420,16 +387,42 @@ fn simple_scalar_conversion() {
|
||||
#[test]
|
||||
fn apply() {
|
||||
let mut a = Matrix4::new(
|
||||
1.1, 2.2, 3.3, 4.4,
|
||||
5.5, 6.6, 7.7, 8.8,
|
||||
9.9, 8.8, 7.7, 6.6,
|
||||
5.5, 4.4, 3.3, 2.2);
|
||||
1.1,
|
||||
2.2,
|
||||
3.3,
|
||||
4.4,
|
||||
5.5,
|
||||
6.6,
|
||||
7.7,
|
||||
8.8,
|
||||
9.9,
|
||||
8.8,
|
||||
7.7,
|
||||
6.6,
|
||||
5.5,
|
||||
4.4,
|
||||
3.3,
|
||||
2.2,
|
||||
);
|
||||
|
||||
let expected = Matrix4::new(
|
||||
1.0, 2.0, 3.0, 4.0,
|
||||
6.0, 7.0, 8.0, 9.0,
|
||||
10.0, 9.0, 8.0, 7.0,
|
||||
6.0, 4.0, 3.0, 2.0);
|
||||
1.0,
|
||||
2.0,
|
||||
3.0,
|
||||
4.0,
|
||||
6.0,
|
||||
7.0,
|
||||
8.0,
|
||||
9.0,
|
||||
10.0,
|
||||
9.0,
|
||||
8.0,
|
||||
7.0,
|
||||
6.0,
|
||||
4.0,
|
||||
3.0,
|
||||
2.0,
|
||||
);
|
||||
|
||||
a.apply(|e| e.round());
|
||||
|
||||
@ -439,16 +432,25 @@ fn apply() {
|
||||
#[test]
|
||||
fn map() {
|
||||
let a = Matrix4::new(
|
||||
1.1f64, 2.2, 3.3, 4.4,
|
||||
5.5, 6.6, 7.7, 8.8,
|
||||
9.9, 8.8, 7.7, 6.6,
|
||||
5.5, 4.4, 3.3, 2.2);
|
||||
1.1f64,
|
||||
2.2,
|
||||
3.3,
|
||||
4.4,
|
||||
5.5,
|
||||
6.6,
|
||||
7.7,
|
||||
8.8,
|
||||
9.9,
|
||||
8.8,
|
||||
7.7,
|
||||
6.6,
|
||||
5.5,
|
||||
4.4,
|
||||
3.3,
|
||||
2.2,
|
||||
);
|
||||
|
||||
let expected = Matrix4::new(
|
||||
1, 2, 3, 4,
|
||||
6, 7, 8, 9,
|
||||
10, 9, 8, 7,
|
||||
6, 4, 3, 2);
|
||||
let expected = Matrix4::new(1, 2, 3, 4, 6, 7, 8, 9, 10, 9, 8, 7, 6, 4, 3, 2);
|
||||
|
||||
let computed = a.map(|e| e.round() as i64);
|
||||
|
||||
@ -457,20 +459,11 @@ fn map() {
|
||||
|
||||
#[test]
|
||||
fn zip_map() {
|
||||
let a = Matrix3::new(
|
||||
11i32, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33);
|
||||
let a = Matrix3::new(11i32, 12, 13, 21, 22, 23, 31, 32, 33);
|
||||
|
||||
let b = Matrix3::new(
|
||||
11u32, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33);
|
||||
let b = Matrix3::new(11u32, 12, 13, 21, 22, 23, 31, 32, 33);
|
||||
|
||||
let expected = Matrix3::new(
|
||||
22.0f32, 24.0, 26.0,
|
||||
42.0, 44.0, 46.0,
|
||||
62.0, 64.0, 66.0);
|
||||
let expected = Matrix3::new(22.0f32, 24.0, 26.0, 42.0, 44.0, 46.0, 62.0, 64.0, 66.0);
|
||||
|
||||
let computed = a.zip_map(&b, |ea, eb| ea as f32 + eb as f32);
|
||||
|
||||
@ -486,30 +479,22 @@ fn trace_panic() {
|
||||
|
||||
#[test]
|
||||
fn trace() {
|
||||
let m = Matrix2::new(1.0, 20.0,
|
||||
30.0, 4.0);
|
||||
let m = Matrix2::new(1.0, 20.0, 30.0, 4.0);
|
||||
assert_eq!(m.trace(), 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_transpose() {
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0);
|
||||
let expected = Matrix3x2::new(1.0, 4.0,
|
||||
2.0, 5.0,
|
||||
3.0, 6.0);
|
||||
let a = Matrix2x3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
||||
let expected = Matrix3x2::new(1.0, 4.0, 2.0, 5.0, 3.0, 6.0);
|
||||
|
||||
assert_eq!(a.transpose(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_transpose_mut() {
|
||||
let mut a = Matrix3::new(1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0,
|
||||
7.0, 8.0, 9.0);
|
||||
let expected = Matrix3::new(1.0, 4.0, 7.0,
|
||||
2.0, 5.0, 8.0,
|
||||
3.0, 6.0, 9.0);
|
||||
let mut a = Matrix3::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
|
||||
let expected = Matrix3::new(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0);
|
||||
|
||||
a.transpose_mut();
|
||||
assert_eq!(a, expected);
|
||||
@ -538,30 +523,100 @@ fn components_mut() {
|
||||
let mut m5 = Matrix5::from_element(1.0);
|
||||
let mut m6 = Matrix6::from_element(1.0);
|
||||
|
||||
m2.m11 = 0.0; m2.m12 = 0.0;
|
||||
m2.m21 = 0.0; m2.m22 = 0.0;
|
||||
m2.m11 = 0.0;
|
||||
m2.m12 = 0.0;
|
||||
m2.m21 = 0.0;
|
||||
m2.m22 = 0.0;
|
||||
|
||||
m3.m11 = 0.0; m3.m12 = 0.0; m3.m13 = 0.0;
|
||||
m3.m21 = 0.0; m3.m22 = 0.0; m3.m23 = 0.0;
|
||||
m3.m31 = 0.0; m3.m32 = 0.0; m3.m33 = 0.0;
|
||||
m3.m11 = 0.0;
|
||||
m3.m12 = 0.0;
|
||||
m3.m13 = 0.0;
|
||||
m3.m21 = 0.0;
|
||||
m3.m22 = 0.0;
|
||||
m3.m23 = 0.0;
|
||||
m3.m31 = 0.0;
|
||||
m3.m32 = 0.0;
|
||||
m3.m33 = 0.0;
|
||||
|
||||
m4.m11 = 0.0; m4.m12 = 0.0; m4.m13 = 0.0; m4.m14 = 0.0;
|
||||
m4.m21 = 0.0; m4.m22 = 0.0; m4.m23 = 0.0; m4.m24 = 0.0;
|
||||
m4.m31 = 0.0; m4.m32 = 0.0; m4.m33 = 0.0; m4.m34 = 0.0;
|
||||
m4.m41 = 0.0; m4.m42 = 0.0; m4.m43 = 0.0; m4.m44 = 0.0;
|
||||
m4.m11 = 0.0;
|
||||
m4.m12 = 0.0;
|
||||
m4.m13 = 0.0;
|
||||
m4.m14 = 0.0;
|
||||
m4.m21 = 0.0;
|
||||
m4.m22 = 0.0;
|
||||
m4.m23 = 0.0;
|
||||
m4.m24 = 0.0;
|
||||
m4.m31 = 0.0;
|
||||
m4.m32 = 0.0;
|
||||
m4.m33 = 0.0;
|
||||
m4.m34 = 0.0;
|
||||
m4.m41 = 0.0;
|
||||
m4.m42 = 0.0;
|
||||
m4.m43 = 0.0;
|
||||
m4.m44 = 0.0;
|
||||
|
||||
m5.m11 = 0.0; m5.m12 = 0.0; m5.m13 = 0.0; m5.m14 = 0.0; m5.m15 = 0.0;
|
||||
m5.m21 = 0.0; m5.m22 = 0.0; m5.m23 = 0.0; m5.m24 = 0.0; m5.m25 = 0.0;
|
||||
m5.m31 = 0.0; m5.m32 = 0.0; m5.m33 = 0.0; m5.m34 = 0.0; m5.m35 = 0.0;
|
||||
m5.m41 = 0.0; m5.m42 = 0.0; m5.m43 = 0.0; m5.m44 = 0.0; m5.m45 = 0.0;
|
||||
m5.m51 = 0.0; m5.m52 = 0.0; m5.m53 = 0.0; m5.m54 = 0.0; m5.m55 = 0.0;
|
||||
m5.m11 = 0.0;
|
||||
m5.m12 = 0.0;
|
||||
m5.m13 = 0.0;
|
||||
m5.m14 = 0.0;
|
||||
m5.m15 = 0.0;
|
||||
m5.m21 = 0.0;
|
||||
m5.m22 = 0.0;
|
||||
m5.m23 = 0.0;
|
||||
m5.m24 = 0.0;
|
||||
m5.m25 = 0.0;
|
||||
m5.m31 = 0.0;
|
||||
m5.m32 = 0.0;
|
||||
m5.m33 = 0.0;
|
||||
m5.m34 = 0.0;
|
||||
m5.m35 = 0.0;
|
||||
m5.m41 = 0.0;
|
||||
m5.m42 = 0.0;
|
||||
m5.m43 = 0.0;
|
||||
m5.m44 = 0.0;
|
||||
m5.m45 = 0.0;
|
||||
m5.m51 = 0.0;
|
||||
m5.m52 = 0.0;
|
||||
m5.m53 = 0.0;
|
||||
m5.m54 = 0.0;
|
||||
m5.m55 = 0.0;
|
||||
|
||||
m6.m11 = 0.0; m6.m12 = 0.0; m6.m13 = 0.0; m6.m14 = 0.0; m6.m15 = 0.0; m6.m16 = 0.0;
|
||||
m6.m21 = 0.0; m6.m22 = 0.0; m6.m23 = 0.0; m6.m24 = 0.0; m6.m25 = 0.0; m6.m26 = 0.0;
|
||||
m6.m31 = 0.0; m6.m32 = 0.0; m6.m33 = 0.0; m6.m34 = 0.0; m6.m35 = 0.0; m6.m36 = 0.0;
|
||||
m6.m41 = 0.0; m6.m42 = 0.0; m6.m43 = 0.0; m6.m44 = 0.0; m6.m45 = 0.0; m6.m46 = 0.0;
|
||||
m6.m51 = 0.0; m6.m52 = 0.0; m6.m53 = 0.0; m6.m54 = 0.0; m6.m55 = 0.0; m6.m56 = 0.0;
|
||||
m6.m61 = 0.0; m6.m62 = 0.0; m6.m63 = 0.0; m6.m64 = 0.0; m6.m65 = 0.0; m6.m66 = 0.0;
|
||||
m6.m11 = 0.0;
|
||||
m6.m12 = 0.0;
|
||||
m6.m13 = 0.0;
|
||||
m6.m14 = 0.0;
|
||||
m6.m15 = 0.0;
|
||||
m6.m16 = 0.0;
|
||||
m6.m21 = 0.0;
|
||||
m6.m22 = 0.0;
|
||||
m6.m23 = 0.0;
|
||||
m6.m24 = 0.0;
|
||||
m6.m25 = 0.0;
|
||||
m6.m26 = 0.0;
|
||||
m6.m31 = 0.0;
|
||||
m6.m32 = 0.0;
|
||||
m6.m33 = 0.0;
|
||||
m6.m34 = 0.0;
|
||||
m6.m35 = 0.0;
|
||||
m6.m36 = 0.0;
|
||||
m6.m41 = 0.0;
|
||||
m6.m42 = 0.0;
|
||||
m6.m43 = 0.0;
|
||||
m6.m44 = 0.0;
|
||||
m6.m45 = 0.0;
|
||||
m6.m46 = 0.0;
|
||||
m6.m51 = 0.0;
|
||||
m6.m52 = 0.0;
|
||||
m6.m53 = 0.0;
|
||||
m6.m54 = 0.0;
|
||||
m6.m55 = 0.0;
|
||||
m6.m56 = 0.0;
|
||||
m6.m61 = 0.0;
|
||||
m6.m62 = 0.0;
|
||||
m6.m63 = 0.0;
|
||||
m6.m64 = 0.0;
|
||||
m6.m65 = 0.0;
|
||||
m6.m66 = 0.0;
|
||||
|
||||
assert!(m2.is_zero());
|
||||
assert!(m3.is_zero());
|
||||
@ -569,7 +624,6 @@ fn components_mut() {
|
||||
assert!(m5.is_zero());
|
||||
assert!(m6.is_zero());
|
||||
|
||||
|
||||
let mut v1 = Vector1::from_element(1.0);
|
||||
let mut v2 = Vector2::from_element(1.0);
|
||||
let mut v3 = Vector3::from_element(1.0);
|
||||
@ -578,11 +632,26 @@ fn components_mut() {
|
||||
let mut v6 = Vector6::from_element(1.0);
|
||||
|
||||
v1.x = 0.0;
|
||||
v2.x = 0.0; v2.y = 0.0;
|
||||
v3.x = 0.0; v3.y = 0.0; v3.z = 0.0;
|
||||
v4.x = 0.0; v4.y = 0.0; v4.z = 0.0; v4.w = 0.0;
|
||||
v5.x = 0.0; v5.y = 0.0; v5.z = 0.0; v5.w = 0.0; v5.a = 0.0;
|
||||
v6.x = 0.0; v6.y = 0.0; v6.z = 0.0; v6.w = 0.0; v6.a = 0.0; v6.b = 0.0;
|
||||
v2.x = 0.0;
|
||||
v2.y = 0.0;
|
||||
v3.x = 0.0;
|
||||
v3.y = 0.0;
|
||||
v3.z = 0.0;
|
||||
v4.x = 0.0;
|
||||
v4.y = 0.0;
|
||||
v4.z = 0.0;
|
||||
v4.w = 0.0;
|
||||
v5.x = 0.0;
|
||||
v5.y = 0.0;
|
||||
v5.z = 0.0;
|
||||
v5.w = 0.0;
|
||||
v5.a = 0.0;
|
||||
v6.x = 0.0;
|
||||
v6.y = 0.0;
|
||||
v6.z = 0.0;
|
||||
v6.w = 0.0;
|
||||
v6.a = 0.0;
|
||||
v6.b = 0.0;
|
||||
|
||||
assert!(v1.is_zero());
|
||||
assert!(v2.is_zero());
|
||||
@ -592,37 +661,57 @@ fn components_mut() {
|
||||
assert!(v6.is_zero());
|
||||
|
||||
// Check that the components order is correct.
|
||||
m3.m11 = 11.0; m3.m12 = 12.0; m3.m13 = 13.0;
|
||||
m3.m21 = 21.0; m3.m22 = 22.0; m3.m23 = 23.0;
|
||||
m3.m31 = 31.0; m3.m32 = 32.0; m3.m33 = 33.0;
|
||||
m3.m11 = 11.0;
|
||||
m3.m12 = 12.0;
|
||||
m3.m13 = 13.0;
|
||||
m3.m21 = 21.0;
|
||||
m3.m22 = 22.0;
|
||||
m3.m23 = 23.0;
|
||||
m3.m31 = 31.0;
|
||||
m3.m32 = 32.0;
|
||||
m3.m33 = 33.0;
|
||||
|
||||
let expected_m3 = Matrix3::new(11.0, 12.0, 13.0,
|
||||
21.0, 22.0, 23.0,
|
||||
31.0, 32.0, 33.0);
|
||||
let expected_m3 = Matrix3::new(11.0, 12.0, 13.0, 21.0, 22.0, 23.0, 31.0, 32.0, 33.0);
|
||||
assert_eq!(expected_m3, m3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kronecker() {
|
||||
let a = Matrix2x3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23);
|
||||
let a = Matrix2x3::new(11, 12, 13, 21, 22, 23);
|
||||
|
||||
let b = Matrix4x5::new(
|
||||
110, 120, 130, 140, 150,
|
||||
210, 220, 230, 240, 250,
|
||||
310, 320, 330, 340, 350,
|
||||
410, 420, 430, 440, 450);
|
||||
110,
|
||||
120,
|
||||
130,
|
||||
140,
|
||||
150,
|
||||
210,
|
||||
220,
|
||||
230,
|
||||
240,
|
||||
250,
|
||||
310,
|
||||
320,
|
||||
330,
|
||||
340,
|
||||
350,
|
||||
410,
|
||||
420,
|
||||
430,
|
||||
440,
|
||||
450,
|
||||
);
|
||||
|
||||
let expected = MatrixMN::<_, U8, U15>::from_row_slice(&[
|
||||
1210, 1320, 1430, 1540, 1650, 1320, 1440, 1560, 1680, 1800, 1430, 1560, 1690, 1820, 1950,
|
||||
2310, 2420, 2530, 2640, 2750, 2520, 2640, 2760, 2880, 3000, 2730, 2860, 2990, 3120, 3250,
|
||||
3410, 3520, 3630, 3740, 3850, 3720, 3840, 3960, 4080, 4200, 4030, 4160, 4290, 4420, 4550,
|
||||
4510, 4620, 4730, 4840, 4950, 4920, 5040, 5160, 5280, 5400, 5330, 5460, 5590, 5720, 5850,
|
||||
2310, 2520, 2730, 2940, 3150, 2420, 2640, 2860, 3080, 3300, 2530, 2760, 2990, 3220, 3450,
|
||||
4410, 4620, 4830, 5040, 5250, 4620, 4840, 5060, 5280, 5500, 4830, 5060, 5290, 5520, 5750,
|
||||
6510, 6720, 6930, 7140, 7350, 6820, 7040, 7260, 7480, 7700, 7130, 7360, 7590, 7820, 8050,
|
||||
8610, 8820, 9030, 9240, 9450, 9020, 9240, 9460, 9680, 9900, 9430, 9660, 9890, 10120, 10350 ]);
|
||||
let expected = MatrixMN::<_, U8, U15>::from_row_slice(&[
|
||||
1210, 1320, 1430, 1540, 1650, 1320, 1440, 1560, 1680, 1800, 1430, 1560, 1690, 1820, 1950,
|
||||
2310, 2420, 2530, 2640, 2750, 2520, 2640, 2760, 2880, 3000, 2730, 2860, 2990, 3120, 3250,
|
||||
3410, 3520, 3630, 3740, 3850, 3720, 3840, 3960, 4080, 4200, 4030, 4160, 4290, 4420, 4550,
|
||||
4510, 4620, 4730, 4840, 4950, 4920, 5040, 5160, 5280, 5400, 5330, 5460, 5590, 5720, 5850,
|
||||
2310, 2520, 2730, 2940, 3150, 2420, 2640, 2860, 3080, 3300, 2530, 2760, 2990, 3220, 3450,
|
||||
4410, 4620, 4830, 5040, 5250, 4620, 4840, 5060, 5280, 5500, 4830, 5060, 5290, 5520, 5750,
|
||||
6510, 6720, 6930, 7140, 7350, 6820, 7040, 7260, 7480, 7700, 7130, 7360, 7590, 7820, 8050,
|
||||
8610, 8820, 9030, 9240, 9450, 9020, 9240, 9460, 9680, 9900, 9430, 9660, 9890, 10120, 10350,
|
||||
]);
|
||||
|
||||
let computed = a.kronecker(&b);
|
||||
|
||||
@ -636,9 +725,7 @@ fn kronecker() {
|
||||
|
||||
let a = Vector2::new(1, 2);
|
||||
let b = RowVector4::new(10, 20, 30, 40);
|
||||
let expected = Matrix2x4::new(
|
||||
10, 20, 30, 40,
|
||||
20, 40, 60, 80);
|
||||
let expected = Matrix2x4::new(10, 20, 30, 40, 20, 40, 60, 80);
|
||||
|
||||
assert_eq!(a.kronecker(&b), expected);
|
||||
}
|
||||
@ -646,22 +733,73 @@ fn kronecker() {
|
||||
#[test]
|
||||
fn set_row_column() {
|
||||
let a = Matrix4x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35,
|
||||
41, 42, 43, 44, 45);
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25,
|
||||
31,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
);
|
||||
|
||||
let expected1 = Matrix4x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
42, 43, 44, 45, 46,
|
||||
31, 32, 33, 34, 35,
|
||||
41, 42, 43, 44, 45);
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
46,
|
||||
31,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
);
|
||||
|
||||
let expected2 = Matrix4x5::new(
|
||||
11, 12, 100, 14, 15,
|
||||
42, 43, 101, 45, 46,
|
||||
31, 32, 102, 34, 35,
|
||||
41, 42, 103, 44, 45);
|
||||
11,
|
||||
12,
|
||||
100,
|
||||
14,
|
||||
15,
|
||||
42,
|
||||
43,
|
||||
101,
|
||||
45,
|
||||
46,
|
||||
31,
|
||||
32,
|
||||
102,
|
||||
34,
|
||||
35,
|
||||
41,
|
||||
42,
|
||||
103,
|
||||
44,
|
||||
45,
|
||||
);
|
||||
|
||||
let row = RowVector5::new(42, 43, 44, 45, 46);
|
||||
let col = Vector4::new(100, 101, 102, 103);
|
||||
@ -784,7 +922,6 @@ mod inversion_tests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod normalization_tests {
|
||||
use super::*;
|
||||
@ -888,18 +1025,23 @@ mod finite_dim_inner_space_tests {
|
||||
*/
|
||||
#[cfg(feature = "arbitrary")]
|
||||
fn is_subspace_basis<T: FiniteDimInnerSpace<Real = f64> + Display>(vs: &[T]) -> bool {
|
||||
for i in 0 .. vs.len() {
|
||||
for i in 0..vs.len() {
|
||||
// Basis elements must be normalized.
|
||||
if !relative_eq!(vs[i].norm(), 1.0, epsilon = 1.0e-7) {
|
||||
println!("Non-zero basis element norm: {}", vs[i].norm());
|
||||
return false;
|
||||
}
|
||||
|
||||
for j in 0 .. i {
|
||||
for j in 0..i {
|
||||
// Basis elements must be orthogonal.
|
||||
if !relative_eq!(vs[i].dot(&vs[j]), 0.0, epsilon = 1.0e-7) {
|
||||
println!("Non-orthogonal basis elements: {} · {} = {}", vs[i], vs[j], vs[i].dot(&vs[j]));
|
||||
return false
|
||||
println!(
|
||||
"Non-orthogonal basis elements: {} · {} = {}",
|
||||
vs[i],
|
||||
vs[j],
|
||||
vs[i].dot(&vs[j])
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_snake_case)]
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::{U2, U3, U4};
|
||||
use na::{DMatrix,
|
||||
|
@ -1,10 +1,10 @@
|
||||
// mod conversion;
|
||||
// mod edition;
|
||||
// mod matrix;
|
||||
// mod matrix_slice;
|
||||
mod conversion;
|
||||
mod edition;
|
||||
mod matrix;
|
||||
mod matrix_slice;
|
||||
mod blas;
|
||||
// mod serde;
|
||||
// #[cfg(feature = "abomonation-serialize")]
|
||||
// mod abomonation;
|
||||
// #[cfg(feature = "mint")]
|
||||
// mod mint;
|
||||
mod serde;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
mod abomonation;
|
||||
#[cfg(feature = "mint")]
|
||||
mod mint;
|
||||
|
@ -14,5 +14,5 @@ extern crate rand;
|
||||
extern crate serde_json;
|
||||
|
||||
mod core;
|
||||
// mod linalg;
|
||||
// mod geometry;
|
||||
mod linalg;
|
||||
mod geometry;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::Matrix3;
|
||||
|
||||
#[test]
|
||||
@ -155,3 +157,306 @@ mod quickcheck_tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn swap_rows() {
|
||||
let mut m = Matrix5x3::new(
|
||||
11.0, 12.0, 13.0,
|
||||
21.0, 22.0, 23.0,
|
||||
31.0, 32.0, 33.0,
|
||||
41.0, 42.0, 43.0,
|
||||
51.0, 52.0, 53.0);
|
||||
|
||||
let expected = Matrix5x3::new(
|
||||
11.0, 12.0, 13.0,
|
||||
41.0, 42.0, 43.0,
|
||||
31.0, 32.0, 33.0,
|
||||
21.0, 22.0, 23.0,
|
||||
51.0, 52.0, 53.0);
|
||||
|
||||
m.swap_rows(1, 3);
|
||||
|
||||
assert_eq!(m, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swap_columns() {
|
||||
let mut m = Matrix3x5::new(
|
||||
11.0, 12.0, 13.0, 14.0, 15.0,
|
||||
21.0, 22.0, 23.0, 24.0, 25.0,
|
||||
31.0, 32.0, 33.0, 34.0, 35.0);
|
||||
|
||||
let expected = Matrix3x5::new(
|
||||
11.0, 14.0, 13.0, 12.0, 15.0,
|
||||
21.0, 24.0, 23.0, 22.0, 25.0,
|
||||
31.0, 34.0, 33.0, 32.0, 35.0);
|
||||
|
||||
m.swap_columns(1, 3);
|
||||
|
||||
assert_eq!(m, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_columns() {
|
||||
let m = Matrix3x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
let expected1 = Matrix3x4::new(
|
||||
12, 13, 14, 15,
|
||||
22, 23, 24, 25,
|
||||
32, 33, 34, 35);
|
||||
|
||||
let expected2 = Matrix3x4::new(
|
||||
11, 12, 13, 14,
|
||||
21, 22, 23, 24,
|
||||
31, 32, 33, 34);
|
||||
|
||||
let expected3 = Matrix3x4::new(
|
||||
11, 12, 14, 15,
|
||||
21, 22, 24, 25,
|
||||
31, 32, 34, 35);
|
||||
|
||||
assert_eq!(m.remove_column(0), expected1);
|
||||
assert_eq!(m.remove_column(4), expected2);
|
||||
assert_eq!(m.remove_column(2), expected3);
|
||||
|
||||
let expected1 = Matrix3::new(
|
||||
13, 14, 15,
|
||||
23, 24, 25,
|
||||
33, 34, 35);
|
||||
|
||||
let expected2 = Matrix3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33);
|
||||
|
||||
let expected3 = Matrix3::new(
|
||||
11, 12, 15,
|
||||
21, 22, 25,
|
||||
31, 32, 35);
|
||||
|
||||
assert_eq!(m.remove_fixed_columns::<U2>(0), expected1);
|
||||
assert_eq!(m.remove_fixed_columns::<U2>(3), expected2);
|
||||
assert_eq!(m.remove_fixed_columns::<U2>(2), expected3);
|
||||
|
||||
// The following is just to verify that the return type dimensions is correctly inferred.
|
||||
let computed: Matrix<_, U3, Dynamic, _> = m.remove_columns(3, 2);
|
||||
assert!(computed.eq(&expected2));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn remove_rows() {
|
||||
let m = Matrix5x3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33,
|
||||
41, 42, 43,
|
||||
51, 52, 53);
|
||||
|
||||
let expected1 = Matrix4x3::new(
|
||||
21, 22, 23,
|
||||
31, 32, 33,
|
||||
41, 42, 43,
|
||||
51, 52, 53);
|
||||
|
||||
let expected2 = Matrix4x3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33,
|
||||
41, 42, 43);
|
||||
|
||||
let expected3 = Matrix4x3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
41, 42, 43,
|
||||
51, 52, 53);
|
||||
|
||||
assert_eq!(m.remove_row(0), expected1);
|
||||
assert_eq!(m.remove_row(4), expected2);
|
||||
assert_eq!(m.remove_row(2), expected3);
|
||||
|
||||
let expected1 = Matrix3::new(
|
||||
31, 32, 33,
|
||||
41, 42, 43,
|
||||
51, 52, 53);
|
||||
|
||||
let expected2 = Matrix3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33);
|
||||
|
||||
let expected3 = Matrix3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
51, 52, 53);
|
||||
|
||||
assert_eq!(m.remove_fixed_rows::<U2>(0), expected1);
|
||||
assert_eq!(m.remove_fixed_rows::<U2>(3), expected2);
|
||||
assert_eq!(m.remove_fixed_rows::<U2>(2), expected3);
|
||||
|
||||
// The following is just to verify that the return type dimensions is correctly inferred.
|
||||
let computed: Matrix<_, Dynamic, U3, _> = m.remove_rows(3, 2);
|
||||
assert!(computed.eq(&expected2));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn insert_columns() {
|
||||
let m = Matrix5x3::new(
|
||||
11, 12, 13,
|
||||
21, 22, 23,
|
||||
31, 32, 33,
|
||||
41, 42, 43,
|
||||
51, 52, 53);
|
||||
|
||||
let expected1 = Matrix5x4::new(
|
||||
0, 11, 12, 13,
|
||||
0, 21, 22, 23,
|
||||
0, 31, 32, 33,
|
||||
0, 41, 42, 43,
|
||||
0, 51, 52, 53);
|
||||
|
||||
let expected2 = Matrix5x4::new(
|
||||
11, 12, 13, 0,
|
||||
21, 22, 23, 0,
|
||||
31, 32, 33, 0,
|
||||
41, 42, 43, 0,
|
||||
51, 52, 53, 0);
|
||||
|
||||
let expected3 = Matrix5x4::new(
|
||||
11, 12, 0, 13,
|
||||
21, 22, 0, 23,
|
||||
31, 32, 0, 33,
|
||||
41, 42, 0, 43,
|
||||
51, 52, 0, 53);
|
||||
|
||||
assert_eq!(m.insert_column(0, 0), expected1);
|
||||
assert_eq!(m.insert_column(3, 0), expected2);
|
||||
assert_eq!(m.insert_column(2, 0), expected3);
|
||||
|
||||
let expected1 = Matrix5::new(
|
||||
0, 0, 11, 12, 13,
|
||||
0, 0, 21, 22, 23,
|
||||
0, 0, 31, 32, 33,
|
||||
0, 0, 41, 42, 43,
|
||||
0, 0, 51, 52, 53);
|
||||
|
||||
let expected2 = Matrix5::new(
|
||||
11, 12, 13, 0, 0,
|
||||
21, 22, 23, 0, 0,
|
||||
31, 32, 33, 0, 0,
|
||||
41, 42, 43, 0, 0,
|
||||
51, 52, 53, 0, 0);
|
||||
|
||||
let expected3 = Matrix5::new(
|
||||
11, 12, 0, 0, 13,
|
||||
21, 22, 0, 0, 23,
|
||||
31, 32, 0, 0, 33,
|
||||
41, 42, 0, 0, 43,
|
||||
51, 52, 0, 0, 53);
|
||||
|
||||
assert_eq!(m.insert_fixed_columns::<U2>(0, 0), expected1);
|
||||
assert_eq!(m.insert_fixed_columns::<U2>(3, 0), expected2);
|
||||
assert_eq!(m.insert_fixed_columns::<U2>(2, 0), expected3);
|
||||
|
||||
// The following is just to verify that the return type dimensions is correctly inferred.
|
||||
let computed: Matrix<_, U5, Dynamic, _> = m.insert_columns(3, 2, 0);
|
||||
assert!(computed.eq(&expected2));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn insert_rows() {
|
||||
let m = Matrix3x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
let expected1 = Matrix4x5::new(
|
||||
0, 0, 0, 0, 0,
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
let expected2 = Matrix4x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35,
|
||||
0, 0, 0, 0, 0);
|
||||
|
||||
let expected3 = Matrix4x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
0, 0, 0, 0, 0,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
assert_eq!(m.insert_row(0, 0), expected1);
|
||||
assert_eq!(m.insert_row(3, 0), expected2);
|
||||
assert_eq!(m.insert_row(2, 0), expected3);
|
||||
|
||||
let expected1 = Matrix5::new(
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
let expected2 = Matrix5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0);
|
||||
|
||||
let expected3 = Matrix5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
assert_eq!(m.insert_fixed_rows::<U2>(0, 0), expected1);
|
||||
assert_eq!(m.insert_fixed_rows::<U2>(3, 0), expected2);
|
||||
assert_eq!(m.insert_fixed_rows::<U2>(2, 0), expected3);
|
||||
|
||||
// The following is just to verify that the return type dimensions is correctly inferred.
|
||||
let computed: Matrix<_, Dynamic, U5, _> = m.insert_rows(3, 2, 0);
|
||||
assert!(computed.eq(&expected2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resize() {
|
||||
let m = Matrix3x5::new(
|
||||
11, 12, 13, 14, 15,
|
||||
21, 22, 23, 24, 25,
|
||||
31, 32, 33, 34, 35);
|
||||
|
||||
let add_add = DMatrix::from_row_slice(5, 6, &[
|
||||
11, 12, 13, 14, 15, 42,
|
||||
21, 22, 23, 24, 25, 42,
|
||||
31, 32, 33, 34, 35, 42,
|
||||
42, 42, 42, 42, 42, 42,
|
||||
42, 42, 42, 42, 42, 42]);
|
||||
|
||||
let del_del = DMatrix::from_row_slice(1, 2, &[11, 12]);
|
||||
|
||||
let add_del = DMatrix::from_row_slice(5, 2, &[
|
||||
11, 12,
|
||||
21, 22,
|
||||
31, 32,
|
||||
42, 42,
|
||||
42, 42]);
|
||||
|
||||
let del_add = DMatrix::from_row_slice(1, 8, &[
|
||||
11, 12, 13, 14, 15, 42, 42, 42]);
|
||||
|
||||
assert_eq!(del_del, m.resize(1, 2, 42));
|
||||
assert_eq!(add_add, m.resize(5, 6, 42));
|
||||
assert_eq!(add_del, m.resize(5, 2, 42));
|
||||
assert_eq!(del_add, m.resize(1, 8, 42));
|
||||
}
|
||||
*/
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::{Matrix1, Matrix2, Matrix3, Matrix4, Matrix5};
|
||||
|
||||
#[test]
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::Matrix3;
|
||||
|
||||
#[test]
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::{DMatrix, Matrix3, Matrix4};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user