From 0668c68b031351488712f21290c77412b02c5de8 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 27 Jan 2021 23:29:33 +0100 Subject: Allow for negative strides. Note that using a stride of -1 is still not possible because it would clash with the definition of Eigen::Dynamic. This fixes #747. --- test/mapstride.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'test/mapstride.cpp') diff --git a/test/mapstride.cpp b/test/mapstride.cpp index 09196600b..fde73f2ec 100644 --- a/test/mapstride.cpp +++ b/test/mapstride.cpp @@ -162,6 +162,32 @@ template void map_class_matrix(const MatrixTy VERIFY_IS_APPROX(map,s1*m); } + // test negative strides + { + Matrix::Map(a_array1, arraysize+1).setRandom(); + Index outerstride = m.innerSize()+4; + Scalar* array = array1; + + { + Map > map1(array, rows, cols, OuterStride<>( outerstride)); + Map > map2(array+(m.outerSize()-1)*outerstride, rows, cols, OuterStride<>(-outerstride)); + if(MatrixType::IsRowMajor) VERIFY_IS_APPROX(map1.colwise().reverse(), map2); + else VERIFY_IS_APPROX(map1.rowwise().reverse(), map2); + } + + { + Map > map1(array, rows, cols, OuterStride<>( outerstride)); + Map > map2(array+(m.outerSize()-1)*outerstride+m.innerSize()-1, rows, cols, Stride(-outerstride,-1)); + VERIFY_IS_APPROX(map1.reverse(), map2); + } + + { + Map > map1(array, rows, cols, OuterStride<>( outerstride)); + Map > map2(array+(m.outerSize()-1)*outerstride+m.innerSize()-1, rows, cols, Stride(-outerstride,-1)); + VERIFY_IS_APPROX(map1.reverse(), map2); + } + } + internal::aligned_delete(a_array1, arraysize+1); } @@ -200,7 +226,7 @@ void bug1453() EIGEN_DECLARE_TEST(mapstride) { for(int i = 0; i < g_repeat; i++) { - int maxn = 30; + int maxn = 3; CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_2( map_class_vector(Vector4d()) ); -- cgit v1.2.3