30 #ifndef SACADO_LFAD_LOGICALSPARSE_HPP
31 #define SACADO_LFAD_LOGICALSPARSE_HPP
47 template <
typename ExprT>
class Expr {};
57 static const unsigned value = 0;
69 static const bool value =
false;
84 template <
typename ValT,
typename LogT>
113 template <
typename S>
140 template <
typename S>
145 if (sz != this->
size())
149 if (x.hasFastAccess())
150 for(
int i=0; i<sz; ++i)
153 for(
int i=0; i<sz; ++i)
157 this->
val() = x.val();
170 void diff(
const int ith,
const int n) {
171 if (this->
size() != n)
179 template <
typename S>
182 if (x.size() != this->
size())
return false;
183 bool eq = IE::eval(x.val(), this->
val());
184 for (
int i=0; i<this->
size(); i++)
185 eq = eq && IE::eval(x.dx(i), this->
dx(i));
204 if (is_const && this->
size()!=0)
216 template <
typename S>
235 template <
typename S>
239 if (sz != this->
size())
243 if (x.hasFastAccess())
244 for(
int i=0; i<sz; ++i)
247 for(
int i=0; i<sz; ++i)
251 this->
val() = x.val();
264 template <
typename S>
271 template <
typename S>
278 template <
typename S>
285 template <
typename S>
293 int xsz = x.size(), sz = this->
size();
296 if ((xsz != sz) && (xsz != 0) && (sz != 0))
297 throw "LFad Error: Attempt to assign with incompatible sizes";
302 for (
int i=0; i<xsz; ++i)
307 for (
int i=0; i<xsz; ++i)
312 this->
val() += x.val();
319 int xsz = x.size(), sz = this->
size();
322 if ((xsz != sz) && (xsz != 0) && (sz != 0))
323 throw "LFad Error: Attempt to assign with incompatible sizes";
328 for (
int i=0; i<xsz; ++i)
333 for (
int i=0; i<xsz; ++i)
338 this->
val() -= x.val();
346 int xsz = x.size(), sz = this->
size();
349 if ((xsz != sz) && (xsz != 0) && (sz != 0))
350 throw "LFad Error: Attempt to assign with incompatible sizes";
355 for (
int i=0; i<xsz; ++i)
360 for (
int i=0; i<xsz; ++i)
365 this->
val() *= x.val();
372 int xsz = x.size(), sz = this->
size();
375 if ((xsz != sz) && (xsz != 0) && (sz != 0))
376 throw "LFad Error: Attempt to assign with incompatible sizes";
381 for (
int i=0; i<xsz; ++i)
386 for (
int i=0; i<xsz; ++i)
391 this->
val() /= x.val();
397 template <
typename S>
399 int xsz = x.size(), sz = this->
size();
402 if ((xsz != sz) && (xsz != 0) && (sz != 0))
403 throw "LFad Error: Attempt to assign with incompatible sizes";
408 if (x.hasFastAccess())
409 for (
int i=0; i<xsz; ++i)
412 for (
int i=0; i<xsz; ++i)
417 if (x.hasFastAccess())
418 for (
int i=0; i<xsz; ++i)
421 for (
int i=0; i<xsz; ++i)
426 this->
val() += x.val();
432 template <
typename S>
434 int xsz = x.size(), sz = this->
size();
437 if ((xsz != sz) && (xsz != 0) && (sz != 0))
438 throw "LFad Error: Attempt to assign with incompatible sizes";
443 if (x.hasFastAccess())
444 for (
int i=0; i<xsz; ++i)
447 for (
int i=0; i<xsz; ++i)
452 if (x.hasFastAccess())
453 for (
int i=0; i<xsz; ++i)
456 for (
int i=0; i<xsz; ++i)
461 this->
val() -= x.val();
468 template <
typename S>
470 int xsz = x.size(), sz = this->
size();
473 if ((xsz != sz) && (xsz != 0) && (sz != 0))
474 throw "LFad Error: Attempt to assign with incompatible sizes";
479 if (x.hasFastAccess())
480 for (
int i=0; i<xsz; ++i)
483 for (
int i=0; i<xsz; ++i)
488 if (x.hasFastAccess())
489 for (
int i=0; i<xsz; ++i)
492 for (
int i=0; i<xsz; ++i)
497 this->
val() *= x.val();
503 template <
typename S>
505 int xsz = x.size(), sz = this->
size();
508 if ((xsz != sz) && (xsz != 0) && (sz != 0))
509 throw "LFad Error: Attempt to assign with incompatible sizes";
514 if (x.hasFastAccess())
515 for (
int i=0; i<xsz; ++i)
518 for (
int i=0; i<xsz; ++i)
523 if (x.hasFastAccess())
524 for (
int i=0; i<xsz; ++i)
527 for (
int i=0; i<xsz; ++i)
532 this->
val() /= x.val();
542 template <
typename ValT,
typename LogT>
565 template <
typename S>
573 Expr(
const int sz,
const ValT & x) :
582 Expr(
const int sz,
const int i,
const ValT & x) :
590 template <
typename S>
603 template <
typename ValT,
typename LogT >
604 class LogicalSparse :
public Expr< LogicalSparseImp<ValT,LogT > > {
619 template <
typename T,
typename U = LogT>
640 template <
typename S>
665 template <
typename S>
675 template <
typename S>
688 template <
typename S>
696 template <
typename S>
698 ImplType::operator+=(x);
703 template <
typename S>
705 ImplType::operator-=(x);
710 template <
typename S>
712 ImplType::operator*=(x);
717 template <
typename S>
719 ImplType::operator/=(x);
725 ImplType::operator+=(static_cast<const ImplType&>(x));
731 ImplType::operator-=(static_cast<const ImplType&>(x));
737 ImplType::operator*=(static_cast<const ImplType&>(x));
743 ImplType::operator/=(static_cast<const ImplType&>(x));
748 template <
typename S>
750 ImplType::operator+=(x);
755 template <
typename S>
757 ImplType::operator-=(x);
762 template <
typename S>
764 ImplType::operator*=(x);
769 template <
typename S>
771 ImplType::operator/=(x);
777 template <
typename T,
typename L>
785 template <
typename T>
790 template <
typename T>
795 template <
typename T,
typename L>
796 struct IsExpr< LFad::LogicalSparse<T,L> > {
800 template <
typename T,
typename L>
809 #endif // SACADO_LFAD_LOGICALSPARSE_HPP
LogicalSparseImp()
Default constructor.
LogicalSparseImp< ValT, LogT > ImplType
Base classes.
Implementation class for computing the logical sparsity of a derivative using forward-mode AD...
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
LogicalSparse(const int sz, const int i, const ValT &x)
Constructor with size sz, index i, and value x.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
Determine whether a given type is an expression.
Derivative array storage class using dynamic memory allocation.
#define SACADO_ENABLE_VALUE_CTOR_DECL
LogicalSparseImp(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
KOKKOS_INLINE_FUNCTION const ValT & val() const
Returns value.
~LogicalSparseImp()
Destructor.
LogicalSparse(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x of type ValueT.
ValT value_type
Typename of values (e.g., double)
LogicalSparse(const int sz, const ValT &x)
Constructor with size sz and value x.
#define SACADO_ENABLE_EXPR_CTOR_DECL
Fad::DynamicStorage< ValT, LogT > Storage
LogicalSparse< T, U > type
LogicalSparse(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
void diff(const int ith, const int n)
Set LogicalSparseImp object as the ith independent variable.
LogicalSparse< ValT, LogT > base_expr_type
Typename of base-expressions.
LogicalSparseImp(const int sz, const value_type &x)
Constructor with size sz and value x.
SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
Expr(const int sz, const ValT &x)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION const LogT * dx() const
Returns derivative array.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Base template specification for testing equivalence.
LFad::LogicalSparse< T, L >::base_expr_type type
Get the base Fad type from a view/expression.
LogicalSparseImp(const LogicalSparseImp &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
LogT logical_type
Logical type (i.e., type for derivative array components (e.g., bool)
static const unsigned value
Wrapper for a generic expression template.
LogicalSparseImp< ValT, LogT >::value_type value_type
Typename of values.
~LogicalSparse()
Destructor.
bool isPassive() const
Returns true if derivative array is empty.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from ValT)
User inteface class for computing the logical sparsity pattern of a derivative via forward-mode AD...
Meta-function for determining nesting with an expression.
LogicalSparse()
Default constructor.
Expr(const int sz, const int i, const ValT &x)
Constructor with size sz, index i, and value x.
Turn LogicalSparse into a meta-function class usable with mpl::apply.
KOKKOS_INLINE_FUNCTION DynamicStorage & operator=(const DynamicStorage &x)
Assignment.
ExprType::value_type value_type
Typename of values.
Initialize the derivative array.
LogicalSparseImp< ValT, LogT >::scalar_type scalar_type
Typename of scalar's (which may be different from value_type)
LogicalSparse(const LogicalSparse &x)
Copy constructor.
ExprType::scalar_type scalar_type
Typename of scalar's (which may be different from value_type)
Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
Expr< ImplType > ExprType
KOKKOS_INLINE_FUNCTION LogT & fastAccessDx(int i)
Returns derivative component i without bounds checking.
LFad::Expr< T >::base_expr_type type
LogicalSparseImp(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
Expr(const Expr &x)
Copy constructor.
LogicalSparseImp(const int sz, const int i, const value_type &x)
Constructor with size sz, index i, and value x.
bool hasFastAccess() const
Returns true if derivative array is not empty.
Expr()
Default constructor.
void setIsConstant(bool is_const)
Set whether variable is constant.