1
Ich versuche, diese MWE zu kompilieren, aber viele Fehler bekommen:Warum wird das folgende Eigen-Beispiel nicht kompiliert?
#include <eigen/Eigen/Core>
#include <eigen/unsupported/Eigen/CXX11/Tensor>
#include <array>
using namespace Eigen;
int main()
{
// Create 2 matrices using tensors of rank 2
Eigen::Tensor<int, 2> a(2, 3);
a.setValues({{1, 2, 3}, {6, 5, 4}});
Eigen::Tensor<int, 2> b(3, 2);
a.setValues({{1, 2}, {4, 5}, {5, 6}});
// Compute the traditional matrix product
array<IndexPair<int>, 1> product_dims = { IndexPair<int>(1, 0) };
Eigen::Tensor<int, 2> AB = a.contract(b, product_dims);
// Compute the product of the transpose of the matrices
array<IndexPair<int>, 1> transpose_product_dims = { IndexPair<int>(0, 1) };
Eigen::Tensor<int, 2> AtBt = a.contract(b, transpose_product_dims);
}
Dies ist tatsächlich von einem Beispiel für Eigen Tensoren:
über Kontraktion, aber ich denke, es hat einige Fehler und wurde nicht richtig kompiliert, was ich versuchte zu beheben.
Fehler:
1.cc:11:3: error: no member named 'setValues' in 'Eigen::Tensor<int, 2, 0, long>'
a.setValues({{1, 2, 3}, {6, 5, 4}});
~^
1.cc:11:13: error: expected expression
a.setValues({{1, 2, 3}, {6, 5, 4}});
^
1.cc:13:3: error: no member named 'setValues' in 'Eigen::Tensor<int, 2, 0, long>'
a.setValues({{1, 2}, {4, 5}, {5, 6}});
~^
1.cc:13:13: error: expected expression
a.setValues({{1, 2}, {4, 5}, {5, 6}});
^
1.cc:16:26: error: non-aggregate type 'array<IndexPair<int>, 1>' cannot be initialized with an initializer list
array<IndexPair<int>, 1> product_dims = { IndexPair<int>(1, 0) };
^ ~~~~~~~~~~~~~~~~~~~~~~~~
1.cc:20:26: error: non-aggregate type 'array<IndexPair<int>, 1>' cannot be initialized with an initializer list
array<IndexPair<int>, 1> transpose_product_dims = { IndexPair<int>(0, 1) };
^ ~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.
[ 'TensorBase :: setValues' wird durch die' EIGEN_HAS_VARIADIC_TEMPLATES' Makro bewacht] (https://eigen.tuxfamily.org/dox-devel/unsupported/TensorBase_8h_source.html#l00856). Definieren Sie dieses Makro? – Cornstalks
Nein. Ich bin nicht sicher, was es bedeutet? Ich werde nachsehen müssen. Aber ich mache mir mehr Sorgen, dass der Kontraktionsversuch nicht funktioniert, weniger bei setValues, die ich sowieso nicht verwenden möchte. – kloop
Fügen Sie '#define EIGEN_HAS_VARIADIC_TEMPLATES 1' vor Ihren Includes hinzu (oder übergeben Sie alternativ '-DEIGEN_HAS_VARIADIC_TEMPLATES = 1' an gcc/clang). – Cornstalks