xt::adapt of shape of xt::view bugs
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,
Also, if it is not a bug, could I ask why it is so?
Perhaps you can resolve the error by adding the line using allocator_type = typename E::allocator_type; to xstorage.hpp.
@eugene-sanscartier why are you adapting an xview when it's already an xexpression the adapt calls are to convert containers or pointer outside xtensor into the xtensor expression system so they can be operated on using xtensor.
See here: https://xtensor.readthedocs.io/en/latest/adaptor.html