1 // Copyright (c) 2018-2019 Cem Bassoy
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)
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.
15 #include <boost/test/unit_test.hpp>
16 #include <boost/numeric/ublas/tensor/strides.hpp>
17 #include <boost/numeric/ublas/tensor/extents.hpp>
19 //BOOST_AUTO_TEST_SUITE(test_strides, * boost::unit_test::depends_on("test_extents"));
21 BOOST_AUTO_TEST_SUITE(test_strides
)
23 using test_types
= std::tuple
<boost::numeric::ublas::first_order
, boost::numeric::ublas::last_order
>;
25 BOOST_AUTO_TEST_CASE_TEMPLATE( test_strides_ctor
, value
, test_types
)
27 using namespace boost::numeric
;
29 using extents_type
= ublas::basic_extents
<unsigned>;
30 using strides_type
= ublas::strides
<value
>;
33 BOOST_CHECK ( s0
.empty());
34 BOOST_CHECK_EQUAL ( s0
.size(), 0);
36 strides_type s1
{extents_type
{1,1}};
37 BOOST_CHECK (!s1
.empty());
38 BOOST_CHECK_EQUAL ( s1
.size(), 2);
40 strides_type s2
{extents_type
{1,2}};
41 BOOST_CHECK (!s2
.empty());
42 BOOST_CHECK_EQUAL ( s2
.size(), 2);
44 strides_type s3
{extents_type
{2,1}};
45 BOOST_CHECK (!s3
.empty());
46 BOOST_CHECK_EQUAL ( s3
.size(), 2);
48 strides_type s4
{extents_type
{2,3}};
49 BOOST_CHECK (!s4
.empty());
50 BOOST_CHECK_EQUAL ( s4
.size(), 2);
52 strides_type s5
{extents_type
{2,3,1}};
53 BOOST_CHECK (!s5
.empty());
54 BOOST_CHECK_EQUAL ( s5
.size(), 3);
56 strides_type s6
{extents_type
{1,2,3}};
57 BOOST_CHECK (!s6
.empty());
58 BOOST_CHECK_EQUAL ( s6
.size(), 3);
60 strides_type s7
{extents_type
{4,2,3}};
61 BOOST_CHECK (!s7
.empty());
62 BOOST_CHECK_EQUAL ( s7
.size(), 3);
67 BOOST_AUTO_TEST_CASE( test_strides_ctor_access_first_order
)
69 using namespace boost::numeric
;
71 using extents_type
= ublas::basic_extents
<unsigned>;
72 using strides_type
= ublas::strides
<ublas::first_order
>;
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);
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);
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);
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);
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);
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);
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);
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);
119 BOOST_AUTO_TEST_CASE( test_strides_ctor_access_last_order
)
121 using namespace boost::numeric
;
123 using extents_type
= ublas::basic_extents
<unsigned>;
124 using strides_type
= ublas::strides
<ublas::last_order
>;
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);
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);
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);
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);
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);
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);
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);
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);
172 BOOST_AUTO_TEST_SUITE_END()