52 #ifndef SACADO_FAD_GENERALFAD_HPP
53 #define SACADO_FAD_GENERALFAD_HPP
62 #ifndef SACADO_FAD_DERIV_LOOP
63 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
64 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=threadIdx.x; I<SZ; I+=blockDim.x)
66 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=0; I<SZ; ++I)
70 #ifndef SACADO_FAD_THREAD_SINGLE
71 #if (defined(SACADO_VIEW_CUDA_HIERARCHICAL) || defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
72 #define SACADO_FAD_THREAD_SINGLE if (threadIdx.x == 0)
74 #define SACADO_FAD_THREAD_SINGLE
84 template <
typename T,
typename Storage>
108 template <
typename S>
119 Storage(sz, x, zero_out) {}
143 template <
typename S>
148 const int sz = x.size();
151 if (x.hasFastAccess())
159 this->
val() = x.val();
174 void diff(
const int ith,
const int n) {
175 if (this->size() !=
n)
195 template <
typename S>
199 if (x.size() != this->size())
return false;
200 bool eq = IE::eval(x.val(), this->
val());
201 const int sz = this->size();
203 eq = eq && IE::eval(x.dx(i), this->
dx(i));
232 if (is_const && this->size()!=0)
244 template <
typename S>
248 if (this->size()) this->resize(0);
257 Storage::operator=(x);
262 template <
typename S>
265 const int xsz = x.size();
267 if (xsz != this->size())
268 this->resizeAndZero(xsz);
270 const int sz = this->size();
278 if (x.hasFastAccess()) {
287 this->
val() = x.val();
300 template <
typename S>
308 template <
typename S>
316 template <
typename S>
319 const int sz = this->size();
327 template <
typename S>
330 const int sz = this->size();
340 const int xsz = x.size(), sz = this->size();
342 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
343 if ((xsz != sz) && (xsz != 0) && (sz != 0))
344 throw "Fad Error: Attempt to assign with incompatible sizes";
353 this->resizeAndZero(xsz);
359 this->
val() += x.val();
367 const int xsz = x.size(), sz = this->size();
369 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
370 if ((xsz != sz) && (xsz != 0) && (sz != 0))
371 throw "Fad Error: Attempt to assign with incompatible sizes";
380 this->resizeAndZero(xsz);
386 this->
val() -= x.val();
395 const int xsz = x.size(), sz = this->size();
399 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
400 if ((xsz != sz) && (xsz != 0) && (sz != 0))
401 throw "Fad Error: Attempt to assign with incompatible sizes";
410 this->resizeAndZero(xsz);
430 const int xsz = x.size(), sz = this->size();
434 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
435 if ((xsz != sz) && (xsz != 0) && (sz != 0))
436 throw "Fad Error: Attempt to assign with incompatible sizes";
443 ( this->
fastAccessDx(i)*xval - v*x.fastAccessDx(i) )/ (xval*xval);
446 this->resizeAndZero(xsz);
448 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
464 template <
typename S>
467 const int xsz = x.size(), sz = this->size();
469 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
470 if ((xsz != sz) && (xsz != 0) && (sz != 0))
471 throw "Fad Error: Attempt to assign with incompatible sizes";
476 if (x.hasFastAccess())
480 for (
int i=0; i<sz; ++i)
484 this->resizeAndZero(xsz);
485 if (x.hasFastAccess())
494 this->
val() += x.val();
500 template <
typename S>
503 const int xsz = x.size(), sz = this->size();
505 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
506 if ((xsz != sz) && (xsz != 0) && (sz != 0))
507 throw "Fad Error: Attempt to assign with incompatible sizes";
512 if (x.hasFastAccess())
520 this->resizeAndZero(xsz);
521 if (x.hasFastAccess())
530 this->
val() -= x.val();
537 template <
typename S>
540 const int xsz = x.size(), sz = this->size();
544 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
545 if ((xsz != sz) && (xsz != 0) && (sz != 0))
546 throw "Fad Error: Attempt to assign with incompatible sizes";
551 if (x.hasFastAccess())
559 this->resizeAndZero(xsz);
560 if (x.hasFastAccess())
581 template <
typename S>
584 const int xsz = x.size(), sz = this->size();
588 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
589 if ((xsz != sz) && (xsz != 0) && (sz != 0))
590 throw "Fad Error: Attempt to assign with incompatible sizes";
595 if (x.hasFastAccess())
603 this->resizeAndZero(xsz);
604 if (x.hasFastAccess())
606 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
632 #endif // SACADO_FAD_GENERALFAD_HPP