1 // -*-indent-tabs-mode:t;c-basic-offset:4;tab-width:4-*-
2
3 #define BOOST_TEST_MODULE "C++ Unit Tests for Multi reversed"
4 #define BOOST_TEST_DYN_LINK
5 #include<boost/test/unit_test.hpp>
6
7 #include "../array.hpp"
8
9 #include<numeric> // iota
10
11 namespace multi = boost::multi;
12
BOOST_AUTO_TEST_CASE(multi_reversed_3d)13 BOOST_AUTO_TEST_CASE(multi_reversed_3d){
14
15 multi::array<double, 3> A({30, 40, 50});
16
17 BOOST_TEST_REQUIRE( A.reversed().size() == 50 );
18
19 BOOST_REQUIRE( & A.reversed()[3][5][7] == &A[7][5][3] );
20
21 }
22
23 template<class Array>
flatted_last(Array && arr)24 auto flatted_last(Array&& arr){
25 return reversed(flatted(transposed(reversed(std::forward<Array>(arr)))));
26 }
27
28 template<class Array>
partitioned_last(Array && arr,std::size_t n)29 auto partitioned_last(Array&& arr, std::size_t n){
30 return reversed(transposed(partitioned(reversed(std::forward<Array>(arr)), n)));
31 }
32
BOOST_AUTO_TEST_CASE(multi_reversed_4d)33 BOOST_AUTO_TEST_CASE(multi_reversed_4d){
34
35 multi::array<double, 4> A({3, 5, 7, 11});
36
37 BOOST_TEST_REQUIRE( A.reversed().size() == 11 );
38
39 BOOST_REQUIRE( & A.reversed()[1][2][3][4] == &A[4][3][2][1] );
40
41 BOOST_REQUIRE( & A.reversed().transposed().flatted().reversed()[1][2][ 5] == & A[1][2][0][ 5] );
42 BOOST_REQUIRE( & A.reversed().transposed().flatted().reversed()[1][2][10] == & A[1][2][0][10] );
43 BOOST_REQUIRE( & A.reversed().transposed().flatted().reversed()[1][2][11] == & A[1][2][1][ 0] );
44 BOOST_REQUIRE( & A.reversed().transposed().flatted().reversed()[1][2][12] == & A[1][2][1][ 1] );
45
46 BOOST_REQUIRE( & flatted_last(A)[1][2][12] == & A[1][2][1][1] );
47 }
48
BOOST_AUTO_TEST_CASE(multi_reversed_4d_partition_last)49 BOOST_AUTO_TEST_CASE(multi_reversed_4d_partition_last){
50
51 multi::array<double, 4> A({3, 5, 7, 12});
52
53 BOOST_TEST_REQUIRE( A.reversed().size() == 12 );
54
55 BOOST_REQUIRE( & A.reversed()[1][2][3][4] == &A[4][3][2][1] );
56
57 BOOST_REQUIRE( & A.reversed().partitioned(3).transposed().reversed()[1][2][3][0][1] == & A[1][2][3][1] );
58 BOOST_REQUIRE( & A.reversed().partitioned(3).transposed().reversed()[1][2][3][1][0] == & A[1][2][3][4] );
59 BOOST_REQUIRE( & A.reversed().partitioned(3).transposed().reversed()[1][2][3][1][1] == & A[1][2][3][5] );
60
61 BOOST_REQUIRE( & partitioned_last(A, 3)[1][2][3][1][1] == & A[1][2][3][5] );
62 }
63
64