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