diff options
author | Gael Guennebaud <g.gael@free.fr> | 2021-01-27 23:29:33 +0100 |
---|---|---|
committer | David Tellenbach <david.tellenbach@me.com> | 2021-01-27 23:32:12 +0100 |
commit | 0668c68b031351488712f21290c77412b02c5de8 (patch) | |
tree | e7179ffbeb1d7681cda08070d259615989e42eef /test/mapstride.cpp | |
parent | 288d456c2951013e423ae4107f0207ef4594bb45 (diff) |
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.
Diffstat (limited to 'test/mapstride.cpp')
-rw-r--r-- | test/mapstride.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
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<int Alignment,typename MatrixType> void map_class_matrix(const MatrixTy VERIFY_IS_APPROX(map,s1*m); } + // test negative strides + { + Matrix<Scalar,Dynamic,1>::Map(a_array1, arraysize+1).setRandom(); + Index outerstride = m.innerSize()+4; + Scalar* array = array1; + + { + Map<MatrixType, Alignment, OuterStride<> > map1(array, rows, cols, OuterStride<>( outerstride)); + Map<MatrixType, Unaligned, OuterStride<> > 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<MatrixType, Alignment, OuterStride<> > map1(array, rows, cols, OuterStride<>( outerstride)); + Map<MatrixType, Unaligned, Stride<Dynamic,Dynamic> > map2(array+(m.outerSize()-1)*outerstride+m.innerSize()-1, rows, cols, Stride<Dynamic,Dynamic>(-outerstride,-1)); + VERIFY_IS_APPROX(map1.reverse(), map2); + } + + { + Map<MatrixType, Alignment, OuterStride<> > map1(array, rows, cols, OuterStride<>( outerstride)); + Map<MatrixType, Unaligned, Stride<Dynamic,-1> > map2(array+(m.outerSize()-1)*outerstride+m.innerSize()-1, rows, cols, Stride<Dynamic,-1>(-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<Aligned>(Matrix<float, 1, 1>()) ); CALL_SUBTEST_1( map_class_vector<Unaligned>(Matrix<float, 1, 1>()) ); CALL_SUBTEST_2( map_class_vector<Aligned>(Vector4d()) ); |