Error when using the tensor calculation part of "unsupported" in C++'s linear algebra library Eigen.
https://qiita.com/suzuryo3893/items/1a79b4e9410f1803b4fa#geometrica...
// Increased tensor rank with introduction of a new dimension of size 1
Tensor<float,2>input(7,11);
array<int,3>three_dims {{7,11,1}};
Tensor<float,3>result=input.reshape(three_dims);
In an attempt to copy the description, I wrote the source code as follows:
#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;
}
My PC is mac (Mojave) and I compiled it as follows:
g++-std=c++14-I(path to Eigen) eigen_practice.cpp-oeigen_practice
However, I get the following error:
error:
no matching member function for call to 'resize'
(omitted)
candidate function not visible:requires 0 arguments, but 1 was provided
void resize()
^
1 error generated.
Is there something missing to include?
Also, why is the function "resize" asked when it should be called "reshape"?
This is a poor explanation, but I will supplement it accordingly.
Thank you for your cooperation.
Here is the full error statement:
Infile included from eigen_practice.cpp:12:
File included from /Users/yamamoto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/Tensor: 145:
/Users/yamamoto/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,Default...)
^~~~~~
eigen_practice.cpp:63:28:note:instantiation of function template
specialization'Eigen::Tensor<float,3,0,
long>::Tensor<Eigen::TensorReshapingOp<conststd::__1::array<int,3>,
Eigen::Tensor<float,2,0,long>>'requested here
Tensor<float,3>result=input.reshape(three_dims);
^
/Users/yamamoto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:423:10:note:
candidate function template not visible: no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<conststd::__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...otherDimension)
^
/Users/yamamoto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:432:28:note:
candidate function not visible —no known conversion from
'array<int,[...]>'to' const array<long,[...]>' for 1st argument
EIGEN_DEVICE_FUNC void resize (constray <Index,NumIndices > & dimensions)
^
/Users/yamamoto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:450:28:note:
candidate function not visible —no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<conststd::__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/yamamoto/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/yamamoto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:459:10:note:
candidate function not visible:requires 0 arguments, but 1 was provided
void resize()
^
1 error generated.
I'm sorry, but I was told that there is an answer at the following URL.
https://stackoverflow.com/questions/56985731/how-to-reshape-a-tensor-in-eigen3
The array that specifies the shape of the tensor must be an index of the tensor, not an integer type.
So
Eigen::array<int,3>three_dims {{7,11,1}};
Not
Eigen::array<Eigen::Index, 3>three_dims {{7,11,1}}};
It seemed necessary to write
© 2024 OneMinuteCode. All rights reserved.