52 #ifndef SACADO_CACHEFAD_GENERALFAD_HPP
53 #define SACADO_CACHEFAD_GENERALFAD_HPP
74 template <
typename T,
typename Storage>
109 Storage(sz, x, zero_out) {}
133 template <
typename S>
139 const int sz = x.size();
141 this->
val() = x.val();
144 if (x.hasFastAccess())
145 for(
int i=0; i<sz; ++i)
148 for(
int i=0; i<sz; ++i)
165 void diff(
const int ith,
const int n) {
166 if (this->size() != n)
186 template <
typename S>
190 if (x.size() != this->size())
return false;
191 bool eq = IE::eval(x.val(), this->
val());
192 for (
int i=0; i<this->size(); i++)
193 eq = eq && IE::eval(x.dx(i), this->
dx(i));
222 if (is_const && this->size()!=0)
234 template <
typename S>
238 if (this->size()) this->resize(0);
247 Storage::operator=(x);
252 template <
typename S>
257 const int xsz = x.size();
259 if (xsz != this->size())
260 this->resizeAndZero(xsz);
262 const int sz = this->size();
270 if (x.hasFastAccess())
271 for(
int i=0; i<sz; ++i)
274 for(
int i=0; i<sz; ++i)
278 this->
val() = x.val();
291 template <
typename S>
299 template <
typename S>
307 template <
typename S>
310 const int sz = this->size();
312 for (
int i=0; i<sz; ++i)
318 template <
typename S>
321 const int sz = this->size();
323 for (
int i=0; i<sz; ++i)
331 const int xsz = x.size(), sz = this->size();
333 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
334 if ((xsz != sz) && (xsz != 0) && (sz != 0))
335 throw "Fad Error: Attempt to assign with incompatible sizes";
340 for (
int i=0; i<sz; ++i)
344 this->resizeAndZero(xsz);
345 for (
int i=0; i<xsz; ++i)
350 this->
val() += x.val();
358 const int xsz = x.size(), sz = this->size();
360 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
361 if ((xsz != sz) && (xsz != 0) && (sz != 0))
362 throw "Fad Error: Attempt to assign with incompatible sizes";
367 for(
int i=0; i<sz; ++i)
371 this->resizeAndZero(xsz);
372 for(
int i=0; i<xsz; ++i)
377 this->
val() -= x.val();
386 const int xsz = x.size(), sz = this->size();
390 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
391 if ((xsz != sz) && (xsz != 0) && (sz != 0))
392 throw "Fad Error: Attempt to assign with incompatible sizes";
397 for(
int i=0; i<sz; ++i)
401 this->resizeAndZero(xsz);
402 for(
int i=0; i<xsz; ++i)
408 for (
int i=0; i<sz; ++i)
421 const int xsz = x.size(), sz = this->size();
425 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
426 if ((xsz != sz) && (xsz != 0) && (sz != 0))
427 throw "Fad Error: Attempt to assign with incompatible sizes";
432 for(
int i=0; i<sz; ++i)
434 ( this->
fastAccessDx(i)*xval - v*x.fastAccessDx(i) )/ (xval*xval);
437 this->resizeAndZero(xsz);
438 for(
int i=0; i<xsz; ++i)
439 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
444 for (
int i=0; i<sz; ++i)
455 template <
typename S>
460 const int xsz = x.size(), sz = this->size();
462 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
463 if ((xsz != sz) && (xsz != 0) && (sz != 0))
464 throw "Fad Error: Attempt to assign with incompatible sizes";
469 if (x.hasFastAccess())
470 for (
int i=0; i<sz; ++i)
473 for (
int i=0; i<sz; ++i)
477 this->resizeAndZero(xsz);
478 if (x.hasFastAccess())
479 for (
int i=0; i<xsz; ++i)
482 for (
int i=0; i<xsz; ++i)
487 this->
val() += x.val();
493 template <
typename S>
498 const int xsz = x.size(), sz = this->size();
500 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
501 if ((xsz != sz) && (xsz != 0) && (sz != 0))
502 throw "Fad Error: Attempt to assign with incompatible sizes";
507 if (x.hasFastAccess())
508 for(
int i=0; i<sz; ++i)
511 for (
int i=0; i<sz; ++i)
515 this->resizeAndZero(xsz);
516 if (x.hasFastAccess())
517 for(
int i=0; i<xsz; ++i)
520 for (
int i=0; i<xsz; ++i)
525 this->
val() -= x.val();
532 template <
typename S>
537 const int xsz = x.size(), sz = this->size();
540 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
541 if ((xsz != sz) && (xsz != 0) && (sz != 0))
542 throw "Fad Error: Attempt to assign with incompatible sizes";
547 if (x.hasFastAccess())
548 for(
int i=0; i<sz; ++i)
551 for (
int i=0; i<sz; ++i)
555 this->resizeAndZero(xsz);
556 if (x.hasFastAccess())
557 for(
int i=0; i<xsz; ++i)
560 for (
int i=0; i<xsz; ++i)
566 for (
int i=0; i<sz; ++i)
577 template <
typename S>
582 const int xsz = x.size(), sz = this->size();
585 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
586 if ((xsz != sz) && (xsz != 0) && (sz != 0))
587 throw "Fad Error: Attempt to assign with incompatible sizes";
592 if (x.hasFastAccess())
593 for(
int i=0; i<sz; ++i)
596 for (
int i=0; i<sz; ++i)
600 this->resizeAndZero(xsz);
601 if (x.hasFastAccess())
602 for(
int i=0; i<xsz; ++i)
605 for (
int i=0; i<xsz; ++i)
611 for (
int i=0; i<sz; ++i)
629 #endif // SACADO_CACHEFAD_GENERALFAD_HPP
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
KOKKOS_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
Forward-mode AD class templated on the storage for the derivative array.
#define SACADO_ENABLE_VALUE_CTOR_DECL
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
KOKKOS_INLINE_FUNCTION SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
KOKKOS_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION GeneralFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
KOKKOS_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
Base template specification for testing equivalence.
KOKKOS_INLINE_FUNCTION ~GeneralFad()
Destructor.
Do not initialize the derivative array.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION void cache() const
Cache values.
KOKKOS_INLINE_FUNCTION GeneralFad(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION GeneralFad()
Default constructor.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
Wrapper for a generic expression template.