10 #ifndef STOKHOS_MP_VECTOR_MASKTRAITS_HPP
11 #define STOKHOS_MP_VECTOR_MASKTRAITS_HPP
19 static const std::size_t
size = 1;
21 KOKKOS_INLINE_FUNCTION
23 KOKKOS_INLINE_FUNCTION
29 static const std::size_t
size = S::static_size ? S::static_size : 1;
31 KOKKOS_INLINE_FUNCTION
33 return x.fastAccessCoeff(i);
35 KOKKOS_INLINE_FUNCTION
37 return x.fastAccessCoeff(i);
60 auto st_array = st.begin();
81 auto st_array = st.begin();
84 data = st_array[0]+st_array[1];
101 auto st_array = st.begin();
104 data = st_array[0]-st_array[1];
121 auto st_array = st.begin();
124 data = st_array[0]*st_array[1];
141 auto st_array = st.begin();
144 data = st_array[0]/st_array[1];
152 template<
typename scalar>
class Mask;
167 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
170 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
171 #pragma vector aligned
173 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
176 for(std::size_t i=0; i<size; ++i)
185 auto st_array = st.begin();
186 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
189 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
190 #pragma vector aligned
192 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
195 for(std::size_t i=0; i<size; ++i)
197 data[i] = st_array[0][i];
199 data[i] = st_array[1][i];
207 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
210 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
211 #pragma vector aligned
213 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
216 for(std::size_t i=0; i<size; ++i)
225 auto st_array = st.begin();
226 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
229 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
230 #pragma vector aligned
232 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
235 for(std::size_t i=0; i<size; ++i)
237 data[i] = st_array[0][i]+st_array[1][i];
239 data[i] = st_array[2][i];
246 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
249 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
250 #pragma vector aligned
252 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
255 for(std::size_t i=0; i<size; ++i)
264 auto st_array = st.begin();
265 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
268 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
269 #pragma vector aligned
271 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
274 for(std::size_t i=0; i<size; ++i)
276 data[i] = st_array[0][i]-st_array[1][i];
278 data[i] = st_array[2][i];
285 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
288 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
289 #pragma vector aligned
291 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
294 for(std::size_t i=0; i<size; ++i)
303 auto st_array = st.begin();
304 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
307 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
308 #pragma vector aligned
310 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
313 for(std::size_t i=0; i<size; ++i)
315 data[i] = st_array[0][i]*st_array[1][i];
317 data[i] = st_array[2][i];
324 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
327 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
328 #pragma vector aligned
330 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
333 for(std::size_t i=0; i<size; ++i)
342 auto st_array = st.begin();
343 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
346 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
347 #pragma vector aligned
349 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
352 for(std::size_t i=0; i<size; ++i)
354 data[i] = st_array[0][i]/st_array[1][i];
356 data[i] = st_array[2][i];
362 template <
typename ordinal_t,
typename value_t,
typename device_t>
class MaskedAssign< Sacado::MP::Vector<Stokhos::DynamicStorage<ordinal_t,value_t,device_t>> >
383 auto st_array = st.begin();
404 auto st_array = st.begin();
407 data = st_array[0]+st_array[1];
424 auto st_array = st.begin();
427 data = st_array[0]-st_array[1];
444 auto st_array = st.begin();
447 data = st_array[0]*st_array[1];
464 auto st_array = st.begin();
467 data = st_array[0]/st_array[1];
475 template<
typename scalar>
class Mask
485 for(std::size_t i=0; i<
size; ++i)
489 KOKKOS_INLINE_FUNCTION
Mask(
bool a){
490 for(std::size_t i=0; i<
size; ++i)
495 for(std::size_t i=0; i<
size; ++i)
500 for(std::size_t i=0; i<
size; ++i)
510 for(std::size_t i=0; i<
size; ++i)
511 sum = sum + this->
get(i);
519 for(std::size_t i=0; i<
size; ++i)
520 sum = sum + this->
get(i);
528 for(std::size_t i=0; i<
size; ++i)
529 sum = sum + this->
get(i);
531 return sum >= v*
size;
537 for(std::size_t i=0; i<
size; ++i)
538 sum = sum + this->
get(i);
540 return sum <= v*
size;
546 for(std::size_t i=0; i<
size; ++i)
547 sum = sum + this->
get(i);
549 return sum == v*
size;
555 for(std::size_t i=0; i<
size; ++i)
556 sum = sum + this->
get(i);
558 return sum != v*
size;
564 for (std::size_t i = 0; i <
size; ++i) {
565 all = all && (this->
get(i) == m2.
get(i));
578 for(std::size_t i=0; i<
size; ++i)
579 m3.
set(i,(this->get(i) && m2.
get(i)));
586 for(std::size_t i=0; i<
size; ++i)
587 m3.
set(i,(this->get(i) || m2.
get(i)));
595 for(std::size_t i=0; i<
size; ++i)
596 m3.
set(i,(this->get(i) && m2));
603 for(std::size_t i=0; i<
size; ++i)
604 m3.
set(i,(this->get(i) || m2));
612 for(std::size_t i=0; i<
size; ++i)
613 m3.
set(i,(this->get(i) + m2.
get(i)));
621 for(std::size_t i=0; i<
size; ++i)
622 m3.
set(i,(this->get(i) - m2.
get(i)));
627 KOKKOS_INLINE_FUNCTION scalar
operator* (
const scalar &v)
631 for(std::size_t i=0; i<
size; ++i)
632 ET::coeff(v2,i) = ET::coeff(v,i)*this->
get(i);
637 KOKKOS_INLINE_FUNCTION
bool get (
int i)
const
639 return this->
data[i];
642 KOKKOS_INLINE_FUNCTION
void set (
int i,
bool b)
650 for(std::size_t i=0; i<
size; ++i)
651 m2.
set(i,!(this->get(i)));
655 KOKKOS_INLINE_FUNCTION
operator bool()
const
660 KOKKOS_INLINE_FUNCTION
operator double()
const
663 for(std::size_t i=0; i<
size; ++i)
664 sum = sum + this->
get(i);
670 template<
typename scalar> std::ostream &operator<<(std::ostream &os, const Mask<scalar>& m) {
672 for(std::size_t i=0; i<m.getSize(); ++i)
673 os << m.get(i) <<
" ";
681 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
684 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
685 #pragma vector aligned
687 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
690 for(std::size_t i=0; i<ET::size; ++i){
691 ET::coeff(mul,i) = ET::coeff(a1,i)*m.get(i);
700 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
703 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
704 #pragma vector aligned
706 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
709 for(std::size_t i=0; i<ET::size; ++i){
710 ET::coeff(mul,i) = m.get(i)*a1;
719 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
722 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
723 #pragma vector aligned
725 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
728 for(std::size_t i=0; i<ET::size; ++i){
729 ET::coeff(mul,i) = m.get(i)*a1;
769 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
772 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
773 #pragma vector aligned
775 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
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));
794 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
797 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
798 #pragma vector aligned
800 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
803 for(std::size_t i=0; i<ET::size; ++i)
804 mask.
set(i, signbit(ET::coeff(a1,i)));
876 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
908 template<
typename T> KOKKOS_INLINE_FUNCTION
bool OR(
Mask<T> m){
909 return (((
double) m)!=0.);
912 KOKKOS_INLINE_FUNCTION
bool OR(
bool m){
916 template<
typename T> KOKKOS_INLINE_FUNCTION
bool XOR(
Mask<T> m){
917 return (((
double) m)==1./m.getSize());
920 KOKKOS_INLINE_FUNCTION
bool XOR(
bool m){
924 template<
typename T> KOKKOS_INLINE_FUNCTION
bool AND(
Mask<T> m){
925 return (((
double) m)==1.);
928 KOKKOS_INLINE_FUNCTION
bool AND(
bool m){
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)
Sacado::MP::Vector< S > scalar
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 MaskedAssign(scalar &data_, Mask< scalar > 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