1

I want to use "reshape()" fuction in Eigen unsupported tensor, but my source code cannot be compiled.

The compilation was done as follows.

g++ -std=c++14 -I (path to Eigen) eigen_practice.cpp -o eigen_practice

and here is my source code.

# include "unsupported/Eigen/CXX11/Tensor"
using namespace Eigen;

int main(){
 Tensor<float, 2> input(7, 11);
 Eigen::array<int, 3> three_dims{{7, 11, 1}};
 Tensor<float, 3> result = input.reshape(three_dims);
 return 0;
}

And here is the error messeage.

In file included from eigen_practice.cpp:12:
In file included from /Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/Tensor:145:
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:397:7: error: 
      no matching member function for call to 'resize'
      resize(TensorEvaluator<const Assign, DefaultDevice>(assign, Defaul...
      ^~~~~~
eigen_practice.cpp:63:28: note: in instantiation of function template
      specialization 'Eigen::Tensor<float, 3, 0,
      long>::Tensor<Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
      Eigen::Tensor<float, 2, 0, long> > >' requested here
        Tensor<float, 3> result = input.reshape(three_dims);
                                  ^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:423:10: note: 
      candidate function template not viable: no known conversion from 'const
      Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
      0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
      Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
      (aka 'const std::__1::array<int, 3>') to 'Eigen::Tensor<float, 3, 0,
      long>::Index' (aka 'long') for 1st argument
    void resize(Index firstDimension, IndexTypes... otherDimensions)
         ^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:432:28: note: 
      candidate function not viable: no known conversion from
      'array<int, [...]>' to 'const array<long, [...]>' for 1st argument
    EIGEN_DEVICE_FUNC void resize(const array<Index, NumIndices>& dimensions)
                           ^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:450:28: note: 
      candidate function not viable: no known conversion from 'const
      Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
      0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
      Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
      (aka 'const std::__1::array<int, 3>') to 'const
      DSizes<Eigen::Tensor<float, 3, 0, long>::Index, NumIndices>' (aka 'const
      DSizes<long, NumIndices>') for 1st argument
    EIGEN_DEVICE_FUNC void resize(const DSizes<Index, NumIndices>& dimensions) {
                           ^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:479:10: note: 
      candidate template ignored: could not match 'Sizes' against 'array'
    void resize(const Sizes<Indices...>& dimensions) {
         ^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:459:10: note: 
      candidate function not viable: requires 0 arguments, but 1 was provided
    void resize()
         ^
1 error generated.

This source code is just a copy of what is in the documentation. (https://eigen.tuxfamily.org/dox/unsupported/eigen_tensors.html)

So it should compile, but it doesn't.

How can I solve it?

And why the error message mentions about "resize()" function?

Hamcatu
  • 11
  • 1
  • 1
    Did you read the error messages the compiler gave you? It states very clearly what the problem is (`no known conversion from 'array' to 'const array' for 1st argument`). So yes, the problem is in the usage of the resize function. – tos-1 Jul 13 '19 at 08:20
  • 1
    @tos-1 To be fair, template error messages are very hard to read. It takes some concentration. – john Jul 13 '19 at 08:22
  • Essentially a duplicate of this: https://stackoverflow.com/questions/56985731/how-to-reshape-a-tensor-in-eigen3 (can't flag it, since the latter did not get any votes yet) – chtz Jul 15 '19 at 17:13
  • Thank you very much! This is what I need. And I'm sorry I asked for duplicate questions..... – Hamcatu Jul 16 '19 at 01:59
  • Possible duplicate of [How to reshape a tensor in Eigen3?](https://stackoverflow.com/questions/56985731/how-to-reshape-a-tensor-in-eigen3) – chtz Jul 16 '19 at 08:45
  • No problem regarding the duplicate. I actually considered answering this question and flagging the other, since your example is much more reduced to the actual problem. – chtz Jul 16 '19 at 08:47

0 Answers0