Couple questions about types and casting:
I have a function for the Math library that accepts two arguments. I want those arguments to be limited to:
int, double, double, double double, var var, var double, fvar<var> fvar<var>, fvar<var> double, fvar<fvar<var>> fvar<fvar<var>>, fvar<fvar<var>>
(all the autodiff types and mixes of types a Stan model might need to use)
What I ended up hacking together was:
typename boost::disable_if_c<is_vector_like<T1>::value || is_vector_like<T2>::value, myReturnType >::type
Is there any standard way of doing this? I saw
is_var_or_arithmetic (https://github.com/stan-dev/math/blob/develop/stan/math/prim/scal/meta/is_var_or_arithmetic.hpp) but when I tried it (if I didn’t mess anything up) that would accept Eigen::Matrixes (Eigen::Matrices? Eigen::Matrixs?..)
What I want to avoid are Eigen::Matrixes and std::vectors leaking in as my T1s and T2s.
The other thing I wanted to know is if I have Eigen::Matrices of things I want to cast to other things (so like
Eigen::Matrix<double> to Eigen::Matrix<var>).
I ended up using:
m.template cast<typename return_type<T1, T2>::type>()
m is being cast from one type to another. The issue I think with this is that it might allow casts in the wrong direction (vars to doubles instead of doubles to vars?). I’m honestly not 100% sure. Any preferred way to do this higher level cast? I assume internally Eigen’s cast is just using whatever copy constructors are available to it, but I’m not sure.