STK++ 0.9.13
STK_ExprBase.h File Reference

In this file we define the base class for Arrays and Expressions. More...

Include dependency graph for STK_ExprBase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  STK::ExprBase< Derived >
 base class for template evaluation expressions and visitors. More...
 

Namespaces

namespace  STK
 The namespace STK is the main domain space of the Statistical ToolKit project.
 
namespace  STK::hidden
 The hidden namespace enclose the classes and methods which are used internally by the STK++ classes.
 

Macros

#define DEFINE_BINARY_OPERATOR(OPERATORNAME, BINARYOPERATORNAME)
 utility macro allowing to define binary operators
 
#define MAKE_UNARY_OPERATOR_NOARG(FUNCTION, FUNCTOR)
 utility macro allowing to construct unary operators
 
#define MAKE_UNARY_OPERATOR_1ARG(FUNCTION, FUNCTOR)
 utility macro allowing to construct unary operators with one argument
 
#define MAKE_RESHAPE_OPERATOR(OPERATOR, SHAPE)
 utility macro allowing to construct reshape operators
 

Detailed Description

In this file we define the base class for Arrays and Expressions.

Definition in file STK_ExprBase.h.

Macro Definition Documentation

◆ DEFINE_BINARY_OPERATOR

#define DEFINE_BINARY_OPERATOR (   OPERATORNAME,
  BINARYOPERATORNAME 
)
Value:
template<typename Rhs> \
typename hidden::OperatorSelector<Derived, Rhs, Arrays::BINARYOPERATORNAME>::Result const \
OPERATORNAME( ExprBase<Rhs> const& other) const;

utility macro allowing to define binary operators

Definition at line 77 of file STK_ExprBase.h.

