33 #ifndef SACADO_CACHEFAD_GENERALFAD_HPP
34 #define SACADO_CACHEFAD_GENERALFAD_HPP
55 template <
typename T,
typename Storage>
90 Storage(sz, x, zero_out) {}
114 template <
typename S>
120 const int sz = x.size();
122 this->
val() = x.val();
125 if (x.hasFastAccess())
126 for(
int i=0;
i<sz; ++
i)
129 for(
int i=0;
i<sz; ++
i)
146 void diff(
const int ith,
const int n) {
147 if (this->size() != n)
167 template <
typename S>
171 if (x.size() != this->size())
return false;
172 bool eq = IE::eval(x.val(), this->
val());
173 for (
int i=0;
i<this->size();
i++)
174 eq = eq && IE::eval(x.dx(
i), this->
dx(
i));
203 if (is_const && this->size()!=0)
215 template <
typename S>
219 if (this->size()) this->resize(0);
228 Storage::operator=(x);
233 template <
typename S>
238 const int xsz = x.size();
240 if (xsz != this->size())
241 this->resizeAndZero(xsz);
243 const int sz = this->size();
251 if (x.hasFastAccess())
252 for(
int i=0;
i<sz; ++
i)
255 for(
int i=0;
i<sz; ++
i)
259 this->
val() = x.val();
272 template <
typename S>
280 template <
typename S>
288 template <
typename S>
291 const int sz = this->size();
293 for (
int i=0;
i<sz; ++
i)
299 template <
typename S>
302 const int sz = this->size();
304 for (
int i=0;
i<sz; ++
i)
312 const int xsz = x.size(), sz = this->size();
314 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
315 if ((xsz != sz) && (xsz != 0) && (sz != 0))
316 throw "Fad Error: Attempt to assign with incompatible sizes";
321 for (
int i=0;
i<sz; ++
i)
325 this->resizeAndZero(xsz);
326 for (
int i=0;
i<xsz; ++
i)
331 this->
val() += x.val();
339 const int xsz = x.size(), sz = this->size();
341 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
342 if ((xsz != sz) && (xsz != 0) && (sz != 0))
343 throw "Fad Error: Attempt to assign with incompatible sizes";
348 for(
int i=0;
i<sz; ++
i)
352 this->resizeAndZero(xsz);
353 for(
int i=0;
i<xsz; ++
i)
358 this->
val() -= x.val();
367 const int xsz = x.size(), sz = this->size();
371 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
372 if ((xsz != sz) && (xsz != 0) && (sz != 0))
373 throw "Fad Error: Attempt to assign with incompatible sizes";
378 for(
int i=0;
i<sz; ++
i)
382 this->resizeAndZero(xsz);
383 for(
int i=0;
i<xsz; ++
i)
389 for (
int i=0;
i<sz; ++
i)
402 const int xsz = x.size(), sz = this->size();
406 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
407 if ((xsz != sz) && (xsz != 0) && (sz != 0))
408 throw "Fad Error: Attempt to assign with incompatible sizes";
413 for(
int i=0;
i<sz; ++
i)
415 ( this->
fastAccessDx(
i)*xval - v*x.fastAccessDx(
i) )/ (xval*xval);
418 this->resizeAndZero(xsz);
419 for(
int i=0;
i<xsz; ++
i)
425 for (
int i=0;
i<sz; ++
i)
436 template <
typename S>
441 const int xsz = x.size(), sz = this->size();
443 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
444 if ((xsz != sz) && (xsz != 0) && (sz != 0))
445 throw "Fad Error: Attempt to assign with incompatible sizes";
450 if (x.hasFastAccess())
451 for (
int i=0;
i<sz; ++
i)
454 for (
int i=0;
i<sz; ++
i)
458 this->resizeAndZero(xsz);
459 if (x.hasFastAccess())
460 for (
int i=0;
i<xsz; ++
i)
463 for (
int i=0;
i<xsz; ++
i)
468 this->
val() += x.val();
474 template <
typename S>
479 const int xsz = x.size(), sz = this->size();
481 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
482 if ((xsz != sz) && (xsz != 0) && (sz != 0))
483 throw "Fad Error: Attempt to assign with incompatible sizes";
488 if (x.hasFastAccess())
489 for(
int i=0;
i<sz; ++
i)
492 for (
int i=0;
i<sz; ++
i)
496 this->resizeAndZero(xsz);
497 if (x.hasFastAccess())
498 for(
int i=0;
i<xsz; ++
i)
501 for (
int i=0;
i<xsz; ++
i)
506 this->
val() -= x.val();
513 template <
typename S>
518 const int xsz = x.size(), sz = this->size();
521 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
522 if ((xsz != sz) && (xsz != 0) && (sz != 0))
523 throw "Fad Error: Attempt to assign with incompatible sizes";
528 if (x.hasFastAccess())
529 for(
int i=0;
i<sz; ++
i)
532 for (
int i=0;
i<sz; ++
i)
536 this->resizeAndZero(xsz);
537 if (x.hasFastAccess())
538 for(
int i=0;
i<xsz; ++
i)
541 for (
int i=0;
i<xsz; ++
i)
547 for (
int i=0;
i<sz; ++
i)
558 template <
typename S>
563 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)
586 for (
int i=0;
i<xsz; ++
i)
592 for (
int i=0;
i<sz; ++
i)
610 #endif // SACADO_CACHEFAD_GENERALFAD_HPP
SACADO_INLINE_FUNCTION void cache() const
Cache values.
Forward-mode AD class templated on the storage for the derivative array.
SACADO_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
#define SACADO_ENABLE_VALUE_CTOR_DECL
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
RemoveConst< T >::type value_type
Typename of values.
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
SACADO_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
SACADO_INLINE_FUNCTION GeneralFad()
Default constructor.
#define SACADO_ENABLE_EXPR_CTOR_DECL
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
Base template specification for testing equivalence.
SACADO_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
SACADO_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
Do not initialize the derivative array.
SACADO_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
SACADO_INLINE_FUNCTION ~GeneralFad()
Destructor.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
SACADO_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
SACADO_INLINE_FUNCTION GeneralFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
SACADO_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
Initialize the derivative array.
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
#define SACADO_INLINE_FUNCTION
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 void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
Wrapper for a generic expression template.