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;
92 return expr.getSize1();
101 return expr.getSize2();
110 return expr.getSize3();
122 return FunctorType::apply(expr(i, j, k));
126 ExpressionClosureType expr;
134 template <
typename E,
typename F>
150 template <
typename E1,
typename E2,
typename F>
155 typedef F FunctorType;
156 typedef E1 Expression1Type;
157 typedef E2 Expression2Type;
158 typedef typename E1::ConstClosureType Expression1ClosureType;
159 typedef typename E2::ConstClosureType Expression2ClosureType;
182 GridBinary1(
const Expression1Type& e1,
const Expression2Type& e2):
183 expr1(e1), expr2(e2) {}
224 return FunctorType::apply(expr1(i, j, k), expr2(i, j, k));
228 Expression1ClosureType expr1;
229 Expression2ClosureType expr2;
238 template <
typename E1,
typename E2,
typename F>
254 template <
typename E1,
typename E2,
typename F>
259 typedef F FunctorType;
260 typedef E1 Expression1Type;
261 typedef E2 Expression2Type;
262 typedef const E1 Expression1ClosureType;
263 typedef typename E2::ConstClosureType Expression2ClosureType;
287 expr1(e1), expr2(e2) {}
295 return expr2.getSize1();
304 return expr2.getSize2();
313 return expr2.getSize3();
325 return FunctorType::apply(expr1, expr2(i, j, k));
329 Expression1ClosureType expr1;
330 Expression2ClosureType expr2;
339 template <
typename E1,
typename E2,
typename F>
355 template <
typename E1,
typename E2,
typename F>
360 typedef F FunctorType;
361 typedef E1 Expression1Type;
362 typedef E2 Expression2Type;
363 typedef typename E1::ConstClosureType Expression1ClosureType;
364 typedef const E2 Expression2ClosureType;
388 expr1(e1), expr2(e2) {}
396 return expr1.getSize1();
405 return expr1.getSize2();
414 return expr1.getSize3();
426 return FunctorType::apply(expr1(i, j, k), expr2);
430 Expression1ClosureType expr1;
431 Expression2ClosureType expr2;
440 template <
typename E1,
typename E2,
typename F>
456 template <
typename E>
462 return ExpressionType(e());
471 template <
typename E>
487 template <
typename E1,
typename E2>
488 typename GridBinary1Traits<E1, E2, ScalarAddition<typename E1::ValueType, typename E2::ValueType> >::ResultType
494 return ExpressionType(e1(), e2());
505 template <
typename E1,
typename E2>
506 typename GridBinary1Traits<E1, E2, ScalarSubtraction<typename E1::ValueType, typename E2::ValueType> >::ResultType
512 return ExpressionType(e1(), e2());
523 template <
typename E,
typename T>
524 typename std::enable_if<IsScalar<T>::value,
typename Scalar2GridBinaryTraits<E, T, ScalarMultiplication<typename E::ValueType, T> >::ResultType>::type
530 return ExpressionType(e(), t);
541 template <
typename T,
typename E>
542 typename std::enable_if<IsScalar<T>::value,
typename Scalar1GridBinaryTraits<T, E, ScalarMultiplication<T, typename E::ValueType> >::ResultType>::type
548 return ExpressionType(t, e());
559 template <
typename E,
typename T>
560 typename std::enable_if<IsScalar<T>::value,
typename Scalar2GridBinaryTraits<E, T, ScalarDivision<typename E::ValueType, T> >::ResultType>::type
566 return ExpressionType(e(), t);
577 template <
typename E1,
typename E2>
592 template <
typename E1,
typename E2>
609 template <
typename E1,
typename E2,
typename T>
622 template <
typename E>
623 typename GridUnaryTraits<E, ScalarConjugation<typename E::ValueType> >::ResultType
628 return ExpressionType(e());
637 template <
typename E>
638 typename GridUnaryTraits<E, ScalarConjugation<typename E::ValueType> >::ResultType
643 return ExpressionType(e());
652 template <
typename E>
653 typename GridUnaryTraits<E, ScalarReal<typename E::ValueType> >::ResultType
658 return ExpressionType(e());
667 template <
typename E>
668 typename GridUnaryTraits<E, ScalarImaginary<typename E::ValueType> >::ResultType
673 return ExpressionType(e());
684 template <
typename E1,
typename E2>
685 typename GridBinary1Traits<E1, E2, ScalarDivision<typename E1::ValueType, typename E2::ValueType> >::ResultType
691 return ExpressionType(e1(), e2());
702 template <
typename E1,
typename E2>
703 typename GridBinary1Traits<E1, E2, ScalarMultiplication<typename E1::ValueType, typename E2::ValueType> >::ResultType
709 return ExpressionType(e1(), e2());
718 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 (made available to expression-template machinery).
Definition: Expression.hpp:47
Expression-template node combining two grid expressions E1 and E2 element-wise via the binary functor...
Definition: GridExpression.hpp:152
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:163
CommonType< typename E1::SizeType, typename E2::SizeType >::Type SizeType
The common size type of the two wrapped expressions.
Definition: GridExpression.hpp:173
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:222
GridBinary1(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression-template node wrapping e1 and e2.
Definition: GridExpression.hpp:182
SizeType getSize1() const
Returns the size along the first dimension after verifying that both wrapped expressions agree on it.
Definition: GridExpression.hpp:190
const ValueType ConstReference
Constant reference type to an element value.
Definition: GridExpression.hpp:165
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:171
CommonType< typename E1::DifferenceType, typename E2::DifferenceType >::Type DifferenceType
The common signed difference type of the two wrapped expressions.
Definition: GridExpression.hpp:175
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:169
SizeType getSize3() const
Returns the size along the third dimension after verifying that both wrapped expressions agree on it.
Definition: GridExpression.hpp:210
const ValueType Reference
Mutable reference type (degrades to const for expression-template results).
Definition: GridExpression.hpp:167
SizeType getSize2() const
Returns the size along the second dimension after verifying that both wrapped expressions agree on it...
Definition: GridExpression.hpp:200
CRTP base class for all grid expression types.
Definition: Expression.hpp:180
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:75
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:99
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:71
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:90
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:108
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:73
E::DifferenceType DifferenceType
The signed difference type inherited from the wrapped expression.
Definition: GridExpression.hpp:77
GridUnary(const ExpressionType &e)
Constructs the expression-template node wrapping e.
Definition: GridExpression.hpp:83
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:120
const ValueType ConstReference
Constant reference type to an element value.
Definition: GridExpression.hpp:67
const ValueType Reference
Mutable reference type (degrades to const for expression-template results).
Definition: GridExpression.hpp:69
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:65
Expression-template node combining a scalar E1 (lhs) and a grid expression E2 (rhs) element-wise via ...
Definition: GridExpression.hpp:256
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:302
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:273
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:267
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:311
Scalar1GridBinary(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression-template node combining the scalar e1 and the grid expression e2.
Definition: GridExpression.hpp:286
E2::DifferenceType DifferenceType
The signed difference type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:279
const ValueType ConstReference
Constant reference type to an element value.
Definition: GridExpression.hpp:269
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:323
E2::SizeType SizeType
The size type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:277
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:293
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:275
const ValueType Reference
Mutable reference type (degrades to const for expression-template results).
Definition: GridExpression.hpp:271
Expression-template node combining a grid expression E1 (lhs) and a scalar E2 (rhs) element-wise via ...
Definition: GridExpression.hpp:357
E1::SizeType SizeType
The size type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:378
const ValueType Reference
Mutable reference type (degrades to const for expression-template results).
Definition: GridExpression.hpp:372
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:424
SizeType getSize2() const
Returns the size of the wrapped grid expression along the second dimension.
Definition: GridExpression.hpp:403
const SelfType ConstClosureType
Constant closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:374
SizeType getSize3() const
Returns the size of the wrapped grid expression along the third dimension.
Definition: GridExpression.hpp:412
SizeType getSize1() const
Returns the size of the wrapped grid expression along the first dimension.
Definition: GridExpression.hpp:394
Scalar2GridBinary(const Expression1Type &e1, const Expression2Type &e2)
Constructs the expression-template node combining the grid expression e1 and the scalar e2.
Definition: GridExpression.hpp:387
SelfType ClosureType
Closure type used when this expression appears inside another expression.
Definition: GridExpression.hpp:376
F::ResultType ValueType
The element value type of the expression (the functor's result type).
Definition: GridExpression.hpp:368
const ValueType ConstReference
Constant reference type to an element value.
Definition: GridExpression.hpp:370
E1::DifferenceType DifferenceType
The signed difference type inherited from the wrapped grid expression.
Definition: GridExpression.hpp:380
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:704
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:639
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:624
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:611
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:561
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:654
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:594
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:579
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:525
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:686
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:669
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:458
GridElementSum< E >::ResultType sum(const GridExpression< E > &e)
Returns the sum of all elements of the grid expression e.
Definition: GridExpression.hpp:720
const E & operator+(const GridExpression< E > &e)
Returns the grid expression e unchanged (unary +).
Definition: GridExpression.hpp:474
The namespace of the Chemical Data Processing Library.
std::common_type< T1, T2 >::type Type
The common type.
Definition: CommonType.hpp:49
Traits selecting the expression-template node and its result type for the Math::GridBinary1 instantia...
Definition: GridExpression.hpp:240
GridBinary1< E1, E2, F > ExpressionType
The expression-template node type.
Definition: GridExpression.hpp:243
ExpressionType ResultType
The expression-template result type returned by free-function operators.
Definition: GridExpression.hpp:245
GridScalarUnaryFunctor< G >::ResultType ResultType
Definition: Functional.hpp:2627
static ResultType apply(const GridExpression< G > &e)
Returns the cell sum of e.
Definition: Functional.hpp:2634
static ResultType apply(const GridExpression< G1 > &e1, const GridExpression< G2 > &e2)
Tells whether e1 and e2 have the same dimensions and equal cell values.
Definition: Functional.hpp:2519
GridBooleanBinaryFunctor< G1, G2 >::ResultType ResultType
Definition: Functional.hpp:2511
Scalar3GridBooleanTernaryFunctor< G1, G2, T >::ResultType ResultType
Definition: Functional.hpp:2572
static ResultType apply(const GridExpression< G1 > &e1, const GridExpression< G2 > &e2, Argument3Type epsilon)
Tells whether e1 and e2 agree cell-wise within the absolute tolerance epsilon.
Definition: Functional.hpp:2582
Traits selecting the expression-template node and its result type for the Math::GridUnary instantiati...
Definition: GridExpression.hpp:136
ExpressionType ResultType
The expression-template result type returned by free-function operators.
Definition: GridExpression.hpp:141
GridUnary< E, F > ExpressionType
The expression-template node type.
Definition: GridExpression.hpp:139
Traits selecting the expression-template node and its result type for the Math::Scalar1GridBinary ins...
Definition: GridExpression.hpp:341
ExpressionType ResultType
The expression-template result type returned by free-function operators.
Definition: GridExpression.hpp:346
Scalar1GridBinary< E1, E2, F > ExpressionType
The expression-template node type.
Definition: GridExpression.hpp:344
Traits selecting the expression-template node and its result type for the Math::Scalar2GridBinary ins...
Definition: GridExpression.hpp:442
ExpressionType ResultType
The expression-template result type returned by free-function operators.
Definition: GridExpression.hpp:447
Scalar2GridBinary< E1, E2, F > ExpressionType
The expression-template node type.
Definition: GridExpression.hpp:445
Scalar binary addition functor: apply(t1, t2) returns t1 + t2.
Definition: Functional.hpp:344
Scalar binary division functor: apply(t1, t2) returns t1 / t2.
Definition: Functional.hpp:419
Scalar binary multiplication functor: apply(t1, t2) returns t1 * t2.
Definition: Functional.hpp:394
Scalar binary subtraction functor: apply(t1, t2) returns t1 - t2.
Definition: Functional.hpp:369