Eigen で テンソル を扱おうとしていますが、reshape が使えません
C++の線形代数ライブラリーEigenで、"unsupported" に含まれるテンソル計算の部分を用いた際のエラーです。Eigen のドキュメント(の日本語訳版)に記載されていた
// サイズ1の新しい次元の導入によるテンソルのランクの増大 Tensor<float, 2> input(7, 11); array<int, 3> three_dims{{7, 11, 1}}; Tensor<float, 3> result = input.reshape(three_dims);
というという記述を真似してみたのですが、同じようなコードを書いているのにコンパイルが通りません。
なにかしら、include するべきものが足りていないのでしょうか?
また、"reshape"という関数を呼んでいるはずなのに、エラーメッセージでは"resize"という関数について問われています。それはどうしてでしょうか?
拙い説明ではありますが、適宜補足させていただきます。
よろしくお願いいたします。
発生しているエラーメッセージ
error: no matching member function for call to 'resize' (中略) candidate function not viable: requires 0 arguments, but 1 was provided void resize() ^ 1 error generated.
該当のソースコード
C++
1# include "unsupported/Eigen/CXX11/Tensor" 2using namespace Eigen; 3 4int main(){ 5 Tensor<float, 2> input(7, 11); 6 Eigen::array<int, 3> three_dims{{7, 11, 1}}; 7 Tensor<float, 3> result = input.reshape(three_dims); 8 return 0; 9}
補足情報(FW/ツールのバージョンなど)
以下がエラーメッセージの全文です。使っているPCはMacです。
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.
参考にしたコードは
「Eigen Tensors ドキュメント日本語訳」というサイトのものです。
https://qiita.com/suzuryo3893/items/1a79b4e9410f1803b4fa#geometrica
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。