27 #ifndef CDPL_MATH_GRIDEXPRESSION_HPP
28 #define CDPL_MATH_GRIDEXPRESSION_HPP
30 #include <type_traits>
54 template <
typename E,
typename F>
59 typedef F FunctorType;
61 typedef typename E::ConstClosureType ExpressionClosureType;
112 return expr.getSize1();
121 return expr.getSize2();
130 return expr.getSize3();
142 return FunctorType::apply(expr(i, j, k));
146 ExpressionClosureType expr;
154 template <
typename E,
typename F>
175 template <
typename E1,
typename E2,
typename F>
180 typedef F FunctorType;
181 typedef E1 Expression1Type;
182 typedef E2 Expression2Type;
183 typedef typename E1::ConstClosureType Expression1ClosureType;
184 typedef typename E2::ConstClosureType Expression2ClosureType;
227 GridBinary1(
const Expression1Type& e1,
const Expression2Type& e2):
228 expr1(e1), expr2(e2) {}
269 return FunctorType::apply(expr1(i, j, k), expr2(i, j, k));
273 Expression1ClosureType expr1;
274 Expression2ClosureType expr2;
283 template <
typename E1,
typename E2,
typename F>
304 template <
typename E1,
typename E2,
typename F>
309 typedef F FunctorType;
310 typedef E1 Expression1Type;
311 typedef E2 Expression2Type;
312 typedef const E1 Expression1ClosureType;
313 typedef typename E2::ConstClosureType Expression2ClosureType;
357 expr1(e1), expr2(e2) {}
365 return expr2.getSize1();
374 return expr2.getSize2();
383 return expr2.getSize3();
395 return FunctorType::apply(expr1, expr2(i, j, k));
399 Expression1ClosureType expr1;
400 Expression2ClosureType expr2;
409 template <
typename E1,
typename E2,
typename F>
429 template <
typename E1,
typename E2,
typename F>
434 typedef F FunctorType;
435 typedef E1 Expression1Type;
436 typedef E2 Expression2Type;
437 typedef typename E1::ConstClosureType Expression1ClosureType;
438 typedef const E2 Expression2ClosureType;
482 expr1(e1), expr2(e2) {}
490 return expr1.getSize1();
499 return expr1.getSize2();
508 return expr1.getSize3();
520 return FunctorType::apply(expr1(i, j, k), expr2);
524 Expression1ClosureType expr1;
525 Expression2ClosureType expr2;
534 template <
typename E1,
typename E2,
typename F>
555 template <
typename E>
561 return ExpressionType(e());
570 template <
typename E>
585 template <
typename E1,
typename E2>
586 typename GridBinary1Traits<E1, E2, ScalarAddition<typename E1::ValueType, typename E2::ValueType> >::ResultType
592 return ExpressionType(e1(), e2());
603 template <
typename E1,
typename E2>
604 typename GridBinary1Traits<E1, E2, ScalarSubtraction<typename E1::ValueType, typename E2::ValueType> >::ResultType
610 return ExpressionType(e1(), e2());
621 template <
typename E,
typename T>
622 typename std::enable_if<IsScalar<T>::value,
typename Scalar2GridBinaryTraits<E, T, ScalarMultiplication<typename E::ValueType, T> >::ResultType>::type
628 return ExpressionType(e(), t);
639 template <
typename T,
typename E>
640 typename std::enable_if<IsScalar<T>::value,
typename Scalar1GridBinaryTraits<T, E, ScalarMultiplication<T, typename E::ValueType> >::ResultType>::type
646 return ExpressionType(t, e());
657 template <
typename E,
typename T>
658 typename std::enable_if<IsScalar<T>::value,
typename Scalar2GridBinaryTraits<E, T, ScalarDivision<typename E::ValueType, T> >::ResultType>::type
664 return ExpressionType(e(), t);
675 template <
typename E1,
typename E2>
690 template <
typename E1,
typename E2>
707 template <
typename E1,
typename E2,
typename T>
720 template <
typename E>
721 typename GridUnaryTraits<E, ScalarConjugation<typename E::ValueType> >::ResultType
726 return ExpressionType(e());
735 template <
typename E>
736 typename GridUnaryTraits<E, ScalarConjugation<typename E::ValueType> >::ResultType
741 return ExpressionType(e());
750 template <
typename E>
751 typename GridUnaryTraits<E, ScalarReal<typename E::ValueType> >::ResultType
756 return ExpressionType(e());
765 template <
typename E>
766 typename GridUnaryTraits<E, ScalarImaginary<typename E::ValueType> >::ResultType
771 return ExpressionType(e());
782 template <
typename E1,
typename E2>
783 typename GridBinary1Traits<E1, E2, ScalarDivision<typename E1::ValueType, typename E2::ValueType> >::ResultType
789 return ExpressionType(e1(), e2());
800 template <
typename E1,
typename E2>
801 typename GridBinary1Traits<E1, E2, ScalarMultiplication<typename E1::ValueType, typename E2::ValueType> >::ResultType
807 return ExpressionType(e1(), e2());
816 template <
typename E>
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e)
Throws the exception e if size1 differs from size2, otherwise returns std::min(size1,...
Definition: Check.hpp:84
Definition of basic expression types.
Definition of various functors.
Definition of type traits.
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
E ExpressionType
The derived expression type.
Definition: Expression.hpp:49
Expression template node combining two grid expressions E1 and E2 element-wise via the binary functor...
Definition: GridExpression.hpp:177
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:190
CommonType< typename E1::SizeType, typename E2::SizeType >::Type SizeType
The common size type of the two wrapped expressions.
Definition: GridExpression.hpp:215
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Applies the binary functor to the elements at (i, j, k) of the two wrapped expressions and returns th...
Definition: GridExpression.hpp:267
GridBinary1(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression template node wrapping e1 and e2.
Definition: GridExpression.hpp:227
SizeType getSize1() const
Returns the size along the first dimension after verifying that both wrapped expressions agree on it.
Definition: GridExpression.hpp:235
const ValueType ConstReference
Constant element reference type.
Definition: GridExpression.hpp:195
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:210
CommonType< typename E1::DifferenceType, typename E2::DifferenceType >::Type DifferenceType
The common signed difference type of the two wrapped expressions.
Definition: GridExpression.hpp:220
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:205
SizeType getSize3() const
Returns the size along the third dimension after verifying that both wrapped expressions agree on it.
Definition: GridExpression.hpp:255
const ValueType Reference
Mutable element reference type (degrades to const for expression template results).
Definition: GridExpression.hpp:200
SizeType getSize2() const
Returns the size along the second dimension after verifying that both wrapped expressions agree on it...
Definition: GridExpression.hpp:245
CRTP base class of all grid expression types.
Definition: Expression.hpp:188
Expression template node applying a unary functor F element-wise to a grid expression E.
Definition: GridExpression.hpp:56
E::SizeType SizeType
The size type inherited from the wrapped expression.
Definition: GridExpression.hpp:92
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:119
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:82
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:110
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:128
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:87
E::DifferenceType DifferenceType
The signed difference type inherited from the wrapped expression.
Definition: GridExpression.hpp:97
GridUnary(const ExpressionType &e)
Constructs the expression template node wrapping e.
Definition: GridExpression.hpp:103
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Applies the unary functor to the element at (i, j, k) of the wrapped expression and returns the resul...
Definition: GridExpression.hpp:140
const ValueType ConstReference
Constant element reference type.
Definition: GridExpression.hpp:72
const ValueType Reference
Mutable element reference type (degrades to const for expression template results).
Definition: GridExpression.hpp:77
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:67
Expression template node combining a scalar E1 (lhs) and a grid expression E2 (rhs) element-wise via ...
Definition: GridExpression.hpp:306
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:372
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:334
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:319
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:381
Scalar1GridBinary(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression template node combining the scalar e1 and the grid expression e2.
Definition: GridExpression.hpp:356
E2::DifferenceType DifferenceType
The signed difference type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:349
const ValueType ConstReference
Constant element reference type.
Definition: GridExpression.hpp:324
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Applies the binary functor to the scalar and the element at (i, j, k) of the wrapped grid expression ...
Definition: GridExpression.hpp:393
E2::SizeType SizeType
The size type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:344
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:363
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:339
const ValueType Reference
Mutable element reference type (degrades to const for expression template results).
Definition: GridExpression.hpp:329
Expression template node combining a grid expression E1 (lhs) and a scalar E2 (rhs) element-wise via ...
Definition: GridExpression.hpp:431
E1::SizeType SizeType
The size type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:469
const ValueType Reference
Mutable element reference type (degrades to const for expression template results).
Definition: GridExpression.hpp:454
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Applies the binary functor to the element at (i, j, k) of the wrapped grid expression and the scalar ...
Definition: GridExpression.hpp:518
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:497
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:459
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:506
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:488
Scalar2GridBinary(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression template node combining the grid expression e1 and the scalar e2.
Definition: GridExpression.hpp:481
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:464
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:444
const ValueType ConstReference
Constant element reference type.
Definition: GridExpression.hpp:449
E1::DifferenceType DifferenceType
The signed difference type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:474
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int F
Specifies Fluorine.
Definition: AtomType.hpp:107
constexpr unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
GridBinary1Traits< E1, E2, ScalarMultiplication< typename E1::ValueType, typename E2::ValueType > >::ResultType elemProd(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Returns the element-wise product of the grid expressions e1 and e2 (Hadamard product).
Definition: GridExpression.hpp:802
GridUnaryTraits< E, ScalarConjugation< typename E::ValueType > >::ResultType herm(const GridExpression< E > &e)
Returns the Hermitian conjugate of the grid expression e (alias of conj() for grids).
Definition: GridExpression.hpp:737
GridUnaryTraits< E, ScalarConjugation< typename E::ValueType > >::ResultType conj(const GridExpression< E > &e)
Returns the element-wise complex conjugate of the grid expression e (identity for real-valued grids).
Definition: GridExpression.hpp:722
std::enable_if< std::is_arithmetic< T >::value, typename GridToleranceEquality< E1, E2, T >::ResultType >::type equals(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2, const T &eps)
Tells whether the grid expressions e1 and e2 agree element-wise within the absolute tolerance eps.
Definition: GridExpression.hpp:709
std::enable_if< IsScalar< T >::value, typename Scalar2GridBinaryTraits< E, T, ScalarDivision< typename E::ValueType, T > >::ResultType >::type operator/(const GridExpression< E > &e, const T &t)
Returns the element-wise quotient of the grid expression e by the scalar t.
Definition: GridExpression.hpp:659
GridUnaryTraits< E, ScalarReal< typename E::ValueType > >::ResultType real(const GridExpression< E > &e)
Returns the element-wise real part of the grid expression e.
Definition: GridExpression.hpp:752
GridEquality< E1, E2 >::ResultType operator!=(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Tells whether the grid expressions e1 and e2 differ in at least one element.
Definition: GridExpression.hpp:692
GridEquality< E1, E2 >::ResultType operator==(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Tells whether the grid expressions e1 and e2 are element-wise equal.
Definition: GridExpression.hpp:677
std::enable_if< IsScalar< T >::value, typename Scalar2GridBinaryTraits< E, T, ScalarMultiplication< typename E::ValueType, T > >::ResultType >::type operator*(const GridExpression< E > &e, const T &t)
Returns the element-wise product of the grid expression e and the scalar t.
Definition: GridExpression.hpp:623
GridBinary1Traits< E1, E2, ScalarDivision< typename E1::ValueType, typename E2::ValueType > >::ResultType elemDiv(const GridExpression< E1 > &e1, const GridExpression< E2 > &e2)
Returns the element-wise quotient of the grid expressions e1 and e2.
Definition: GridExpression.hpp:784
GridUnaryTraits< E, ScalarImaginary< typename E::ValueType > >::ResultType imag(const GridExpression< E > &e)
Returns the element-wise imaginary part of the grid expression e.
Definition: GridExpression.hpp:767
GridUnaryTraits< E, ScalarNegation< typename E::ValueType > >::ResultType operator-(const GridExpression< E > &e)
Returns the element-wise negation of the grid expression e.
Definition: GridExpression.hpp:557
GridElementSum< E >::ResultType sum(const GridExpression< E > &e)
Returns the sum of all elements of the grid expression e.
Definition: GridExpression.hpp:818
const E & operator+(const GridExpression< E > &e)
Returns the grid expression e unchanged (unary +).
Definition: GridExpression.hpp:572
The namespace of the Chemical Data Processing Library.
std::common_type< T1, T2 >::type Type
The common type.
Definition: CommonType.hpp:51
Traits selecting the expression template node and its result type for the Math::GridBinary1 instantia...
Definition: GridExpression.hpp:285
GridBinary1< E1, E2, F > ExpressionType
The expression template node type.
Definition: GridExpression.hpp:290
ExpressionType ResultType
The expression template result type returned by free-function operators.
Definition: GridExpression.hpp:295
GridScalarUnaryFunctor< G >::ResultType ResultType
Definition: Functional.hpp:2829
static ResultType apply(const GridExpression< G > &e)
Returns the element sum of e.
Definition: Functional.hpp:2836
static ResultType apply(const GridExpression< G1 > &e1, const GridExpression< G2 > &e2)
Tells whether e1 and e2 have the same dimensions and equal element values.
Definition: Functional.hpp:2708
GridBooleanBinaryFunctor< G1, G2 >::ResultType ResultType
Definition: Functional.hpp:2700
Scalar3GridBooleanTernaryFunctor< G1, G2, T >::ResultType ResultType
Definition: Functional.hpp:2772
static ResultType apply(const GridExpression< G1 > &e1, const GridExpression< G2 > &e2, Argument3Type epsilon)
Tells whether e1 and e2 agree element-wise within the absolute tolerance epsilon.
Definition: Functional.hpp:2782
Traits selecting the expression template node and its result type for the Math::GridUnary instantiati...
Definition: GridExpression.hpp:156
ExpressionType ResultType
The expression template result type returned by free-function operators.
Definition: GridExpression.hpp:166
GridUnary< E, F > ExpressionType
The expression template node type.
Definition: GridExpression.hpp:161
Traits selecting the expression template node and its result type for the Math::Scalar1GridBinary ins...
Definition: GridExpression.hpp:411
ExpressionType ResultType
The expression template result type returned by free-function operators.
Definition: GridExpression.hpp:420
Scalar1GridBinary< E1, E2, F > ExpressionType
The expression template node type.
Definition: GridExpression.hpp:415
Traits selecting the expression template node and its result type for the Math::Scalar2GridBinary ins...
Definition: GridExpression.hpp:536
ExpressionType ResultType
The expression template result type returned by free-function operators.
Definition: GridExpression.hpp:546
Scalar2GridBinary< E1, E2, F > ExpressionType
The expression template node type.
Definition: GridExpression.hpp:541
Scalar binary addition functor: apply(t1, t2) returns t1 + t2.
Definition: Functional.hpp:373
Scalar binary division functor: apply(t1, t2) returns t1 / t2.
Definition: Functional.hpp:448
Scalar binary multiplication functor: apply(t1, t2) returns t1 * t2.
Definition: Functional.hpp:423
Scalar binary subtraction functor: apply(t1, t2) returns t1 - t2.
Definition: Functional.hpp:398