10 #ifndef SACADO_MP_VECTOR_HPP
11 #define SACADO_MP_VECTOR_HPP
15 #ifdef HAVE_STOKHOS_SACADO
18 #include <initializer_list>
20 #include "Kokkos_Macros.hpp"
24 #include "Sacado_Traits.hpp"
25 #include "Sacado_mpl_apply.hpp"
26 #include "Sacado_mpl_range_c.hpp"
62 typedef T derived_type;
69 KOKKOS_INLINE_FUNCTION
70 const derived_type& derived()
const {
71 return static_cast<const derived_type&
>(*this);
79 KOKKOS_INLINE_FUNCTION
80 const volatile derived_type& derived()
const volatile {
81 return static_cast<const volatile derived_type&
>(*this);
86 template <typename U, typename Enabled = typename std::enable_if<std::is_integral<U>::value>::type>
87 KOKKOS_INLINE_FUNCTION
88 explicit operator U()
const {
return static_cast<U
>(derived().val()); }
93 template <
typename Storage>
94 class Vector :
public Expr< Vector<Storage> > {
104 typedef typename storage_type::volatile_pointer volatile_pointer;
106 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
108 typedef typename storage_type::volatile_reference volatile_reference;
110 typedef typename storage_type::const_volatile_reference const_volatile_reference;
112 typedef typename execution_space::memory_space memory_space;
116 typedef typename ScalarType<value_type>::type
scalar_type;
118 typedef Vector base_expr_type;
121 template <
class NewStorageType >
123 typedef Vector< NewStorageType > type;
127 static const int num_args = 1;
129 #if STOKHOS_ALIGN_MEMORY
130 KOKKOS_INLINE_FUNCTION
131 static void*
operator new(std::size_t sz) {
132 return MemTraits::alloc(sz);
134 KOKKOS_INLINE_FUNCTION
135 static void*
operator new[](std::size_t sz) {
136 return MemTraits::alloc(sz);
138 KOKKOS_INLINE_FUNCTION
139 static void*
operator new(std::size_t sz,
void* ptr) {
142 KOKKOS_INLINE_FUNCTION
143 static void*
operator new[](std::size_t sz,
void* ptr) {
146 KOKKOS_INLINE_FUNCTION
147 static void operator delete(
void* ptr) {
148 MemTraits::free(ptr);
150 KOKKOS_INLINE_FUNCTION
151 static void operator delete[](
void* ptr) {
152 MemTraits::free(ptr);
154 KOKKOS_INLINE_FUNCTION
155 static void operator delete(
void* ptr,
void*) {
156 MemTraits::free(ptr);
158 KOKKOS_INLINE_FUNCTION
159 static void operator delete[](
void* ptr,
void*) {
160 MemTraits::free(ptr);
168 KOKKOS_DEFAULTED_FUNCTION
175 KOKKOS_INLINE_FUNCTION
183 KOKKOS_INLINE_FUNCTION
184 Vector(
ordinal_type sz, pointer v,
bool owned) : s(sz,v,owned) {}
190 KOKKOS_INLINE_FUNCTION
194 KOKKOS_INLINE_FUNCTION
198 KOKKOS_DEFAULTED_FUNCTION
199 Vector(
const Vector& x) =
default;
202 KOKKOS_INLINE_FUNCTION
203 Vector(
const volatile Vector& x) : s(x.s) {}
206 template <
typename S>
207 KOKKOS_INLINE_FUNCTION
208 Vector(
const Expr<S>& xx) :
209 s(xx.derived().size()) {
210 typedef typename Expr<S>::derived_type expr_type;
211 const expr_type& x = xx.derived();
214 if (s.size() != x.size())
218 if (x.hasFastAccess(s.size())) {
219 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
222 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
223 #pragma vector aligned
225 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
229 s[i] = x.fastAccessCoeff(i);
244 KOKKOS_INLINE_FUNCTION
245 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {
246 if constexpr (Storage::is_static) {
251 Kokkos::abort(
"Size mismatch in list initialization of MP Vector with static fixed storage.");
262 KOKKOS_DEFAULTED_FUNCTION
266 KOKKOS_INLINE_FUNCTION
270 KOKKOS_INLINE_FUNCTION
271 void init(
const value_type& v)
volatile { s.init(v); }
274 KOKKOS_INLINE_FUNCTION
278 KOKKOS_INLINE_FUNCTION
279 void init(
const value_type* v)
volatile { s.init(v); }
282 template <
typename S>
283 KOKKOS_INLINE_FUNCTION
284 void init(
const Vector<S>& v) {
285 s.init(v.s.coeff(), v.s.size());
289 template <
typename S>
290 KOKKOS_INLINE_FUNCTION
291 void init(
const Vector<S>& v)
volatile {
292 s.init(v.s.coeff(), v.s.size());
296 KOKKOS_INLINE_FUNCTION
300 KOKKOS_INLINE_FUNCTION
301 void load(
value_type* v)
volatile { s.load(v); }
304 template <
typename S>
305 KOKKOS_INLINE_FUNCTION
306 void load(Vector<S>& v) { s.load(v.s.coeff()); }
309 template <
typename S>
310 KOKKOS_INLINE_FUNCTION
311 void load(Vector<S>& v)
volatile { s.load(v.s.coeff()); }
317 KOKKOS_INLINE_FUNCTION
321 if (sz == 1 && sz_new > sz)
330 KOKKOS_INLINE_FUNCTION
334 if (sz == 1 && sz_new > sz)
349 KOKKOS_INLINE_FUNCTION
350 void copyForWrite()
volatile { }
353 template <
typename S>
354 KOKKOS_INLINE_FUNCTION
355 bool isEqualTo(
const Expr<S>& xx)
const {
356 const typename Expr<S>::derived_type& x = xx.derived();
357 typedef IsEqual<value_type> IE;
358 if (x.size() != this->size())
return false;
361 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
366 template <
typename S>
367 KOKKOS_INLINE_FUNCTION
368 bool isEqualTo(
const Expr<S>& xx)
const volatile {
369 const typename Expr<S>::derived_type& x = xx.derived();
370 typedef IsEqual<value_type> IE;
371 if (x.size() != this->size())
return false;
374 eq = eq && IE::eval(x.coeff(i), this->coeff(i));
387 Vector& operator=(std::initializer_list<value_type> l) {
391 s.init(l.begin(), lsz);
400 operator=(std::initializer_list<value_type> l)
volatile {
404 s.init(l.begin(), lsz);
405 return const_cast<Vector&
>(*this);
409 KOKKOS_INLINE_FUNCTION
416 KOKKOS_INLINE_FUNCTION
417 Vector& operator=(
const value_type& x)
volatile {
419 return const_cast<Vector&
>(*this);
423 KOKKOS_INLINE_FUNCTION
424 Vector& operator=(
const Vector& x) {
438 if (s.size() > x.s.size())
447 KOKKOS_INLINE_FUNCTION
448 Vector& operator=(
const volatile Vector& x) {
462 if (s.size() > x.s.size())
471 KOKKOS_INLINE_FUNCTION
472 Vector& operator=(
const Vector& x)
volatile {
486 if (s.size() > x.s.size())
491 return const_cast<Vector&
>(*this);
495 KOKKOS_INLINE_FUNCTION
496 Vector& operator=(
const volatile Vector& x)
volatile {
510 if (s.size() > x.s.size())
515 return const_cast<Vector&
>(*this);
519 template <
typename S>
520 KOKKOS_INLINE_FUNCTION
521 Vector& operator=(
const Expr<S>& xx) {
522 typedef typename Expr<S>::derived_type expr_type;
523 const expr_type& x = xx.derived();
525 this->reset(x.size());
528 if (s.size() != x.size())
532 if (x.hasFastAccess(s.size())) {
533 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
536 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
537 #pragma vector aligned
539 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
543 s[i] = x.fastAccessCoeff(i);
553 template <
typename S>
554 KOKKOS_INLINE_FUNCTION
555 Vector& operator=(
const Expr<S>& xx)
volatile {
556 typedef typename Expr<S>::derived_type expr_type;
557 const expr_type& x = xx.derived();
559 this->reset(x.size());
562 if (s.size() != x.size())
566 if (x.hasFastAccess(s.size())) {
567 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
570 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
571 #pragma vector aligned
573 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
577 s[i] = x.fastAccessCoeff(i);
583 return const_cast<Vector&
>(*this);
587 template<
typename S >
588 KOKKOS_INLINE_FUNCTION
589 typename std::enable_if<( ! std::is_same<S,void>::value &&
592 ::type
const &
operator = (
const Expr<S> & xx )
const
594 const typename Expr<S>::derived_type & x = xx.derived();
596 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
599 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
600 #pragma vector aligned
602 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
605 for (
ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
611 template<
typename S >
612 KOKKOS_INLINE_FUNCTION
614 typename std::enable_if<( ! std::is_same<S,void>::value &&
617 ::type
const &
operator = (
const Expr<S> & xx )
const volatile
619 const typename Expr<S>::derived_type & x = xx.derived();
621 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
624 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
625 #pragma vector aligned
627 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
630 for (
ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] = x.coeff(i); }
641 KOKKOS_INLINE_FUNCTION
643 const volatile storage_type& storage()
const volatile {
return s; }
646 KOKKOS_INLINE_FUNCTION
650 KOKKOS_INLINE_FUNCTION
654 KOKKOS_INLINE_FUNCTION
663 KOKKOS_INLINE_FUNCTION
664 const_volatile_reference
val()
const volatile {
return s[0]; }
667 KOKKOS_INLINE_FUNCTION
668 const_reference
val()
const {
return s[0]; }
671 KOKKOS_INLINE_FUNCTION
672 volatile_reference
val()
volatile {
return s[0]; }
675 KOKKOS_INLINE_FUNCTION
676 reference
val() {
return s[0]; }
686 KOKKOS_INLINE_FUNCTION
690 KOKKOS_INLINE_FUNCTION
694 KOKKOS_INLINE_FUNCTION
695 bool hasFastAccess(
ordinal_type sz)
const {
return s.size()>=sz;}
698 KOKKOS_INLINE_FUNCTION
699 bool hasFastAccess(
ordinal_type sz)
const volatile {
return s.size()>=sz;}
702 KOKKOS_INLINE_FUNCTION
703 const_pointer coeff()
const {
return s.coeff();}
706 KOKKOS_INLINE_FUNCTION
707 const_volatile_pointer coeff()
const volatile {
return s.coeff();}
710 KOKKOS_INLINE_FUNCTION
711 volatile_pointer coeff()
volatile {
return s.coeff();}
714 KOKKOS_INLINE_FUNCTION
715 pointer coeff() {
return s.coeff();}
718 KOKKOS_INLINE_FUNCTION
720 return i<s.size() ? s[i] : s[0]; }
723 KOKKOS_INLINE_FUNCTION
725 return i<s.size() ? s[i] : s[0]; }
728 KOKKOS_INLINE_FUNCTION
730 return i<s.size() ? s[i] : s[0]; }
733 KOKKOS_INLINE_FUNCTION
735 return i<s.size() ? s[i] : s[0]; }
738 KOKKOS_INLINE_FUNCTION
743 KOKKOS_INLINE_FUNCTION
748 KOKKOS_INLINE_FUNCTION
753 KOKKOS_INLINE_FUNCTION
758 KOKKOS_INLINE_FUNCTION
759 const_volatile_reference operator[](
ordinal_type i)
const volatile {
763 KOKKOS_INLINE_FUNCTION
768 KOKKOS_INLINE_FUNCTION
769 volatile_reference operator[](
ordinal_type i)
volatile {
773 KOKKOS_INLINE_FUNCTION
778 KOKKOS_INLINE_FUNCTION
780 return s.template getCoeff<i>(); }
783 KOKKOS_INLINE_FUNCTION
785 return s.template getCoeff<i>(); }
788 KOKKOS_INLINE_FUNCTION
789 volatile_reference getCoeff()
volatile {
790 return s.template getCoeff<i>(); }
793 KOKKOS_INLINE_FUNCTION
794 reference getCoeff() {
795 return s.template getCoeff<i>(); }
798 KOKKOS_INLINE_FUNCTION
799 pointer begin() {
return s.coeff(); }
802 KOKKOS_INLINE_FUNCTION
803 const_pointer begin()
const {
return s.coeff(); }
806 KOKKOS_INLINE_FUNCTION
807 volatile_pointer begin()
volatile {
return s.coeff(); }
810 KOKKOS_INLINE_FUNCTION
811 const_volatile_pointer begin()
const volatile {
return s.coeff(); }
814 KOKKOS_INLINE_FUNCTION
815 const_pointer cbegin()
const {
return s.coeff(); }
818 KOKKOS_INLINE_FUNCTION
819 const_volatile_pointer cbegin()
const volatile {
return s.coeff(); }
822 KOKKOS_INLINE_FUNCTION
823 pointer end() {
return s.coeff() + s.size(); }
826 KOKKOS_INLINE_FUNCTION
827 const_pointer end()
const {
return s.coeff() + s.size(); }
830 KOKKOS_INLINE_FUNCTION
831 volatile_pointer end()
volatile {
return s.coeff() + s.size(); }
834 KOKKOS_INLINE_FUNCTION
835 const_volatile_pointer end()
const volatile {
return s.coeff() + s.size(); }
838 KOKKOS_INLINE_FUNCTION
839 const_pointer cend()
const {
return s.coeff()+ s.size(); }
842 KOKKOS_INLINE_FUNCTION
843 const_volatile_pointer cend()
const volatile {
return s.coeff()+ s.size(); }
853 KOKKOS_INLINE_FUNCTION
855 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
858 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
859 #pragma vector aligned
861 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
870 KOKKOS_INLINE_FUNCTION
871 Vector& operator += (
const volatile value_type& x) {
872 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
875 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
876 #pragma vector aligned
878 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
887 KOKKOS_INLINE_FUNCTION
888 Vector& operator += (
const value_type& x)
volatile {
889 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
892 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
893 #pragma vector aligned
895 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
900 return const_cast<Vector&
>(*this);
904 KOKKOS_INLINE_FUNCTION
905 Vector& operator += (
const volatile value_type& x)
volatile {
906 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
909 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
910 #pragma vector aligned
912 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
917 return const_cast<Vector&
>(*this);
921 KOKKOS_INLINE_FUNCTION
923 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
926 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
927 #pragma vector aligned
929 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
938 KOKKOS_INLINE_FUNCTION
939 Vector& operator -= (
const volatile value_type& x) {
940 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
943 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
944 #pragma vector aligned
946 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
955 KOKKOS_INLINE_FUNCTION
956 Vector& operator -= (
const value_type& x)
volatile {
957 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
960 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
961 #pragma vector aligned
963 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
968 return const_cast<Vector&
>(*this);
972 KOKKOS_INLINE_FUNCTION
973 Vector& operator -= (
const volatile value_type& x)
volatile {
974 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
977 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
978 #pragma vector aligned
980 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
985 return const_cast<Vector&
>(*this);
989 KOKKOS_INLINE_FUNCTION
991 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
994 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
995 #pragma vector aligned
997 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1006 KOKKOS_INLINE_FUNCTION
1007 Vector& operator *= (
const volatile value_type& x) {
1008 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1011 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1012 #pragma vector aligned
1014 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1023 KOKKOS_INLINE_FUNCTION
1024 Vector& operator *= (
const value_type& x)
volatile {
1025 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1028 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1029 #pragma vector aligned
1031 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1036 return const_cast<Vector&
>(*this);
1040 KOKKOS_INLINE_FUNCTION
1041 Vector& operator *= (
const volatile value_type& x)
volatile {
1042 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1045 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1046 #pragma vector aligned
1048 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1053 return const_cast<Vector&
>(*this);
1057 KOKKOS_INLINE_FUNCTION
1059 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1062 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1063 #pragma vector aligned
1065 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1074 KOKKOS_INLINE_FUNCTION
1075 Vector& operator /= (
const volatile value_type& x) {
1076 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1079 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1080 #pragma vector aligned
1082 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1091 KOKKOS_INLINE_FUNCTION
1092 Vector& operator /= (
const value_type& x)
volatile {
1093 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1096 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1097 #pragma vector aligned
1099 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1104 return const_cast<Vector&
>(*this);
1108 KOKKOS_INLINE_FUNCTION
1109 Vector& operator /= (
const volatile value_type& x)
volatile {
1110 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1113 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1114 #pragma vector aligned
1116 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1121 return const_cast<Vector&
>(*this);
1125 template <
typename S>
1126 KOKKOS_INLINE_FUNCTION
1127 Vector& operator += (
const Expr<S>& xx) {
1129 typedef typename Expr<S>::derived_type expr_type;
1130 const expr_type& x = xx.derived();
1132 if (x.size() > s.size())
1133 this->reset(x.size());
1135 #ifdef STOKHOS_DEBUG
1136 if (s.size() < x.size())
1140 if (x.hasFastAccess(s.size())) {
1141 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1144 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1145 #pragma vector aligned
1147 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1151 s[i] += x.fastAccessCoeff(i);
1161 template <
typename S>
1162 KOKKOS_INLINE_FUNCTION
1163 Vector& operator += (
const volatile Expr<S>& xx) {
1165 typedef typename Expr<S>::derived_type expr_type;
1166 const volatile expr_type& x = xx.derived();
1168 if (x.size() > s.size())
1169 this->reset(x.size());
1171 #ifdef STOKHOS_DEBUG
1172 if (s.size() < x.size())
1176 if (x.hasFastAccess(s.size())) {
1177 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1180 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1181 #pragma vector aligned
1183 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1187 s[i] += x.fastAccessCoeff(i);
1197 template <
typename S>
1198 KOKKOS_INLINE_FUNCTION
1199 Vector& operator += (
const Expr<S>& xx)
volatile {
1201 typedef typename Expr<S>::derived_type expr_type;
1202 const expr_type& x = xx.derived();
1204 if (x.size() > s.size())
1205 this->reset(x.size());
1207 #ifdef STOKHOS_DEBUG
1208 if (s.size() < x.size())
1212 if (x.hasFastAccess(s.size())) {
1213 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1216 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1217 #pragma vector aligned
1219 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1223 s[i] += x.fastAccessCoeff(i);
1229 return const_cast<Vector&
>(*this);
1233 template <
typename S>
1234 KOKKOS_INLINE_FUNCTION
1235 Vector& operator += (
const volatile Expr<S>& xx)
volatile {
1237 typedef typename Expr<S>::derived_type expr_type;
1238 const volatile expr_type& x = xx.derived();
1240 if (x.size() > s.size())
1241 this->reset(x.size());
1243 #ifdef STOKHOS_DEBUG
1244 if (s.size() < x.size())
1248 if (x.hasFastAccess(s.size())) {
1249 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1252 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1253 #pragma vector aligned
1255 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1259 s[i] += x.fastAccessCoeff(i);
1265 return const_cast<Vector&
>(*this);
1269 template <
typename S>
1270 KOKKOS_INLINE_FUNCTION
1271 Vector& operator -= (
const Expr<S>& xx) {
1273 typedef typename Expr<S>::derived_type expr_type;
1274 const expr_type& x = xx.derived();
1276 if (x.size() > s.size())
1277 this->reset(x.size());
1279 #ifdef STOKHOS_DEBUG
1280 if (s.size() < x.size())
1284 if (x.hasFastAccess(s.size())) {
1285 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1288 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1289 #pragma vector aligned
1291 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1295 s[i] -= x.fastAccessCoeff(i);
1305 template <
typename S>
1306 KOKKOS_INLINE_FUNCTION
1307 Vector& operator -= (
const volatile Expr<S>& xx) {
1309 typedef typename Expr<S>::derived_type expr_type;
1310 const volatile expr_type& x = xx.derived();
1312 if (x.size() > s.size())
1313 this->reset(x.size());
1315 #ifdef STOKHOS_DEBUG
1316 if (s.size() < x.size())
1320 if (x.hasFastAccess(s.size())) {
1321 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1324 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1325 #pragma vector aligned
1327 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1331 s[i] -= x.fastAccessCoeff(i);
1341 template <
typename S>
1342 KOKKOS_INLINE_FUNCTION
1343 Vector& operator -= (
const Expr<S>& xx)
volatile {
1345 typedef typename Expr<S>::derived_type expr_type;
1346 const expr_type& x = xx.derived();
1348 if (x.size() > s.size())
1349 this->reset(x.size());
1351 #ifdef STOKHOS_DEBUG
1352 if (s.size() < x.size())
1356 if (x.hasFastAccess(s.size())) {
1357 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1360 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1361 #pragma vector aligned
1363 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1367 s[i] -= x.fastAccessCoeff(i);
1373 return const_cast<Vector&
>(*this);
1377 template <
typename S>
1378 KOKKOS_INLINE_FUNCTION
1379 Vector& operator -= (
const volatile Expr<S>& xx)
volatile {
1381 typedef typename Expr<S>::derived_type expr_type;
1382 const volatile expr_type& x = xx.derived();
1384 if (x.size() > s.size())
1385 this->reset(x.size());
1387 #ifdef STOKHOS_DEBUG
1388 if (s.size() < x.size())
1392 if (x.hasFastAccess(s.size())) {
1393 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1396 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1397 #pragma vector aligned
1399 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1403 s[i] -= x.fastAccessCoeff(i);
1409 return const_cast<Vector&
>(*this);
1413 template <
typename S>
1414 KOKKOS_INLINE_FUNCTION
1415 Vector& operator *= (
const Expr<S>& xx) {
1417 typedef typename Expr<S>::derived_type expr_type;
1418 const expr_type& x = xx.derived();
1420 if (x.size() > s.size())
1421 this->reset(x.size());
1423 #ifdef STOKHOS_DEBUG
1424 if (s.size() < x.size())
1428 if (x.hasFastAccess(s.size())) {
1429 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1432 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1433 #pragma vector aligned
1435 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1439 s[i] *= x.fastAccessCoeff(i);
1449 template <
typename S>
1450 KOKKOS_INLINE_FUNCTION
1451 Vector& operator *= (
const volatile Expr<S>& xx) {
1453 typedef typename Expr<S>::derived_type expr_type;
1454 const volatile expr_type& x = xx.derived();
1456 if (x.size() > s.size())
1457 this->reset(x.size());
1459 #ifdef STOKHOS_DEBUG
1460 if (s.size() < x.size())
1464 if (x.hasFastAccess(s.size())) {
1465 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1468 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1469 #pragma vector aligned
1471 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1475 s[i] *= x.fastAccessCoeff(i);
1485 template <
typename S>
1486 KOKKOS_INLINE_FUNCTION
1487 Vector& operator *= (
const Expr<S>& xx)
volatile {
1489 typedef typename Expr<S>::derived_type expr_type;
1490 const expr_type& x = xx.derived();
1492 if (x.size() > s.size())
1493 this->reset(x.size());
1495 #ifdef STOKHOS_DEBUG
1496 if (s.size() < x.size())
1500 if (x.hasFastAccess(s.size())) {
1501 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1504 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1505 #pragma vector aligned
1507 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1511 s[i] *= x.fastAccessCoeff(i);
1517 return const_cast<Vector&
>(*this);
1521 template <
typename S>
1522 KOKKOS_INLINE_FUNCTION
1523 Vector& operator *= (
const volatile Expr<S>& xx)
volatile {
1525 typedef typename Expr<S>::derived_type expr_type;
1526 const volatile expr_type& x = xx.derived();
1528 if (x.size() > s.size())
1529 this->reset(x.size());
1531 #ifdef STOKHOS_DEBUG
1532 if (s.size() < x.size())
1536 if (x.hasFastAccess(s.size())) {
1537 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1540 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1541 #pragma vector aligned
1543 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1547 s[i] *= x.fastAccessCoeff(i);
1553 return const_cast<Vector&
>(*this);
1557 template <
typename S>
1558 KOKKOS_INLINE_FUNCTION
1559 Vector& operator /= (
const Expr<S>& xx) {
1561 typedef typename Expr<S>::derived_type expr_type;
1562 const expr_type& x = xx.derived();
1564 if (x.size() > s.size())
1565 this->reset(x.size());
1567 #ifdef STOKHOS_DEBUG
1568 if (s.size() < x.size())
1572 if (x.hasFastAccess(s.size())) {
1573 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1576 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1577 #pragma vector aligned
1579 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1583 s[i] /= x.fastAccessCoeff(i);
1593 template <
typename S>
1594 KOKKOS_INLINE_FUNCTION
1595 Vector& operator /= (
const volatile Expr<S>& xx) {
1597 typedef typename Expr<S>::derived_type expr_type;
1598 const volatile expr_type& x = xx.derived();
1600 if (x.size() > s.size())
1601 this->reset(x.size());
1603 #ifdef STOKHOS_DEBUG
1604 if (s.size() < x.size())
1608 if (x.hasFastAccess(s.size())) {
1609 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1612 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1613 #pragma vector aligned
1615 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1619 s[i] /= x.fastAccessCoeff(i);
1629 template <
typename S>
1630 KOKKOS_INLINE_FUNCTION
1631 Vector& operator /= (
const Expr<S>& xx)
volatile {
1633 typedef typename Expr<S>::derived_type expr_type;
1634 const expr_type& x = xx.derived();
1636 if (x.size() > s.size())
1637 this->reset(x.size());
1639 #ifdef STOKHOS_DEBUG
1640 if (s.size() < x.size())
1644 if (x.hasFastAccess(s.size())) {
1645 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1648 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1649 #pragma vector aligned
1651 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1655 s[i] /= x.fastAccessCoeff(i);
1661 return const_cast<Vector&
>(*this);
1665 template <
typename S>
1666 KOKKOS_INLINE_FUNCTION
1667 Vector& operator /= (
const volatile Expr<S>& xx)
volatile {
1669 typedef typename Expr<S>::derived_type expr_type;
1670 const volatile expr_type& x = xx.derived();
1672 if (x.size() > s.size())
1673 this->reset(x.size());
1675 #ifdef STOKHOS_DEBUG
1676 if (s.size() < x.size())
1680 if (x.hasFastAccess(s.size())) {
1681 #ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1684 #ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1685 #pragma vector aligned
1687 #ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1691 s[i] /= x.fastAccessCoeff(i);
1697 return const_cast<Vector&
>(*this);
1701 KOKKOS_INLINE_FUNCTION
1702 Vector& operator++() {
1709 KOKKOS_INLINE_FUNCTION
1710 volatile Vector& operator++()
volatile {
1717 KOKKOS_INLINE_FUNCTION
1718 Vector operator++(
int) {
1725 KOKKOS_INLINE_FUNCTION
1726 Vector operator++(
int)
volatile {
1733 KOKKOS_INLINE_FUNCTION
1734 Vector& operator--() {
1741 KOKKOS_INLINE_FUNCTION
1742 volatile Vector& operator--()
volatile {
1749 KOKKOS_INLINE_FUNCTION
1750 Vector operator--(
int) {
1757 KOKKOS_INLINE_FUNCTION
1758 Vector operator--(
int)
volatile {
1766 KOKKOS_INLINE_FUNCTION
1767 std::string name()
const volatile {
return "x"; }
1773 template <
typename expr_type>
1778 KOKKOS_INLINE_FUNCTION
1779 StaticOp(
storage_type& s_,
const expr_type& x_) : s(s_), x(x_) {}
1781 template <
typename ArgT>
1782 KOKKOS_INLINE_FUNCTION
1783 void operator() (ArgT arg)
const {
1784 const int Arg = ArgT::value;
1785 s.template getCoeff<Arg>() = x.template getCoeff<Arg>();
1794 #if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1806 template <
typename T>
struct const_expr_ref {
1807 typedef const T type;
1815 template <
typename S>
struct const_expr_ref< Vector<S> > {
1816 typedef const Vector<S>& type;
1824 template <
typename S>
struct const_expr_ref< volatile Vector<S> > {
1825 typedef const volatile Vector<S>& type;
1829 template <
typename T>
struct remove_volatile {
1832 template <
typename T>
struct remove_volatile<volatile T> {
1837 template <
typename T>
struct add_volatile {
1838 typedef volatile T type;
1840 template <
typename T>
struct add_volatile<volatile T> {
1841 typedef volatile T type;
1844 template <
typename Storage>
1846 operator << (std::ostream& os, const Vector<Storage>& a)
1852 for (ordinal_type i=0; i<a.size(); i++) {
1853 os << a.coeff(i) <<
" ";
1860 template <
typename Storage>
1862 operator << (std::ostream& os, const volatile Vector<Storage>& a)
1868 for (ordinal_type i=0; i<a.size(); i++) {
1869 os << a.coeff(i) <<
" ";
1876 template <
typename Storage>
1878 operator >> (std::istream& is, Vector<Storage>& a)
1888 if (Storage::is_static) {
1890 for (ordinal_type i=0; i<a.size(); i++) {
1891 is >> a.fastAccessCoeff(i);
1896 std::vector<value_type> c;
1899 while (is >> b && b !=
']') {
1904 ordinal_type
n = c.size();
1906 for (ordinal_type i=0; i<n; ++i)
1907 a.fastAccessCoeff(i) = c[i];
1917 template <
unsigned Size = 0>
1918 struct VectorPartition {
1919 static const unsigned PartitionSize = Size;
1923 template<
typename iType0 ,
typename iType1 >
1924 KOKKOS_INLINE_FUNCTION
1925 VectorPartition(
const iType0 & i0 ,
const iType1 & i1 ) :
1926 begin(i0), end(i1) {
1930 template <
typename T>
1931 struct is_vector_partition {
1932 static const bool value =
false;
1935 template <
unsigned Size>
1936 struct is_vector_partition< VectorPartition<Size> > {
1937 static const bool value =
true;
1942 template <
typename T>
1943 struct IsExpr< MP::Expr<T> > {
1944 static const bool value =
true;
1947 template <
typename T>
1948 struct BaseExprType< MP::Expr<T> > {
1949 typedef typename MP::Expr<T>::derived_type derived_type;
1950 typedef typename derived_type::base_expr_type type;
1953 template <
typename S>
1954 struct IsExpr< MP::Vector<S> > {
1955 static const bool value =
true;
1958 template <
typename S>
1959 struct BaseExprType< MP::Vector<S> > {
1960 typedef MP::Vector<S> type;
1964 template <
typename T>
struct is_mp_vector {
1965 static const bool value =
false;
1967 template <
typename S>
struct is_mp_vector< MP::Vector<S> > {
1968 static const bool value =
true;
1970 template <
typename T>
struct is_mp_vector< const T > {
1971 static const bool value = is_mp_vector<T>::value;
1973 template <
typename T>
struct is_mp_vector< T* > {
1974 static const bool value = is_mp_vector<T>::value;
1976 template <
typename T>
struct is_mp_vector< T[] > {
1977 static const bool value = is_mp_vector<T>::value;
1979 template <
typename T,
unsigned N>
struct is_mp_vector< T[N] > {
1980 static const bool value = is_mp_vector<T>::value;
1984 template <
typename Storage>
1991 const ordinal_type sz = x.size();
1992 if (sz == 1)
return true;
1995 const value_type
val = x.fastAccessCoeff(0);
1996 for (ordinal_type i=1; i<sz; ++i)
1997 if (x.fastAccessCoeff(i) !=
val)
return false;
2007 #if STOKHOS_ALIGN_MEMORY
2013 template <
typename Storage>
2014 class allocator< Sacado::MP::Vector< Storage > >
2020 typedef typename Base::pointer pointer;
2021 typedef typename Base::const_pointer const_pointer;
2022 typedef typename Base::reference reference;
2023 typedef typename Base::const_reference const_reference;
2024 typedef typename Base::size_type size_type;
2025 typedef typename Base::difference_type difference_type;
2027 template <
class U>
struct rebind {
typedef allocator<U> other; };
2029 template <
class U> allocator(
const allocator<U>&) {}
2032 template <
typename Storage>
2033 class allocator< const Sacado::MP::Vector< Storage > >
2039 typedef typename Base::pointer pointer;
2040 typedef typename Base::const_pointer const_pointer;
2041 typedef typename Base::reference reference;
2042 typedef typename Base::const_reference const_reference;
2043 typedef typename Base::size_type size_type;
2044 typedef typename Base::difference_type difference_type;
2046 template <
class U>
struct rebind {
typedef allocator<U> other; };
2048 template <
class U> allocator(
const allocator<U>&) {}
2055 #include "Kokkos_NumericTraits.hpp"
2059 template <
typename Storage>
2060 struct reduction_identity< Sacado::MP::Vector<Storage> > {
2063 typedef reduction_identity<scalar> RIS;
2064 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
sum() {
2067 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector prod() {
2068 return Vector(RIS::prod());
2070 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
max() {
2073 KOKKOS_FORCEINLINE_FUNCTION constexpr
static Vector
min() {
2079 template <
typename Storage>
2080 struct promote<Sacado::MP::Vector<Storage>,false> {
2087 #endif // HAVE_STOKHOS_SACADO
2089 #endif // SACADO_MP_VECTOR_HPP
An aligned STL allocator.
Stokhos::StandardStorage< int, double > storage_type
const double & const_reference
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
const double * const_pointer
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Traits class encapsulting memory alignment.
An aligned STL allocator.
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
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)