ublas icon indicating copy to clipboard operation
ublas copied to clipboard

Extension of lifetime within tensor expression templates for prvalues not guaranteed.

Open bassoy opened this issue 4 years ago • 1 comments

The current expression template implementation binds rvalue expressions to const references. In such cases the lifetime of designated temporary objects are automatically extended due to prvalue to xvalue expression conversion, see also temporary materialization and value categorization.

In case of prvalue expressions such as 42 or 42+13, it seems that such a lifetime extension dos not work such that tensor expressions are not correctly evaluated although tensor expression objects are never copied. We suspect that this bug results from the mandatory copy elision rules as the prvalue is passed without materialization.

Possible fixes are

  • to use value_type instead of const_reference in expressions such as in https://github.com/boostorg/ublas/blob/db29cdf76cdd4c3732164c99e9a22e9e02bf994f/include/boost/numeric/ublas/tensor/operators_arithmetic.hpp#L291
  • or to distinguish between tensor element and tensor types, see also this example

bassoy avatar Jun 04 '21 22:06 bassoy

Hello! If there is no ongoing work done on this issue by anyone, then can i try to fix this issue. Kindly assign it to me if no one is working on it.

Neel-Shah-29 avatar Feb 07 '22 20:02 Neel-Shah-29