Be more flexible regarding mixing types
@ggael
Submitted by Gael GuennebaudAssigned to Nobody
Link to original bugzilla bug (#279)
Version: 3.0
Description
Our ability to allow mixed scalar types in operations is currently very limited, basically we only allow complex<real> * real including scalar multiples, coeff-wise product and matrix product.
However, it might be really desirable to allow, e.g., to mix an autodiff type with a standard scalar type. Casting a constant matrix to a matrix of autodiff variable is a waste of memory and computation.
We should also extend the mixing of types to other operations than products. It makes perfect sens to add complex to real, or substract scalars and autodiff variables.
All this information could be provide through a unique:
template<A,B> struct PromoteType { typedef XXX ResulType; };
By default, when A!=B, this class would be empty and we could detect that to trigger a static assertion.
So this is more like a generalization of our current scalar_product_traits and generalization of our current static assertions in BinaryOp.
The main questions are:
- is it ok to assume the result scalar type does not depend on the operation?
- is ok to assume that if mixing two type for a given operation is allowed, then it is allowed for any binary op? In the worst case, if the underlying binary scalar operation is not defined, then the user will get a compilation failure which should still be pretty clear, like:
cannot find atan2(double,my_custom_type)
see also the "overriding scalar_X_op for auto-dif" thread on the ML.