You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
bassoy
changed the title
Bug in Tensor Expression Templates
Extension of lifetime within tensor expression templates for prvalues not guaranteed.
Sep 6, 2021
Fix for issue #125.
The current implementation does not take into account the prvalue that
creates an issue while storing it. The prvalue is destroyed after the
end of its scope, and if you try access it, you are entering into
undefined land of C++.
To solve this issue, we employ the trait `std::is_lvalue_reference` to
determine if need to extend the lifetime or not. If extension is needed,
we store the value with the help of universal forwarding. Otherwise, we
extend lifetime using `const &`.
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
toxvalue
expression conversion, see also temporary materialization and value categorization.In case of
prvalue
expressions such as42
or42+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 theprvalue
is passed without materialization.Possible fixes are
value_type
instead ofconst_reference
in expressions such as inublas/include/boost/numeric/ublas/tensor/operators_arithmetic.hpp
Line 291 in db29cdf
The text was updated successfully, but these errors were encountered: