Skip to content

xshared_expression is hard to use #2864

@matwey

Description

@matwey

Hello,

I am using xtensor 0.26.0 and the following code snipped adapted from the documentation:

template <class E, xt::enable_xexpression<E, bool> = true>
auto cos_plus_sin(E&& expr) {
        auto shared_expr = xt::make_xshared(std::forward<E>(expr));
        return xt::sin(shared_expr) + xt::cos(shared_expr);
}

None of the following three code snipped can be compiled successfully:

        const xt::xtensor<float, 1> x{1, 2, 4, 8};

        std::cout << x << std::endl;
        std::cout << cos_plus_sin(x) << std::endl;

complains about incompatible cv-qualifiers.

        xt::xtensor<float, 1> x{1, 2, 4, 8};

        std::cout << x << std::endl;
        std::cout << cos_plus_sin(x) << std::endl;

complains that cannot bind rvalue reference to lvalue.

        std::cout << xt::arange<float>(0, 4) << std::endl;
        std::cout << cos_plus_sin(xt::arange<float>(0, 4)) << std::endl;

complains as the following:

/usr/include/xtensor/core/xexpression.hpp:575:9: error: ‘class xt::xgenerator<xt::detail::arange_generator<float, float, float>, float, std::array<long unsigned int, 1> >’ has no member named ‘linear_begin’
  575 |         XTENSOR_FORWARD_METHOD(linear_begin)
      |         ^
/usr/include/xtensor/core/xexpression.hpp:576:9: error: ‘class xt::xgenerator<xt::detail::arange_generator<float, float, float>, float, std::array<long unsigned int, 1> >’ has no member named ‘linear_end’
  576 |         XTENSOR_FORWARD_METHOD(linear_end)
      |         ^

So, how the function from the documentation is supposed to be implemented for all this pretty valid scenarios?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions