Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eigen const TensorMap

Tags:

c++

eigen

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)

like image 211
user357269 Avatar asked Jul 24 '17 14:07

user357269


1 Answers

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.

like image 111
AlexM Avatar answered Nov 08 '22 07:11

AlexM