Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
49template <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
59template <typename S>
60struct 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
69 return x.fastAccessCoeff(i);
70 }
71};
72
73template<typename scalar> class MaskedAssign
74{
75private:
76 scalar &data;
77 bool m;
78
79public:
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
184template<typename scalar> class Mask;
185
186template<typename S> class MaskedAssign< Sacado::MP::Vector<S> >
187{
189private:
190 static const std::size_t size = EnsembleTraits_m<scalar>::size;
192 Mask<scalar> m;
193
194public:
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
394template <typename ordinal_t, typename value_t, typename device_t> class MaskedAssign< Sacado::MP::Vector<Stokhos::DynamicStorage<ordinal_t,value_t,device_t>> >
395{
397private:
398 static const std::size_t size = EnsembleTraits_m<scalar>::size;
400 Mask<scalar> m;
401
402public:
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
507template<typename scalar> class Mask
508{
509public:
510 static const std::size_t size = EnsembleTraits_m<scalar>::size;
511
512private:
513 bool data[size];
514
515public:
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 Mask& operator=(const Mask &a){
532 for(std::size_t i=0; i<size; ++i)
533 this->data[i] = a.data[i];
534 return *this;
535 }
536
537 KOKKOS_INLINE_FUNCTION std::size_t getSize() const {return size;}
538
539 KOKKOS_INLINE_FUNCTION bool operator> (double v)
540 {
541 double sum = 0;
542 for(std::size_t i=0; i<size; ++i)
543 sum = sum + this->get(i);
544
545 return sum > v*size;
546 }
547
548 KOKKOS_INLINE_FUNCTION bool operator< (double v)
549 {
550 double sum = 0;
551 for(std::size_t i=0; i<size; ++i)
552 sum = sum + this->get(i);
553
554 return sum < v*size;
555 }
556
557 KOKKOS_INLINE_FUNCTION bool operator>= (double v)
558 {
559 double sum = 0;
560 for(std::size_t i=0; i<size; ++i)
561 sum = sum + this->get(i);
562
563 return sum >= v*size;
564 }
565
566 KOKKOS_INLINE_FUNCTION bool operator<= (double v)
567 {
568 double sum = 0;
569 for(std::size_t i=0; i<size; ++i)
570 sum = sum + this->get(i);
571
572 return sum <= v*size;
573 }
574
575 KOKKOS_INLINE_FUNCTION bool operator== (double v)
576 {
577 double sum = 0;
578 for(std::size_t i=0; i<size; ++i)
579 sum = sum + this->get(i);
580
581 return sum == v*size;
582 }
583
584 KOKKOS_INLINE_FUNCTION bool operator!= (double v)
585 {
586 double sum = 0;
587 for(std::size_t i=0; i<size; ++i)
588 sum = sum + this->get(i);
589
590 return sum != v*size;
591 }
592
593 KOKKOS_INLINE_FUNCTION bool operator== (const Mask<scalar> &m2)
594 {
595 bool all = true;
596 for (std::size_t i = 0; i < size; ++i) {
597 all = all && (this->get(i) == m2.get(i));
598 }
599 return all;
600 }
601
602 KOKKOS_INLINE_FUNCTION bool operator!= (const Mask<scalar> &m2)
603 {
604 return !(this==m2);
605 }
606
607 KOKKOS_INLINE_FUNCTION Mask<scalar> operator&& (const Mask<scalar> &m2)
608 {
609 Mask<scalar> m3;
610 for(std::size_t i=0; i<size; ++i)
611 m3.set(i,(this->get(i) && m2.get(i)));
612 return m3;
613 }
614
615 KOKKOS_INLINE_FUNCTION Mask<scalar> operator|| (const Mask<scalar> &m2)
616 {
617 Mask<scalar> m3;
618 for(std::size_t i=0; i<size; ++i)
619 m3.set(i,(this->get(i) || m2.get(i)));
620
621 return m3;
622 }
623
624 KOKKOS_INLINE_FUNCTION Mask<scalar> operator&& (bool m2)
625 {
626 Mask<scalar> m3;
627 for(std::size_t i=0; i<size; ++i)
628 m3.set(i,(this->get(i) && m2));
629 return m3;
630 }
631
632 KOKKOS_INLINE_FUNCTION Mask<scalar> operator|| (bool m2)
633 {
634 Mask<scalar> m3;
635 for(std::size_t i=0; i<size; ++i)
636 m3.set(i,(this->get(i) || m2));
637
638 return m3;
639 }
640
641 KOKKOS_INLINE_FUNCTION Mask<scalar> operator+ (const Mask<scalar> &m2)
642 {
643 Mask<scalar> m3;
644 for(std::size_t i=0; i<size; ++i)
645 m3.set(i,(this->get(i) + m2.get(i)));
646
647 return m3;
648 }
649
650 KOKKOS_INLINE_FUNCTION Mask<scalar> operator- (const Mask<scalar> &m2)
651 {
652 Mask<scalar> m3;
653 for(std::size_t i=0; i<size; ++i)
654 m3.set(i,(this->get(i) - m2.get(i)));
655
656 return m3;
657 }
658
659 KOKKOS_INLINE_FUNCTION scalar operator* (const scalar &v)
660 {
661 typedef EnsembleTraits_m<scalar> ET;
662 scalar v2;
663 for(std::size_t i=0; i<size; ++i)
664 ET::coeff(v2,i) = ET::coeff(v,i)*this->get(i);
665
666 return v2;
667 }
668
669 KOKKOS_INLINE_FUNCTION bool get (int i) const
670 {
671 return this->data[i];
672 }
673
674 KOKKOS_INLINE_FUNCTION void set (int i, bool b)
675 {
676 this->data[i] = b;
677 }
678
679 KOKKOS_INLINE_FUNCTION Mask<scalar> operator! ()
680 {
681 Mask<scalar> m2;
682 for(std::size_t i=0; i<size; ++i)
683 m2.set(i,!(this->get(i)));
684 return m2;
685 }
686
687 KOKKOS_INLINE_FUNCTION operator bool() const
688 {
689 return this->get(0);
690 }
691
692 KOKKOS_INLINE_FUNCTION operator double() const
693 {
694 double sum = 0;
695 for(std::size_t i=0; i<size; ++i)
696 sum = sum + this->get(i);
697
698 return sum/size;
699 }
700};
701
702template<typename scalar> std::ostream &operator<<(std::ostream &os, const Mask<scalar>& m) {
703 os << "[ ";
704 for(std::size_t i=0; i<m.getSize(); ++i)
705 os << m.get(i) << " ";
706 return os << "]";
707}
708
709template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const Sacado::MP::Vector<S> &a1, const Mask<Sacado::MP::Vector<S>> &m)
710{
711 typedef EnsembleTraits_m<Sacado::MP::Vector<S>> ET;
713#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
714#pragma ivdep
715#endif
716#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
717#pragma vector aligned
718#endif
719#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
720#pragma unroll
721#endif
722 for(std::size_t i=0; i<ET::size; ++i){
723 ET::coeff(mul,i) = ET::coeff(a1,i)*m.get(i);
724 }
725 return mul;
726}
727
728template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const typename S::value_type &a1, const Mask<Sacado::MP::Vector<S>> &m)
729{
731 typedef EnsembleTraits_m<Sacado::MP::Vector<S>> ET;
732#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
733#pragma ivdep
734#endif
735#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
736#pragma vector aligned
737#endif
738#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
739#pragma unroll
740#endif
741 for(std::size_t i=0; i<ET::size; ++i){
742 ET::coeff(mul,i) = m.get(i)*a1;
743 }
744 return mul;
745}
746
747template<typename S> KOKKOS_INLINE_FUNCTION Sacado::MP::Vector<S> operator* (const Mask<Sacado::MP::Vector<S>> &m, const typename S::value_type &a1)
748{
750 typedef EnsembleTraits_m<Sacado::MP::Vector<S>> ET;
751#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
752#pragma ivdep
753#endif
754#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
755#pragma vector aligned
756#endif
757#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
758#pragma unroll
759#endif
760 for(std::size_t i=0; i<ET::size; ++i){
761 ET::coeff(mul,i) = m.get(i)*a1;
762 }
763 return mul;
764}
765
766template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(bool b, scalar *s)
767{
768 Mask<scalar> m = Mask<scalar>(b);
769 MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(*s,m);
770 return maskedAssign;
771}
772
773template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(Mask<scalar> m, scalar *s)
774{
775 MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(*s,m);
776 return maskedAssign;
777}
778
779template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(bool b, scalar &s)
780{
781 Mask<scalar> m = Mask<scalar>(b);
782 MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(s,m);
783 return maskedAssign;
784}
785
786template<typename scalar> KOKKOS_INLINE_FUNCTION MaskedAssign<scalar> mask_assign(Mask<scalar> m, scalar &s)
787{
788 MaskedAssign<scalar> maskedAssign = MaskedAssign<scalar>(s,m);
789 return maskedAssign;
790}
791
792namespace Sacado {
793 namespace MP {
794 template <typename S> KOKKOS_INLINE_FUNCTION Vector<S> copysign(const Vector<S> &a1, const Vector<S> &a2)
795 {
796 typedef EnsembleTraits_m< Vector<S> > ET;
797
798 Vector<S> a_out;
799
800 using std::copysign;
801#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
802#pragma ivdep
803#endif
804#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
805#pragma vector aligned
806#endif
807#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
808#pragma unroll
809#endif
810 for(std::size_t i=0; i<ET::size; ++i){
811 ET::coeff(a_out,i) = copysign(ET::coeff(a1,i),ET::coeff(a2,i));
812 }
813
814 return a_out;
815 }
816 }
817}
818
819
820template<typename S> KOKKOS_INLINE_FUNCTION Mask<Sacado::MP::Vector<S> > signbit_v(const Sacado::MP::Vector<S> &a1)
821{
822 typedef EnsembleTraits_m<Sacado::MP::Vector<S> > ET;
823 using std::signbit;
824
825 Mask<Sacado::MP::Vector<S> > mask;
826#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
827#pragma ivdep
828#endif
829#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
830#pragma vector aligned
831#endif
832#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
833#pragma unroll
834#endif
835 for(std::size_t i=0; i<ET::size; ++i)
836 mask.set(i, signbit(ET::coeff(a1,i)));
837 return mask;
838}
839
840// Relation operations for vector:
841
842#define OPNAME ==
844#undef OPNAME
845
846#define OPNAME !=
848#undef OPNAME
849
850#define OPNAME >
852#undef OPNAME
853
854#define OPNAME >=
856#undef OPNAME
857
858#define OPNAME <
860#undef OPNAME
861
862#define OPNAME <=
864#undef OPNAME
865
866// Relation operations for expressions:
867
868#define OPNAME ==
870#undef OPNAME
871
872#define OPNAME !=
874#undef OPNAME
875
876#define OPNAME <
878#undef OPNAME
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#define OPNAME |
906#undef OPNAME
907
908#if STOKHOS_USE_MP_VECTOR_SFS_SPEC
909
910// Relation operations for static fixed storage:
911
912#define OPNAME ==
914#undef OPNAME
915
916#define OPNAME !=
918#undef OPNAME
919
920#define OPNAME >
922#undef OPNAME
923
924#define OPNAME >=
926#undef OPNAME
927
928#define OPNAME <
930#undef OPNAME
931
932#define OPNAME <=
934#undef OPNAME
935
936#endif
937
938namespace MaskLogic{
939
940 template<typename T> KOKKOS_INLINE_FUNCTION bool OR(Mask<T> m){
941 return (((double) m)!=0.);
942 }
943
944 KOKKOS_INLINE_FUNCTION bool OR(bool m){
945 return m;
946 }
947
948 template<typename T> KOKKOS_INLINE_FUNCTION bool XOR(Mask<T> m){
949 return (((double) m)==1./m.getSize());
950 }
951
952 KOKKOS_INLINE_FUNCTION bool XOR(bool m){
953 return m;
954 }
955
956 template<typename T> KOKKOS_INLINE_FUNCTION bool AND(Mask<T> m){
957 return (((double) m)==1.);
958 }
959
960 KOKKOS_INLINE_FUNCTION bool AND(bool m){
961 return m;
962 }
963
964}
965
966#endif // STOKHOS_MP_VECTOR_MASKTRAITS_HPP
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > mask_assign(bool b, scalar *s)
KOKKOS_INLINE_FUNCTION Mask< Sacado::MP::Vector< S > > signbit_v(const Sacado::MP::Vector< S > &a1)
KOKKOS_INLINE_FUNCTION Sacado::MP::Vector< S > operator*(const Sacado::MP::Vector< S > &a1, const Mask< Sacado::MP::Vector< S > > &m)
std::ostream & operator<<(std::ostream &os, const Mask< scalar > &m)
KOKKOS_INLINE_FUNCTION bool get(int i) const
KOKKOS_INLINE_FUNCTION Mask< scalar > operator+(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator||(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator&&(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION Mask(const Mask &a)
KOKKOS_INLINE_FUNCTION Mask()
static const std::size_t size
KOKKOS_INLINE_FUNCTION bool operator<(double v)
KOKKOS_INLINE_FUNCTION bool operator>=(double v)
KOKKOS_INLINE_FUNCTION bool operator!=(double v)
KOKKOS_INLINE_FUNCTION Mask & operator=(const Mask &a)
KOKKOS_INLINE_FUNCTION std::size_t getSize() const
KOKKOS_INLINE_FUNCTION bool operator<=(double v)
KOKKOS_INLINE_FUNCTION Mask(bool a)
KOKKOS_INLINE_FUNCTION Mask< scalar > operator!()
KOKKOS_INLINE_FUNCTION Mask< scalar > operator-(const Mask< scalar > &m2)
KOKKOS_INLINE_FUNCTION bool operator==(double v)
KOKKOS_INLINE_FUNCTION scalar operator*(const scalar &v)
KOKKOS_INLINE_FUNCTION bool operator>(double v)
KOKKOS_INLINE_FUNCTION void set(int i, bool b)
KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, Mask< scalar > m_)
Sacado::MP::Vector< Stokhos::DynamicStorage< ordinal_t, value_t, device_t > > scalar
KOKKOS_INLINE_FUNCTION MaskedAssign(scalar &data_, bool m_)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator*=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator/=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator-=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > & operator+=(const scalar &KOKKOS_RESTRICT s)
KOKKOS_INLINE_FUNCTION bool XOR(Mask< T > m)
KOKKOS_INLINE_FUNCTION bool AND(Mask< T > m)
KOKKOS_INLINE_FUNCTION bool OR(Mask< T > m)
KOKKOS_INLINE_FUNCTION Vector< S > copysign(const Vector< S > &a1, const Vector< S > &a2)
static KOKKOS_INLINE_FUNCTION const value_type & coeff(const Sacado::MP::Vector< S > &x, int i)
static KOKKOS_INLINE_FUNCTION value_type & coeff(Sacado::MP::Vector< S > &x, int i)
static const std::size_t size
static KOKKOS_INLINE_FUNCTION const value_type & coeff(const T &x, int i)
static KOKKOS_INLINE_FUNCTION value_type & coeff(T &x, int i)