#[cfg(test)] #[cfg(feature = "simd")] mod matrix_simd_tests { extern crate linearalgebra; use linearalgebra::matrix::*; #[test] fn matrix_trivial_matrix_product_test() { let matrix = Matrix::new( 3, 3, vec![1f64, 1f64, 2f64, 3f64, 4f64, 5f64, 6f64, 1f64, 2f64], ) .unwrap(); let matrix2 = Matrix::new( 3, 3, vec![1f64, 9f64, 2f64, 7f64, 1f64, 5f64, 3f64, 8f64, 2f64], ) .unwrap(); assert_eq!( matrix.simd_product_matrix(&matrix2).unwrap().as_vec(), &vec![14f64, 26f64, 11f64, 46f64, 71f64, 36f64, 19f64, 71f64, 21f64] ) } #[test] fn matrix_trivial_matrix_product_nonsquare_test() { let matrix = Matrix::new(3, 2, vec![3f64, 4f64, 5f64, 6f64, 1f64, 2f64]).unwrap(); let matrix2 = Matrix::new(2, 3, vec![7f64, 1f64, 5f64, 3f64, 8f64, 2f64]).unwrap(); assert_eq!( matrix.simd_product_matrix(&matrix2).unwrap().as_vec(), &vec![81f64, 25f64, 63f64, 13f64] ) } #[test] fn simd_i32_test() { let matrix1 = Matrix::new(3,3,vec![1,1,2,3,4,5,6,1,2]).unwrap(); let matrix2 = Matrix::new(3,3,vec![1,3,2,1,4,5,4,1,2]).unwrap(); let matrix = matrix1.simd_product_matrix(&matrix2).unwrap(); assert_eq!( &vec![10,9,11,27,30,36,15,24,21], matrix.as_vec() ) } #[test] fn simd_big_i32_test() { let matrix1 = Matrix::new(16,16,vec![ 3,8,6,2,0,9,5,6,2,7,5,1,2,3,7,4, 8,5,0,5,2,8,6,7,7,3,1,4,3,9,2,1, 5,7,5,3,3,5,4,9,2,1,0,2,5,3,5,1, 5,0,5,6,6,2,7,2,8,6,7,0,8,1,2,5, 7,1,2,9,6,4,7,0,7,8,7,0,9,2,9,5, 5,2,7,0,8,7,4,0,0,8,7,3,8,9,3,0, 7,5,3,4,5,8,7,0,7,2,5,1,7,3,1,7, 2,5,8,5,3,4,6,4,2,6,4,5,3,0,6,4, 8,9,0,2,6,5,1,3,4,7,2,9,4,1,7,5, 1,6,3,5,8,0,8,2,3,5,8,7,2,9,4,6, 5,0,1,3,9,6,2,7,7,2,6,4,0,3,5,1, 9,0,5,8,7,1,6,4,2,8,4,1,3,0,9,5, 6,1,7,0,5,2,8,9,0,3,4,9,6,8,7,2, 1,5,2,8,4,7,3,6,8,7,6,3,2,5,1,0, 9,6,8,4,1,0,5,7,5,3,1,2,7,9,0,8, 4,2,0,7,6,8,3,1,3,9,5,1,0,2,6,4, ]).unwrap(); let matrix2 = Matrix::new(16,16,vec![ 4,2,0,7,6,8,3,1,4,0,3,2,1,7,9,6, 8,5,6,7,9,2,3,1,5,1,9,4,6,0,8,2, 2,7,8,3,5,1,4,9,6,3,4,0,8,9,2,7, 9,8,2,5,1,7,6,3,7,2,1,8,9,3,5,0, 3,6,5,1,7,4,0,8,1,9,0,6,8,2,7,4, 0,4,7,2,3,5,8,1,8,5,2,3,0,1,6,9, 2,3,1,9,4,8,0,7,5,0,6,8,7,2,1,3, 7,1,8,4,5,9,3,6,4,9,3,0,2,6,7,5, 6,8,7,5,1,0,4,2,9,5,2,1,3,0,8,4, 5,1,9,4,6,0,8,2,2,7,8,3,5,1,4,9, 6,3,4,0,8,9,2,7,9,8,2,5,1,7,6,3, 7,2,1,8,9,3,5,0,3,6,5,1,7,4,0,8, 1,9,0,6,8,2,7,4,0,4,7,2,3,5,8,1, 8,5,2,3,0,1,6,9,2,3,1,9,4,8,0,7, 5,0,6,8,7,2,1,3,7,1,8,4,5,9,3,6, 4,9,3,0,2,6,7,5,6,8,7,5,1,0,4,2 ]).unwrap(); let matrix = matrix1.simd_product_matrix(&matrix2).unwrap(); assert_eq!( &vec![ 319,270,374,315,365,292,305,280,382,290,349,249,274,279,341,369, 364,301,285,356,304,314,312,267,344,273,260,285,276,268,362,361, 282,253,278,308,321,265,232,250,278,232,269,196,262,265,323,284, 296,373,286,292,335,309,286,328,350,324,279,275,304,259,380,282, 367,399,327,383,408,354,343,339,420,337,361,357,360,323,442,347, 280,309,300,283,392,253,311,356,283,322,281,290,308,337,324,396, 292,391,271,307,338,322,312,294,373,296,294,295,274,229,400,303, 308,288,322,319,368,278,271,282,344,286,326,237,333,270,300,325, 364,288,315,369,441,278,309,208,330,324,365,241,309,247,393,373, 415,351,299,333,394,322,286,384,355,358,322,374,389,300,310,343, 298,240,293,244,302,292,212,264,322,326,179,221,243,252,331,317, 330,295,308,337,371,343,265,313,349,300,314,289,343,319,363,331, 355,282,297,387,430,341,280,383,314,336,331,276,351,411,307,413, 367,310,344,284,308,279,308,272,362,331,240,270,301,226,355,328, 374,394,284,345,335,313,337,356,328,295,328,276,312,326,372,328, 288,248,298,243,288,268,272,225,327,287,245,274,258,199,311,312 ], matrix.as_vec() ) } }