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>
139 template <
typename S>
144 if (sz != this->
size())
148 if (x.hasFastAccess())
149 for(
int i=0; i<sz; ++i)
152 for(
int i=0; i<sz; ++i)
156 this->
val() = x.val();
169 void diff(
const int ith,
const int n) {
170 if (this->
size() != n)
178 template <
typename S>
181 if (x.size() != this->
size())
return false;
182 bool eq = IE::eval(x.val(), this->
val());
183 for (
int i=0; i<this->
size(); i++)
184 eq = eq && IE::eval(x.dx(i), this->
dx(i));
203 if (is_const && this->
size()!=0)
215 template <
typename S>
234 template <
typename S>
238 if (sz != this->
size())
242 if (x.hasFastAccess())
243 for(
int i=0; i<sz; ++i)
246 for(
int i=0; i<sz; ++i)
250 this->
val() = x.val();
263 template <
typename S>
270 template <
typename S>
277 template <
typename S>
284 template <
typename S>
292 int xsz = x.size(), sz = this->
size();
295 if ((xsz != sz) && (xsz != 0) && (sz != 0))
296 throw "LFad Error: Attempt to assign with incompatible sizes";
301 for (
int i=0; i<xsz; ++i)
306 for (
int i=0; i<xsz; ++i)
311 this->
val() += x.val();
318 int xsz = x.size(), sz = this->
size();
321 if ((xsz != sz) && (xsz != 0) && (sz != 0))
322 throw "LFad Error: Attempt to assign with incompatible sizes";
327 for (
int i=0; i<xsz; ++i)
332 for (
int i=0; i<xsz; ++i)
337 this->
val() -= x.val();
345 int xsz = x.size(), sz = this->
size();
348 if ((xsz != sz) && (xsz != 0) && (sz != 0))
349 throw "LFad Error: Attempt to assign with incompatible sizes";
354 for (
int i=0; i<xsz; ++i)
359 for (
int i=0; i<xsz; ++i)
364 this->
val() *= x.val();
371 int xsz = x.size(), sz = this->
size();
374 if ((xsz != sz) && (xsz != 0) && (sz != 0))
375 throw "LFad Error: Attempt to assign with incompatible sizes";
380 for (
int i=0; i<xsz; ++i)
385 for (
int i=0; i<xsz; ++i)
390 this->
val() /= x.val();
396 template <
typename S>
398 int xsz = x.size(), sz = this->
size();
401 if ((xsz != sz) && (xsz != 0) && (sz != 0))
402 throw "LFad Error: Attempt to assign with incompatible sizes";
407 if (x.hasFastAccess())
408 for (
int i=0; i<xsz; ++i)
411 for (
int i=0; i<xsz; ++i)
416 if (x.hasFastAccess())
417 for (
int i=0; i<xsz; ++i)
420 for (
int i=0; i<xsz; ++i)
425 this->
val() += x.val();
431 template <
typename S>
433 int xsz = x.size(), sz = this->
size();
436 if ((xsz != sz) && (xsz != 0) && (sz != 0))
437 throw "LFad Error: Attempt to assign with incompatible sizes";
442 if (x.hasFastAccess())
443 for (
int i=0; i<xsz; ++i)
446 for (
int i=0; i<xsz; ++i)
451 if (x.hasFastAccess())
452 for (
int i=0; i<xsz; ++i)
455 for (
int i=0; i<xsz; ++i)
460 this->
val() -= x.val();
467 template <
typename S>
469 int xsz = x.size(), sz = this->
size();
472 if ((xsz != sz) && (xsz != 0) && (sz != 0))
473 throw "LFad Error: Attempt to assign with incompatible sizes";
478 if (x.hasFastAccess())
479 for (
int i=0; i<xsz; ++i)
482 for (
int i=0; i<xsz; ++i)
487 if (x.hasFastAccess())
488 for (
int i=0; i<xsz; ++i)
491 for (
int i=0; i<xsz; ++i)
496 this->
val() *= x.val();
502 template <
typename S>
504 int xsz = x.size(), sz = this->
size();
507 if ((xsz != sz) && (xsz != 0) && (sz != 0))
508 throw "LFad Error: Attempt to assign with incompatible sizes";
513 if (x.hasFastAccess())
514 for (
int i=0; i<xsz; ++i)
517 for (
int i=0; i<xsz; ++i)
522 if (x.hasFastAccess())
523 for (
int i=0; i<xsz; ++i)
526 for (
int i=0; i<xsz; ++i)
531 this->
val() /= x.val();
541 template <
typename ValT,
typename LogT>
564 template <
typename S>
572 Expr(
const int sz,
const ValT & x) :
581 Expr(
const int sz,
const int i,
const ValT & x) :
589 template <
typename S>
602 template <
typename ValT,
typename LogT >
603 class LogicalSparse :
public Expr< LogicalSparseImp<ValT,LogT > > {
618 template <
typename T,
typename U = LogT>
639 template <
typename S>
664 template <
typename S>
674 template <
typename S>
687 template <
typename S>
695 template <
typename S>
697 ImplType::operator+=(x);
702 template <
typename S>
704 ImplType::operator-=(x);
709 template <
typename S>
711 ImplType::operator*=(x);
716 template <
typename S>
718 ImplType::operator/=(x);
724 ImplType::operator+=(static_cast<const ImplType&>(x));
730 ImplType::operator-=(static_cast<const ImplType&>(x));
736 ImplType::operator*=(static_cast<const ImplType&>(x));
742 ImplType::operator/=(static_cast<const ImplType&>(x));
747 template <
typename S>
749 ImplType::operator+=(x);
754 template <
typename S>
756 ImplType::operator-=(x);
761 template <
typename S>
763 ImplType::operator*=(x);
768 template <
typename S>
770 ImplType::operator/=(x);
776 template <
typename T,
typename L>
784 template <
typename T>
789 template <
typename T>
794 template <
typename T,
typename L>
795 struct IsExpr< LFad::LogicalSparse<T,L> > {
799 template <
typename T,
typename L>
808 #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...
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.
~LogicalSparseImp()
Destructor.
LogicalSparse(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x of type ValueT.
bool isPassive() const
Returns true if derivative array is empty.
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
KOKKOS_INLINE_FUNCTION const ValT & val() const
Returns value.
LogicalSparse(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
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.
Expr(const int sz, const ValT &x)
Constructor with size sz and value x.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION const LogT * dx() const
Returns derivative array.
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.
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.
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 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.
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.
bool hasFastAccess() const
Returns true if derivative array is not empty.
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.
Expr()
Default constructor.
void setIsConstant(bool is_const)
Set whether variable is constant.