![]() |
Eigen
5.0.1-dev+master
|
#include <Eigen/src/Core/util/XprHelper.h>
Determines whether the given binary operation of two numeric types is allowed and what the scalar return type is.
This class permits to control the scalar return type of any binary operation performed on two different scalar types through (partial) template specializations.
For instance, let U1, U2 and U3 be three user defined scalar types for which most operations between instances of U1 and U2 returns an U3. You can let Eigen knows that by defining:
You can then explicitly disable some particular operations to get more explicit error messages:
Or customize the return type for individual operation:
Custom multiplication can opt into commutative product traversals and reductions by adding IsCommutative to its product specialization:
This promises that reversing the operands preserves the value and result type for all valid inputs. For mixed scalar types, opt in for both ordered pairs. Missing metadata keeps custom multiplication on the conservative path; built-in arithmetic and standard complex types with arithmetic components are recognized automatically. Commutative traversals may reorder and reassociate products, changing floating-point rounding. Moving scalar factors in dense GEMM additionally requires commutativity within each input scalar type and within the result scalar type. Unannotated commutative custom scalars remain supported, but the conservative dense product path may use operand/result workspaces and ordered scalar GEMV evaluation. Declare this property to retain commutative optimizations; it must not be inferred merely from the existence of multiplication or conjugation.
By default, the following generic combinations are supported:
| ScalarA | ScalarB | BinaryOp | ReturnType | Note |
|---|---|---|---|---|
T | T | * | T | |
NumTraits<T>::Real | T | * | T | Only if NumTraits<T>::IsComplex |
T | NumTraits<T>::Real | * | T | Only if NumTraits<T>::IsComplex |