Evaluating Eigen::KroneckerProduct-matrix-multiplication fails to compile for custom types
I'm trying to use KroneckerProduct with custom autodiff types. All of the ones I've tried (autodiff.github.io, TinyAD, stan::math) fail on this minimal example:
#include <unsupported/Eigen/KroneckerProduct>
#include <complex>
#include <TinyAD/Scalar.hh>
#include <stan/math.hpp>
#include <autodiff/forward/dual.hpp>
int main()
{
const int N = 4;
// These work.
//using Scalar = double;
//using Scalar = std::complex<double>;
// These fail to compile for N≥4
//using Scalar = stan::math::var;
//using Scalar = autodiff::detail::Dual<double, double>;
using Scalar = TinyAD::Scalar<1,double,true>;
Eigen::Matrix<Scalar,N,N> A;
Eigen::Matrix<double,N*2,1> B;
auto K = Eigen::kroneckerProduct(A,Eigen::Matrix2d::Identity());
(K*B).eval();
}
I'm guessing that this means that those types aren't doing their traits correctly? But maybe there's something to fix on the Eigen end if they're hitting the same issue (or at least improved documentation?).
(Stan math still fails even when I patch a fix for #2852)