42#ifndef SACADO_MP_VECTOR_HPP
43#define SACADO_MP_VECTOR_HPP
47#ifdef HAVE_STOKHOS_SACADO
50#include <initializer_list>
52#include "Kokkos_Macros.hpp"
56#include "Sacado_Traits.hpp"
57#include "Sacado_mpl_apply.hpp"
58#include "Sacado_mpl_range_c.hpp"
94 typedef T derived_type;
101 KOKKOS_INLINE_FUNCTION
102 const derived_type& derived()
const {
103 return static_cast<const derived_type&
>(*this);
111 KOKKOS_INLINE_FUNCTION
112 const volatile derived_type& derived()
const volatile {
113 return static_cast<const volatile derived_type&
>(*this);
118 template <typename U, typename Enabled = typename std::enable_if<std::is_integral<U>::value>::type>
119 KOKKOS_INLINE_FUNCTION
120 explicit operator U()
const {
return static_cast<U
>(derived().val()); }
125 template <
typename Storage>
126 class Vector :
public Expr< Vector<Storage> > {
132 typedef typename storage_type::value_type
value_type;
133 typedef typename storage_type::ordinal_type
ordinal_type;
136 typedef typename storage_type::volatile_pointer volatile_pointer;
138 typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
140 typedef typename storage_type::volatile_reference volatile_reference;
142 typedef typename storage_type::const_volatile_reference const_volatile_reference;
144 typedef typename execution_space::memory_space memory_space;
145 typedef typename Stokhos::MemoryTraits<memory_space> MemTraits;
148 typedef typename ScalarType<value_type>::type
scalar_type;
150 typedef Vector base_expr_type;
153 template <
class NewStorageType >
155 typedef Vector< NewStorageType > type;
159 static const int num_args = 1;
161#if STOKHOS_ALIGN_MEMORY
162 KOKKOS_INLINE_FUNCTION
163 static void*
operator new(std::size_t sz) {
164 return MemTraits::alloc(sz);
166 KOKKOS_INLINE_FUNCTION
167 static void*
operator new[](std::size_t sz) {
168 return MemTraits::alloc(sz);
170 KOKKOS_INLINE_FUNCTION
171 static void*
operator new(std::size_t sz,
void* ptr) {
174 KOKKOS_INLINE_FUNCTION
175 static void*
operator new[](std::size_t sz,
void* ptr) {
178 KOKKOS_INLINE_FUNCTION
179 static void operator delete(
void* ptr) {
180 MemTraits::free(ptr);
182 KOKKOS_INLINE_FUNCTION
183 static void operator delete[](
void* ptr) {
184 MemTraits::free(ptr);
186 KOKKOS_INLINE_FUNCTION
187 static void operator delete(
void* ptr,
void*) {
188 MemTraits::free(ptr);
190 KOKKOS_INLINE_FUNCTION
191 static void operator delete[](
void* ptr,
void*) {
192 MemTraits::free(ptr);
200 KOKKOS_DEFAULTED_FUNCTION
207 KOKKOS_INLINE_FUNCTION
208 Vector(
const value_type& x) : s(1,
x) {}
215 KOKKOS_INLINE_FUNCTION
216 Vector(ordinal_type sz, pointer v,
bool owned) : s(sz,v,owned) {}
222 KOKKOS_INLINE_FUNCTION
223 Vector(ordinal_type sz,
const value_type& x) : s(sz,
x) {}
226 KOKKOS_INLINE_FUNCTION
230 KOKKOS_DEFAULTED_FUNCTION
231 Vector(
const Vector& x) =
default;
234 KOKKOS_INLINE_FUNCTION
235 Vector(
const volatile Vector& x) : s(
x.s) {}
238 template <
typename S>
239 KOKKOS_INLINE_FUNCTION
240 Vector(
const Expr<S>& xx) :
241 s(xx.derived().size()) {
242 typedef typename Expr<S>::derived_type expr_type;
243 const expr_type&
x = xx.derived();
246 if (s.size() !=
x.size())
250 if (
x.hasFastAccess(s.size())) {
251#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
254#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
255#pragma vector aligned
257#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
260 for (ordinal_type i=0; i<s.size(); i++)
261 s[i] = x.fastAccessCoeff(i);
264 for (ordinal_type i=0; i<s.size(); i++)
276 KOKKOS_INLINE_FUNCTION
277 Vector(std::initializer_list<value_type> l) : s(l.size(), l.begin()) {
278 if constexpr (Storage::is_static) {
283 Kokkos::abort(
"Size mismatch in list initialization of MP Vector with static fixed storage.");
294 KOKKOS_DEFAULTED_FUNCTION
298 KOKKOS_INLINE_FUNCTION
299 void init(
const value_type& v) { s.init(v); }
302 KOKKOS_INLINE_FUNCTION
303 void init(
const value_type& v)
volatile { s.init(v); }
306 KOKKOS_INLINE_FUNCTION
307 void init(
const value_type* v) { s.init(v); }
310 KOKKOS_INLINE_FUNCTION
311 void init(
const value_type* v)
volatile { s.init(v); }
314 template <
typename S>
315 KOKKOS_INLINE_FUNCTION
316 void init(
const Vector<S>& v) {
317 s.init(v.s.coeff(), v.s.size());
321 template <
typename S>
322 KOKKOS_INLINE_FUNCTION
323 void init(
const Vector<S>& v)
volatile {
324 s.init(v.s.coeff(), v.s.size());
328 KOKKOS_INLINE_FUNCTION
329 void load(value_type* v) { s.load(v); }
332 KOKKOS_INLINE_FUNCTION
333 void load(value_type* v)
volatile { s.load(v); }
336 template <
typename S>
337 KOKKOS_INLINE_FUNCTION
338 void load(Vector<S>& v) { s.load(v.s.coeff()); }
341 template <
typename S>
342 KOKKOS_INLINE_FUNCTION
343 void load(Vector<S>& v)
volatile { s.load(v.s.coeff()); }
349 KOKKOS_INLINE_FUNCTION
350 void reset(ordinal_type sz_new) {
353 if (sz == 1 && sz_new > sz)
354 for (ordinal_type i=1; i<sz_new; i++)
362 KOKKOS_INLINE_FUNCTION
363 void reset(ordinal_type sz_new)
volatile {
366 if (sz == 1 && sz_new > sz)
367 for (ordinal_type i=1; i<sz_new; i++)
381 KOKKOS_INLINE_FUNCTION
382 void copyForWrite()
volatile { }
385 template <
typename S>
386 KOKKOS_INLINE_FUNCTION
387 bool isEqualTo(
const Expr<S>& xx)
const {
388 const typename Expr<S>::derived_type&
x = xx.derived();
389 typedef IsEqual<value_type> IE;
390 if (
x.size() != this->size())
return false;
392 for (ordinal_type i=0; i<this->size(); i++)
393 eq = eq && IE::eval(
x.coeff(i), this->coeff(i));
398 template <
typename S>
399 KOKKOS_INLINE_FUNCTION
400 bool isEqualTo(
const Expr<S>& xx)
const volatile {
401 const typename Expr<S>::derived_type&
x = xx.derived();
402 typedef IsEqual<value_type> IE;
403 if (
x.size() != this->size())
return false;
405 for (ordinal_type i=0; i<this->size(); i++)
406 eq = eq && IE::eval(
x.coeff(i), this->coeff(i));
419 Vector& operator=(std::initializer_list<value_type> l) {
423 s.init(l.begin(), lsz);
432 operator=(std::initializer_list<value_type> l)
volatile {
436 s.init(l.begin(), lsz);
437 return const_cast<Vector&
>(*this);
441 KOKKOS_INLINE_FUNCTION
442 Vector& operator=(
const value_type& x) {
448 KOKKOS_INLINE_FUNCTION
449 Vector& operator=(
const value_type& x)
volatile {
451 return const_cast<Vector&
>(*this);
455 KOKKOS_INLINE_FUNCTION
456 Vector& operator=(
const Vector& x) {
470 if (s.size() >
x.s.size())
471 for (ordinal_type i=
x.s.size(); i<s.size(); i++)
479 KOKKOS_INLINE_FUNCTION
480 Vector& operator=(
const volatile Vector& x) {
494 if (s.size() >
x.s.size())
495 for (ordinal_type i=
x.s.size(); i<s.size(); i++)
503 KOKKOS_INLINE_FUNCTION
504 Vector& operator=(
const Vector& x)
volatile {
518 if (s.size() >
x.s.size())
519 for (ordinal_type i=
x.s.size(); i<s.size(); i++)
523 return const_cast<Vector&
>(*this);
527 KOKKOS_INLINE_FUNCTION
528 Vector& operator=(
const volatile Vector& x)
volatile {
542 if (s.size() >
x.s.size())
543 for (ordinal_type i=
x.s.size(); i<s.size(); i++)
547 return const_cast<Vector&
>(*this);
551 template <
typename S>
552 KOKKOS_INLINE_FUNCTION
553 Vector& operator=(
const Expr<S>& xx) {
554 typedef typename Expr<S>::derived_type expr_type;
555 const expr_type&
x = xx.derived();
557 this->reset(
x.size());
560 if (s.size() !=
x.size())
564 if (
x.hasFastAccess(s.size())) {
565#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
568#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
569#pragma vector aligned
571#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
574 for (ordinal_type i=0; i<s.size(); i++)
575 s[i] =
x.fastAccessCoeff(i);
578 for (ordinal_type i=0; i<s.size(); i++)
585 template <
typename S>
586 KOKKOS_INLINE_FUNCTION
587 Vector& operator=(
const Expr<S>& xx)
volatile {
588 typedef typename Expr<S>::derived_type expr_type;
589 const expr_type&
x = xx.derived();
591 this->reset(
x.size());
594 if (s.size() !=
x.size())
598 if (
x.hasFastAccess(s.size())) {
599#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
602#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
603#pragma vector aligned
605#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
608 for (ordinal_type i=0; i<s.size(); i++)
609 s[i] =
x.fastAccessCoeff(i);
612 for (ordinal_type i=0; i<s.size(); i++)
615 return const_cast<Vector&
>(*this);
619 template<
typename S >
620 KOKKOS_INLINE_FUNCTION
621 typename std::enable_if<( ! std::is_same<S,void>::value &&
624 ::type
const &
operator = (
const Expr<S> & xx )
const
626 const typename Expr<S>::derived_type &
x = xx.derived();
628#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
631#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
632#pragma vector aligned
634#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
637 for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] =
x.coeff(i); }
643 template<
typename S >
644 KOKKOS_INLINE_FUNCTION
646 typename std::enable_if<( ! std::is_same<S,void>::value &&
649 ::type
const &
operator = (
const Expr<S> & xx )
const volatile
651 const typename Expr<S>::derived_type &
x = xx.derived();
653#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
656#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
657#pragma vector aligned
659#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
662 for ( ordinal_type i = 0 ; i < s.size() ; ++i ) { s[i] =
x.coeff(i); }
674 KOKKOS_INLINE_FUNCTION
675 const volatile storage_type& storage()
const volatile {
return s; }
678 KOKKOS_INLINE_FUNCTION
682 KOKKOS_INLINE_FUNCTION
686 KOKKOS_INLINE_FUNCTION
695 KOKKOS_INLINE_FUNCTION
696 const_volatile_reference
val()
const volatile {
return s[0]; }
699 KOKKOS_INLINE_FUNCTION
700 const_reference
val()
const {
return s[0]; }
703 KOKKOS_INLINE_FUNCTION
704 volatile_reference
val()
volatile {
return s[0]; }
707 KOKKOS_INLINE_FUNCTION
708 reference
val() {
return s[0]; }
718 KOKKOS_INLINE_FUNCTION
722 KOKKOS_INLINE_FUNCTION
726 KOKKOS_INLINE_FUNCTION
727 bool hasFastAccess(ordinal_type sz)
const {
return s.size()>=sz;}
730 KOKKOS_INLINE_FUNCTION
731 bool hasFastAccess(ordinal_type sz)
const volatile {
return s.size()>=sz;}
734 KOKKOS_INLINE_FUNCTION
735 const_pointer coeff()
const {
return s.coeff();}
738 KOKKOS_INLINE_FUNCTION
739 const_volatile_pointer coeff()
const volatile {
return s.coeff();}
742 KOKKOS_INLINE_FUNCTION
743 volatile_pointer coeff()
volatile {
return s.coeff();}
746 KOKKOS_INLINE_FUNCTION
747 pointer coeff() {
return s.coeff();}
750 KOKKOS_INLINE_FUNCTION
751 value_type coeff(ordinal_type i)
const volatile {
752 return i<s.size() ? s[i] : s[0]; }
755 KOKKOS_INLINE_FUNCTION
757 return i<s.size() ? s[i] : s[0]; }
760 KOKKOS_INLINE_FUNCTION
762 return i<s.size() ? s[i] : s[0]; }
765 KOKKOS_INLINE_FUNCTION
767 return i<s.size() ? s[i] : s[0]; }
770 KOKKOS_INLINE_FUNCTION
771 const_volatile_reference
fastAccessCoeff(ordinal_type i)
const volatile {
775 KOKKOS_INLINE_FUNCTION
780 KOKKOS_INLINE_FUNCTION
785 KOKKOS_INLINE_FUNCTION
790 KOKKOS_INLINE_FUNCTION
791 const_volatile_reference operator[](ordinal_type i)
const volatile {
795 KOKKOS_INLINE_FUNCTION
796 const_reference operator[](ordinal_type i)
const {
800 KOKKOS_INLINE_FUNCTION
801 volatile_reference operator[](ordinal_type i)
volatile {
805 KOKKOS_INLINE_FUNCTION
806 reference operator[](ordinal_type i) {
810 KOKKOS_INLINE_FUNCTION
812 return s.template getCoeff<i>(); }
815 KOKKOS_INLINE_FUNCTION
817 return s.template getCoeff<i>(); }
820 KOKKOS_INLINE_FUNCTION
821 volatile_reference getCoeff()
volatile {
822 return s.template getCoeff<i>(); }
825 KOKKOS_INLINE_FUNCTION
826 reference getCoeff() {
827 return s.template getCoeff<i>(); }
830 KOKKOS_INLINE_FUNCTION
831 pointer begin() {
return s.coeff(); }
834 KOKKOS_INLINE_FUNCTION
835 const_pointer begin()
const {
return s.coeff(); }
838 KOKKOS_INLINE_FUNCTION
839 volatile_pointer begin()
volatile {
return s.coeff(); }
842 KOKKOS_INLINE_FUNCTION
843 const_volatile_pointer begin()
const volatile {
return s.coeff(); }
846 KOKKOS_INLINE_FUNCTION
847 const_pointer cbegin()
const {
return s.coeff(); }
850 KOKKOS_INLINE_FUNCTION
851 const_volatile_pointer cbegin()
const volatile {
return s.coeff(); }
854 KOKKOS_INLINE_FUNCTION
855 pointer end() {
return s.coeff() + s.size(); }
858 KOKKOS_INLINE_FUNCTION
859 const_pointer end()
const {
return s.coeff() + s.size(); }
862 KOKKOS_INLINE_FUNCTION
863 volatile_pointer end()
volatile {
return s.coeff() + s.size(); }
866 KOKKOS_INLINE_FUNCTION
867 const_volatile_pointer end()
const volatile {
return s.coeff() + s.size(); }
870 KOKKOS_INLINE_FUNCTION
871 const_pointer cend()
const {
return s.coeff()+ s.size(); }
874 KOKKOS_INLINE_FUNCTION
875 const_volatile_pointer cend()
const volatile {
return s.coeff()+ s.size(); }
885 KOKKOS_INLINE_FUNCTION
886 Vector& operator += (
const value_type& x) {
887#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
890#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
891#pragma vector aligned
893#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
896 for (ordinal_type i=0; i<s.size(); i++)
902 KOKKOS_INLINE_FUNCTION
903 Vector& operator += (
const volatile value_type& x) {
904#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
907#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
908#pragma vector aligned
910#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
913 for (ordinal_type i=0; i<s.size(); i++)
919 KOKKOS_INLINE_FUNCTION
920 Vector& operator += (
const value_type& x)
volatile {
921#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
924#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
925#pragma vector aligned
927#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
930 for (ordinal_type i=0; i<s.size(); i++)
932 return const_cast<Vector&
>(*this);
936 KOKKOS_INLINE_FUNCTION
937 Vector& operator += (
const volatile value_type& x)
volatile {
938#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
941#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
942#pragma vector aligned
944#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
947 for (ordinal_type i=0; i<s.size(); i++)
949 return const_cast<Vector&
>(*this);
953 KOKKOS_INLINE_FUNCTION
954 Vector& operator -= (
const value_type& x) {
955#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
958#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
959#pragma vector aligned
961#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
964 for (ordinal_type i=0; i<s.size(); i++)
970 KOKKOS_INLINE_FUNCTION
971 Vector& operator -= (
const volatile value_type& x) {
972#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
975#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
976#pragma vector aligned
978#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
981 for (ordinal_type i=0; i<s.size(); i++)
987 KOKKOS_INLINE_FUNCTION
988 Vector& operator -= (
const value_type& x)
volatile {
989#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
992#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
993#pragma vector aligned
995#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
998 for (ordinal_type i=0; i<s.size(); i++)
1000 return const_cast<Vector&
>(*this);
1004 KOKKOS_INLINE_FUNCTION
1005 Vector& operator -= (
const volatile value_type& x)
volatile {
1006#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1009#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1010#pragma vector aligned
1012#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1015 for (ordinal_type i=0; i<s.size(); i++)
1017 return const_cast<Vector&
>(*this);
1021 KOKKOS_INLINE_FUNCTION
1022 Vector& operator *= (
const value_type& x) {
1023#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1026#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1027#pragma vector aligned
1029#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1032 for (ordinal_type i=0; i<s.size(); i++)
1038 KOKKOS_INLINE_FUNCTION
1039 Vector& operator *= (
const volatile value_type& x) {
1040#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1043#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1044#pragma vector aligned
1046#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1049 for (ordinal_type i=0; i<s.size(); i++)
1055 KOKKOS_INLINE_FUNCTION
1056 Vector& operator *= (
const value_type& x)
volatile {
1057#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1060#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1061#pragma vector aligned
1063#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1066 for (ordinal_type i=0; i<s.size(); i++)
1068 return const_cast<Vector&
>(*this);
1072 KOKKOS_INLINE_FUNCTION
1073 Vector& operator *= (
const volatile value_type& x)
volatile {
1074#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1077#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1078#pragma vector aligned
1080#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1083 for (ordinal_type i=0; i<s.size(); i++)
1085 return const_cast<Vector&
>(*this);
1089 KOKKOS_INLINE_FUNCTION
1090 Vector& operator /= (
const value_type& x) {
1091#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1094#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1095#pragma vector aligned
1097#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1100 for (ordinal_type i=0; i<s.size(); i++)
1106 KOKKOS_INLINE_FUNCTION
1107 Vector& operator /= (
const volatile value_type& x) {
1108#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1111#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1112#pragma vector aligned
1114#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1117 for (ordinal_type i=0; i<s.size(); i++)
1123 KOKKOS_INLINE_FUNCTION
1124 Vector& operator /= (
const value_type& x)
volatile {
1125#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1128#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1129#pragma vector aligned
1131#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1134 for (ordinal_type i=0; i<s.size(); i++)
1136 return const_cast<Vector&
>(*this);
1140 KOKKOS_INLINE_FUNCTION
1141 Vector& operator /= (
const volatile value_type& x)
volatile {
1142#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1145#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1146#pragma vector aligned
1148#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1151 for (ordinal_type i=0; i<s.size(); i++)
1153 return const_cast<Vector&
>(*this);
1157 template <
typename S>
1158 KOKKOS_INLINE_FUNCTION
1159 Vector& operator += (
const Expr<S>& xx) {
1161 typedef typename Expr<S>::derived_type expr_type;
1162 const expr_type&
x = xx.derived();
1164 if (
x.size() > s.size())
1165 this->reset(
x.size());
1168 if (s.size() <
x.size())
1172 if (
x.hasFastAccess(s.size())) {
1173#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1176#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1177#pragma vector aligned
1179#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1182 for (ordinal_type i=0; i<s.size(); i++)
1183 s[i] +=
x.fastAccessCoeff(i);
1186 for (ordinal_type i=0; i<s.size(); i++)
1193 template <
typename S>
1194 KOKKOS_INLINE_FUNCTION
1195 Vector& operator += (
const volatile Expr<S>& xx) {
1197 typedef typename Expr<S>::derived_type expr_type;
1198 const volatile expr_type&
x = xx.derived();
1200 if (
x.size() > s.size())
1201 this->reset(
x.size());
1204 if (s.size() <
x.size())
1208 if (
x.hasFastAccess(s.size())) {
1209#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1212#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1213#pragma vector aligned
1215#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1218 for (ordinal_type i=0; i<s.size(); i++)
1219 s[i] +=
x.fastAccessCoeff(i);
1222 for (ordinal_type i=0; i<s.size(); i++)
1229 template <
typename S>
1230 KOKKOS_INLINE_FUNCTION
1231 Vector& operator += (
const Expr<S>& xx)
volatile {
1233 typedef typename Expr<S>::derived_type expr_type;
1234 const expr_type&
x = xx.derived();
1236 if (
x.size() > s.size())
1237 this->reset(
x.size());
1240 if (s.size() <
x.size())
1244 if (
x.hasFastAccess(s.size())) {
1245#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1248#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1249#pragma vector aligned
1251#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1254 for (ordinal_type i=0; i<s.size(); i++)
1255 s[i] +=
x.fastAccessCoeff(i);
1258 for (ordinal_type i=0; i<s.size(); i++)
1261 return const_cast<Vector&
>(*this);
1265 template <
typename S>
1266 KOKKOS_INLINE_FUNCTION
1267 Vector& operator += (
const volatile Expr<S>& xx)
volatile {
1269 typedef typename Expr<S>::derived_type expr_type;
1270 const volatile expr_type&
x = xx.derived();
1272 if (
x.size() > s.size())
1273 this->reset(
x.size());
1276 if (s.size() <
x.size())
1280 if (
x.hasFastAccess(s.size())) {
1281#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1284#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1285#pragma vector aligned
1287#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1290 for (ordinal_type i=0; i<s.size(); i++)
1291 s[i] +=
x.fastAccessCoeff(i);
1294 for (ordinal_type i=0; i<s.size(); i++)
1297 return const_cast<Vector&
>(*this);
1301 template <
typename S>
1302 KOKKOS_INLINE_FUNCTION
1303 Vector& operator -= (
const Expr<S>& xx) {
1305 typedef typename Expr<S>::derived_type expr_type;
1306 const expr_type&
x = xx.derived();
1308 if (
x.size() > s.size())
1309 this->reset(
x.size());
1312 if (s.size() <
x.size())
1316 if (
x.hasFastAccess(s.size())) {
1317#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1320#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1321#pragma vector aligned
1323#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1326 for (ordinal_type i=0; i<s.size(); i++)
1327 s[i] -=
x.fastAccessCoeff(i);
1330 for (ordinal_type i=0; i<s.size(); i++)
1337 template <
typename S>
1338 KOKKOS_INLINE_FUNCTION
1339 Vector& operator -= (
const volatile Expr<S>& xx) {
1341 typedef typename Expr<S>::derived_type expr_type;
1342 const volatile expr_type&
x = xx.derived();
1344 if (
x.size() > s.size())
1345 this->reset(
x.size());
1348 if (s.size() <
x.size())
1352 if (
x.hasFastAccess(s.size())) {
1353#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1356#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1357#pragma vector aligned
1359#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1362 for (ordinal_type i=0; i<s.size(); i++)
1363 s[i] -=
x.fastAccessCoeff(i);
1366 for (ordinal_type i=0; i<s.size(); i++)
1373 template <
typename S>
1374 KOKKOS_INLINE_FUNCTION
1375 Vector& operator -= (
const Expr<S>& xx)
volatile {
1377 typedef typename Expr<S>::derived_type expr_type;
1378 const expr_type&
x = xx.derived();
1380 if (
x.size() > s.size())
1381 this->reset(
x.size());
1384 if (s.size() <
x.size())
1388 if (
x.hasFastAccess(s.size())) {
1389#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1392#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1393#pragma vector aligned
1395#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1398 for (ordinal_type i=0; i<s.size(); i++)
1399 s[i] -=
x.fastAccessCoeff(i);
1402 for (ordinal_type i=0; i<s.size(); i++)
1405 return const_cast<Vector&
>(*this);
1409 template <
typename S>
1410 KOKKOS_INLINE_FUNCTION
1411 Vector& operator -= (
const volatile Expr<S>& xx)
volatile {
1413 typedef typename Expr<S>::derived_type expr_type;
1414 const volatile expr_type&
x = xx.derived();
1416 if (
x.size() > s.size())
1417 this->reset(
x.size());
1420 if (s.size() <
x.size())
1424 if (
x.hasFastAccess(s.size())) {
1425#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1428#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1429#pragma vector aligned
1431#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1434 for (ordinal_type i=0; i<s.size(); i++)
1435 s[i] -=
x.fastAccessCoeff(i);
1438 for (ordinal_type i=0; i<s.size(); i++)
1441 return const_cast<Vector&
>(*this);
1445 template <
typename S>
1446 KOKKOS_INLINE_FUNCTION
1447 Vector& operator *= (
const Expr<S>& xx) {
1449 typedef typename Expr<S>::derived_type expr_type;
1450 const expr_type&
x = xx.derived();
1452 if (
x.size() > s.size())
1453 this->reset(
x.size());
1456 if (s.size() <
x.size())
1460 if (
x.hasFastAccess(s.size())) {
1461#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1464#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1465#pragma vector aligned
1467#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1470 for (ordinal_type i=0; i<s.size(); i++)
1471 s[i] *=
x.fastAccessCoeff(i);
1474 for (ordinal_type i=0; i<s.size(); i++)
1481 template <
typename S>
1482 KOKKOS_INLINE_FUNCTION
1483 Vector& operator *= (
const volatile Expr<S>& xx) {
1485 typedef typename Expr<S>::derived_type expr_type;
1486 const volatile expr_type&
x = xx.derived();
1488 if (
x.size() > s.size())
1489 this->reset(
x.size());
1492 if (s.size() <
x.size())
1496 if (
x.hasFastAccess(s.size())) {
1497#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1500#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1501#pragma vector aligned
1503#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1506 for (ordinal_type i=0; i<s.size(); i++)
1507 s[i] *=
x.fastAccessCoeff(i);
1510 for (ordinal_type i=0; i<s.size(); i++)
1517 template <
typename S>
1518 KOKKOS_INLINE_FUNCTION
1519 Vector& operator *= (
const Expr<S>& xx)
volatile {
1521 typedef typename Expr<S>::derived_type expr_type;
1522 const expr_type&
x = xx.derived();
1524 if (
x.size() > s.size())
1525 this->reset(
x.size());
1528 if (s.size() <
x.size())
1532 if (
x.hasFastAccess(s.size())) {
1533#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1536#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1537#pragma vector aligned
1539#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1542 for (ordinal_type i=0; i<s.size(); i++)
1543 s[i] *=
x.fastAccessCoeff(i);
1546 for (ordinal_type i=0; i<s.size(); i++)
1549 return const_cast<Vector&
>(*this);
1553 template <
typename S>
1554 KOKKOS_INLINE_FUNCTION
1555 Vector& operator *= (
const volatile Expr<S>& xx)
volatile {
1557 typedef typename Expr<S>::derived_type expr_type;
1558 const volatile expr_type&
x = xx.derived();
1560 if (
x.size() > s.size())
1561 this->reset(
x.size());
1564 if (s.size() <
x.size())
1568 if (
x.hasFastAccess(s.size())) {
1569#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1572#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1573#pragma vector aligned
1575#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1578 for (ordinal_type i=0; i<s.size(); i++)
1579 s[i] *=
x.fastAccessCoeff(i);
1582 for (ordinal_type i=0; i<s.size(); i++)
1585 return const_cast<Vector&
>(*this);
1589 template <
typename S>
1590 KOKKOS_INLINE_FUNCTION
1591 Vector& operator /= (
const Expr<S>& xx) {
1593 typedef typename Expr<S>::derived_type expr_type;
1594 const expr_type&
x = xx.derived();
1596 if (
x.size() > s.size())
1597 this->reset(
x.size());
1600 if (s.size() <
x.size())
1604 if (
x.hasFastAccess(s.size())) {
1605#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1608#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1609#pragma vector aligned
1611#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1614 for (ordinal_type i=0; i<s.size(); i++)
1615 s[i] /=
x.fastAccessCoeff(i);
1618 for (ordinal_type i=0; i<s.size(); i++)
1625 template <
typename S>
1626 KOKKOS_INLINE_FUNCTION
1627 Vector& operator /= (
const volatile Expr<S>& xx) {
1629 typedef typename Expr<S>::derived_type expr_type;
1630 const volatile expr_type&
x = xx.derived();
1632 if (
x.size() > s.size())
1633 this->reset(
x.size());
1636 if (s.size() <
x.size())
1640 if (
x.hasFastAccess(s.size())) {
1641#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1644#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1645#pragma vector aligned
1647#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1650 for (ordinal_type i=0; i<s.size(); i++)
1651 s[i] /=
x.fastAccessCoeff(i);
1654 for (ordinal_type i=0; i<s.size(); i++)
1661 template <
typename S>
1662 KOKKOS_INLINE_FUNCTION
1663 Vector& operator /= (
const Expr<S>& xx)
volatile {
1665 typedef typename Expr<S>::derived_type expr_type;
1666 const expr_type&
x = xx.derived();
1668 if (
x.size() > s.size())
1669 this->reset(
x.size());
1672 if (s.size() <
x.size())
1676 if (
x.hasFastAccess(s.size())) {
1677#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1680#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1681#pragma vector aligned
1683#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1686 for (ordinal_type i=0; i<s.size(); i++)
1687 s[i] /=
x.fastAccessCoeff(i);
1690 for (ordinal_type i=0; i<s.size(); i++)
1693 return const_cast<Vector&
>(*this);
1697 template <
typename S>
1698 KOKKOS_INLINE_FUNCTION
1699 Vector& operator /= (
const volatile Expr<S>& xx)
volatile {
1701 typedef typename Expr<S>::derived_type expr_type;
1702 const volatile expr_type&
x = xx.derived();
1704 if (
x.size() > s.size())
1705 this->reset(
x.size());
1708 if (s.size() <
x.size())
1712 if (
x.hasFastAccess(s.size())) {
1713#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
1716#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
1717#pragma vector aligned
1719#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
1722 for (ordinal_type i=0; i<s.size(); i++)
1723 s[i] /=
x.fastAccessCoeff(i);
1726 for (ordinal_type i=0; i<s.size(); i++)
1729 return const_cast<Vector&
>(*this);
1733 KOKKOS_INLINE_FUNCTION
1734 Vector& operator++() {
1735 for (ordinal_type i=0; i<s.size(); i++)
1741 KOKKOS_INLINE_FUNCTION
1742 volatile Vector& operator++()
volatile {
1743 for (ordinal_type i=0; i<s.size(); i++)
1749 KOKKOS_INLINE_FUNCTION
1750 Vector operator++(
int) {
1757 KOKKOS_INLINE_FUNCTION
1758 Vector operator++(
int)
volatile {
1765 KOKKOS_INLINE_FUNCTION
1766 Vector& operator--() {
1767 for (ordinal_type i=0; i<s.size(); i++)
1773 KOKKOS_INLINE_FUNCTION
1774 volatile Vector& operator--()
volatile {
1775 for (ordinal_type i=0; i<s.size(); i++)
1781 KOKKOS_INLINE_FUNCTION
1782 Vector operator--(
int) {
1789 KOKKOS_INLINE_FUNCTION
1790 Vector operator--(
int)
volatile {
1798 KOKKOS_INLINE_FUNCTION
1799 std::string name()
const volatile {
return "x"; }
1805 template <
typename expr_type>
1810 KOKKOS_INLINE_FUNCTION
1811 StaticOp(
storage_type& s_,
const expr_type& x_) : s(s_),
x(x_) {}
1813 template <
typename ArgT>
1814 KOKKOS_INLINE_FUNCTION
1815 void operator() (ArgT arg)
const {
1816 const int Arg = ArgT::value;
1817 s.template getCoeff<Arg>() =
x.template getCoeff<Arg>();
1826#if STOKHOS_USE_MP_VECTOR_SFS_SPEC
1838 template <
typename T>
struct const_expr_ref {
1839 typedef const T type;
1847 template <
typename S>
struct const_expr_ref<
Vector<S> > {
1848 typedef const Vector<S>& type;
1856 template <
typename S>
struct const_expr_ref< volatile
Vector<S> > {
1857 typedef const volatile Vector<S>& type;
1861 template <
typename T>
struct remove_volatile {
1864 template <
typename T>
struct remove_volatile<volatile T> {
1869 template <
typename T>
struct add_volatile {
1870 typedef volatile T type;
1872 template <
typename T>
struct add_volatile<volatile T> {
1873 typedef volatile T type;
1876 template <
typename Storage>
1884 for (ordinal_type i=0; i<a.size(); i++) {
1885 os << a.coeff(i) <<
" ";
1892 template <
typename Storage>
1900 for (ordinal_type i=0; i<a.size(); i++) {
1901 os << a.coeff(i) <<
" ";
1908 template <
typename Storage>
1920 if (Storage::is_static) {
1922 for (ordinal_type i=0; i<a.size(); i++) {
1923 is >> a.fastAccessCoeff(i);
1928 std::vector<value_type> c;
1931 while (is >> b && b !=
']') {
1938 for (ordinal_type i=0; i<n; ++i)
1939 a.fastAccessCoeff(i) = c[i];
1949 template <
unsigned Size = 0>
1950 struct VectorPartition {
1951 static const unsigned PartitionSize = Size;
1955 template<
typename iType0 ,
typename iType1 >
1956 KOKKOS_INLINE_FUNCTION
1957 VectorPartition(
const iType0 & i0 ,
const iType1 & i1 ) :
1958 begin(i0), end(i1) {
1962 template <
typename T>
1963 struct is_vector_partition {
1964 static const bool value =
false;
1967 template <
unsigned Size>
1968 struct is_vector_partition< VectorPartition<Size> > {
1969 static const bool value =
true;
1974 template <
typename T>
1975 struct IsExpr<
MP::Expr<T> > {
1976 static const bool value =
true;
1979 template <
typename T>
1980 struct BaseExprType<
MP::Expr<T> > {
1981 typedef typename MP::Expr<T>::derived_type derived_type;
1982 typedef typename derived_type::base_expr_type type;
1985 template <
typename S>
1986 struct IsExpr<
MP::Vector<S> > {
1987 static const bool value =
true;
1990 template <
typename S>
1991 struct BaseExprType<
MP::Vector<S> > {
1992 typedef MP::Vector<S> type;
1996 template <
typename T>
struct is_mp_vector {
1997 static const bool value =
false;
1999 template <
typename S>
struct is_mp_vector<
MP::Vector<S> > {
2000 static const bool value =
true;
2002 template <
typename T>
struct is_mp_vector< const T > {
2003 static const bool value = is_mp_vector<T>::value;
2005 template <
typename T>
struct is_mp_vector< T* > {
2006 static const bool value = is_mp_vector<T>::value;
2008 template <
typename T>
struct is_mp_vector< T[] > {
2009 static const bool value = is_mp_vector<T>::value;
2011 template <
typename T,
unsigned N>
struct is_mp_vector< T[N] > {
2012 static const bool value = is_mp_vector<T>::value;
2016 template <
typename Storage>
2017 bool is_constant(
const Sacado::MP::Vector<Storage>& x)
2020 typedef typename Storage::value_type
value_type;
2024 if (sz == 1)
return true;
2028 for (ordinal_type i=1; i<sz; ++i)
2029 if (
x.fastAccessCoeff(i) !=
val)
return false;
2039#if STOKHOS_ALIGN_MEMORY
2045template <
typename Storage>
2046class allocator< Sacado::MP::Vector< Storage > >
2047 :
public Stokhos::aligned_allocator< Sacado::MP::Vector< Storage > > {
2049 typedef Sacado::MP::Vector<Storage> T;
2050 typedef Stokhos::aligned_allocator<T> Base;
2051 typedef typename Base::value_type
value_type;
2052 typedef typename Base::pointer pointer;
2053 typedef typename Base::const_pointer const_pointer;
2054 typedef typename Base::reference reference;
2055 typedef typename Base::const_reference const_reference;
2056 typedef typename Base::size_type size_type;
2057 typedef typename Base::difference_type difference_type;
2059 template <
class U>
struct rebind {
typedef allocator<U> other; };
2061 template <
class U> allocator(
const allocator<U>&) {}
2064template <
typename Storage>
2065class allocator< const Sacado::MP::Vector< Storage > >
2066 :
public Stokhos::aligned_allocator< const Sacado::MP::Vector< Storage > > {
2068 typedef Sacado::MP::Vector<Storage> T;
2069 typedef Stokhos::aligned_allocator<const T> Base;
2070 typedef typename Base::value_type
value_type;
2071 typedef typename Base::pointer pointer;
2072 typedef typename Base::const_pointer const_pointer;
2073 typedef typename Base::reference reference;
2074 typedef typename Base::const_reference const_reference;
2075 typedef typename Base::size_type size_type;
2076 typedef typename Base::difference_type difference_type;
2078 template <
class U>
struct rebind {
typedef allocator<U> other; };
2080 template <
class U> allocator(
const allocator<U>&) {}
2087#include "Kokkos_NumericTraits.hpp"
2091template <
typename Storage>
2092struct reduction_identity< Sacado::MP::Vector<Storage> > {
2093 typedef Sacado::MP::Vector<Storage> Vector;
2094 typedef typename Storage::value_type scalar;
2095 typedef reduction_identity<scalar> RIS;
2096 KOKKOS_FORCEINLINE_FUNCTION
constexpr static Vector
sum() {
2097 return Vector(RIS::sum());
2099 KOKKOS_FORCEINLINE_FUNCTION
constexpr static Vector prod() {
2100 return Vector(RIS::prod());
2102 KOKKOS_FORCEINLINE_FUNCTION
constexpr static Vector
max() {
2103 return Vector(RIS::max());
2105 KOKKOS_FORCEINLINE_FUNCTION
constexpr static Vector
min() {
2106 return Vector(RIS::min());
2111 template <
typename Storage>
2112 struct promote<Sacado::MP::Vector<Storage>,false> {
2113 using type =
typename Sacado::MP::Vector<Storage>;
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j) - expr2.val(j)
Stokhos::StandardStorage< int, double > storage_type
Kokkos::DefaultHostExecutionSpace execution_space
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
const double * const_pointer
const double & const_reference
Stokhos::StandardStorage< int, double > Storage
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 void raise_error(const char *msg)
std::ostream & operator<<(std::ostream &os, const Expr< T > &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x