97 typedef typename value_type::value_type
val_type;
105 KOKKOS_INLINE_FUNCTION
112 template <
typename S>
113 KOKKOS_INLINE_FUNCTION
121 KOKKOS_INLINE_FUNCTION
122 GeneralFad(
const int sz,
const T & x,
const DerivInit zero_out = InitDerivArray) :
131 KOKKOS_INLINE_FUNCTION
138 KOKKOS_INLINE_FUNCTION
142 KOKKOS_INLINE_FUNCTION
147 template <
typename S>
148 KOKKOS_INLINE_FUNCTION
152 const int sz = x.size();
155 if (x.hasFastAccess())
156 for(
int i=0; i<sz; ++i)
157 for (
int j=0;
j<VecNum; ++
j)
160 for(
int i=0; i<sz; ++i)
161 for (
int j=0;
j<VecNum; ++
j)
165 for (
int j=0;
j<VecNum; ++
j)
170 KOKKOS_INLINE_FUNCTION
180 KOKKOS_INLINE_FUNCTION
181 void diff(
const int ith,
const int n) {
182 if (this->size() != n)
190 KOKKOS_INLINE_FUNCTION
194 KOKKOS_INLINE_FUNCTION
198 template <
typename S>
199 KOKKOS_INLINE_FUNCTION
201 typedef IsEqual<value_type> IE;
202 if (x.size() != this->size())
return false;
203 bool eq = IE::eval(x.val(), this->val());
204 for (
int i=0; i<this->size(); i++)
205 eq = eq && IE::eval(x.dx(i), this->
dx(i));
217 KOKKOS_INLINE_FUNCTION
218 const T&
val()
const {
return Storage::val();}
221 KOKKOS_INLINE_FUNCTION
222 T&
val() {
return Storage::val();}
225 KOKKOS_INLINE_FUNCTION
226 const val_type&
val(
int j)
const {
return Storage::val().fastAccessCoeff(
j);}
229 KOKKOS_INLINE_FUNCTION
243 KOKKOS_INLINE_FUNCTION
247 KOKKOS_INLINE_FUNCTION
251 KOKKOS_INLINE_FUNCTION
255 KOKKOS_INLINE_FUNCTION
257 if (is_const && this->size()!=0)
262 KOKKOS_INLINE_FUNCTION
263 const T*
dx()
const {
return this->dx_; }
266 KOKKOS_INLINE_FUNCTION
267 T dx(
int i)
const {
return this->size() ? this->dx_[i] :
T(0.); }
270 KOKKOS_INLINE_FUNCTION
274 KOKKOS_INLINE_FUNCTION
278 KOKKOS_INLINE_FUNCTION
282 KOKKOS_INLINE_FUNCTION
284 return this->dx_[i].fastAccessCoeff(
j);
288 KOKKOS_INLINE_FUNCTION
290 return this->dx_[i].fastAccessCoeff(
j);
301 template <
typename S>
302 KOKKOS_INLINE_FUNCTION
303 SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator=(
const S& v) {
305 if (this->size()) this->resize(0);
310 KOKKOS_INLINE_FUNCTION
312 operator=(
const GeneralFad& x) {
314 Storage::operator=(x);
319 template <
typename S>
320 KOKKOS_INLINE_FUNCTION
321 SACADO_ENABLE_EXPR_FUNC(GeneralFad&) operator=(
const Expr<S>& x) {
322 const int xsz = x.size();
324 if (xsz != this->size())
325 this->resizeAndZero(xsz);
327 const int sz = this->size();
335 if (x.hasFastAccess())
336 for(
int i=0; i<sz; ++i)
337 for (
int j=0;
j<VecNum; ++
j)
340 for(
int i=0; i<sz; ++i)
341 for (
int j=0;
j<VecNum; ++
j)
345 for (
int j=0;
j<VecNum; ++
j)
359 template <
typename S>
360 KOKKOS_INLINE_FUNCTION
361 SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator += (
const S& v) {
367 template <
typename S>
368 KOKKOS_INLINE_FUNCTION
369 SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator -= (
const S& v) {
375 template <
typename S>
376 KOKKOS_INLINE_FUNCTION
377 SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator *= (
const S& v) {
378 const int sz = this->size();
380 for (
int i=0; i<sz; ++i)
386 template <
typename S>
387 KOKKOS_INLINE_FUNCTION
388 SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator /= (
const S& v) {
389 const int sz = this->size();
391 for (
int i=0; i<sz; ++i)
397 KOKKOS_INLINE_FUNCTION
398 GeneralFad& operator += (
const GeneralFad& x) {
399 const int xsz =
x.size(), sz = this->size();
401#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
402 if ((xsz != sz) && (xsz != 0) && (sz != 0))
403 throw "Fad Error: Attempt to assign with incompatible sizes";
408 for (
int i=0; i<sz; ++i)
412 this->resizeAndZero(xsz);
413 for (
int i=0; i<xsz; ++i)
418 this->
val() += x.val();
423 KOKKOS_INLINE_FUNCTION
424 GeneralFad& operator -= (
const GeneralFad& x) {
425 const int xsz =
x.size(), sz = this->size();
427#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
428 if ((xsz != sz) && (xsz != 0) && (sz != 0))
429 throw "Fad Error: Attempt to assign with incompatible sizes";
434 for(
int i=0; i<sz; ++i)
438 this->resizeAndZero(xsz);
439 for(
int i=0; i<xsz; ++i)
444 this->
val() -= x.val();
450 KOKKOS_INLINE_FUNCTION
451 GeneralFad& operator *= (
const GeneralFad& x) {
452 const int xsz =
x.size(), sz = this->size();
456#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
457 if ((xsz != sz) && (xsz != 0) && (sz != 0))
458 throw "Fad Error: Attempt to assign with incompatible sizes";
463 for(
int i=0; i<sz; ++i)
467 this->resizeAndZero(xsz);
468 for(
int i=0; i<xsz; ++i)
474 for (
int i=0; i<sz; ++i)
485 KOKKOS_INLINE_FUNCTION
486 GeneralFad& operator /= (
const GeneralFad& x) {
487 const int xsz =
x.size(), sz = this->size();
491#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
492 if ((xsz != sz) && (xsz != 0) && (sz != 0))
493 throw "Fad Error: Attempt to assign with incompatible sizes";
498 for(
int i=0; i<sz; ++i)
500 ( this->
fastAccessDx(i)*xval - v*
x.fastAccessDx(i) )/ (xval*xval);
503 this->resizeAndZero(xsz);
504 for(
int i=0; i<xsz; ++i)
510 for (
int i=0; i<sz; ++i)
521 template <
typename S>
522 KOKKOS_INLINE_FUNCTION
523 SACADO_ENABLE_EXPR_FUNC(GeneralFad&) operator += (
const Expr<S>& x) {
524 const int xsz =
x.size();
525 int sz = this->size();
527#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
528 if ((xsz != sz) && (xsz != 0) && (sz != 0))
529 throw "Fad Error: Attempt to assign with incompatible sizes";
533 this->resizeAndZero(xsz);
538 if (
x.hasFastAccess())
539 for(
int i=0; i<sz; ++i)
540 for (
int j=0;
j<VecNum; ++
j)
543 for(
int i=0; i<sz; ++i)
544 for (
int j=0;
j<VecNum; ++
j)
548 for (
int j=0;
j<VecNum; ++
j)
555 template <
typename S>
556 KOKKOS_INLINE_FUNCTION
557 SACADO_ENABLE_EXPR_FUNC(GeneralFad&) operator -= (
const Expr<S>& x) {
558 const int xsz =
x.size(), sz = this->size();
560#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
561 if ((xsz != sz) && (xsz != 0) && (sz != 0))
562 throw "Fad Error: Attempt to assign with incompatible sizes";
567 if (
x.hasFastAccess())
568 for(
int i=0; i<sz; ++i)
569 for (
int j=0;
j<VecNum; ++
j)
572 for (
int i=0; i<sz; ++i)
573 for (
int j=0;
j<VecNum; ++
j)
577 this->resizeAndZero(xsz);
578 if (
x.hasFastAccess())
579 for(
int i=0; i<xsz; ++i)
580 for (
int j=0;
j<VecNum; ++
j)
583 for (
int i=0; i<xsz; ++i)
584 for (
int j=0;
j<VecNum; ++
j)
589 for (
int j=0;
j<VecNum; ++
j)
596 template <
typename S>
597 KOKKOS_INLINE_FUNCTION
598 SACADO_ENABLE_EXPR_FUNC(GeneralFad&) operator *= (
const Expr<S>& x) {
599 const int xsz =
x.size(), sz = this->size();
603#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
604 if ((xsz != sz) && (xsz != 0) && (sz != 0))
605 throw "Fad Error: Attempt to assign with incompatible sizes";
610 if (
x.hasFastAccess())
611 for(
int i=0; i<sz; ++i)
612 for (
int j=0;
j<VecNum; ++
j)
615 for (
int i=0; i<sz; ++i)
616 for (
int j=0;
j<VecNum; ++
j)
620 this->resizeAndZero(xsz);
621 if (
x.hasFastAccess())
622 for(
int i=0; i<xsz; ++i)
623 for (
int j=0;
j<VecNum; ++
j)
626 for (
int i=0; i<xsz; ++i)
627 for (
int j=0;
j<VecNum; ++
j)
633 for (
int i=0; i<sz; ++i)
634 for (
int j=0;
j<VecNum; ++
j)
639 for (
int j=0;
j<VecNum; ++
j)
640 val(
j) *= xval.fastAccessCoeff(
j);
646 template <
typename S>
647 KOKKOS_INLINE_FUNCTION
648 SACADO_ENABLE_EXPR_FUNC(GeneralFad&) operator /= (
const Expr<S>& x) {
649 const int xsz =
x.size(), sz = this->size();
653#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
654 if ((xsz != sz) && (xsz != 0) && (sz != 0))
655 throw "Fad Error: Attempt to assign with incompatible sizes";
661 if (
x.hasFastAccess())
662 for(
int i=0; i<sz; ++i)
663 for (
int j=0;
j<VecNum; ++
j)
666 for (
int i=0; i<sz; ++i)
667 for (
int j=0;
j<VecNum; ++
j)
671 this->resizeAndZero(xsz);
672 if (
x.hasFastAccess())
673 for(
int i=0; i<xsz; ++i)
674 for (
int j=0;
j<VecNum; ++
j)
675 fastAccessDx(i,
j) = - v.fastAccessCoeff(
j)*
x.fastAccessDx(i,
j) / (xval2.fastAccessCoeff(
j));
677 for (
int i=0; i<xsz; ++i)
678 for (
int j=0;
j<VecNum; ++
j)
679 fastAccessDx(i,
j) = -v.fastAccessCoeff(
j)*
x.dx(i,
j) / (xval2.fastAccessCoeff(
j));
684 for (
int i=0; i<sz; ++i)
685 for (
int j=0;
j<VecNum; ++
j)
690 for (
int j=0;
j<VecNum; ++
j)
691 val(
j) /= xval.fastAccessCoeff(
j);
700 template <
typename S>
701 KOKKOS_INLINE_FUNCTION
703 fastAssign(
const Expr<S>& x) {
704 const int sz = this->size();
705 for(
int i=0; i<sz; ++i)
706 for (
int j=0;
j<VecNum; ++
j)
709 for (
int j=0;
j<VecNum; ++
j)
713 template <
typename S>
714 KOKKOS_INLINE_FUNCTION
716 slowAssign(
const Expr<S>& x) {
717 const int sz = this->size();
718 for(
int i=0; i<sz; ++i)
719 for (
int j=0;
j<VecNum; ++
j)
722 for (
int j=0;
j<VecNum; ++
j)