Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_SacadoMPVectorUnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Teuchos_UnitTestHarness.hpp"
43 #include "Teuchos_TestingHelpers.hpp"
44 #include "Teuchos_UnitTestRepository.hpp"
45 #include "Teuchos_GlobalMPISession.hpp"
46 
49 
50 #include "Kokkos_Core.hpp"
51 #include "Kokkos_Complex.hpp"
52 
53 //
54 // Currently this doesn't test:
55 // * the device
56 // * threaded storage (needs the device)
57 // * strided storage with non-trivial stride
58 //
59 
60 // Common setup for unit tests
61 template <typename VectorType>
62 struct UnitTestSetup {
63 
64  typedef VectorType vec_type;
65  typedef typename vec_type::value_type value_type;
66 
67  double rtol, atol;
68  double crtol, catol;
69  int sz;
72 
74  rtol = 1e-4;
75  atol = 1e-5;
76  crtol = 1e-12;
77  catol = 1e-12;
78  a = 3.1;
79  sz = 8;
80 
81  // Create vector
82  x.reset(sz);
83  y.reset(sz);
84  cx.reset(1);
85  cx = a;
86  for (int i=0; i<sz; i++) {
87  x.fastAccessCoeff(i) = 0.1*i;
88  y.fastAccessCoeff(i) = 0.25*i;
89  }
90  }
91 };
92 
97 #define UNARY_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME, USING_OP) \
98  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
99  UTS setup; \
100  UTS::vec_type u = OP(setup.x); \
101  UTS::vec_type v(setup.sz, 0.0); \
102  for (int i=0; i<setup.sz; i++) \
103  { \
104  USING_OP \
105  v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
106  } \
107  success = compareVecs(u, "u",v, "v", \
108  setup.rtol, setup.atol, out); \
109  } \
110  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const) { \
111  UTS setup; \
112  UTS::vec_type u = OP(setup.cx); \
113  UTS::vec_type v(1, 0.0); \
114  for (int i=0; i<v.size(); i++) \
115  { \
116  USING_OP \
117  v.fastAccessCoeff(i) = OP(setup.cx.fastAccessCoeff(0)); \
118  } \
119  success = compareVecs(u, "u",v, "v", \
120  setup.rtol, setup.atol, out); \
121  } \
122  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
123  UTS setup; \
124  UTS::vec_type u; \
125  u = OP(setup.x); \
126  UTS::vec_type v(setup.sz, 0.0); \
127  for (int i=0; i<setup.sz; i++) \
128  { \
129  USING_OP \
130  v.fastAccessCoeff(i) = OP(setup.x.fastAccessCoeff(i)); \
131  } \
132  success = compareVecs(u, "u",v, "v", \
133  setup.rtol, setup.atol, out); \
134  }
135 
136 #define BINARY_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME) \
137  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
138  UTS setup; \
139  UTS::vec_type u = setup.x OP setup.y; \
140  UTS::vec_type v(setup.sz, 0.0); \
141  for (int i=0; i<setup.sz; i++) \
142  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
143  setup.y.fastAccessCoeff(i); \
144  success = compareVecs(u, "u",v, "v", \
145  setup.rtol, setup.atol, out); \
146  } \
147  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const) { \
148  UTS setup; \
149  UTS::vec_type u = setup.a OP setup.y; \
150  UTS::vec_type v(setup.sz, 0.0); \
151  for (int i=0; i<setup.sz; i++) \
152  v.fastAccessCoeff(i) = setup.a OP setup.y.fastAccessCoeff(i); \
153  success = compareVecs(u, "u",v, "v", \
154  setup.rtol, setup.atol, out); \
155  } \
156  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const) { \
157  UTS setup; \
158  UTS::vec_type u = setup.x OP setup.a ; \
159  UTS::vec_type v(setup.sz, 0.0); \
160  for (int i=0; i<setup.sz; i++) \
161  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
162  setup.a; \
163  success = compareVecs(u, "u",v, "v", \
164  setup.rtol, setup.atol, out); \
165  } \
166  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_both_const) { \
167  UTS setup; \
168  UTS::vec_type u = setup.cx OP setup.cx; \
169  UTS::vec_type v(1, 0.0); \
170  for (int i=0; i<v.size(); i++) \
171  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
172  setup.cx.fastAccessCoeff(0); \
173  success = compareVecs(u, "u",v, "v", \
174  setup.rtol, setup.atol, out); \
175  } \
176  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const2) { \
177  UTS setup; \
178  UTS::vec_type u = setup.cx OP setup.x; \
179  UTS::vec_type v(setup.sz, 0.0); \
180  for (int i=0; i<setup.sz; i++) \
181  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) OP \
182  setup.x.fastAccessCoeff(i); \
183  success = compareVecs(u, "u",v, "v", \
184  setup.rtol, setup.atol, out); \
185  } \
186  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const2) { \
187  UTS setup; \
188  UTS::vec_type u = setup.x OP setup.cx; \
189  UTS::vec_type v(setup.sz, 0.0); \
190  for (int i=0; i<setup.sz; i++) \
191  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
192  setup.cx.fastAccessCoeff(0); \
193  success = compareVecs(u, "u",v, "v", \
194  setup.rtol, setup.atol, out); \
195  } \
196  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
197  UTS setup; \
198  UTS::vec_type u; \
199  u = setup.x OP setup.y; \
200  UTS::vec_type v(setup.sz, 0.0); \
201  for (int i=0; i<setup.sz; i++) \
202  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
203  setup.y.fastAccessCoeff(i); \
204  success = compareVecs(u, "u",v, "v", \
205  setup.rtol, setup.atol, out); \
206  } \
207  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const_resize) { \
208  UTS setup; \
209  UTS::vec_type u; \
210  u = setup.a OP setup.y; \
211  UTS::vec_type v(setup.sz, 0.0); \
212  for (int i=0; i<setup.sz; i++) \
213  v.fastAccessCoeff(i) = setup.a OP \
214  setup.y.fastAccessCoeff(i); \
215  success = compareVecs(u, "u",v, "v", \
216  setup.rtol, setup.atol, out); \
217  } \
218  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const_resize) { \
219  UTS setup; \
220  UTS::vec_type u; \
221  u = setup.x OP setup.a; \
222  UTS::vec_type v(setup.sz, 0.0); \
223  for (int i=0; i<setup.sz; i++) \
224  v.fastAccessCoeff(i) = setup.x.fastAccessCoeff(i) OP \
225  setup.a; \
226  success = compareVecs(u, "u",v, "v", \
227  setup.rtol, setup.atol, out); \
228  }
229 
230 #define BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, OP, SOP, USING_SOP, OPNAME) \
231  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
232  UTS setup; \
233  UTS::vec_type u = OP(setup.x,setup.y); \
234  UTS::vec_type v(setup.sz, 0.0); \
235  for (int i=0; i<setup.sz; i++) \
236  { \
237  USING_SOP \
238  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
239  setup.y.fastAccessCoeff(i)); \
240  } \
241  success = compareVecs(u, "u",v, "v", \
242  setup.rtol, setup.atol, out); \
243  } \
244  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const) { \
245  UTS setup; \
246  UTS::vec_type u = OP(setup.a,setup.y); \
247  UTS::vec_type v(setup.sz, 0.0); \
248  for (int i=0; i<setup.sz; i++) \
249  { \
250  USING_SOP \
251  v.fastAccessCoeff(i) = SOP(setup.a, \
252  setup.y.fastAccessCoeff(i)); \
253  } \
254  success = compareVecs(u, "u",v, "v", \
255  setup.rtol, setup.atol, out); \
256  } \
257  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const) { \
258  UTS setup; \
259  UTS::vec_type u = OP(setup.x,setup.a); \
260  UTS::vec_type v(setup.sz, 0.0); \
261  for (int i=0; i<setup.sz; i++) \
262  { \
263  USING_SOP \
264  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
265  setup.a); \
266  } \
267  success = compareVecs(u, "u",v, "v", \
268  setup.rtol, setup.atol, out); \
269  } \
270  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_both_const) { \
271  UTS setup; \
272  UTS::vec_type u = OP(setup.cx,setup.cx); \
273  UTS::vec_type v(1, 0.0); \
274  for (int i=0; i<v.size(); i++) \
275  { \
276  USING_SOP \
277  v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
278  setup.cx.fastAccessCoeff(0)); \
279  } \
280  success = compareVecs(u, "u",v, "v", \
281  setup.rtol, setup.atol, out); \
282  } \
283  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const2) { \
284  UTS setup; \
285  UTS::vec_type u = OP(setup.cx,setup.x); \
286  UTS::vec_type v(setup.sz, 0.0); \
287  for (int i=0; i<setup.sz; i++) \
288  { \
289  USING_SOP \
290  v.fastAccessCoeff(i) = SOP(setup.cx.fastAccessCoeff(0), \
291  setup.x.fastAccessCoeff(i)); \
292  } \
293  success = compareVecs(u, "u",v, "v", \
294  setup.rtol, setup.atol, out); \
295  } \
296  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const2) { \
297  UTS setup; \
298  UTS::vec_type u = OP(setup.x,setup.cx); \
299  UTS::vec_type v(setup.sz, 0.0); \
300  for (int i=0; i<setup.sz; i++) \
301  { \
302  USING_SOP \
303  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
304  setup.cx.fastAccessCoeff(0)); \
305  } \
306  success = compareVecs(u, "u",v, "v", \
307  setup.rtol, setup.atol, out); \
308  } \
309  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
310  UTS setup; \
311  UTS::vec_type u; \
312  u = OP(setup.x,setup.y); \
313  UTS::vec_type v(setup.sz, 0.0); \
314  for (int i=0; i<setup.sz; i++) \
315  { \
316  USING_SOP \
317  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
318  setup.y.fastAccessCoeff(i)); \
319  } \
320  success = compareVecs(u, "u",v, "v", \
321  setup.rtol, setup.atol, out); \
322  } \
323  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_left_const_resize) { \
324  UTS setup; \
325  UTS::vec_type u; \
326  u = OP(setup.a,setup.y); \
327  UTS::vec_type v(setup.sz, 0.0); \
328  for (int i=0; i<setup.sz; i++) \
329  { \
330  USING_SOP \
331  v.fastAccessCoeff(i) = SOP(setup.a, \
332  setup.y.fastAccessCoeff(i)); \
333  } \
334  success = compareVecs(u, "u",v, "v", \
335  setup.rtol, setup.atol, out); \
336  } \
337  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_right_const_resize) { \
338  UTS setup; \
339  UTS::vec_type u; \
340  u = OP(setup.x,setup.a); \
341  UTS::vec_type v(setup.sz, 0.0); \
342  for (int i=0; i<setup.sz; i++) \
343  { \
344  USING_SOP \
345  v.fastAccessCoeff(i) = SOP(setup.x.fastAccessCoeff(i), \
346  setup.a); \
347  } \
348  success = compareVecs(u, "u",v, "v", \
349  setup.rtol, setup.atol, out); \
350  }
351 
352 #define OPASSIGN_UNIT_TEST(VEC, SCALAR_T, OP, OPNAME) \
353  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME) { \
354  UTS setup; \
355  UTS::vec_type u = std::sin(setup.x); \
356  UTS::vec_type v = std::sin(setup.x); \
357  u OP setup.x; \
358  for (int i=0; i<setup.sz; i++) \
359  v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
360  success = compareVecs(u, "u",v, "v", \
361  setup.rtol, setup.atol, out); \
362  } \
363  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const) { \
364  UTS setup; \
365  UTS::vec_type u = std::sin(setup.x); \
366  UTS::vec_type v = std::sin(setup.x); \
367  u OP setup.a; \
368  for (int i=0; i<setup.sz; i++) \
369  v.fastAccessCoeff(i) OP setup.a; \
370  success = compareVecs(u, "u",v, "v", \
371  setup.rtol, setup.atol, out); \
372  } \
373  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_const2) { \
374  UTS setup; \
375  UTS::vec_type u = std::sin(setup.x); \
376  UTS::vec_type v = std::sin(setup.x); \
377  u OP setup.cx; \
378  for (int i=0; i<setup.sz; i++) \
379  v.fastAccessCoeff(i) OP setup.cx.fastAccessCoeff(0); \
380  success = compareVecs(u, "u",v, "v", \
381  setup.rtol, setup.atol, out); \
382  } \
383  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, OPNAME##_resize) { \
384  UTS setup; \
385  UTS::vec_type u = setup.a; \
386  UTS::vec_type v(setup.sz, 0.0); \
387  u OP setup.x; \
388  for (int i=0; i<setup.sz; i++) { \
389  v.fastAccessCoeff(i) = setup.a; \
390  v.fastAccessCoeff(i) OP setup.x.fastAccessCoeff(i); \
391  } \
392  success = compareVecs(u, "u",v, "v", \
393  setup.rtol, setup.atol, out); \
394  }
395 
396 #define SAXPY_UNIT_TEST(VEC, SCALAR_T) \
397  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy) { \
398  UTS setup; \
399  UTS::vec_type u = std::sin(setup.x); \
400  UTS::vec_type v = std::sin(setup.x); \
401  u += setup.x*setup.y; \
402  for (int i=0; i<setup.sz; i++) \
403  v.fastAccessCoeff(i) += \
404  setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
405  success = compareVecs(u, "u",v, "v", \
406  setup.rtol, setup.atol, out); \
407  } \
408  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_resize) { \
409  UTS setup; \
410  UTS::vec_type u = setup.cx; \
411  UTS::vec_type v(setup.sz, 0.0); \
412  u += setup.x*setup.y; \
413  for (int i=0; i<setup.sz; i++) \
414  v.fastAccessCoeff(i) = setup.cx.fastAccessCoeff(0) + \
415  setup.x.fastAccessCoeff(i)*setup.y.fastAccessCoeff(i); \
416  success = compareVecs(u, "u",v, "v", \
417  setup.rtol, setup.atol, out); \
418  } \
419  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_const) { \
420  UTS setup; \
421  UTS::vec_type u = std::sin(setup.x); \
422  UTS::vec_type v = std::sin(setup.x); \
423  u += setup.a*setup.y; \
424  for (int i=0; i<setup.sz; i++) \
425  v.fastAccessCoeff(i) += \
426  setup.a*setup.y.fastAccessCoeff(i); \
427  success = compareVecs(u, "u",v, "v", \
428  setup.rtol, setup.atol, out); \
429  } \
430  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, saxpy_const2) { \
431  UTS setup; \
432  UTS::vec_type u = std::sin(setup.x); \
433  UTS::vec_type v = std::sin(setup.x); \
434  u += setup.cx*setup.y; \
435  for (int i=0; i<setup.sz; i++) \
436  v.fastAccessCoeff(i) += \
437  setup.cx.fastAccessCoeff(0)*setup.y.fastAccessCoeff(i); \
438  success = compareVecs(u, "u",v, "v", \
439  setup.rtol, setup.atol, out); \
440  }
441 
442 #define TERNARY_UNIT_TEST(VEC, SCALAR_T) \
443  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, ternay) { \
444  UTS setup; \
445  UTS::vec_type u = std::sin(setup.x); \
446  UTS::vec_type v = -std::sin(setup.x); \
447  u = u >= 0 ? -u : u; \
448  success = compareVecs(u, "u", v, "v", \
449  setup.rtol, setup.atol, out); \
450  }
451 
456 #define VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T) \
457  UNARY_UNIT_TEST(VEC, SCALAR_T, + , UnaryPlus ,) \
458  UNARY_UNIT_TEST(VEC, SCALAR_T, - , UnaryMinus,) \
459  UNARY_UNIT_TEST(VEC, SCALAR_T, exp , Exp , using std::exp; ) \
460  UNARY_UNIT_TEST(VEC, SCALAR_T, log , Log , using std::log; ) \
461  UNARY_UNIT_TEST(VEC, SCALAR_T, log10, Log10 , using std::log10;) \
462  UNARY_UNIT_TEST(VEC, SCALAR_T, sqrt , Sqrt , using std::sqrt; ) \
463  UNARY_UNIT_TEST(VEC, SCALAR_T, sin , Sin , using std::sin; ) \
464  UNARY_UNIT_TEST(VEC, SCALAR_T, cos , Cos , using std::cos; ) \
465  UNARY_UNIT_TEST(VEC, SCALAR_T, tan , Tan , using std::tan; ) \
466  UNARY_UNIT_TEST(VEC, SCALAR_T, sinh , Sinh , using std::sinh; ) \
467  UNARY_UNIT_TEST(VEC, SCALAR_T, cosh , Cosh , using std::cosh; ) \
468  UNARY_UNIT_TEST(VEC, SCALAR_T, tanh , Tanh , using std::tanh; ) \
469  UNARY_UNIT_TEST(VEC, SCALAR_T, asin , ASin , using std::asin; ) \
470  UNARY_UNIT_TEST(VEC, SCALAR_T, acos , ACos , using std::acos; ) \
471  UNARY_UNIT_TEST(VEC, SCALAR_T, atan , ATan , using std::atan; ) \
472  UNARY_UNIT_TEST(VEC, SCALAR_T, asinh, ASinh , using std::asinh;) \
473  UNARY_UNIT_TEST(VEC, SCALAR_T, acosh, ACosh , using std::acosh;) \
474  UNARY_UNIT_TEST(VEC, SCALAR_T, atanh, ATanh , using std::atanh;) \
475  \
476  BINARY_UNIT_TEST(VEC, SCALAR_T, +, Plus) \
477  BINARY_UNIT_TEST(VEC, SCALAR_T, -, Minus) \
478  BINARY_UNIT_TEST(VEC, SCALAR_T, *, Times) \
479  BINARY_UNIT_TEST(VEC, SCALAR_T, /, Divide) \
480  \
481  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, pow, pow, using std::pow;, Pow) \
482  \
483  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, +=, PlusEqual) \
484  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, -=, MinusEqual) \
485  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, *=, TimesEqual) \
486  OPASSIGN_UNIT_TEST(VEC, SCALAR_T, /=, DivideEqual) \
487  \
488  SAXPY_UNIT_TEST(VEC, SCALAR_T) \
489  \
490  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_constructor ) { \
491  UTS setup; \
492  UTS::vec_type u{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
493  UTS::vec_type v(setup.sz, 0.0); \
494  for (int i=0; i<setup.sz; i++) \
495  v.fastAccessCoeff(i) = i+1; \
496  success = compareVecs(u, "u", v, "v", \
497  setup.rtol, setup.atol, out); \
498  } \
499  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_copy ) { \
500  UTS setup; \
501  UTS::vec_type u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
502  UTS::vec_type v(setup.sz, 0.0); \
503  for (int i=0; i<setup.sz; i++) \
504  v.fastAccessCoeff(i) = i+1; \
505  success = compareVecs(u, "u", v, "v", \
506  setup.rtol, setup.atol, out); \
507  } \
508  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, initializer_list_assign ) { \
509  UTS setup; \
510  UTS::vec_type u; \
511  u = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; \
512  UTS::vec_type v(setup.sz, 0.0); \
513  for (int i=0; i<setup.sz; i++) \
514  v.fastAccessCoeff(i) = i+1; \
515  success = compareVecs(u, "u", v, "v", \
516  setup.rtol, setup.atol, out); \
517  } \
518  TEUCHOS_UNIT_TEST( VEC##_##SCALAR_T, range_based_for ) { \
519  UTS setup; \
520  UTS::vec_type u(setup.sz, 0.0); \
521  for (auto& z : u) { z = 3.0; } \
522  UTS::vec_type v(setup.sz, 3.0); \
523  success = compareVecs(u, "u", v, "v", \
524  setup.rtol, setup.atol, out); \
525  }
526 
530  #define VECTOR_UNIT_TESTS_SFS_ANY_VALUE_TYPE(SCALAR_T) \
531  TEUCHOS_UNIT_TEST( StaticFixedVector##_##SCALAR_T, initializer_list_constructor_partial ) {\
532  UTS setup; \
533  UTS::vec_type u{ 1.0}; \
534  UTS::vec_type v(setup.sz, 1.0); \
535  success = compareVecs(u, "u", v, "v", \
536  setup.rtol, setup.atol, out); \
537  } \
538  TEUCHOS_UNIT_TEST( StaticFixedVector##_##SCALAR_T, initializer_list_constructor_empty ) { \
539  UTS setup; \
540  UTS::vec_type u{ std::initializer_list<typename UTS::value_type>()}; \
541  UTS::vec_type v(setup.sz, 0.0); \
542  success = compareVecs(u, "u", v, "v", \
543  setup.rtol, setup.atol, out); \
544  }
545 
549 #define VECTOR_UNIT_TESTS_COMPLEX_TYPE(VEC,SCALAR_T) \
550  /* Run the series of tests for any type. */ \
551  VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T)
552 
558 #define VECTOR_UNIT_TESTS_REAL_TYPE(VEC,SCALAR_T) \
559  /* Run the series of tests for any type. */ \
560  VECTOR_UNIT_TESTS_ANY_TYPE(VEC,SCALAR_T) \
561  /* Operator cbrt not supported for complex type but supported for real type. */ \
562  UNARY_UNIT_TEST(VEC, SCALAR_T, cbrt , Cbrt, using std::cbrt;) \
563  /* Operator atan2 not supported for complex type but supported for real type. */ \
564  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, atan2, atan2, using std::atan2;, ATan2) \
565  /* Operators min and max are not supported for complex type. */ \
566  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, max , max , using std::max ;, Max) \
567  BINARYFUNC_UNIT_TEST(VEC, SCALAR_T, min , min , using std::min ;, Min) \
568  /* Ternary test uses 'operator<' that is not defined for complex type. */ \
569  TERNARY_UNIT_TEST(VEC, SCALAR_T)
570 
574 #define TEST_DYNAMIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__macro_for_tests__)\
575  typedef Kokkos::DefaultExecutionSpace execution_space; \
576  typedef Stokhos::__storage_type__<int,__scalar_type__,execution_space> storage_type; \
577  typedef Sacado::MP::Vector<storage_type> vec_type; \
578  typedef UnitTestSetup<vec_type> UTS; \
579  __macro_for_tests__(__vec_type__,__scalar_type__)
580 
581 namespace DynamicVecTest
582 {
583  TEST_DYNAMIC_STORAGE(DynamicStorage, DynamicVector, double, VECTOR_UNIT_TESTS_REAL_TYPE)
584 }
585 
586 namespace DynamicStridedVecTest
587 {
588  TEST_DYNAMIC_STORAGE(DynamicStridedStorage, DynamicStridedVector, double, VECTOR_UNIT_TESTS_REAL_TYPE)
589 }
590 
594 #define TEST_STATIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
595  typedef ::Kokkos::DefaultExecutionSpace execution_space; \
596  typedef ::Stokhos::__storage_type__<int,__scalar_type__,__storage_size__,execution_space> storage_type; \
597  typedef ::Sacado::MP::Vector<storage_type> vec_type; \
598  typedef UnitTestSetup<vec_type> UTS; \
599  __macro_for_tests__(__vec_type__,__scalar_type_name__)
600 
601 namespace StaticVecTest
602 {
603  TEST_STATIC_STORAGE(StaticStorage, StaticVector, double, double, 8, VECTOR_UNIT_TESTS_REAL_TYPE)
604 }
605 
609 #define TEST_STATIC_FIXED_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
610  TEST_STATIC_STORAGE(__storage_type__,__vec_type__,__scalar_type__,__scalar_type_name__,__storage_size__,__macro_for_tests__) \
611  VECTOR_UNIT_TESTS_SFS_ANY_VALUE_TYPE(__scalar_type_name__)
612 
613 
614 namespace StaticFixedVecTest
615 {
616  namespace Double {TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, double , double, 8, VECTOR_UNIT_TESTS_REAL_TYPE )}
617 
618 // Skip std::complex when compiling with CUDA, because std::complex isn't supported in that case.
619 // Note that even though the tests aren't run on the device, nvcc still complains that __device__ code functions are called
620 // from __host__ code (or vice versa).
621 #if !defined(KOKKOS_ENABLE_CUDA) && !defined(KOKKOS_ENABLE_HIP)
622  namespace Complex_std {TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, std ::complex<double>, std_complex_double, 8, VECTOR_UNIT_TESTS_COMPLEX_TYPE)}
623 #endif
624 
625  // Always test for Kokkos::complex because it is always shipped as part of Kokkos, whatever the space.
626  namespace Complex_Kokkos{TEST_STATIC_FIXED_STORAGE(StaticFixedStorage, StaticFixedVector, ::Kokkos::complex<double>, kokkos_complex_double, 8, VECTOR_UNIT_TESTS_COMPLEX_TYPE)}
627 }
#define VECTOR_UNIT_TESTS_REAL_TYPE(VEC, SCALAR_T)
#define TEST_DYNAMIC_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __macro_for_tests__)
#define TEST_STATIC_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __scalar_type_name__, __storage_size__, __macro_for_tests__)
#define TEST_STATIC_FIXED_STORAGE(__storage_type__, __vec_type__, __scalar_type__, __scalar_type_name__, __storage_size__, __macro_for_tests__)
#define VECTOR_UNIT_TESTS_COMPLEX_TYPE(VEC, SCALAR_T)
vec_type::value_type value_type