为什么会出现以下段故障
Why does the following segfault?
在使用
编译后,由于某种原因,下面的segg出现了错误: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同样,2维张量的内积(通过收缩)返回一个1d张量。
编辑:下面给出一个断言错误:
#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.
文档已经过时了。压缩结果的秩由以下公式给出:RankL + RankR - 2*CDims,其中RankL为第一个输入张量的秩,RankR为第二个输入张量的秩,CDims为压缩维数。
在您的示例中,结果的秩为0。你应该写Eigen::Tensor<double, 0> tensor3 = tensor.contract(tensor2, product_dims);
相关文章:
- Python & C-C++ 扩展模块案例段故障
- 中断;导致段故障
- 带指针的调用函数会导致段故障
- 由于变量范围导致的段故障
- 为什么通过shared_from_this()会导致段故障
- 简单的C++字符数组加密功能 - 段故障
- std::vector的函数push_back中的堰段故障
- 在openCV中将cvPoint[][]转换为cvPoint**时出现段故障
- 模板变量分配段故障11
- CIN 一个非常大的 int 数组,段故障 11
- C++段故障错误
- 段故障 -> 在标准::basic_ostream<字符中,标准::char_traits<char>
- C++中的二叉树段故障
- 调试执行工作正常,但正常的一段故障
- c++:几乎相同的输入,但第二次调用显示段故障
- 段故障。地址0x0不是堆叠的、恶意的或(最近)释放的
- 使用矢量引起的段故障
- 使用arm-linux- gnuabi -g++ -o时出现段故障,不使用-o也不会出现问题
- 为什么会出现以下段故障
- 在类文件和缓冲区中查找段故障