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

Possible to use 1D and (N-1)D slice iteration with xt::xtensor? #2116

Open
AntoinePrv opened this issue Aug 19, 2020 · 3 comments · May be fixed by #2747
Open

Possible to use 1D and (N-1)D slice iteration with xt::xtensor? #2116

AntoinePrv opened this issue Aug 19, 2020 · 3 comments · May be fixed by #2747
Labels

Comments

@AntoinePrv
Copy link
Contributor

Description of the problem

I've tried using the examples of 1-D slice iteration and (N-1)-dimensional iteration by replacing xt::xarray<int> with xt::xtensor<int, 3> and found unexpected outcomes:

  • 1-D slice iteration (xt::axis_slice_begin1): compiles and run without errors, but all slice are empty (prints {}). Changing the axis does not change the outcome
  • (N-1)-dimensional iteration: does not compile, fails with
    xtensor/xaxis_iterator.hpp:112:24: error: no matching constructor for
      initialization of 'shape_type' (aka 'array<unsigned long, 3UL>')
            shape_type shape(e_shape.size() - 1);
    

Desired outcome

Similar iteration as xt::xarray. Eventually with compile time check on the axis (given that shape is known).

Alternative considered

Casting back and forth to an xt::xarray. I am unsure of the performance impacts, if any.

System information

This is running xtensor 0.21.5 from conda-forge and compiling on MacOs with AppleClang 11.0.3

@tdegeus
Copy link
Member

tdegeus commented Sep 7, 2020

That sounds like a bug. Was the only thing you changed with respect to the example the type of the array?

@AntoinePrv
Copy link
Contributor Author

Yes, I recall making a proper test where I only changed the type of the array.

@bjmiao
Copy link

bjmiao commented Mar 5, 2021

hi is there any update on this issue?
A similar thing is when I apply axis_end(xt, 0) to an xtensor, the compiler will complain:

/scratch/user/include/xtensor/xaxis_iterator.hpp: In instantiation of ‘auto xt::detail::derive_xstrided_view(CT&&, typename std::decay<_Tp>::type::size_type, typename std::decay<_Tp>::type::size_type) [with CT = const xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 3, (xt::layout_type)1, xt::xtensor_expression_tag>&; typename std::decay<_Tp>::type::size_type = long unsigned int]’:
/scratch/user/include/xtensor/xaxis_iterator.hpp:172:49:   required from ‘xt::xaxis_iterator<CT>::xaxis_iterator(CTA&&, xt::xaxis_iterator<CT>::size_type, xt::xaxis_iterator<CT>::size_type, xt::xaxis_iterator<CT>::size_type) [with CTA = const xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 3, (xt::layout_type)1, xt::xtensor_expression_tag>&; CT = const xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 3, (xt::layout_type)1, xt::xtensor_expression_tag>&; xt::xaxis_iterator<CT>::size_type = long unsigned int]’
/scratch/user/include/xtensor/xaxis_iterator.hpp:329:16:   required from ‘auto xt::axis_end(E&&, typename std::decay<_Tp>::type::size_type) [with E = const xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 3, (xt::layout_type)1, xt::xtensor_expression_tag>&; typename std::decay<_Tp>::type::size_type = long unsigned int]’
xtensor.cpp:66:34:   required from here
/scratch/user/include/xtensor/xaxis_iterator.hpp:111:24: error: no matching function for call to ‘std::array<long unsigned int, 3>::array(std::array<long unsigned int, 3>::size_type)’
             shape_type shape(e_shape.size() - 1);
                        ^~~~~
In file included from /usr/include/c++/8/tuple:39,
                 from /usr/include/c++/8/functional:54,
                 from /scratch/user/include/xtensor/xstrides.hpp:14,
                 from /scratch/user/include/xtensor/xaccessible.hpp:14,
                 from /scratch/user/include/xtensor.hpp:4,
                 from xtensor.cpp:6:
/usr/include/c++/8/array:94:12: note: candidate: ‘std::array<long unsigned int, 3>::array()’
     struct array
            ^~~~~
/usr/include/c++/8/array:94:12: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/8/array:94:12: note: candidate: ‘constexpr std::array<long unsigned int, 3>::array(const std::array<long unsigned int, 3>&)’
/usr/include/c++/8/array:94:12: note:   no known conversion for argument 1 from ‘std::array<long unsigned int, 3>::size_type’ {aka ‘long unsigned int’} to ‘const std::array<long unsigned int, 3>&’
/usr/include/c++/8/array:94:12: note: candidate: ‘constexpr std::array<long unsigned int, 3>::array(std::array<long unsigned int, 3>&&)’
/usr/include/c++/8/array:94:12: note:   no known conversion for argument 1 from ‘std::array<long unsigned int, 3>::size_type’ {aka ‘long unsigned int’} to ‘std::array<long unsigned int, 3>&&’
In file included from /scratch/user/include/xtensor.hpp:9,
                 from xtensor.cpp:6:
/scratch/user/include/xtensor/xaxis_iterator.hpp:116:26: error: no matching function for call to ‘std::array<long int, 3>::array(std::array<long int, 3>::size_type)’
             strides_type strides(e_strides.size() - 1);
                          ^~~~~~~
In file included from /usr/include/c++/8/tuple:39,
                 from /usr/include/c++/8/functional:54,
                 from /scratch/user/include/xtensor/xstrides.hpp:14,
                 from /scratch/user/include/xtensor/xaccessible.hpp:14,
                 from /scratch/user/include/xtensor.hpp:4,
                 from xtensor.cpp:6:
/usr/include/c++/8/array:94:12: note: candidate: ‘std::array<long int, 3>::array()’
     struct array
            ^~~~~
/usr/include/c++/8/array:94:12: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/8/array:94:12: note: candidate: ‘constexpr std::array<long int, 3>::array(const std::array<long int, 3>&)’
/usr/include/c++/8/array:94:12: note:   no known conversion for argument 1 from ‘std::array<long int, 3>::size_type’ {aka ‘long unsigned int’} to ‘const std::array<long int, 3>&’
/usr/include/c++/8/array:94:12: note: candidate: ‘constexpr std::array<long int, 3>::array(std::array<long int, 3>&&)’
/usr/include/c++/8/array:94:12: note:   no known conversion for argument 1 from ‘std::array<long int, 3>::size_type’ {aka ‘long unsigned int’} to ‘std::array<long int, 3>&&’
make: *** [Makefile:10: xtensor] Error 1

I guess this is somehow related to this issue

Stef-Sijben added a commit to Stef-Sijben/xtensor that referenced this issue Nov 22, 2023
An `xaxis_slice_iterator` always refers to a 1d view, so just use an
array of size 1 for the shape and stride.
Another type would probably be more optimal in case of compile-time
fixed size (e.g. `xtensor_fixed`), but at least this is correct.

Always use runtime dimensionality `xaxis_iterator` shape and strides.
Other types would probably be more optimal in case of compile-time
fixed dimension and/or size (e.g. `xtensor`, `xtensor_fixed`), but at
least this is correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants