50 #include <Kokkos_Core.hpp>
60 template <
typename VectorType>
84 for (
int i=0; i<
sz; i++) {
85 x.fastAccessCoeff(i) = 0.1*i;
86 y.fastAccessCoeff(i) = 0.25*i;
91 #define UNARY_UNIT_TEST(VEC, OP, OPNAME) \
92 TEUCHOS_UNIT_TEST( VEC, OPNAME) { \
94 UTS::vec_type u = OP(setup.x); \
95 UTS::vec_type v(setup.sz, 0.0); \
96 for (int i=0; i<setup.sz; i++) \
97 v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
98 success = compareVecs(u, "u",v, "v", \
99 setup.rtol, setup.atol, out); \
101 TEUCHOS_UNIT_TEST( VEC, OPNAME##_const) { \
103 UTS::vec_type u = OP(setup.cx); \
104 UTS::vec_type v(1, 0.0); \
105 for (int i=0; i<v.size(); i++) \
106 v.fastAccessCoeff(i) = OP(setup.cx.fastAccessCoeff(0)); \
107 success = compareVecs(u, "u",v, "v", \
108 setup.rtol, setup.atol, out); \
110 TEUCHOS_UNIT_TEST( VEC, OPNAME##_resize) { \
114 UTS::vec_type v(setup.sz, 0.0); \
115 for (int i=0; i<setup.sz; i++) \
116 v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
117 success = compareVecs(u, "u",v, "v", \
118 setup.rtol, setup.atol, out); \
121 #define BINARY_UNIT_TEST(VEC, OP, OPNAME) \
122 TEUCHOS_UNIT_TEST( VEC, OPNAME) { \
124 UTS::vec_type u = setup.x OP setup.y; \
125 UTS::vec_type v(setup.sz, 0.0); \
126 for (int i=0; i<setup.sz; i++) \
127 v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
128 setup.y.fastAccessCoeff(i); \
129 success = compareVecs(u, "u",v, "v", \
130 setup.rtol, setup.atol, out); \
132 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const) { \
134 UTS::vec_type u = setup.a OP setup.y; \
135 UTS::vec_type v(setup.sz, 0.0); \
136 for (int i=0; i<setup.sz; i++) \
137 v.fastAccessCoeff(i) = setup.a OP setup.y.fastAccessCoeff(i); \
138 success = compareVecs(u, "u",v, "v", \
139 setup.rtol, setup.atol, out); \
141 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const) { \
143 UTS::vec_type u = setup.x OP setup.a ; \
144 UTS::vec_type v(setup.sz, 0.0); \
145 for (int i=0; i<setup.sz; i++) \
146 v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
148 success = compareVecs(u, "u",v, "v", \
149 setup.rtol, setup.atol, out); \
151 TEUCHOS_UNIT_TEST( VEC, OPNAME##_both_const) { \
153 UTS::vec_type u = setup.cx OP setup.cx; \
154 UTS::vec_type v(1, 0.0); \
155 for (int i=0; i<v.size(); i++) \
156 v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
157 setup.cx.fastAccessCoeff(0); \
158 success = compareVecs(u, "u",v, "v", \
159 setup.rtol, setup.atol, out); \
161 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const2) { \
163 UTS::vec_type u = setup.cx OP setup.x; \
164 UTS::vec_type v(setup.sz, 0.0); \
165 for (int i=0; i<setup.sz; i++) \
166 v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
167 setup.x.fastAccessCoeff(i); \
168 success = compareVecs(u, "u",v, "v", \
169 setup.rtol, setup.atol, out); \
171 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const2) { \
173 UTS::vec_type u = setup.x OP setup.cx; \
174 UTS::vec_type v(setup.sz, 0.0); \
175 for (int i=0; i<setup.sz; i++) \
176 v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
177 setup.cx.fastAccessCoeff(0); \
178 success = compareVecs(u, "u",v, "v", \
179 setup.rtol, setup.atol, out); \
181 TEUCHOS_UNIT_TEST( VEC, OPNAME##_resize) { \
184 u = setup.x OP setup.y; \
185 UTS::vec_type v(setup.sz, 0.0); \
186 for (int i=0; i<setup.sz; i++) \
187 v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
188 setup.y.fastAccessCoeff(i); \
189 success = compareVecs(u, "u",v, "v", \
190 setup.rtol, setup.atol, out); \
192 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const_resize) { \
195 u = setup.a OP setup.y; \
196 UTS::vec_type v(setup.sz, 0.0); \
197 for (int i=0; i<setup.sz; i++) \
198 v.fastAccessCoeff(i) = setup.a OP \
199 setup.y.fastAccessCoeff(i); \
200 success = compareVecs(u, "u",v, "v", \
201 setup.rtol, setup.atol, out); \
203 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const_resize) { \
206 u = setup.x OP setup.a; \
207 UTS::vec_type v(setup.sz, 0.0); \
208 for (int i=0; i<setup.sz; i++) \
209 v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
211 success = compareVecs(u, "u",v, "v", \
212 setup.rtol, setup.atol, out); \
215 #define BINARYFUNC_UNIT_TEST(VEC, OP, SOP, OPNAME) \
216 TEUCHOS_UNIT_TEST( VEC, OPNAME) { \
218 UTS::vec_type u = OP(setup.x,setup.y); \
219 UTS::vec_type v(setup.sz, 0.0); \
220 for (int i=0; i<setup.sz; i++) \
221 v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
222 setup.y.fastAccessCoeff(i)); \
223 success = compareVecs(u, "u",v, "v", \
224 setup.rtol, setup.atol, out); \
226 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const) { \
228 UTS::vec_type u = OP(setup.a,setup.y); \
229 UTS::vec_type v(setup.sz, 0.0); \
230 for (int i=0; i<setup.sz; i++) \
231 v.fastAccessCoeff(i) = SOP(setup.a, \
232 setup.y.fastAccessCoeff(i)); \
233 success = compareVecs(u, "u",v, "v", \
234 setup.rtol, setup.atol, out); \
236 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const) { \
238 UTS::vec_type u = OP(setup.x,setup.a); \
239 UTS::vec_type v(setup.sz, 0.0); \
240 for (int i=0; i<setup.sz; i++) \
241 v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
243 success = compareVecs(u, "u",v, "v", \
244 setup.rtol, setup.atol, out); \
246 TEUCHOS_UNIT_TEST( VEC, OPNAME##_both_const) { \
248 UTS::vec_type u = OP(setup.cx,setup.cx); \
249 UTS::vec_type v(1, 0.0); \
250 for (int i=0; i<v.size(); i++) \
251 v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
252 setup.cx.fastAccessCoeff(0)); \
253 success = compareVecs(u, "u",v, "v", \
254 setup.rtol, setup.atol, out); \
256 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const2) { \
258 UTS::vec_type u = OP(setup.cx,setup.x); \
259 UTS::vec_type v(setup.sz, 0.0); \
260 for (int i=0; i<setup.sz; i++) \
261 v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
262 setup.x.fastAccessCoeff(i)); \
263 success = compareVecs(u, "u",v, "v", \
264 setup.rtol, setup.atol, out); \
266 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const2) { \
268 UTS::vec_type u = OP(setup.x,setup.cx); \
269 UTS::vec_type v(setup.sz, 0.0); \
270 for (int i=0; i<setup.sz; i++) \
271 v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
272 setup.cx.fastAccessCoeff(0)); \
273 success = compareVecs(u, "u",v, "v", \
274 setup.rtol, setup.atol, out); \
276 TEUCHOS_UNIT_TEST( VEC, OPNAME##_resize) { \
279 u = OP(setup.x,setup.y); \
280 UTS::vec_type v(setup.sz, 0.0); \
281 for (int i=0; i<setup.sz; i++) \
282 v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
283 setup.y.fastAccessCoeff(i)); \
284 success = compareVecs(u, "u",v, "v", \
285 setup.rtol, setup.atol, out); \
287 TEUCHOS_UNIT_TEST( VEC, OPNAME##_left_const_resize) { \
290 u = OP(setup.a,setup.y); \
291 UTS::vec_type v(setup.sz, 0.0); \
292 for (int i=0; i<setup.sz; i++) \
293 v.fastAccessCoeff(i) = SOP(setup.a, \
294 setup.y.fastAccessCoeff(i)); \
295 success = compareVecs(u, "u",v, "v", \
296 setup.rtol, setup.atol, out); \
298 TEUCHOS_UNIT_TEST( VEC, OPNAME##_right_const_resize) { \
301 u = OP(setup.x,setup.a); \
302 UTS::vec_type v(setup.sz, 0.0); \
303 for (int i=0; i<setup.sz; i++) \
304 v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
306 success = compareVecs(u, "u",v, "v", \
307 setup.rtol, setup.atol, out); \
310 #define OPASSIGN_UNIT_TEST(VEC, OP, OPNAME) \
311 TEUCHOS_UNIT_TEST( VEC, OPNAME) { \
313 UTS::vec_type u = std::sin(setup.x); \
314 UTS::vec_type v = std::sin(setup.x); \
316 for (int i=0; i<setup.sz; i++) \
317 v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
318 success = compareVecs(u, "u",v, "v", \
319 setup.rtol, setup.atol, out); \
321 TEUCHOS_UNIT_TEST( VEC, OPNAME##_const) { \
323 UTS::vec_type u = std::sin(setup.x); \
324 UTS::vec_type v = std::sin(setup.x); \
326 for (int i=0; i<setup.sz; i++) \
327 v.fastAccessCoeff(i) OP setup.a; \
328 success = compareVecs(u, "u",v, "v", \
329 setup.rtol, setup.atol, out); \
331 TEUCHOS_UNIT_TEST( VEC, OPNAME##_const2) { \
333 UTS::vec_type u = std::sin(setup.x); \
334 UTS::vec_type v = std::sin(setup.x); \
336 for (int i=0; i<setup.sz; i++) \
337 v.fastAccessCoeff(i) OP setup.cx.fastAccessCoeff(0); \
338 success = compareVecs(u, "u",v, "v", \
339 setup.rtol, setup.atol, out); \
341 TEUCHOS_UNIT_TEST( VEC, OPNAME##_resize) { \
343 UTS::vec_type u = setup.a; \
344 UTS::vec_type v(setup.sz, 0.0); \
346 for (int i=0; i<setup.sz; i++) { \
347 v.fastAccessCoeff(i) = setup.a; \
348 v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
350 success = compareVecs(u, "u",v, "v", \
351 setup.rtol, setup.atol, out); \
354 #define SAXPY_UNIT_TEST(VEC) \
355 TEUCHOS_UNIT_TEST( VEC, saxpy) { \
357 UTS::vec_type u = std::sin(setup.x); \
358 UTS::vec_type v = std::sin(setup.x); \
359 u += setup.x*setup.y; \
360 for (int i=0; i<setup.sz; i++) \
361 v.fastAccessCoeff(i) += \
362 setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
363 success = compareVecs(u, "u",v, "v", \
364 setup.rtol, setup.atol, out); \
366 TEUCHOS_UNIT_TEST( VEC, saxpy_resize) { \
368 UTS::vec_type u = setup.cx; \
369 UTS::vec_type v(setup.sz, 0.0); \
370 u += setup.x*setup.y; \
371 for (int i=0; i<setup.sz; i++) \
372 v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) + \
373 setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
374 success = compareVecs(u, "u",v, "v", \
375 setup.rtol, setup.atol, out); \
377 TEUCHOS_UNIT_TEST( VEC, saxpy_const) { \
379 UTS::vec_type u = std::sin(setup.x); \
380 UTS::vec_type v = std::sin(setup.x); \
381 u += setup.a*setup.y; \
382 for (int i=0; i<setup.sz; i++) \
383 v.fastAccessCoeff(i) += \
384 setup.a*setup.y.fastAccessCoeff(i); \
385 success = compareVecs(u, "u",v, "v", \
386 setup.rtol, setup.atol, out); \
388 TEUCHOS_UNIT_TEST( VEC, saxpy_const2) { \
390 UTS::vec_type u = std::sin(setup.x); \
391 UTS::vec_type v = std::sin(setup.x); \
392 u += setup.cx*setup.y; \
393 for (int i=0; i<setup.sz; i++) \
394 v.fastAccessCoeff(i) += \
395 setup.cx.fastAccessCoeff(0)*setup.y.fastAccessCoeff(i); \
396 success = compareVecs(u, "u",v, "v", \
397 setup.rtol, setup.atol, out); \
400 #define VECTOR_UNIT_TESTS(VEC) \
401 UNARY_UNIT_TEST(VEC, +, UnaryPlus) \
402 UNARY_UNIT_TEST(VEC, -, UnaryMinus) \
403 UNARY_UNIT_TEST(VEC, std::exp, Exp) \
404 UNARY_UNIT_TEST(VEC, std::log, Log) \
405 UNARY_UNIT_TEST(VEC, std::log10, Log10) \
406 UNARY_UNIT_TEST(VEC, std::sqrt, Sqrt) \
407 UNARY_UNIT_TEST(VEC, std::cbrt, Cbrt) \
408 UNARY_UNIT_TEST(VEC, std::sin, Sin) \
409 UNARY_UNIT_TEST(VEC, std::cos, Cos) \
410 UNARY_UNIT_TEST(VEC, std::tan, Tan) \
411 UNARY_UNIT_TEST(VEC, std::sinh, Sinh) \
412 UNARY_UNIT_TEST(VEC, std::cosh, Cosh) \
413 UNARY_UNIT_TEST(VEC, std::tanh, Tanh) \
414 UNARY_UNIT_TEST(VEC, std::asin, ASin) \
415 UNARY_UNIT_TEST(VEC, std::acos, ACos) \
416 UNARY_UNIT_TEST(VEC, std::atan, ATan) \
417 UNARY_UNIT_TEST(VEC, std::asinh, ASinh) \
418 UNARY_UNIT_TEST(VEC, std::acosh, ACosh) \
419 UNARY_UNIT_TEST(VEC, std::atanh, ATanh) \
421 BINARY_UNIT_TEST(VEC, +, Plus) \
422 BINARY_UNIT_TEST(VEC, -, Minus) \
423 BINARY_UNIT_TEST(VEC, *, Times) \
424 BINARY_UNIT_TEST(VEC, /, Divide) \
426 BINARYFUNC_UNIT_TEST(VEC, atan2, std::atan2, ATan2) \
427 BINARYFUNC_UNIT_TEST(VEC, pow, std::pow, Pow) \
428 BINARYFUNC_UNIT_TEST(VEC, max, std::max, Max) \
429 BINARYFUNC_UNIT_TEST(VEC, min, std::min, Min) \
431 OPASSIGN_UNIT_TEST(VEC, +=, PlusEqual) \
432 OPASSIGN_UNIT_TEST(VEC, -=, MinusEqual) \
433 OPASSIGN_UNIT_TEST(VEC, *=, TimesEqual) \
434 OPASSIGN_UNIT_TEST(VEC, /=, DivideEqual) \
436 SAXPY_UNIT_TEST(VEC) \
438 TEUCHOS_UNIT_TEST( VEC, initializer_list_copy ) { \
440 UTS::vec_type u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
441 UTS::vec_type v(setup.sz, 0.0); \
442 for (int i=0; i<setup.sz; i++) \
443 v.fastAccessCoeff(i) = i+1; \
444 success = compareVecs(u, "u", v, "v", \
445 setup.rtol, setup.atol, out); \
447 TEUCHOS_UNIT_TEST( VEC, initializer_list_assign ) { \
450 u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
451 UTS::vec_type v(setup.sz, 0.0); \
452 for (int i=0; i<setup.sz; i++) \
453 v.fastAccessCoeff(i) = i+1; \
454 success = compareVecs(u, "u", v, "v", \
455 setup.rtol, setup.atol, out); \
457 TEUCHOS_UNIT_TEST( VEC, range_based_for ) { \
459 UTS::vec_type u(setup.sz, 0.0); \
460 for (auto& z : u) { z = 3.0; } \
461 UTS::vec_type v(setup.sz, 3.0); \
462 success = compareVecs(u, "u", v, "v", \
463 setup.rtol, setup.atol, out); \
466 namespace DynamicVecTest {
474 namespace DynamicStridedVecTest {
482 namespace StaticVecTest {
490 namespace StaticFixedVecTest {
501 Kokkos::initialize();
UnitTestSetup< vec_type > UTS
Stokhos::StaticFixedStorage< int, double, 8, execution_space > storage_type
Kokkos::DefaultExecutionSpace execution_space
Statically allocated storage class.
Kokkos::DefaultExecutionSpace execution_space
UnitTestSetup< vec_type > UTS
Stokhos::DynamicStorage< int, double, execution_space > storage_type
Stokhos::DynamicStridedStorage< int, double, execution_space > storage_type
Stokhos::StaticStorage< int, double, 8, execution_space > storage_type
Sacado::MP::Vector< storage_type > vec_type
static int runUnitTestsFromMain(int argc, char *argv[])
UnitTestSetup< vec_type > UTS
#define VECTOR_UNIT_TESTS(VEC)
Kokkos::DefaultExecutionSpace execution_space
int main(int argc, char **argv)
Kokkos::DefaultExecutionSpace execution_space
Sacado::MP::Vector< storage_type > vec_type
Sacado::MP::Vector< storage_type > vec_type
Sacado::MP::Vector< storage_type > vec_type
Statically allocated storage class.
UnitTestSetup< vec_type > UTS