Why does the following fail with Eigen?

删除回忆录丶 提交于 2019-12-11 04:47:44

问题


I have the following piece of code, which I hoped would do outer product between tensor2 and tensor3 and then add the result to tensor, however I get a dimension mismatch issue:

#include <Eigen/Core>
#include <unsupported/Eigen/CXX11/Tensor>
#include <iostream>

using namespace Eigen;
using namespace std;


int main()
{
        Eigen::Tensor<double, 2> tensor(1,9);
        Eigen::Tensor<double, 1> tensor2(1);
        Eigen::Tensor<double, 1> tensor3(9);

        tensor = tensor + tensor2 * tensor3;
}

The error is an assertion error (the code compiles) and it is coming on the line tensor = tensor + tensor2 * tensor. Actually, even auto v = tensor2*tensor3 doesn't work.

TensorEvaluator.h:328: Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::TensorEvaluator(const XprType&, const Device&) [with BinaryOp = Eigen::internal::scalar_product_op<double, double>; LeftArgType = const Eigen::Tensor<double, 1>; RightArgType = const Eigen::Tensor<double, 1>; Device = Eigen::DefaultDevice; Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::XprType = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Tensor<double, 1>, const Eigen::Tensor<double, 1> >]: Assertion `dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())' failed.

来源:https://stackoverflow.com/questions/41098944/why-does-the-following-fail-with-eigen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!