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();
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();
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";
446 this->resizeAndZero(xsz);
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())
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())
#define SACADO_INLINE_FUNCTION
#define SACADO_FAD_DERIV_LOOP(I, SZ)
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
#define SACADO_ENABLE_VALUE_CTOR_DECL
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
#define SACADO_ENABLE_EXPR_CTOR_DECL
Fad specializations for Teuchos::BLAS wrappers.
Forward-mode AD class templated on the storage for the derivative array.
RemoveConst< T >::type value_type
Typename of values.
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
SACADO_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
SACADO_INLINE_FUNCTION ~GeneralFad()
Destructor.
SACADO_INLINE_FUNCTION SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
SACADO_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
SACADO_INLINE_FUNCTION GeneralFad()
Default constructor.
SACADO_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
SACADO_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
SACADO_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
SACADO_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
SACADO_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
SACADO_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
SACADO_INLINE_FUNCTION GeneralFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors.
@ InitDerivArray
Initialize the derivative array.
@ NoInitDerivArray
Do not initialize the derivative array.