Consider the following (working) snippet:
Eigen::ArrayXd x (8);
x << 1, 2, 3, 4, 5, 6, 7, 8;
Eigen::TensorMap<Eigen::Tensor<double, 2>> y (x.data(), 2, 4);
This is also works:
const Eigen::ArrayXd const_x = x;
const Eigen::Map<const Eigen::ArrayXXd> z (const_x.data(), 2, 4);
I'm trying to figure out why I can't do this though:
const Eigen::TensorMap<const Eigen::Tensor<double, 2>> const_y (const_x.data(), 2, 4);
I'm using Eigen 3.3.3 (also tried 3.3.4)
You are trying to store a const tensor.
Error 2 error C2664: 'Eigen::TensorMap<PlainObjectType>::TensorMap(double *,__w64 int,__w64 int)' : impossible to convert parameter 1 from 'const double *' to 'double *'
I think you meant to have a tensor on a const double (as mentioned by @CarlodelMundo too).
const Eigen::TensorMap<Eigen::Tensor<const double, 2>> const_y(const_x.data(), 2, 4);
In https://eigen.tuxfamily.org/dox/unsupported/TensorMap_8h_source.html it seems that there is no constructor that takes a const as a parameter 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With