为什么下面的特征示例无法编译?
Why the following Eigen example won't compile?
我正在尝试编译这个MWE,但得到很多错误:
#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);
}
这实际上是一个本征张量的例子:
https://bitbucket.org/eigen/eigen/src/default/unsupported/Eigen/CXX11/src/Tensor/README.md?fileviewer=file-view-default关于收缩,但我认为它有一些错误,没有正确编译,我试图修复。
错误:
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.
这个例子需要c++11,所以你需要在编译器上启用它,例如在gcc 6或clang之前使用-std=c++11
和gcc。
相关文章:
- 编译时检查特征专用化是否具有唯一 ID
- 标量类型的特征模板无法编译固定大小的子矩阵操作
- 使用 C++17 编译特征需要_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING定义
- 编译特征程序时出错:错误:'seq'不是'Eigen'的成员
- 特征张量编译误差
- NVCC编译了特征库,并在运行时失败的结构中的MatrixxD大小
- 特征:返回对具有编译时间尺寸检查的矩阵块的引用
- 特征部分PivLU示例无法编译
- 在编译时检查特征类型保存的数据在内存中是否连续
- 如何使用特征访问编译时const值
- C++ 模板特征 -- 编译时不包含标头
- 为什么编译(c ++ 特征)"错误 C2659:'=':函数作为左操作数"后会出现错误?
- C :多态容器 /迭代器与编译时间概念 /特征
- 编译时解决方案以检测特征对象没有eval()成员
- 在 boost::type_traits::条件中使用类型特征的编译错误
- 用nvcc(CUDA)编译特征库
- 编译特征C++QT
- 编译错误 将模板编程与特征C++库结合使用
- 无法使用特征库进行编译
- NVIDIA NVCC 在使用模板特征类型时更改编译时间常量