84 { return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived()); }
85
87#define MAKE_UNARY_OPERATOR_1ARG(FUNCTION, FUNCTOR) \
88 inline UnaryOperator<FUNCTOR<Type>, Derived> FUNCTION(Type const& value) const \
89 { return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived(), FUNCTOR<Type>(value)); }
90
92#define MAKE_RESHAPE_OPERATOR(OPERATOR, SHAPE) \
93 inline OPERATOR##Operator< Derived> const SHAPE() const \
94 { return OPERATOR##Operator< Derived>(this->asDerived()); }
95
96
97namespace STK
98{
99
111template<class Derived>
112class ExprBase: public ITContainer<Derived, hidden::Traits<Derived>::structure_>
113{
114 public:
115 enum
116 {
117 structure_ = hidden::Traits<Derived>::structure_,
118 orient_ = hidden::Traits<Derived>::orient_,
119 sizeRows_ = hidden::Traits<Derived>::sizeRows_,
120 sizeCols_ = hidden::Traits<Derived>::sizeCols_,
121 storage_ = hidden::Traits<Derived>::storage_
122 };
123 typedef ITContainer<Derived, structure_> Base;
124 typedef typename hidden::Traits<Derived>::Type Type;
125 typedef typename hidden::Traits<Derived>::TypeConst TypeConst;
126
127 protected:
129 inline ExprBase(): Base() {}
131 inline ~ExprBase() {}
132
133 public:
134 //--------------
135 // Start Visitors
139 template<typename Visitor>
140 typename Visitor::TypeConst visit(Visitor& visitor) const;
148 int count() const;
156 bool const any() const;
164 bool const all() const;
166 int nbAvailableValues() const;
167
172 Type const minElt( int& row, int& col) const;
177 Type const minEltSafe( int& row, int& col) const;
182 Type const maxElt( int& row, int& col) const;
187 Type const maxEltSafe( int& row, int& col) const;
193 Type const minElt( int& pos) const;
199 Type const minEltSafe( int& pos) const;
205 Type const maxElt( int& pos) const;
211 Type const maxEltSafe( int& pos) const;
215 Type const minElt() const;
219 Type const minEltSafe() const;
223 Type const maxElt() const;
227 Type const maxEltSafe() const;
228
230 Type const sum() const;
232 Type const sumSafe() const;
233
235 Type const norm() const;
237 Type const normSafe() const;
239 Type const norm2() const;
241 Type const norm2Safe() const;
243 Type const normInf() const;
244
246 Type const mean() const;
248 Type const meanSafe() const;
250 Type const variance() const;
252 Type const varianceSafe() const;
254 Type const variance(Type const& mean) const;
256 Type const varianceSafe(Type const& mean) const;
257
261 template<typename Rhs>
262 Type const wsum(ExprBase<Rhs> const& weights) const;
266 template<typename Rhs>
267 Type const wsumSafe(ExprBase<Rhs> const& weights) const;
271 template<typename Rhs>
272 Type const wnorm(ExprBase<Rhs> const& weights) const;
276 template<typename Rhs>
277 Type const wnormSafe(ExprBase<Rhs> const& weights) const;
281 template<typename Rhs>
282 Type const wnorm2(ExprBase<Rhs> const& weights) const;
286 template<typename Rhs>
287 Type const wnorm2Safe(ExprBase<Rhs> const& weights) const;
291 template<typename Rhs>
292 Type const wmean(ExprBase<Rhs> const& weights) const;
296 template<typename Rhs>
297 Type const wmeanSafe(ExprBase<Rhs> const& weights) const;
301 template<typename Rhs>
302 Type const wvariance(ExprBase<Rhs> const& weights) const;
306 template<typename Rhs>
307 Type const wvarianceSafe(ExprBase<Rhs> const& weights) const;
311 template<typename Rhs>
312 Type const wvariance(Type const& mean, ExprBase<Rhs> const& weights) const;
316 template<typename Rhs>
317 Type const wvarianceSafe(Type const& mean, ExprBase<Rhs> const& weights) const;
318 // Visitors terminated
319 //--------------------
320 // BinaryOperators
322 DEFINE_BINARY_OPERATOR(operator==,equalOp_)
324 DEFINE_BINARY_OPERATOR(operator!=,notEqualOp_)
326 DEFINE_BINARY_OPERATOR(operator>,greaterThanOp_)
328 DEFINE_BINARY_OPERATOR(operator<,lessThanOp_)
330 DEFINE_BINARY_OPERATOR(operator>=,greaterThanOrEqualOp_)
332 DEFINE_BINARY_OPERATOR(operator<=,lessThanOrEqualOp_)
333
334
335 DEFINE_BINARY_OPERATOR(operator+,sumOp_)
337 DEFINE_BINARY_OPERATOR(operator-,differenceOp_)
339 DEFINE_BINARY_OPERATOR(prod,productOp_)
341 DEFINE_BINARY_OPERATOR(operator/,divisionOp_)
343 DEFINE_BINARY_OPERATOR(operator%,moduloOp_)
344
345
349
350
351 DEFINE_BINARY_OPERATOR(operator&&,logicalAndOp_)
353 DEFINE_BINARY_OPERATOR(operator||,logicalOrOp_)
354
355
356 DEFINE_BINARY_OPERATOR(operator&,bitwiseAndOp_)
358 DEFINE_BINARY_OPERATOR(operator|,bitwiseOrOp_)
360 DEFINE_BINARY_OPERATOR(operator^,bitwiseXorOp_)
361 // BinaryOperators terminated
362 //--------------------
363 // UnaryOperators
365 MAKE_UNARY_OPERATOR_NOARG(operator-, OppositeOp)
398
399 // boolean operations
401 MAKE_UNARY_OPERATOR_1ARG(operator==, EqualWithOp)
403 MAKE_UNARY_OPERATOR_1ARG(operator!=, NotEqualWithOp)
405 MAKE_UNARY_OPERATOR_1ARG(operator>, GreaterThanOp)
407 MAKE_UNARY_OPERATOR_1ARG(operator<, LessThanOp)
409 MAKE_UNARY_OPERATOR_1ARG(operator<=, LeqThanOp)
411 MAKE_UNARY_OPERATOR_1ARG(operator>=, GeqThanOp)
412
413
414 MAKE_UNARY_OPERATOR_1ARG(min, MinWithOp)
416 MAKE_UNARY_OPERATOR_1ARG(max, MaxWithOp)
417
418
419 MAKE_UNARY_OPERATOR_1ARG(operator+, SumWithOp)
421 MAKE_UNARY_OPERATOR_1ARG(operator-, DifferenceWithOp)
423 MAKE_UNARY_OPERATOR_1ARG(operator*, ProductWithOp)
425 MAKE_UNARY_OPERATOR_1ARG(operator/, DivisionWithOp)
427 MAKE_UNARY_OPERATOR_1ARG(operator%, ModuloWithOp)
428
429
430 MAKE_UNARY_OPERATOR_1ARG(operator&&, LogicalAndWithOp)
432 MAKE_UNARY_OPERATOR_1ARG(operator||, LogicalOrWithOp)
433
434
435 MAKE_UNARY_OPERATOR_1ARG(operator&, BitwiseAndWithOp)
437 MAKE_UNARY_OPERATOR_1ARG(operator|, BitwiseOrWithOp)
439 MAKE_UNARY_OPERATOR_1ARG(operator^, BitwiseXorWithOp)
440
441
445
446
447 inline UnaryOperator<SafeOp<Type>, Derived> const safe(Type const value = Type()) const
448 { return UnaryOperator<SafeOp<Type>, Derived>(this->asDerived(), SafeOp<Type>(value)); }
449
450 // friends
452 inline friend UnaryOperator<SumWithOp<Type>, Derived> const
453 operator+(Type const& value, ExprBase<Derived> const& other)
454 { return other.asDerived() + value;}
456 inline friend UnaryOperator<SubstractToOp<Type>, Derived > const
457 operator-(Type const value, ExprBase<Derived> const& other)
458 { return UnaryOperator<SubstractToOp<Type>, Derived>(other.asDerived(), SubstractToOp<Type>(value));}
460 inline friend UnaryOperator< ProductWithOp<Type>, Derived> const
461 operator*(Type const value, ExprBase<Derived> const& other)
462 { return other.asDerived()*value; }
463
465 template<typename OtherType>
466 inline UnaryOperator<CastOp<Type, OtherType>, Derived> const cast() const
467 { return UnaryOperator<CastOp<Type, OtherType>, Derived>(this->asDerived());}
468
469 // pdf, lpdf, cdf, icdf
471 inline UnaryOperator<Law::PdfOp<Type>, Derived> pdf( Law::IUnivLaw<Type> const& law) const
472 { return UnaryOperator<Law::PdfOp<Type>, Derived>(this->asDerived(), Law::PdfOp<Type>(law));}
474 inline UnaryOperator<Law::LogPdfOp<Type>, Derived> lpdf( Law::IUnivLaw<Type> const& law) const
475 { return UnaryOperator<Law::LogPdfOp<Type>, Derived>(this->asDerived(), Law::LogPdfOp<Type>(law));}
477 inline UnaryOperator<Law::CdfOp<Type>, Derived> cdf( Law::IUnivLaw<Type> const& law) const
478 { return UnaryOperator<Law::CdfOp<Type>, Derived>(this->asDerived(), Law::CdfOp<Type>(law));}
480 inline UnaryOperator<Law::LogCdfOp<Type>, Derived> lcdf( Law::IUnivLaw<Type> const& law) const
481 { return UnaryOperator<Law::LogCdfOp<Type>, Derived>(this->asDerived(), Law::LogCdfOp<Type>(law));}
483 inline UnaryOperator<Law::CdfcOp<Type>, Derived> cdfc( Law::IUnivLaw<Type> const& law) const
484 { return UnaryOperator<Law::CdfcOp<Type>, Derived>(this->asDerived(), Law::CdfcOp<Type>(law));}
486 inline UnaryOperator<Law::LogCdfcOp<Type>, Derived> lcdfc( Law::IUnivLaw<Type> const& law) const
487 { return UnaryOperator<Law::LogCdfcOp<Type>, Derived>(this->asDerived(), Law::LogCdfcOp<Type>(law));}
489 inline UnaryOperator<Law::IcdfOp<Type>, Derived> icdf( Law::IUnivLaw<Type> const& law) const
490 { return UnaryOperator<Law::IcdfOp<Type>, Derived>(this->asDerived(), Law::IcdfOp<Type>(law));}
491
492 // extension
494 template< template<typename> class OtherOperator>
495 inline UnaryOperator<OtherOperator<Type>, Derived> const funct0() const
496 { return UnaryOperator<OtherOperator<Type>, Derived>(this->asDerived());}
498 template< template<typename> class OtherOperator>
499 inline UnaryOperator<OtherOperator<Type>, Derived> const funct1(Type const value) const
500 { return UnaryOperator<OtherOperator<Type>, Derived>(this->asDerived(), OtherOperator<Type>(value));}
501
502 // reshape operations
508 MAKE_RESHAPE_OPERATOR(DiagonalGetter,getDiagonal)
510 MAKE_RESHAPE_OPERATOR(UpperTriangularize,upperTriangularize)
512 MAKE_RESHAPE_OPERATOR(LowerTriangularize,lowerTriangularize)
519
520 // slice operators
522 template<int Size_>
523 inline SubVectorOperator<Derived, Size_> const sub(TRange<Size_> const& I) const
524 {
526 return SubVectorOperator<Derived, Size_>(this->asDerived(), I);
527 }
528
530 inline ColOperator<Derived> const col(int j) const
531 { return ColOperator<Derived> (this->asDerived(), j);}
533 inline RowOperator<Derived> const row(int i) const
534 { return RowOperator<Derived> (this->asDerived(), i);}
536 template<int Size_>
537 inline SubOperator<Derived, sizeRows_, Size_> const col(TRange<Size_> const& J) const
538 { return SubOperator<Derived, sizeRows_, Size_> (this->asDerived(), this->rows(), J);}
540 template<int Size_>
541 inline SubOperator<Derived, Size_, sizeCols_> const row(TRange<Size_> const& I) const
542 { return SubOperator<Derived, Size_, sizeCols_> (this->asDerived(), I, this->cols());}
543
545 template<int SizeRows_, int SizeCols_>
546 inline SubOperator<Derived, SizeRows_, SizeCols_> const sub(TRange<SizeRows_> const& I,TRange<SizeCols_> const& J) const
547 {
549 return SubOperator<Derived, SizeRows_, SizeCols_>(this->asDerived(), I, J);
550 }
551
552 // dot operations
556 template<class Rhs>
558 dot(ExprBase<Rhs> const& other) const;
562 template<class Rhs>
564 dotSafe(ExprBase<Rhs> const& other) const;
565
567 template<typename Rhs>
568 typename hidden::ProductSelector<Derived, Rhs, hidden::Traits<Derived>::structure_, hidden::Traits<Rhs>::structure_>::ProductType const
569 operator*( ExprBase<Rhs> const& other) const;
570};
571
572} // namespace STK
573
574#undef DEFINE_BINARY_OPERATOR
575#undef MAKE_UNARY_OPERATOR_NOARG
576#undef MAKE_UNARY_OPERATOR_1ARG
577#undef MAKE_RESHAPE_OPERATOR
578
579#include "STK_ExprBaseVisitor.h"
580#include "STK_ExprBaseDot.h"
581#include "STK_ExprBaseProduct.h"
583
584
585#endif /* STK_EXPRBASE_H_ */
#define MAKE_RESHAPE_OPERATOR(OPERATOR, SHAPE)
utility macro allowing to construct unary operators
In this file we define the dot product and its particular cases.
In this file we define the matrix-matrix product and its particular cases.
In this file we define the Visitors for ExprBase.
#define MAKE_UNARY_OPERATOR_NOARG(FUNCTION, FUNCTOR)
utility macro allowing to construct unary operators
#define MAKE_UNARY_OPERATOR_1ARG(FUNCTION, FUNCTOR)
utility macro allowing to construct unary operators with one argument
#define DEFINE_BINARY_OPERATOR(OPERATORNAME, BINARYOPERATORNAME)
utility macro allowing to define binary operators
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
#define STK_STATIC_ASSERT_TWO_DIMENSIONS_ONLY(EXPR)
UnaryOperator< CosOp< Type >, Derived > cos() const
UnaryOperator< NegOp< Type >, Derived > neg() const
friend UnaryOperator< ProductWithOp< Type >, Derived > const operator*(Type const value, ExprBase< Derived > const &other)
UnaryOperator< TanOp< Type >, Derived > tan() const
UnaryOperator< LogOp< Type >, Derived > log() const
TransposeOperator< Derived > const transpose() const
Type const varianceSafe() const
Type const norm() const
UnaryOperator< Law::PdfOp< Type >, Derived > pdf(Law::IUnivLaw< Type > const &law) const
compute pdf values to this using distribution law given by user
ITContainer< Derived, structure_ > Base
hidden::Traits< Derived >::TypeConst TypeConst
bool const any() const
check if there is any non-zero element in an expression.
Type const sum() const
UnaryOperator< AbsOp< Type >, Derived > abs() const
Type const wmean(ExprBase< Rhs > const &weights) const
UnaryOperator< Law::IcdfOp< Type >, Derived > icdf(Law::IUnivLaw< Type > const &law) const
compute inverse cumulative distribution function using distribution law given by user
hidden::OperatorSelector< Derived, Rhs, Arrays::maxOp_ >::Result const max(ExprBase< Rhs > const &other) const
RowOperator< Derived > const row(int i) const
bool const all() const
check if all the elements in an expression are not zero.
friend UnaryOperator< SumWithOp< Type >, Derived > const operator+(Type const &value, ExprBase< Derived > const &other)
Type const wnorm2(ExprBase< Rhs > const &weights) const
DiagonalizeOperator< Derived > const diagonalize() const
LowerTriangularizeOperator< Derived > const lowerTriangularize() const
DiagonalGetterOperator< Derived > const getDiagonal() const
Type const meanSafe() const
Type const minElt() const
Type const wnorm2Safe(ExprBase< Rhs > const &weights) const
Type const variance() const
UnaryOperator< SafeOp< Type >, Derived > const safe(Type const value=Type()) const
UnaryOperator< SqrtOp< Type >, Derived > sqrt() const
int count() const
compute the value of non-zero element in an expression.
Type const sumSafe() const
UnaryOperator< SafeInverseOp< Type >, Derived > safeInverse(Type const &value) const
UnaryOperator< CastOp< Type, OtherType >, Derived > const cast() const
UnaryOperator< CubeOp< Type >, Derived > cube() const
hidden::Traits< Derived >::Type Type
UnaryOperator< PowOp< Type >, Derived > pow(Type const &value) const
int nbAvailableValues() const
UnaryOperator< IsFiniteOp< Type >, Derived > isFinite() const
UpperTriangularizeOperator< Derived > const upperTriangularize() const
Visitor::TypeConst visit(Visitor &visitor) const
Visit the container using a constant visitor.
UnaryOperator< IsInfiniteOp< Type >, Derived > isInfinite() const
Type const maxElt() const
Type const minEltSafe() const
Type const wmeanSafe(ExprBase< Rhs > const &weights) const
Type const norm2() const
hidden::OperatorSelector< Derived, Rhs, Arrays::productOp_ >::Result const prod(ExprBase< Rhs > const &other) const
hidden::Promote< Type, typenameRhs::Type >::result_type const dotSafe(ExprBase< Rhs > const &other) const
UnaryOperator< AsinOp< Type >, Derived > asin() const
hidden::Promote< Type, typenameRhs::Type >::result_type const dot(ExprBase< Rhs > const &other) const
UnaryOperator< SquareOp< Type >, Derived > square() const
UnaryOperator< OtherOperator< Type >, Derived > const funct1(Type const value) const
Type const normInf() const
ColOperator< Derived > const col(int j) const
UnaryOperator< Law::LogPdfOp< Type >, Derived > lpdf(Law::IUnivLaw< Type > const &law) const
compute log-pdf values to this using distribution law given by user
SubVectorOperator< Derived, Size_ > const sub(TRange< Size_ > const &I) const
Type const wnormSafe(ExprBase< Rhs > const &weights) const
UnaryOperator< OtherOperator< Type >, Derived > const funct0() const
Type const wvarianceSafe(ExprBase< Rhs > const &weights) const
UnaryOperator< AcosOp< Type >, Derived > acos() const
UnaryOperator< IsNaOp< Type >, Derived > isNA() const
UnaryOperator< Law::LogCdfOp< Type >, Derived > lcdf(Law::IUnivLaw< Type > const &law) const
compute log-cumulative distribution function of this using distribution law given by user
Type const wnorm(ExprBase< Rhs > const &weights) const
SymmetrizeOperator< Derived > const symmetrize() const
ExprBase()
Default constructor.
UnaryOperator< InverseOp< Type >, Derived > inverse() const
UnaryOperator< Law::LogCdfcOp< Type >, Derived > lcdfc(Law::IUnivLaw< Type > const &law) const
compute complementary cumulative distribution function of this using distribution law given by user
hidden::OperatorSelector< Derived, Rhs, Arrays::minOp_ >::Result const min(ExprBase< Rhs > const &other) const
UpperSymmetrizeOperator< Derived > const upperSymmetrize() const
UnaryOperator< Law::CdfcOp< Type >, Derived > cdfc(Law::IUnivLaw< Type > const &law) const
compute complementary cumulative distribution function of this using distribution law given by user
UnaryOperator< Law::CdfOp< Type >, Derived > cdf(Law::IUnivLaw< Type > const &law) const
compute cumulative distribution function of this using distribution law given by user
UnaryOperator< SinOp< Type >, Derived > sin() const
LowerSymmetrizeOperator< Derived > const lowerSymmetrize() const
UnaryOperator< OppositeOp< Type >, Derived > operator-() const
Type const normSafe() const
~ExprBase()
destructor
Type const wvariance(ExprBase< Rhs > const &weights) const
UnaryOperator< ExpOp< Type >, Derived > exp() const
Type const wsum(ExprBase< Rhs > const &weights) const
Type const norm2Safe() const
Type const mean() const
Type const wsumSafe(ExprBase< Rhs > const &weights) const
Type const maxEltSafe() const
The namespace STK is the main domain space of the Statistical ToolKit project.
If<(sizeof(Type1)>sizeof(Type2)), Type1, Type2 >::Result result_type

◆ MAKE_RESHAPE_OPERATOR

#define MAKE_RESHAPE_OPERATOR (   OPERATOR,
  SHAPE 
)
Value:
inline OPERATOR##Operator< Derived> const SHAPE() const \
{ return OPERATOR##Operator< Derived>(this->asDerived()); }

utility macro allowing to construct reshape operators

Definition at line 93 of file STK_ExprBase.h.

95 { return OPERATOR##Operator< Derived>(this->asDerived()); }

◆ MAKE_UNARY_OPERATOR_1ARG

#define MAKE_UNARY_OPERATOR_1ARG (   FUNCTION,
  FUNCTOR 
)
Value:
inline UnaryOperator<FUNCTOR<Type>, Derived> FUNCTION(Type const& value) const \
{ return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived(), FUNCTOR<Type>(value)); }

utility macro allowing to construct unary operators with one argument

Definition at line 88 of file STK_ExprBase.h.

90 { return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived(), FUNCTOR<Type>(value)); }

◆ MAKE_UNARY_OPERATOR_NOARG

#define MAKE_UNARY_OPERATOR_NOARG (   FUNCTION,
  FUNCTOR 
)
Value:
inline UnaryOperator<FUNCTOR<Type>, Derived> FUNCTION() const \
{ return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived()); }

utility macro allowing to construct unary operators

Definition at line 83 of file STK_ExprBase.h.

85 { return UnaryOperator<FUNCTOR<Type>, Derived>(this->asDerived()); }