@@ -14,6 +14,7 @@ use std::mem::MaybeUninit;
1414use ndarray:: ShapeBuilder ;
1515use ndarray:: { arr0, arr1, arr2, azip, s} ;
1616use ndarray:: { Array , Array1 , Array2 , Axis , Ix , Zip } ;
17+ use ndarray:: { Ix1 , Ix2 , Ix3 , Ix5 , IxDyn } ;
1718
1819use test:: black_box;
1920
@@ -941,3 +942,59 @@ fn sum_axis1(bench: &mut test::Bencher) {
941942 let a = range_mat ( MEAN_SUM_N , MEAN_SUM_N ) ;
942943 bench. iter ( || a. sum_axis ( Axis ( 1 ) ) ) ;
943944}
945+
946+ #[ bench]
947+ fn into_dimensionality_ix1_ok ( bench : & mut test:: Bencher ) {
948+ let a = Array :: < f32 , _ > :: zeros ( Ix1 ( 10 ) ) ;
949+ let a = a. view ( ) ;
950+ bench. iter ( || a. into_dimensionality :: < Ix1 > ( ) ) ;
951+ }
952+
953+ #[ bench]
954+ fn into_dimensionality_ix3_ok ( bench : & mut test:: Bencher ) {
955+ let a = Array :: < f32 , _ > :: zeros ( Ix3 ( 10 , 10 , 10 ) ) ;
956+ let a = a. view ( ) ;
957+ bench. iter ( || a. into_dimensionality :: < Ix3 > ( ) ) ;
958+ }
959+
960+ #[ bench]
961+ fn into_dimensionality_ix3_err ( bench : & mut test:: Bencher ) {
962+ let a = Array :: < f32 , _ > :: zeros ( Ix3 ( 10 , 10 , 10 ) ) ;
963+ let a = a. view ( ) ;
964+ bench. iter ( || a. into_dimensionality :: < Ix2 > ( ) ) ;
965+ }
966+
967+ #[ bench]
968+ fn into_dimensionality_dyn_to_ix3 ( bench : & mut test:: Bencher ) {
969+ let a = Array :: < f32 , _ > :: zeros ( IxDyn ( & [ 10 , 10 , 10 ] ) ) ;
970+ let a = a. view ( ) ;
971+ bench. iter ( || a. clone ( ) . into_dimensionality :: < Ix3 > ( ) ) ;
972+ }
973+
974+ #[ bench]
975+ fn into_dimensionality_dyn_to_dyn ( bench : & mut test:: Bencher ) {
976+ let a = Array :: < f32 , _ > :: zeros ( IxDyn ( & [ 10 , 10 , 10 ] ) ) ;
977+ let a = a. view ( ) ;
978+ bench. iter ( || a. clone ( ) . into_dimensionality :: < IxDyn > ( ) ) ;
979+ }
980+
981+ #[ bench]
982+ fn into_dyn_ix3 ( bench : & mut test:: Bencher ) {
983+ let a = Array :: < f32 , _ > :: zeros ( Ix3 ( 10 , 10 , 10 ) ) ;
984+ let a = a. view ( ) ;
985+ bench. iter ( || a. into_dyn ( ) ) ;
986+ }
987+
988+ #[ bench]
989+ fn into_dyn_ix5 ( bench : & mut test:: Bencher ) {
990+ let a = Array :: < f32 , _ > :: zeros ( Ix5 ( 2 , 2 , 2 , 2 , 2 ) ) ;
991+ let a = a. view ( ) ;
992+ bench. iter ( || a. into_dyn ( ) ) ;
993+ }
994+
995+ #[ bench]
996+ fn into_dyn_dyn ( bench : & mut test:: Bencher ) {
997+ let a = Array :: < f32 , _ > :: zeros ( IxDyn ( & [ 10 , 10 , 10 ] ) ) ;
998+ let a = a. view ( ) ;
999+ bench. iter ( || a. clone ( ) . into_dyn ( ) ) ;
1000+ }
0 commit comments