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

adding xt::adapt(xt::sequence_view). #2291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vakokako
Copy link

@vakokako vakokako commented Feb 1, 2021

Usually when working with tensor shapes, we use xt::adapt. This works great, since shapes are always containers, except when using xt::view with xt::all() in all dimensions, the shape returned will be xt::sequence_view, which you cannot adapt correctly.
So this pull request allows the following:

auto shape = xt::adapt(xt::view(tensor, xt::all()).shape());

@JohanMabille
Copy link
Member

JohanMabille commented Feb 1, 2021

What error do you have when you class xt::adapt with an xt::sequence_view object? I would expect the compiler to select this overload.

@vakokako
Copy link
Author

vakokako commented Feb 2, 2021

[build] In file included from ../main.cpp:5:
[build] In file included from /home/code/vcpkg/installed/x64-linux/include/xtensor/xadapt.hpp:20:
[build] In file included from /home/code/vcpkg/installed/x64-linux/include/xtensor/xarray.hpp:20:
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xcontainer.hpp:47:38: error: no type named 'allocator_type' in 'xt::sequence_view<std::array<unsigned long, 2>, 0, 2>'
[build]             using type = typename T::allocator_type;
[build]                          ~~~~~~~~~~~~^~~~~~~~~~~~~~
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xcontainer.hpp:58:5: note: in instantiation of template class 'xt::detail::allocator_type_impl<xt::sequence_view<std::array<unsigned long, 2>, 0, 2>>' requested here
[build]     using allocator_type_t = typename detail::allocator_type_impl<T>::type;
[build]     ^
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xcontainer.hpp:81:32: note: in instantiation of template type alias 'allocator_type_t' requested here
[build]         using allocator_type = allocator_type_t<std::decay_t<storage_type>>;
[build]                                ^
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xcontainer.hpp:257:39: note: in instantiation of template class 'xt::xcontainer<xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>>' requested here
[build]     class xstrided_container : public xcontainer<D>
[build]                                       ^
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xtensor.hpp:209:36: note: in instantiation of template class 'xt::xstrided_container<xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>>' requested here
[build]     class xtensor_adaptor : public xstrided_container<xtensor_adaptor<EC, N, L, Tag>>,
[build]                                    ^
[build] ../main.cpp:64:27: note: in instantiation of template class 'xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>' requested here
[build]     auto sequence_adapt = xt::adapt(xt::view(tensor, xt::all(), xt::all()).shape());
[build]                           ^
[build] In file included from ../main.cpp:5:
[build] In file included from /home/code/vcpkg/installed/x64-linux/include/xtensor/xadapt.hpp:21:
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xtensor.hpp:222:52: error: no type named 'allocator_type' in 'xt::xstrided_container<xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>>'
[build]         using allocator_type = typename base_type::allocator_type;
[build]                                ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
[build] ../main.cpp:64:27: note: in instantiation of template class 'xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>' requested here
[build]     auto sequence_adapt = xt::adapt(xt::view(tensor, xt::all(), xt::all()).shape());
[build]                           ^
[build] In file included from ../main.cpp:5:
[build] In file included from /home/code/vcpkg/installed/x64-linux/include/xtensor/xadapt.hpp:21:
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xtensor.hpp:225:54: error: no type named 'backstrides_type' in 'xt::xstrided_container<xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>>'
[build]         using backstrides_type = typename base_type::backstrides_type;
[build]                                  ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xtensor.hpp:592:11: error: type 'xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>::base_type' (aka 'xstrided_container<xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1UL, (xt::layout_type)1, xt::xtensor_expression_tag>>') is not a direct or virtual base of 'xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>'
[build]         : base_type(), m_storage(std::forward<D>(storage))
[build]           ^~~~~~~~~
[build] /home/code/vcpkg/installed/x64-linux/include/xtensor/xadapt.hpp:218:16: note: in instantiation of function template specialization 'xt::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &, 1, xt::layout_type::row_major, xt::xtensor_expression_tag>::xtensor_adaptor<const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &>' requested here
[build]         return return_type(std::forward<C>(container), shape, l);
[build]                ^
[build] ../main.cpp:64:31: note: in instantiation of function template specialization 'xt::adapt<xt::layout_type::row_major, const xt::sequence_view<std::array<unsigned long, 2>, 0, 2> &>' requested here
[build]     auto sequence_adapt = xt::adapt(xt::view(tensor, xt::all(), xt::all()).shape());
[build]                               ^

@JohanMabille
Copy link
Member

Sorry for the late reply, I think it would be better to add an allocator_type type in xsequence_view rather than adding a specific overload. The allocator_type can be that of the underying expression E.

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

Successfully merging this pull request may close these issues.

2 participants