下面我赛格故障因某种原因与编译后:为什么下面的段错误?
g++ 1.cpp -I/path_to_eigen/eigen -std=c++0x
它应该做同样长度的等级1的两个张量之间的点积(并因此给1级的张量维度1)。
#include <Eigen/Core>
#include <unsupported/Eigen/CXX11/Tensor>
#include <iostream>
#include <array>
using namespace Eigen;
using namespace std;
int main()
{
Eigen::Tensor<double, 1> tensor(5);
Eigen::Tensor<double, 1> tensor2(5);
std::array<Eigen::IndexPair<int>, 1> product_dims = { IndexPair<int>(0, 0) };
Eigen::Tensor<double, 1> tensor3(1);
tensor3 = tensor.contract(tensor2, product_dims);
}
注意:如果我改变
tensor3 = tensor.contract(tensor2, product_dims);
到
auto v = tensor.contract(tensor2, product_dims);
然后再编译,并没有执行段错误,但我不知道v是什么类型的!我需要的是1级和尺寸1张量,这里指定的文件中:
https://github.com/RLovelett/eigen/blob/master/unsupported/Eigen/CXX11/src/Tensor/README.md
Similarly, the inner product of 2 1d tensors (through contractions) returns a 1d tensor.
编辑:下面给出的断言错误:
#include <Eigen/Core>
#include <unsupported/Eigen/CXX11/Tensor>
#include <iostream>
#include <array>
using namespace Eigen;
using namespace std;
int main()
{
Eigen::Tensor<double, 1> tensor(5);
Eigen::Tensor<double, 1> tensor2(5);
tensor.setConstant(1);
tensor2.setConstant(2);
tensor(1) = 1;
tensor2(1) = 2;
std::array<Eigen::IndexPair<int>, 1> product_dims = { IndexPair<int>(0, 0) };
Eigen::Tensor<double, 1> tensor3(1);
tensor3.setConstant(0);
auto v = tensor.contract(tensor2, product_dims);
cerr<<v<<endl;
tensor3 = tensor3 + v;
cerr<<tensor3<<endl;
}
哪里我现在使用tensor3 = tensor3 + v
而不是直接分配v tensor3。
的错误是:
Assertion failed: (dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())), function TensorEvaluator, file /Users/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h, line 355.