Tensor reduction operations can't be assigned to Tensors
Submitted by Arnaud TANGUY
Assigned to Nobody
Link to original bugzilla bug (#1274)
Version: 3.3 (current stable)
Description
The Tensor module README proposes the following reduction example:
Eigen::Tensor<float, 3> a(2, 3, 4);
a.setValues({{{0.0f, 1.0f, 2.0f, 3.0f},
{7.0f, 6.0f, 5.0f, 4.0f},
{8.0f, 9.0f, 10.0f, 11.0f}},
{{12.0f, 13.0f, 14.0f, 15.0f},
{19.0f, 18.0f, 17.0f, 16.0f},
{20.0f, 21.0f, 22.0f, 23.0f}}});
// Reduce along all dimensions using the sum() operator.
Eigen::Tensor<float, 1> b = a.sum();
cout << "b" << endl << b << endl << endl;
Running this code, with latest Eigen (git), on both GCC 4.8.5 and Clang-3.9 results in the following assertion error:
/usr/local/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:122: bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<double, 1, 0, long>, const Eigen::TensorReductionOp<Eigen::internal::ProdReducer<double>, const Eigen::DimensionList<long, 3>, const Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_difference_op<double, double>, const Eigen::Tensor<double, 3, 0, long>, const Eigen::Tensor<double, 3, 0, long> > > > >, Eigen::DefaultDevice>::evalSubExprsIfNeeded(Scalar *) [Derived = const Eigen::TensorAssignOp<Eigen::Tensor<double, 1, 0, long>, const Eigen::TensorReductionOp<Eigen::internal::ProdReducer<double>, const Eigen::DimensionList<long, 3>, const Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_difference_op<double, double>, const Eigen::Tensor<double, 3, 0, long>, const Eigen::Tensor<double, 3, 0, long> > > > >, Device = Eigen::DefaultDevice]: Assertion `dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())' failed.
unknown location(0): fatal error in "test_read_tensor": signal: SIGABRT (application abort requested)
If it's of any help here is what gdb has to say about the dimensions:
(gdb) print m_leftImpl.dimensions()
$3 = (const Eigen::TensorEvaluator<Eigen::Tensor<double, 1, 0, long>, Eigen::DefaultDevice>::Dimensions &) @0x7fffffffc2e8: {<std::array<long, 1>> = {_M_elems = {0}}, static count = 1}
(gdb) print m_rightImpl.dimensions()
$4 = (const Eigen::TensorEvaluator<Eigen::TensorReductionOp<Eigen::internal::ProdReducer<double>, Eigen::DimensionList<long, 3> const, Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_difference_op<double, double>, Eigen::Tensor<double, 3, 0, long> const, Eigen::Tensor<double, 3, 0, long> const> const> const> const, Eigen::DefaultDevice>::Dimensions &) @0x7fffffffc2fb: {<Eigen::internal::numeric_list<long>> = {static count = 0}, static total_size = 1}
The same error occurs for all of the reduction operations (prod...).
Not trying to assign the result to a tensor, and printing it out works fine:
cout << a.sum() << endl;
is perfectly fine and gives the expected result.
Best regards,
Arnaud
Edited by Christoph Hertzberg