52 #ifndef SACADO_ELRFAD_SFAD_HPP
53 #define SACADO_ELRFAD_SFAD_HPP
66 template <
typename T,
int Num>
70 template <
typename T,
int Num>
class SFad;
79 template <
typename T,
int Num>
94 static const int num_args = 1;
97 static const bool is_linear =
true;
112 template <
typename S>
125 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
127 throw "SELRFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
141 Expr(
const int sz,
const int i,
const T & x) :
143 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
145 throw "SELRFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
147 throw "SELRFad::SFad() Error: Invalid derivative index.";
158 for (
int i=0; i<Num; i++)
163 template <
typename S>
166 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
168 throw "SELRFad::SFad() Error: Attempt to assign with incompatible sizes";
172 LocalAccumOp< Expr<S> > op(x);
175 for(
int i=0; i<Num; ++i) {
188 this->
val() = x.val();
203 void diff(
const int ith,
const int n) {
204 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
206 throw "SELRFad::diff() Error: Supplied derivative dimension does not match compile time length.";
220 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
222 throw "SELRFad::resize() Error: Cannot resize fixed derivative array dimension";
251 template <
typename S>
255 if (x.size() != this->size())
return false;
256 bool eq = IE::eval(x.val(), this->
val());
257 for (
int i=0; i<this->size(); i++)
258 eq = eq && IE::eval(x.dx(i), this->
dx(i));
271 const T&
val()
const {
return val_;}
286 int size()
const {
return Num;}
309 const T*
dx()
const {
return &(dx_[0]);}
313 const T&
dx(
int i)
const {
return dx_[i]; }
332 dots[0] = this->dx_[i];
357 template <
typename S>
367 Expr& operator=(
const Expr& x) {
374 for (
int i=0; i<Num; i++)
381 template <
typename S>
384 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
386 throw "SELRFad::operator=() Error: Attempt to assign with incompatible sizes";
390 LocalAccumOp< Expr<S> > op(x);
393 for(
int i=0; i<Num; ++i) {
419 template <
typename S>
427 template <
typename S>
435 template <
typename S>
439 for (
int i=0; i<Num; ++i)
445 template <
typename S>
449 for (
int i=0; i<Num; ++i)
455 template <
typename S>
458 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
460 throw "SELRFad::operator+=() Error: Attempt to assign with incompatible sizes";
464 LocalAccumOp< Expr<S> > op(x);
467 for(
int i=0; i<Num; ++i) {
486 template <
typename S>
489 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
491 throw "SELRFad::operator-=() Error: Attempt to assign with incompatible sizes";
495 LocalAccumOp< Expr<S> > op(x);
498 for(
int i=0; i<Num; ++i) {
517 template <
typename S>
522 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
524 throw "SELRFad::operator*=() Error: Attempt to assign with incompatible sizes";
528 LocalAccumOp< Expr<S> > op(x);
531 for(
int i=0; i<Num; ++i) {
540 dx_[i] = val_ * op.t + dx_[i] * xval;
550 template <
typename S>
555 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
557 throw "SELRFad::operator/=() Error: Attempt to assign with incompatible sizes";
561 LocalAccumOp< Expr<S> > op(x);
566 for(
int i=0; i<Num; ++i) {
575 dx_[i] = (dx_[i] * xval - val_ * op.t) / xval2;
601 template <
typename ExprT>
602 struct LocalAccumOp {
604 static const int N = ExprT::num_args;
615 template <
typename ArgT>
617 void operator () (ArgT arg)
const {
618 const int Arg = ArgT::value;
619 if (x.template isActive<Arg>())
620 t += partials[Arg] * x.template getTangent<Arg>(i);
630 #define FAD_NS ELRFad
637 #endif // SACADO_ELRFAD_SFAD_HPP
KOKKOS_INLINE_FUNCTION Expr(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
#define SACADO_ENABLE_VALUE_CTOR_DECL
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION LocalAccumOp(const ExprT &x_)
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
#define SACADO_ENABLE_EXPR_CTOR_DECL
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
KOKKOS_INLINE_FUNCTION Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION bool isActive() const
Return whether argument is active.
KOKKOS_INLINE_FUNCTION Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
Base template specification for testing equivalence.
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION ~Expr()
Destructor.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION Expr(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
Wrapper for a generic expression template.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
KOKKOS_INLINE_FUNCTION Expr()
Default constructor.
KOKKOS_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
KOKKOS_INLINE_FUNCTION void cache() const
Cache values.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION void zero()
Zero out the derivative array.
KOKKOS_INLINE_FUNCTION void getTangents(int i_)
ExprT::value_type value_type
KOKKOS_INLINE_FUNCTION const value_type * getDx(int j) const
Get dx array.
KOKKOS_INLINE_FUNCTION const T & getTangent(int i) const
Return tangent component i of argument Arg.
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 void computePartials(const T &bar, value_type partials[]) const
Return partials w.r.t. arguments.
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
KOKKOS_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
A tag for specializing Expr for SFad expressions.
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION void getTangents(int i, value_type dots[]) const
Return tangent component i of arguments.