Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assigning a view values from another view #2748

Closed
hassanromhuda opened this issue Nov 23, 2023 · 2 comments
Closed

assigning a view values from another view #2748

hassanromhuda opened this issue Nov 23, 2023 · 2 comments

Comments

@hassanromhuda
Copy link

I'm expecting that the code below should work, but it doesn't compile.

int main(int argc, char** argv) {
  auto a = xt::arange(10);
  auto a_view = xt::reshape_view(a, {1, 5, 2});

  auto b_view = xt::view(a_view, xt::all(), xt::range(3, 5), xt::all());
  auto c_view = xt::view(a_view, xt::all(), xt::range(1, 3), xt::all());

  c_view = b_view;

  return 0;
}

The compilation error I'm getting:

examples/xtensor_main.cc:14:12:   required from here
bazel-out/k8-fastbuild/bin/external/xtensor/_virtual_includes/xtensor/xtensor/xstrided_view.hpp:478:16: error: no matching function for call to 'xt::xindexed_stepper<xt::xstrided_view<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, std::array<long unsigned int, 3>, xt::layout_type::dynamic, xt::detail::flat_adaptor_getter<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, xt::layout_type::row_major> >, false>::xindexed_stepper(xt::xstrided_view<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, std::array<long unsigned int, 3>, xt::layout_type::dynamic, xt::detail::flat_adaptor_getter<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, xt::layout_type::row_major> >*, xt::xstrided_view<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, std::array<long unsigned int, 3>, xt::layout_type::dynamic, xt::detail::flat_adaptor_getter<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, xt::layout_type::row_major> >::container_iterator, xt::xstrided_view<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, std::array<long unsigned int, 3>, xt::layout_type::dynamic, xt::detail::flat_adaptor_getter<xt::xgenerator<xt::detail::arange_generator<int, int, int>, int, std::array<long unsigned int, 1> >&, xt::layout_type::row_major> >::size_type&)'
  478 |         return stepper(this, data_xbegin(), offset);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Any ideas or temporary workarounds?

@JohanMabille
Copy link
Member

As stated in https://xtensor.readthedocs.io/en/latest/builder.html#expression-builders, arange returns a lazy expression, holding no value. Therefore, you cannot assign to it, or to view on it, you need to evaluate it first:

auto avalue = xt::eval(a_view).
auto b_view = xt::view(avalue, xt::all(), xt::range(3, 5), xt::all());
auto c_view = xt::view(avalue, xt::all(), xt::range(1, 3), xt::all());

Copy link
Contributor

github-actions bot commented Jan 2, 2024

This issue is stale because it has been open for 30 days with no activity.
It will be automatically closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants