1 //  Copyright (c) 2018-2019 Cem Bassoy
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See
4 //  accompanying file LICENSE_1_0.txt or copy at
5 //  http://www.boost.org/LICENSE_1_0.txt)
6 //
7 //  The authors gratefully acknowledge the support of
8 //  Fraunhofer and Google in producing this work
9 //  which started as a Google Summer of Code project.
10 //
11 
12 
13 
14 
15 #include <boost/test/unit_test.hpp>
16 #include <boost/numeric/ublas/tensor/strides.hpp>
17 #include <boost/numeric/ublas/tensor/extents.hpp>
18 
19 //BOOST_AUTO_TEST_SUITE(test_strides, * boost::unit_test::depends_on("test_extents"));
20 
21 BOOST_AUTO_TEST_SUITE(test_strides)
22 
23 using test_types = std::tuple<boost::numeric::ublas::first_order, boost::numeric::ublas::last_order>;
24 
BOOST_AUTO_TEST_CASE_TEMPLATE(test_strides_ctor,value,test_types)25 BOOST_AUTO_TEST_CASE_TEMPLATE( test_strides_ctor, value, test_types)
26 {
27 	using namespace boost::numeric;
28 
29 	using extents_type  = ublas::basic_extents<unsigned>;
30 	using strides_type = ublas::strides<value>;
31 
32 	strides_type         s0{};
33 	BOOST_CHECK        ( s0.empty());
34 	BOOST_CHECK_EQUAL  ( s0.size(), 0);
35 
36 	strides_type        s1{extents_type{1,1}};
37 	BOOST_CHECK       (!s1.empty());
38 	BOOST_CHECK_EQUAL ( s1.size(), 2);
39 
40 	strides_type        s2{extents_type{1,2}};
41 	BOOST_CHECK       (!s2.empty());
42 	BOOST_CHECK_EQUAL ( s2.size(), 2);
43 
44 	strides_type        s3{extents_type{2,1}};
45 	BOOST_CHECK       (!s3.empty());
46 	BOOST_CHECK_EQUAL ( s3.size(), 2);
47 
48 	strides_type        s4{extents_type{2,3}};
49 	BOOST_CHECK       (!s4.empty());
50 	BOOST_CHECK_EQUAL ( s4.size(), 2);
51 
52 	strides_type        s5{extents_type{2,3,1}};
53 	BOOST_CHECK       (!s5.empty());
54 	BOOST_CHECK_EQUAL ( s5.size(), 3);
55 
56 	strides_type        s6{extents_type{1,2,3}};
57 	BOOST_CHECK       (!s6.empty());
58 	BOOST_CHECK_EQUAL ( s6.size(), 3);
59 
60 	strides_type        s7{extents_type{4,2,3}};
61 	BOOST_CHECK       (!s7.empty());
62 	BOOST_CHECK_EQUAL ( s7.size(), 3);
63 }
64 
65 
66 
BOOST_AUTO_TEST_CASE(test_strides_ctor_access_first_order)67 BOOST_AUTO_TEST_CASE( test_strides_ctor_access_first_order)
68 {
69 	using namespace boost::numeric;
70 
71 	using extents_type  = ublas::basic_extents<unsigned>;
72 	using strides_type =  ublas::strides<ublas::first_order>;
73 
74 	strides_type         s1{extents_type{1,1}};
75 	BOOST_REQUIRE_EQUAL( s1.size(),2);
76 	BOOST_CHECK_EQUAL  ( s1[0], 1);
77 	BOOST_CHECK_EQUAL  ( s1[1], 1);
78 
79 	strides_type          s2{extents_type{1,2}};
80 	BOOST_REQUIRE_EQUAL ( s2.size(),2);
81 	BOOST_CHECK_EQUAL   ( s2[0], 1);
82 	BOOST_CHECK_EQUAL   ( s2[1], 1);
83 
84 	strides_type          s3{extents_type{2,1}};
85 	BOOST_REQUIRE_EQUAL ( s3.size(),2);
86 	BOOST_CHECK_EQUAL   ( s3[0], 1);
87 	BOOST_CHECK_EQUAL   ( s3[1], 1);
88 
89 	strides_type          s4{extents_type{2,3}};
90 	BOOST_REQUIRE_EQUAL ( s4.size(),2);
91 	BOOST_CHECK_EQUAL   ( s4[0], 1);
92 	BOOST_CHECK_EQUAL   ( s4[1], 2);
93 
94 	strides_type          s5{extents_type{2,3,1}};
95 	BOOST_REQUIRE_EQUAL ( s5.size(),3);
96 	BOOST_CHECK_EQUAL   ( s5[0], 1);
97 	BOOST_CHECK_EQUAL   ( s5[1], 2);
98 	BOOST_CHECK_EQUAL   ( s5[2], 6);
99 
100 	strides_type          s6{extents_type{1,2,3}};
101 	BOOST_REQUIRE_EQUAL ( s6.size(),3);
102 	BOOST_CHECK_EQUAL   ( s6[0], 1);
103 	BOOST_CHECK_EQUAL   ( s6[1], 1);
104 	BOOST_CHECK_EQUAL   ( s6[2], 2);
105 
106 	strides_type          s7{extents_type{2,1,3}};
107 	BOOST_REQUIRE_EQUAL ( s7.size(),3);
108 	BOOST_CHECK_EQUAL   ( s7[0], 1);
109 	BOOST_CHECK_EQUAL   ( s7[1], 2);
110 	BOOST_CHECK_EQUAL   ( s7[2], 2);
111 
112 	strides_type          s8{extents_type{4,2,3}};
113 	BOOST_REQUIRE_EQUAL ( s8.size(),3);
114 	BOOST_CHECK_EQUAL   ( s8[0], 1);
115 	BOOST_CHECK_EQUAL   ( s8[1], 4);
116 	BOOST_CHECK_EQUAL   ( s8[2], 8);
117 }
118 
BOOST_AUTO_TEST_CASE(test_strides_ctor_access_last_order)119 BOOST_AUTO_TEST_CASE( test_strides_ctor_access_last_order)
120 {
121 	using namespace boost::numeric;
122 
123 	using extents_type  = ublas::basic_extents<unsigned>;
124 	using strides_type =  ublas::strides<ublas::last_order>;
125 
126 	strides_type         s1{extents_type{1,1}};
127 	BOOST_REQUIRE_EQUAL( s1.size(),2);
128 	BOOST_CHECK_EQUAL  ( s1[0], 1);
129 	BOOST_CHECK_EQUAL  ( s1[1], 1);
130 
131 	strides_type          s2{extents_type{1,2}};
132 	BOOST_REQUIRE_EQUAL ( s2.size(),2);
133 	BOOST_CHECK_EQUAL   ( s2[0], 1);
134 	BOOST_CHECK_EQUAL   ( s2[1], 1);
135 
136 	strides_type          s3{extents_type{2,1}};
137 	BOOST_REQUIRE_EQUAL ( s3.size(),2);
138 	BOOST_CHECK_EQUAL   ( s3[0], 1);
139 	BOOST_CHECK_EQUAL   ( s3[1], 1);
140 
141 	strides_type          s4{extents_type{2,3}};
142 	BOOST_REQUIRE_EQUAL ( s4.size(),2);
143 	BOOST_CHECK_EQUAL   ( s4[0], 3);
144 	BOOST_CHECK_EQUAL   ( s4[1], 1);
145 
146 	strides_type          s5{extents_type{2,3,1}};
147 	BOOST_REQUIRE_EQUAL ( s5.size(),3);
148 	BOOST_CHECK_EQUAL   ( s5[0], 3);
149 	BOOST_CHECK_EQUAL   ( s5[1], 1);
150 	BOOST_CHECK_EQUAL   ( s5[2], 1);
151 
152 	strides_type          s6{extents_type{1,2,3}};
153 	BOOST_REQUIRE_EQUAL ( s6.size(),3);
154 	BOOST_CHECK_EQUAL   ( s6[0], 6);
155 	BOOST_CHECK_EQUAL   ( s6[1], 3);
156 	BOOST_CHECK_EQUAL   ( s6[2], 1);
157 
158 	strides_type          s7{extents_type{2,1,3}};
159 	BOOST_REQUIRE_EQUAL ( s7.size(),3);
160 	BOOST_CHECK_EQUAL   ( s7[0], 3);
161 	BOOST_CHECK_EQUAL   ( s7[1], 3);
162 	BOOST_CHECK_EQUAL   ( s7[2], 1);
163 
164 	strides_type          s8{extents_type{4,2,3}};
165 	BOOST_REQUIRE_EQUAL ( s8.size(),3);
166 	BOOST_CHECK_EQUAL   ( s8[0], 6);
167 	BOOST_CHECK_EQUAL   ( s8[1], 3);
168 	BOOST_CHECK_EQUAL   ( s8[2], 1);
169 }
170 
171 
172 BOOST_AUTO_TEST_SUITE_END()
173