This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1274 - Tensor reduction operations can't be assigned to Tensors
Summary: Tensor reduction operations can't be assigned to Tensors
Status: DECISIONNEEDED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Tensor (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Unknown
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-12 16:47 UTC by Arnaud TANGUY
Modified: 2019-12-04 16:05 UTC (History)
5 users (show)



Attachments

Description Arnaud TANGUY 2016-08-12 16:47:51 UTC
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
Comment 1 Benoit Steiner 2016-08-12 16:58:13 UTC
Since you're using a full reduction, the result is a scalar. Scalars are now represented using 0 rank tensors. The following statement should work for you:
Eigen::Tensor<float, 0> b = a.sum();
Comment 2 Gael Guennebaud 2016-08-22 11:43:41 UTC
I see the doc has been fixed in rev. 3782cd1de9c4, but what about allowing assignment of tensors with different ranks but compatible runtime sizes? For instance, in Eigen/Core, it is fine to assign a Vector from/to a Matrix.
Comment 3 william.tambellini 2018-12-18 02:13:36 UTC
If that could allow to move forward on that one, I also vote to allow 'transfer' of data from tensor to tensor whatever the rankings as long as the size fits.
(I am anyway globally not super fan of Ranking to be a template param).
Comment 4 Nobody 2019-12-04 16:05:59 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1274.

Note You need to log in before you can comment on or make changes to this bug.