下面我賽格故障因某種原因與編譯後:爲什麼下面的段錯誤?
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.