52 #ifndef SACADO_FAD_GENERALFAD_HPP 53 #define SACADO_FAD_GENERALFAD_HPP 68 template <
typename T,
typename Storage>
103 Storage(sz, x, zero_out) {}
127 template <
typename S>
130 Storage(x.size(),
T(0.))
132 const int sz = x.size();
135 if (x.hasFastAccess())
136 for(
int i=0; i<sz; ++i)
139 for(
int i=0; i<sz; ++i)
143 this->
val() = x.val();
158 void diff(
const int ith,
const int n) {
159 if (this->size() != n)
175 template <
typename S>
179 if (x.size() != this->size())
return false;
180 bool eq = IE::eval(x.val(), this->
val());
181 for (
int i=0; i<this->size(); i++)
182 eq = eq && IE::eval(x.dx(i), this->
dx(i));
211 if (is_const && this->size()!=0)
223 template <
typename S>
227 if (this->size()) this->resize(0);
236 Storage::operator=(x);
241 template <
typename S>
244 const int xsz = x.size();
246 if (xsz != this->size())
247 this->resizeAndZero(xsz);
249 const int sz = this->size();
257 if (x.hasFastAccess())
258 for(
int i=0; i<sz; ++i)
261 for(
int i=0; i<sz; ++i)
265 this->
val() = x.val();
278 template <
typename S>
286 template <
typename S>
294 template <
typename S>
297 const int sz = this->size();
299 for (
int i=0; i<sz; ++i)
305 template <
typename S>
308 const int sz = this->size();
310 for (
int i=0; i<sz; ++i)
318 const int xsz = x.size(), sz = this->size();
320 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 321 if ((xsz != sz) && (xsz != 0) && (sz != 0))
322 throw "Fad Error: Attempt to assign with incompatible sizes";
327 for (
int i=0; i<sz; ++i)
331 this->resizeAndZero(xsz);
332 for (
int i=0; i<xsz; ++i)
337 this->
val() += x.val();
345 const int xsz = x.size(), sz = this->size();
347 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 348 if ((xsz != sz) && (xsz != 0) && (sz != 0))
349 throw "Fad Error: Attempt to assign with incompatible sizes";
354 for(
int i=0; i<sz; ++i)
358 this->resizeAndZero(xsz);
359 for(
int i=0; i<xsz; ++i)
364 this->
val() -= x.val();
373 const int xsz = x.size(), sz = this->size();
377 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 378 if ((xsz != sz) && (xsz != 0) && (sz != 0))
379 throw "Fad Error: Attempt to assign with incompatible sizes";
384 for(
int i=0; i<sz; ++i)
388 this->resizeAndZero(xsz);
389 for(
int i=0; i<xsz; ++i)
395 for (
int i=0; i<sz; ++i)
408 const int xsz = x.size(), sz = this->size();
412 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 413 if ((xsz != sz) && (xsz != 0) && (sz != 0))
414 throw "Fad Error: Attempt to assign with incompatible sizes";
419 for(
int i=0; i<sz; ++i)
421 ( this->
fastAccessDx(i)*xval - v*x.fastAccessDx(i) )/ (xval*xval);
424 this->resizeAndZero(xsz);
425 for(
int i=0; i<xsz; ++i)
426 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
431 for (
int i=0; i<sz; ++i)
442 template <
typename S>
445 const int xsz = x.size(), sz = this->size();
447 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 448 if ((xsz != sz) && (xsz != 0) && (sz != 0))
449 throw "Fad Error: Attempt to assign with incompatible sizes";
454 if (x.hasFastAccess())
455 for (
int i=0; i<sz; ++i)
458 for (
int i=0; i<sz; ++i)
462 this->resizeAndZero(xsz);
463 if (x.hasFastAccess())
464 for (
int i=0; i<xsz; ++i)
467 for (
int i=0; i<xsz; ++i)
472 this->
val() += x.val();
478 template <
typename S>
481 const int xsz = x.size(), sz = this->size();
483 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 484 if ((xsz != sz) && (xsz != 0) && (sz != 0))
485 throw "Fad Error: Attempt to assign with incompatible sizes";
490 if (x.hasFastAccess())
491 for(
int i=0; i<sz; ++i)
494 for (
int i=0; i<sz; ++i)
498 this->resizeAndZero(xsz);
499 if (x.hasFastAccess())
500 for(
int i=0; i<xsz; ++i)
503 for (
int i=0; i<xsz; ++i)
508 this->
val() -= x.val();
515 template <
typename S>
518 const int xsz = x.size(), sz = this->size();
522 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 523 if ((xsz != sz) && (xsz != 0) && (sz != 0))
524 throw "Fad Error: Attempt to assign with incompatible sizes";
529 if (x.hasFastAccess())
530 for(
int i=0; i<sz; ++i)
533 for (
int i=0; i<sz; ++i)
537 this->resizeAndZero(xsz);
538 if (x.hasFastAccess())
539 for(
int i=0; i<xsz; ++i)
542 for (
int i=0; i<xsz; ++i)
548 for (
int i=0; i<sz; ++i)
559 template <
typename S>
562 const int xsz = x.size(), sz = this->size();
566 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 567 if ((xsz != sz) && (xsz != 0) && (sz != 0))
568 throw "Fad Error: Attempt to assign with incompatible sizes";
573 if (x.hasFastAccess())
574 for(
int i=0; i<sz; ++i)
577 for (
int i=0; i<sz; ++i)
581 this->resizeAndZero(xsz);
582 if (x.hasFastAccess())
583 for(
int i=0; i<xsz; ++i)
584 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
586 for (
int i=0; i<xsz; ++i)
592 for (
int i=0; i<sz; ++i)
610 #endif // SACADO_FAD_GENERALFAD_HPP Wrapper for a generic expression template.
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()
Destructor.
KOKKOS_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
#define SACADO_ENABLE_VALUE_CTOR_DECL
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
RemoveConst< T >::type value_type
Typename of values.
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION GeneralFad()
Default constructor.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION GeneralFad(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
Base template specification for testing equivalence.
KOKKOS_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...
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
KOKKOS_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
Forward-mode AD class templated on the storage for the derivative array.
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.