xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.37k stars 400 forks source link

xt::adapt of shape of xt::view bugs #2805

Open eugene-sanscartier opened 1 month ago

eugene-sanscartier commented 1 month ago

With this code:

    xt::xarray<double> A = xt::ones<double>({ 6, 4, 6, 8 });

    auto aa = xt::view(A, 0, xt::all());
    xt::adapt(aa.shape());

    auto bb = xt::view(A, 0, xt::all(), xt::all(), xt::all());
    xt::adapt(bb.shape());

    auto cc = xt::view(A, 0, xt::all(), xt::all(), 0);
    xt::adapt(cc.shape());

    return 0;

xt::adapt(aa.shape()) and xt::adapt(bb.shape()) gives errors at compilation.

xt::adapt(aa.shape()):

[build] In file included from /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xarray.hpp:20,
[build]                  from /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xadapt.hpp:20,
[build]                  from /home/eugene/Master/software/partn_c++/src/test_main.cpp:2:
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xcontainer.hpp: In instantiation of ‘struct xt::detail::allocator_type_impl<xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1> >’:
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xcontainer.hpp:57:11:   required by substitution of ‘template<class T> using xt::allocator_type_t = typename xt::detail::allocator_type_impl::type [with T = xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1>]’
[build]    57 |     using allocator_type_t = typename detail::allocator_type_impl<T>::type;
[build]       |           ^~~~~~~~~~~~~~~~
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xcontainer.hpp:80:15:   required from ‘class xt::xcontainer<xt::xtensor_adaptor<const xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1>&, 1, xt::layout_type::row_major, xt::xtensor_expression_tag> >’
[build]    80 |         using allocator_type = allocator_type_t<std::decay_t<storage_type>>;
[build]       |               ^~~~~~~~~~~~~~
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xcontainer.hpp:260:11:   required from ‘class xt::xstrided_container<xt::xtensor_adaptor<const xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1>&, 1, xt::layout_type::row_major, xt::xtensor_expression_tag> >’
[build]   260 |     class xstrided_container : public xcontainer<D>
[build]       |           ^~~~~~~~~~~~~~~~~~
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xtensor.hpp:209:11:   required from ‘class xt::xtensor_adaptor<const xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1>&, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>’
[build]   209 |     class xtensor_adaptor : public xstrided_container<xtensor_adaptor<EC, N, L, Tag>>,
[build]       |           ^~~~~~~~~~~~~~~
[build] /home/eugene/Master/software/partn_c++/src/test_main.cpp:20:14:   required from here
[build]    20 |     xt::adapt(aa.shape());
[build]       |     ~~~~~~~~~^~~~~~~~~~~~
[build] /home/eugene/Master/software/partn_c++/build/_deps/xtensor-src/include/xtensor/xcontainer.hpp:46:19: error: no type named ‘allocator_type’ in ‘class xt::sequence_view<xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, 1, -1>’
[build]    46 |             using type = typename T::allocator_type;
[build]       |                   ^~~~
[build] ninja: build stopped: subcommand failed.

Both gives similar errors. I tried other method of aa and bb and also get compilation errors. I believe it is a bug or inconsistencies since xt::adapt(cc.shape()) doesn't yield to compilation errors.

Thanks,

eugene-sanscartier commented 1 month ago

Also, if it is not a bug, could I ask why it is so?

zhaojie317 commented 1 month ago

Perhaps you can resolve the error by adding the line using allocator_type = typename E::allocator_type; to xstorage.hpp.

image