8

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)

user357269
  • 1,835
  • 14
  • 40
  • Could you add your compilation error message? – Tobias Ribizel Jul 26 '17 at 16:26
  • 4
    Try "const Eigen::TensorMap> const_y (const_x.data(), 2, 4);". Note the "const double" inside Eigen::Tensor. –  Jul 26 '17 at 20:01
  • 1
    Did you try the suggestion by @CarlodelMundo ? It seems to work, even though it is not standard Eigen-syntax -- but the Tensor-module as a whole does not follow several Eigen standards (starting from naming it `TensorMap`, instead of `Map` and `Map`). – chtz Jul 30 '17 at 14:21

1 Answers1

6

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.

AlexM
  • 146
  • 5
  • I'm aware of the fix mentioned by @CarlodelMundo, but it doesn't feel Eigen-esque (as pointed out by @chtz) – user357269 Jul 31 '17 at 18:31