10 #ifndef SACADO_LFAD_LOGICALSPARSE_HPP
11 #define SACADO_LFAD_LOGICALSPARSE_HPP
27 template <
typename ExprT>
class Expr {};
37 static const unsigned value = 0;
49 static const bool value =
false;
64 template <
typename ValT,
typename LogT>
120 template <
typename S>
125 if (sz != this->
size())
129 if (x.hasFastAccess())
130 for(
int i=0;
i<sz; ++
i)
133 for(
int i=0;
i<sz; ++
i)
137 this->
val() = x.val();
150 void diff(
const int ith,
const int n) {
151 if (this->
size() != n)
159 template <
typename S>
162 if (x.size() != this->
size())
return false;
163 bool eq = IE::eval(x.val(), this->
val());
164 for (
int i=0;
i<this->
size();
i++)
165 eq = eq && IE::eval(x.dx(
i), this->
dx(
i));
184 if (is_const && this->
size()!=0)
196 template <
typename S>
215 template <
typename S>
219 if (sz != this->
size())
223 if (x.hasFastAccess())
224 for(
int i=0;
i<sz; ++
i)
227 for(
int i=0;
i<sz; ++
i)
231 this->
val() = x.val();
244 template <
typename S>
251 template <
typename S>
258 template <
typename S>
265 template <
typename S>
273 int xsz = x.size(), sz = this->
size();
276 if ((xsz != sz) && (xsz != 0) && (sz != 0))
277 throw "LFad Error: Attempt to assign with incompatible sizes";
282 for (
int i=0;
i<xsz; ++
i)
287 for (
int i=0;
i<xsz; ++
i)
292 this->
val() += x.val();
299 int xsz = x.size(), sz = this->
size();
302 if ((xsz != sz) && (xsz != 0) && (sz != 0))
303 throw "LFad Error: Attempt to assign with incompatible sizes";
308 for (
int i=0;
i<xsz; ++
i)
313 for (
int i=0;
i<xsz; ++
i)
318 this->
val() -= x.val();
326 int xsz = x.size(), sz = this->
size();
329 if ((xsz != sz) && (xsz != 0) && (sz != 0))
330 throw "LFad Error: Attempt to assign with incompatible sizes";
335 for (
int i=0;
i<xsz; ++
i)
340 for (
int i=0;
i<xsz; ++
i)
345 this->
val() *= x.val();
352 int xsz = x.size(), sz = this->
size();
355 if ((xsz != sz) && (xsz != 0) && (sz != 0))
356 throw "LFad Error: Attempt to assign with incompatible sizes";
361 for (
int i=0;
i<xsz; ++
i)
366 for (
int i=0;
i<xsz; ++
i)
371 this->
val() /= x.val();
377 template <
typename S>
379 int xsz = x.size(), sz = this->
size();
382 if ((xsz != sz) && (xsz != 0) && (sz != 0))
383 throw "LFad Error: Attempt to assign with incompatible sizes";
388 if (x.hasFastAccess())
389 for (
int i=0;
i<xsz; ++
i)
392 for (
int i=0;
i<xsz; ++
i)
397 if (x.hasFastAccess())
398 for (
int i=0;
i<xsz; ++
i)
401 for (
int i=0;
i<xsz; ++
i)
406 this->
val() += x.val();
412 template <
typename S>
414 int xsz = x.size(), sz = this->
size();
417 if ((xsz != sz) && (xsz != 0) && (sz != 0))
418 throw "LFad Error: Attempt to assign with incompatible sizes";
423 if (x.hasFastAccess())
424 for (
int i=0;
i<xsz; ++
i)
427 for (
int i=0;
i<xsz; ++
i)
432 if (x.hasFastAccess())
433 for (
int i=0;
i<xsz; ++
i)
436 for (
int i=0;
i<xsz; ++
i)
441 this->
val() -= x.val();
448 template <
typename S>
450 int xsz = x.size(), sz = this->
size();
453 if ((xsz != sz) && (xsz != 0) && (sz != 0))
454 throw "LFad Error: Attempt to assign with incompatible sizes";
459 if (x.hasFastAccess())
460 for (
int i=0;
i<xsz; ++
i)
463 for (
int i=0;
i<xsz; ++
i)
468 if (x.hasFastAccess())
469 for (
int i=0;
i<xsz; ++
i)
472 for (
int i=0;
i<xsz; ++
i)
477 this->
val() *= x.val();
483 template <
typename S>
485 int xsz = x.size(), sz = this->
size();
488 if ((xsz != sz) && (xsz != 0) && (sz != 0))
489 throw "LFad Error: Attempt to assign with incompatible sizes";
494 if (x.hasFastAccess())
495 for (
int i=0;
i<xsz; ++
i)
498 for (
int i=0;
i<xsz; ++
i)
503 if (x.hasFastAccess())
504 for (
int i=0;
i<xsz; ++
i)
507 for (
int i=0;
i<xsz; ++
i)
512 this->
val() /= x.val();
522 template <
typename ValT,
typename LogT>
545 template <
typename S>
553 Expr(
const int sz,
const ValT & x) :
562 Expr(
const int sz,
const int i,
const ValT & x) :
570 template <
typename S>
583 template <
typename ValT,
typename LogT >
584 class LogicalSparse :
public Expr< LogicalSparseImp<ValT,LogT > > {
599 template <
typename T,
typename U = LogT>
620 template <
typename S>
645 template <
typename S>
655 template <
typename S>
668 template <
typename S>
676 template <
typename S>
678 ImplType::operator+=(x);
683 template <
typename S>
685 ImplType::operator-=(x);
690 template <
typename S>
692 ImplType::operator*=(x);
697 template <
typename S>
699 ImplType::operator/=(x);
705 ImplType::operator+=(static_cast<const ImplType&>(x));
711 ImplType::operator-=(static_cast<const ImplType&>(x));
717 ImplType::operator*=(static_cast<const ImplType&>(x));
723 ImplType::operator/=(static_cast<const ImplType&>(x));
728 template <
typename S>
730 ImplType::operator+=(x);
735 template <
typename S>
737 ImplType::operator-=(x);
742 template <
typename S>
744 ImplType::operator*=(x);
749 template <
typename S>
751 ImplType::operator/=(x);
757 template <
typename T,
typename L>
765 template <
typename T>
770 template <
typename T>
775 template <
typename T,
typename L>
776 struct IsExpr< LFad::LogicalSparse<T,L> > {
780 template <
typename T,
typename L>
789 #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.
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.
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_INLINE_FUNCTION DynamicStorage & operator=(const DynamicStorage &x)
Assignment.
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.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
SACADO_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
Base template specification for testing equivalence.
SACADO_INLINE_FUNCTION LogT & fastAccessDx(int i)
Returns derivative component i without bounds checking.
LFad::LogicalSparse< T, L >::base_expr_type type
Get the base Fad type from a view/expression.
LogicalSparseImp(const LogicalSparseImp &x)
Copy constructor.
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.
SACADO_INLINE_FUNCTION const ValT & val() const
Returns value.
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.
SACADO_INLINE_FUNCTION int size() const
Returns number of derivative components.
Turn LogicalSparse into a meta-function class usable with mpl::apply.
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
LFad::Expr< T >::base_expr_type type
LogicalSparseImp(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
SACADO_INLINE_FUNCTION void zero()
Zero out derivative array.
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.
SACADO_INLINE_FUNCTION const LogT * dx() const
Returns derivative array.