Skip to content

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

Open

Description

@AntoinePrv

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

Activity

  1. tdegeus commented on Sep 7, 2020

    @tdegeus
    Member

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

  2. AntoinePrv commented on Sep 8, 2020

    @AntoinePrv
    ContributorAuthor

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

  3. bjmiao commented on Mar 5, 2021

    @bjmiao

    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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions