| 14 | using namespace std; |
| 15 | |
| 16 | template<typename MatrixType> void reverse(const MatrixType& m) |
| 17 | { |
| 18 | typedef typename MatrixType::Index Index; |
| 19 | typedef typename MatrixType::Scalar Scalar; |
| 20 | typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType; |
| 21 | |
| 22 | Index rows = m.rows(); |
| 23 | Index cols = m.cols(); |
| 24 | |
| 25 | // this test relies a lot on Random.h, and there's not much more that we can do |
| 26 | // to test it, hence I consider that we will have tested Random.h |
| 27 | MatrixType m1 = MatrixType::Random(rows, cols), m2; |
| 28 | VectorType v1 = VectorType::Random(rows); |
| 29 | |
| 30 | MatrixType m1_r = m1.reverse(); |
| 31 | // Verify that MatrixBase::reverse() works |
| 32 | for ( int i = 0; i < rows; i++ ) { |
| 33 | for ( int j = 0; j < cols; j++ ) { |
| 34 | VERIFY_IS_APPROX(m1_r(i, j), m1(rows - 1 - i, cols - 1 - j)); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | Reverse<MatrixType> m1_rd(m1); |
| 39 | // Verify that a Reverse default (in both directions) of an expression works |
| 40 | for ( int i = 0; i < rows; i++ ) { |
| 41 | for ( int j = 0; j < cols; j++ ) { |
| 42 | VERIFY_IS_APPROX(m1_rd(i, j), m1(rows - 1 - i, cols - 1 - j)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Reverse<MatrixType, BothDirections> m1_rb(m1); |
| 47 | // Verify that a Reverse in both directions of an expression works |
| 48 | for ( int i = 0; i < rows; i++ ) { |
| 49 | for ( int j = 0; j < cols; j++ ) { |
| 50 | VERIFY_IS_APPROX(m1_rb(i, j), m1(rows - 1 - i, cols - 1 - j)); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | Reverse<MatrixType, Vertical> m1_rv(m1); |
| 55 | // Verify that a Reverse in the vertical directions of an expression works |
| 56 | for ( int i = 0; i < rows; i++ ) { |
| 57 | for ( int j = 0; j < cols; j++ ) { |
| 58 | VERIFY_IS_APPROX(m1_rv(i, j), m1(rows - 1 - i, j)); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | Reverse<MatrixType, Horizontal> m1_rh(m1); |
| 63 | // Verify that a Reverse in the horizontal directions of an expression works |
| 64 | for ( int i = 0; i < rows; i++ ) { |
| 65 | for ( int j = 0; j < cols; j++ ) { |
| 66 | VERIFY_IS_APPROX(m1_rh(i, j), m1(i, cols - 1 - j)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | VectorType v1_r = v1.reverse(); |
| 71 | // Verify that a VectorType::reverse() of an expression works |
| 72 | for ( int i = 0; i < rows; i++ ) { |
| 73 | VERIFY_IS_APPROX(v1_r(i), v1(rows - 1 - i)); |