Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MP_Vector_MaskTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_MP_VECTOR_MASKTRAITS_HPP
11 #define STOKHOS_MP_VECTOR_MASKTRAITS_HPP
12 
14 #include <iostream>
15 #include <cmath>
16 
17 template <typename T>
19  static const std::size_t size = 1;
20  typedef T value_type;
21  KOKKOS_INLINE_FUNCTION
22  static const value_type& coeff(const T& x, int i) { return x; }
23  KOKKOS_INLINE_FUNCTION
24  static value_type& coeff(T& x, int i) { return x; }
25 };
26 
27 template <typename S>
28 struct EnsembleTraits_m< Sacado::MP::Vector<S> > {
29  static const std::size_t size = S::static_size ? S::static_size : 1;
30  typedef typename S::value_type value_type;
31  KOKKOS_INLINE_FUNCTION
32  static const value_type& coeff(const Sacado::MP::Vector<S>& x, int i) {
33  return x.fastAccessCoeff(i);
34  }
35  KOKKOS_INLINE_FUNCTION
36  static value_type& coeff(Sacado::MP::Vector<S>& x, int i) {
37  return x.fastAccessCoeff(i);
38  }
39 };
40 
41 template<typename scalar> class MaskedAssign
42 {
43 private:
44  scalar &data;
45  bool m;
46 
47 public:
48  KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, bool m_) : data(data_), m(m_) {};
49 
50  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const scalar & KOKKOS_RESTRICT s)
51  {
52  if(m)
53  data = s;
54 
55  return *this;
56  }
57 
58  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
59  {
60  auto st_array = st.begin();
61 
62  if(m)
63  data = st_array[0];
64  else
65  data = st_array[1];
66 
67  return *this;
68  }
69 
70 
71  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const scalar & KOKKOS_RESTRICT s)
72  {
73  if(m)
74  data += s;
75 
76  return *this;
77  }
78 
79  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
80  {
81  auto st_array = st.begin();
82 
83  if(m)
84  data = st_array[0]+st_array[1];
85  else
86  data = st_array[2];
87 
88  return *this;
89  }
90 
91  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const scalar & KOKKOS_RESTRICT s)
92  {
93  if(m)
94  data -= s;
95 
96  return *this;
97  }
98 
99  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
100  {
101  auto st_array = st.begin();
102 
103  if(m)
104  data = st_array[0]-st_array[1];
105  else
106  data = st_array[2];
107 
108  return *this;
109  }
110 
111  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const scalar & KOKKOS_RESTRICT s)
112  {
113  if(m)
114  data *= s;
115 
116  return *this;
117  }
118 
119  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
120  {
121  auto st_array = st.begin();
122 
123  if(m)
124  data = st_array[0]*st_array[1];
125  else
126  data = st_array[2];
127 
128  return *this;
129  }
130 
131  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const scalar & KOKKOS_RESTRICT s)
132  {
133  if(m)
134  data /= s;
135 
136  return *this;
137  }
138 
139  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
140  {
141  auto st_array = st.begin();
142 
143  if(m)
144  data = st_array[0]/st_array[1];
145  else
146  data = st_array[2];
147 
148  return *this;
149  }
150 };
151 
152 template<typename scalar> class Mask;
153 
154 template<typename S> class MaskedAssign< Sacado::MP::Vector<S> >
155 {
157 private:
158  static const std::size_t size = EnsembleTraits_m<scalar>::size;
161 
162 public:
163  KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, Mask<scalar> m_) : data(data_), m(m_) {};
164 
165  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const scalar & KOKKOS_RESTRICT s)
166  {
167 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
168 #pragma ivdep
169 #endif
170 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
171 #pragma vector aligned
172 #endif
173 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
174 #pragma unroll
175 #endif
176  for(std::size_t i=0; i<size; ++i)
177  if(m.get(i))
178  data[i] = s[i];
179 
180  return *this;
181  }
182 
183  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
184  {
185  auto st_array = st.begin();
186 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
187 #pragma ivdep
188 #endif
189 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
190 #pragma vector aligned
191 #endif
192 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
193 #pragma unroll
194 #endif
195  for(std::size_t i=0; i<size; ++i)
196  if(m.get(i))
197  data[i] = st_array[0][i];
198  else
199  data[i] = st_array[1][i];
200 
201  return *this;
202  }
203 
204 
205  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const scalar & KOKKOS_RESTRICT s)
206  {
207 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
208 #pragma ivdep
209 #endif
210 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
211 #pragma vector aligned
212 #endif
213 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
214 #pragma unroll
215 #endif
216  for(std::size_t i=0; i<size; ++i)
217  if(m.get(i))
218  data[i] += s[i];
219 
220  return *this;
221  }
222 
223  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
224  {
225  auto st_array = st.begin();
226 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
227 #pragma ivdep
228 #endif
229 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
230 #pragma vector aligned
231 #endif
232 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
233 #pragma unroll
234 #endif
235  for(std::size_t i=0; i<size; ++i)
236  if(m.get(i))
237  data[i] = st_array[0][i]+st_array[1][i];
238  else
239  data[i] = st_array[2][i];
240 
241  return *this;
242  }
243 
244  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const scalar & KOKKOS_RESTRICT s)
245  {
246 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
247 #pragma ivdep
248 #endif
249 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
250 #pragma vector aligned
251 #endif
252 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
253 #pragma unroll
254 #endif
255  for(std::size_t i=0; i<size; ++i)
256  if(m.get(i))
257  data[i] -= s[i];
258 
259  return *this;
260  }
261 
262  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
263  {
264  auto st_array = st.begin();
265 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
266 #pragma ivdep
267 #endif
268 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
269 #pragma vector aligned
270 #endif
271 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
272 #pragma unroll
273 #endif
274  for(std::size_t i=0; i<size; ++i)
275  if(m.get(i))
276  data[i] = st_array[0][i]-st_array[1][i];
277  else
278  data[i] = st_array[2][i];
279 
280  return *this;
281  }
282 
283  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const scalar & KOKKOS_RESTRICT s)
284  {
285 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
286 #pragma ivdep
287 #endif
288 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
289 #pragma vector aligned
290 #endif
291 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
292 #pragma unroll
293 #endif
294  for(std::size_t i=0; i<size; ++i)
295  if(m.get(i))
296  data[i] *= s[i];
297 
298  return *this;
299  }
300 
301  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
302  {
303  auto st_array = st.begin();
304 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
305 #pragma ivdep
306 #endif
307 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
308 #pragma vector aligned
309 #endif
310 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
311 #pragma unroll
312 #endif
313  for(std::size_t i=0; i<size; ++i)
314  if(m.get(i))
315  data[i] = st_array[0][i]*st_array[1][i];
316  else
317  data[i] = st_array[2][i];
318 
319  return *this;
320  }
321 
322  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const scalar & KOKKOS_RESTRICT s)
323  {
324 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
325 #pragma ivdep
326 #endif
327 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
328 #pragma vector aligned
329 #endif
330 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
331 #pragma unroll
332 #endif
333  for(std::size_t i=0; i<size; ++i)
334  if(m.get(i))
335  data[i] /= s[i];
336 
337  return *this;
338  }
339 
340  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
341  {
342  auto st_array = st.begin();
343 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
344 #pragma ivdep
345 #endif
346 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
347 #pragma vector aligned
348 #endif
349 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
350 #pragma unroll
351 #endif
352  for(std::size_t i=0; i<size; ++i)
353  if(m.get(i))
354  data[i] = st_array[0][i]/st_array[1][i];
355  else
356  data[i] = st_array[2][i];
357 
358  return *this;
359  }
360 };
361 
362 template <typename ordinal_t, typename value_t, typename device_t> class MaskedAssign< Sacado::MP::Vector<Stokhos::DynamicStorage<ordinal_t,value_t,device_t>> >
363 {
365 private:
366  static const std::size_t size = EnsembleTraits_m<scalar>::size;
369 
370 public:
371  KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, Mask<scalar> m_) : data(data_), m(m_) {};
372 
373  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const scalar & KOKKOS_RESTRICT s)
374  {
375  if(m.get(0))
376  data = s;
377 
378  return *this;
379  }
380 
381  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator = (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
382  {
383  auto st_array = st.begin();
384 
385  if(m.get(0))
386  data = st_array[0];
387  else
388  data = st_array[1];
389 
390  return *this;
391  }
392 
393 
394  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const scalar & KOKKOS_RESTRICT s)
395  {
396  if(m.get(0))
397  data += s;
398 
399  return *this;
400  }
401 
402  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator += (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
403  {
404  auto st_array = st.begin();
405 
406  if(m.get(0))
407  data = st_array[0]+st_array[1];
408  else
409  data = st_array[2];
410 
411  return *this;
412  }
413 
414  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const scalar & KOKKOS_RESTRICT s)
415  {
416  if(m.get(0))
417  data -= s;
418 
419  return *this;
420  }
421 
422  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator -= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
423  {
424  auto st_array = st.begin();
425 
426  if(m.get(0))
427  data = st_array[0]-st_array[1];
428  else
429  data = st_array[2];
430 
431  return *this;
432  }
433 
434  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const scalar & KOKKOS_RESTRICT s)
435  {
436  if(m.get(0))
437  data *= s;
438 
439  return *this;
440  }
441 
442  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator *= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
443  {
444  auto st_array = st.begin();
445 
446  if(m.get(0))
447  data = st_array[0]*st_array[1];
448  else
449  data = st_array[2];
450 
451  return *this;
452  }
453 
454  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const scalar & KOKKOS_RESTRICT s)
455  {
456  if(m.get(0))
457  data /= s;
458 
459  return *this;
460  }
461 
462  KOKKOS_INLINE_FUNCTION MaskedAssign<scalar>& operator /= (const std::initializer_list<scalar> & KOKKOS_RESTRICT st)
463  {
464  auto st_array = st.begin();
465 
466  if(m.get(0))
467  data = st_array[0]/st_array[1];
468  else
469  data = st_array[2];
470 
471  return *this;
472  }
473 };
474 
475 template<typename scalar> class Mask
476 {
477 public:
478  static const std::size_t size = EnsembleTraits_m<scalar>::size;
479 
480 private:
481  bool data[size];
482 
483 public:
484  KOKKOS_INLINE_FUNCTION Mask(){
485  for(std::size_t i=0; i<size; ++i)
486  this->set(i,false);
487  }
488 
489  KOKKOS_INLINE_FUNCTION Mask(bool a){
490  for(std::size_t i=0; i<size; ++i)
491  this->set(i,a);
492  }
493 
494  KOKKOS_INLINE_FUNCTION Mask(const Mask &a){
495  for(std::size_t i=0; i<size; ++i)
496  data[i] = a.data[i];
497  }
498 
499  KOKKOS_INLINE_FUNCTION Mask& operator=(const Mask &a){
500  for(std::size_t i=0; i<size; ++i)
501  this->data[i] = a.data[i];
502  return *this;
503  }
504 
505  KOKKOS_INLINE_FUNCTION std::size_t getSize() const {return size;}
506 
507  KOKKOS_INLINE_FUNCTION bool operator> (double v)
508  {
509  double sum = 0;
510  for(std::size_t i=0; i<size; ++i)
511  sum = sum + this->get(i);
512 
513  return sum > v*size;
514  }
515 
516  KOKKOS_INLINE_FUNCTION bool operator< (double v)
517  {
518  double sum = 0;
519  for(std::size_t i=0; i<size; ++i)
520  sum = sum + this->get(i);
521 
522  return sum < v*size;
523  }
524 
525  KOKKOS_INLINE_FUNCTION bool operator>= (double v)
526  {
527  double sum = 0;
528  for(std::size_t i=0; i<size; ++i)
529  sum = sum + this->get(i);
530 
531  return sum >= v*size;
532  }
533 
534  KOKKOS_INLINE_FUNCTION bool operator<= (double v)
535  {
536  double sum = 0;
537  for(std::size_t i=0; i<size; ++i)
538  sum = sum + this->get(i);
539 
540  return sum <= v*size;
541  }
542 
543  KOKKOS_INLINE_FUNCTION bool operator== (double v)
544  {
545  double sum = 0;
546  for(std::size_t i=0; i<size; ++i)
547  sum = sum + this->get(i);
548 
549  return sum == v*size;
550  }
551 
552  KOKKOS_INLINE_FUNCTION bool operator!= (double v)
553  {
554  double sum = 0;
555  for(std::size_t i=0; i<size; ++i)
556  sum = sum + this->get(i);
557 
558  return sum != v*size;
559  }
560 
561  KOKKOS_INLINE_FUNCTION bool operator== (const Mask<scalar> &m2)
562  {
563  bool all = true;
564  for (std::size_t i = 0; i < size; ++i) {
565  all = all && (this->get(i) == m2.get(i));
566  }
567  return all;
568  }
569 
570  KOKKOS_INLINE_FUNCTION bool operator!= (const Mask<scalar> &m2)
571  {
572  return !(this==m2);
573  }
574 
575  KOKKOS_INLINE_FUNCTION Mask<scalar> operator&& (const Mask<scalar> &m2)
576  {
577  Mask<scalar> m3;
578  for(std::size_t i=0; i<size; ++i)
579  m3.set(i,(this->get(i) && m2.get(i)));
580  return m3;
581  }
582 
583  KOKKOS_INLINE_FUNCTION Mask<scalar> operator|| (const Mask<scalar> &m2)
584  {
585  Mask<scalar> m3;
586  for(std::size_t i=0; i<size; ++i)
587  m3.set(i,(this->get(i) || m2.get(i)));
588 
589  return m3;
590  }
591 
592  KOKKOS_INLINE_FUNCTION Mask<scalar> operator&& (bool m2)
593  {
594  Mask<scalar> m3;
595  for(std::size_t i=0; i<size; ++i)
596  m3.set(i,(this->get(i) && m2));
597  return m3;
598  }
599 
600  KOKKOS_INLINE_FUNCTION Mask<scalar> operator|| (bool m2)
601  {
602  Mask<scalar> m3;
603  for(std::size_t i=0; i<size; ++i)
604  m3.set(i,(this->get(i) || m2));
605 
606  return m3;
607  }
608 
609  KOKKOS_INLINE_FUNCTION Mask<scalar> operator+ (const Mask<scalar> &m2)
610  {
611  Mask<scalar> m3;
612  for(std::size_t i=0; i<size; ++i)
613  m3.set(i,(this->get(i) + m2.get(i)));
614 
615  return m3;
616  }
617 
618  KOKKOS_INLINE_FUNCTION Mask<scalar> operator- (const Mask<scalar> &m2)
619  {
620  Mask<scalar> m3;
621  for(std::size_t i=0; i<size; ++i)
622  m3.set(i,(this->get(i) - m2.get(i)));
623 
624  return m3;
625  }
626 
627  KOKKOS_INLINE_FUNCTION scalar operator* (const scalar &v)
628  {
629  typedef EnsembleTraits_m<scalar> ET;
630  scalar v2;
631  for(std::size_t i=0; i<size; ++i)
632  ET::coeff(v2,i) = ET::coeff(v,i)*this->get(i);
633 
634  return v2;
635  }
636 
637  KOKKOS_INLINE_FUNCTION bool get (int i) const
638  {
639  return this->data[i];
640  }
641 
642  KOKKOS_INLINE_FUNCTION void set (int i, bool b)
643  {
644  this->data[i] = b;
645  }
646 
647  KOKKOS_INLINE_FUNCTION Mask<scalar> operator! ()
648  {
649  Mask<scalar> m2;
650  for(std::size_t i=0; i<size; ++i)
651  m2.set(i,!(this->get(i)));
652  return m2;
653  }
654 
655  KOKKOS_INLINE_FUNCTION operator bool() const
656  {
657  return this->get(0);
658  }
659 
660  KOKKOS_INLINE_FUNCTION operator double() const
661  {
662  double sum = 0;
663  for(std::size_t i=0; i<size; ++i)
664  sum = sum + this->get(i);
665 
666  return sum/size;
667  }
668 };
669 
670 template<typename scalar> std::ostream &operator<<(std::ostream &os, const Mask<scalar>& m) {
671  os << "[ ";
672  for(std::size_t i=0; i<m.getSize(); ++i)
673  os << m.get(i) << " ";
674  return os << "]";
675 }
676 
677 template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const Sacado::MP::Vector<S> &a1, const Mask<Sacado::MP::Vector<S>> &m)
678 {
681 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
682 #pragma ivdep
683 #endif
684 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
685 #pragma vector aligned
686 #endif
687 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
688 #pragma unroll
689 #endif
690  for(std::size_t i=0; i<ET::size; ++i){
691  ET::coeff(mul,i) = ET::coeff(a1,i)*m.get(i);
692  }
693  return mul;
694 }
695 
696 template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const typename S::value_type &a1, const Mask<Sacado::MP::Vector<S>> &m)
697 {
700 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
701 #pragma ivdep
702 #endif
703 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
704 #pragma vector aligned
705 #endif
706 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
707 #pragma unroll
708 #endif
709  for(std::size_t i=0; i<ET::size; ++i){
710  ET::coeff(mul,i) = m.get(i)*a1;
711  }
712  return mul;
713 }
714 
715 template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const Mask<Sacado::MP::Vector<S>> &m, const typename S::value_type &a1)
716 {
719 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
720 #pragma ivdep
721 #endif
722 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
723 #pragma vector aligned
724 #endif
725 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
726 #pragma unroll
727 #endif
728  for(std::size_t i=0; i<ET::size; ++i){
729  ET::coeff(mul,i) = m.get(i)*a1;
730  }
731  return mul;
732 }
733 
734 template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(bool b, scalar *s)
735 {
736  Mask<scalar> m = Mask<scalar>(b);
737  MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(*s,m);
738  return maskedAssign;
739 }
740 
741 template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(Mask<scalar> m, scalar *s)
742 {
743  MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(*s,m);
744  return maskedAssign;
745 }
746 
747 template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(bool b, scalar &s)
748 {
749  Mask<scalar> m = Mask<scalar>(b);
750  MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(s,m);
751  return maskedAssign;
752 }
753 
754 template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(Mask<scalar> m, scalar &s)
755 {
756  MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(s,m);
757  return maskedAssign;
758 }
759 
760 namespace Sacado {
761  namespace MP {
762  template <typename S> KOKKOS_INLINE_FUNCTION Vector<S> copysign(const Vector<S> &a1, const Vector<S> &a2)
763  {
764  typedef EnsembleTraits_m< Vector<S> > ET;
765 
766  Vector<S> a_out;
767 
768  using std::copysign;
769 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
770 #pragma ivdep
771 #endif
772 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
773 #pragma vector aligned
774 #endif
775 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
776 #pragma unroll
777 #endif
778  for(std::size_t i=0; i<ET::size; ++i){
779  ET::coeff(a_out,i) = copysign(ET::coeff(a1,i),ET::coeff(a2,i));
780  }
781 
782  return a_out;
783  }
784  }
785 }
786 
787 
788 template<typename S> KOKKOS_INLINE_FUNCTION Mask<Sacado::MP::Vector<S> > signbit_v(const Sacado::MP::Vector<S> &a1)
789 {
791  using std::signbit;
792 
794 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
795 #pragma ivdep
796 #endif
797 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
798 #pragma vector aligned
799 #endif
800 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
801 #pragma unroll
802 #endif
803  for(std::size_t i=0; i<ET::size; ++i)
804  mask.set(i, signbit(ET::coeff(a1,i)));
805  return mask;
806 }
807 
808 // Relation operations for vector:
809 
810 #define OPNAME ==
812 #undef OPNAME
813 
814 #define OPNAME !=
816 #undef OPNAME
817 
818 #define OPNAME >
820 #undef OPNAME
821 
822 #define OPNAME >=
824 #undef OPNAME
825 
826 #define OPNAME <
828 #undef OPNAME
829 
830 #define OPNAME <=
832 #undef OPNAME
833 
834 // Relation operations for expressions:
835 
836 #define OPNAME ==
838 #undef OPNAME
839 
840 #define OPNAME !=
842 #undef OPNAME
843 
844 #define OPNAME <
846 #undef OPNAME
847 
848 #define OPNAME >
850 #undef OPNAME
851 
852 #define OPNAME <=
854 #undef OPNAME
855 
856 #define OPNAME >=
858 #undef OPNAME
859 
860 #define OPNAME <<=
862 #undef OPNAME
863 
864 #define OPNAME >>=
866 #undef OPNAME
867 
868 #define OPNAME &
870 #undef OPNAME
871 
872 #define OPNAME |
874 #undef OPNAME
875 
876 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
877 
878 // Relation operations for static fixed storage:
879 
880 #define OPNAME ==
882 #undef OPNAME
883 
884 #define OPNAME !=
886 #undef OPNAME
887 
888 #define OPNAME >
890 #undef OPNAME
891 
892 #define OPNAME >=
894 #undef OPNAME
895 
896 #define OPNAME <
898 #undef OPNAME
899 
900 #define OPNAME <=
902 #undef OPNAME
903 
904 #endif
905 
906 namespace MaskLogic{
907 
908  template<typename T> KOKKOS_INLINE_FUNCTION bool OR(Mask<T> m){
909  return (((double) m)!=0.);
910  }
911 
912  KOKKOS_INLINE_FUNCTION bool OR(bool m){
913  return m;
914  }
915 
916  template<typename T> KOKKOS_INLINE_FUNCTION bool XOR(Mask<T> m){
917  return (((double) m)==1./m.getSize());
918  }
919 
920  KOKKOS_INLINE_FUNCTION bool XOR(bool m){
921  return m;
922  }
923 
924  template<typename T> KOKKOS_INLINE_FUNCTION bool AND(Mask<T> m){
925  return (((double) m)==1.);
926  }
927 
928  KOKKOS_INLINE_FUNCTION bool AND(bool m){
929  return m;
930  }
931 
932 }
933 
934 #endif // STOKHOS_MP_VECTOR_MASKTRAITS_HPP
KOKKOS_INLINE_FUNCTION Vector< S > copysign(const Vector< S > &a1, const Vector< S > &a2)
KOKKOS_INLINE_FUNCTION bool operator>=(double v)
static const std::size_t size
KOKKOS_INLINE_FUNCTION bool operator<=(double v)
KOKKOS_INLINE_FUNCTION Mask & operator=(const Mask &a)
KOKKOS_INLINE_FUNCTION bool get(int i) const
KOKKOS_INLINE_FUNCTION Mask(const Mask &a)
KOKKOS_INLINE_FUNCTION bool OR(Mask< T > m)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator*=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION Mask()
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > mask_assign(bool b, scalar *s)
static KOKKOS_INLINE_FUNCTION const value_type & coeff(const Sacado::MP::Vector< S > &x, int i)
KOKKOS_INLINE_FUNCTION void set(int i, bool b)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator+(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, Mask< scalar > m_)
static const std::size_t size
KOKKOS_INLINE_FUNCTION Mask< scalar > operator||(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION bool operator<(double v)
KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, bool m_)
KOKKOS_INLINE_FUNCTION bool operator>(double v)
KOKKOS_INLINE_FUNCTION scalar operator*(const scalar &v)
static KOKKOS_INLINE_FUNCTION value_type & coeff(T &x, int i)
KOKKOS_INLINE_FUNCTION bool operator!=(double v)
static KOKKOS_INLINE_FUNCTION const value_type & coeff(const T &x, int i)
KOKKOS_INLINE_FUNCTION bool operator==(double v)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator-(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator-=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION bool AND(Mask< T > m)
Sacado::MP::Vector< Stokhos::DynamicStorage< ordinal_t, value_t, device_t > > scalar
KOKKOS_INLINE_FUNCTION Mask(bool a)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator/=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION bool XOR(Mask< T > m)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator!()
KOKKOS_INLINE_FUNCTION PCE< Storage > operator*(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator&&(const Mask< scalar > &m2)
static KOKKOS_INLINE_FUNCTION value_type & coeff(Sacado::MP::Vector< S > &x, int i)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator+=(const scalar &KOKKOS_RESTRICT s)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)
KOKKOS_INLINE_FUNCTION Mask< Sacado::MP::Vector< S > > signbit_v(const Sacado::MP::Vector< S > &a1)
KOKKOS_INLINE_FUNCTION std::size_t getSize() const