13 #include <hipipe/core/stream/stream_t.hpp>
14 #include <hipipe/core/stream/template_arguments.hpp>
15 #include <hipipe/core/utility/ndim.hpp>
16 #include <hipipe/core/utility/tuple.hpp>
18 #include <range/v3/view/move.hpp>
19 #include <range/v3/view/transform.hpp>
21 namespace hipipe::stream {
23 namespace rgv = ranges::views;
28 template<std::size_t Dim,
bool OnlyOne,
typename... FromColumns>
31 template<
typename Rng>
32 static auto unpack_columns(Rng&& rng)
35 -> std::tuple<typename FromColumns::data_type...> {
36 return {std::move(source.extract<FromColumns>())...};
40 template<
typename Rng>
42 std::tuple<std::vector<utility::ndim_type_t<typename FromColumns::data_type, Dim>>...>
43 impl(Rng&& range_of_batches)
45 static_assert(std::is_same_v<std::decay_t<ranges::range_value_t<Rng>>, batch_t>,
46 "hipipe::stream::unpack requires a range of batches as input.");
47 static_assert(((Dim <= utility::ndims<typename FromColumns::data_type>::value) && ...),
48 "hipipe::stream::unpack requires the requested dimension to be less or equal to the"
49 " dimension of all the unpacked columns.");
50 auto raw_range_of_tuples = unpack_columns(std::forward<Rng>(range_of_batches));
51 auto tuple_of_batches = utility::unzip(std::move(raw_range_of_tuples));
55 return rgv::move(utility::flat_view<Dim+1>(batch_range));
61 template<std::
size_t Dim,
typename FromColumn>
62 struct unpack_impl<Dim, true, FromColumn>
64 template<
typename Rng>
66 std::vector<utility::ndim_type_t<typename FromColumn::data_type, Dim>>
67 impl(Rng&& range_of_tuples)
70 unpack_impl<Dim, false, FromColumn>::impl(std::forward<Rng>(range_of_tuples)));
108 template<
typename Rng,
typename... FromColumns,
int Dim = 1>
112 unpack(Rng&& rng, from_t<FromColumns...> f, dim_t<Dim> d = dim_t<1>{})
114 return detail::unpack_impl<Dim, (
sizeof...(FromColumns)==1), FromColumns...>::impl(
115 std::forward<Rng>(rng));