13 #include <hipipe/core/stream/transform.hpp>
14 #include <hipipe/core/utility/ndim.hpp>
16 namespace hipipe::stream {
20 template<
typename FromColumn,
typename ToColumn,
typename Gen,
int Dim>
21 struct wrap_generate_fun_for_transform {
25 typename ToColumn::data_type operator()(
typename FromColumn::data_type& source)
27 using SourceVector =
typename FromColumn::data_type;
28 using TargetVector =
typename ToColumn::data_type;
29 constexpr
long SourceDims = utility::ndims<SourceVector>::value;
30 constexpr
long TargetDims = utility::ndims<TargetVector>::value;
31 static_assert(Dim <= SourceDims,
"hipipe::stream::generate requires"
32 " the dimension in which to apply the generator to be at most the number"
33 " of dimensions of the source column (i.e., the column the shape is taken"
35 static_assert(Dim <= TargetDims,
"hipipe::stream::generate: The requested"
36 " dimension is higher than the number of dimensions of the target column.");
38 std::vector<std::vector<long>> target_size = utility::ndim_size<Dim>(source);
41 static_assert(std::is_invocable_r_v<utility::ndim_type_t<TargetVector, Dim>, Gen>,
42 " hipipe::stream::generate: The given generator does not generate a"
43 " type convertible to the given column in the given dimension.");
44 utility::ndim_resize<Dim>(target, target_size);
45 utility::generate<Dim>(target, gen, gendims);
80 template<
typename FromColumn,
typename ToColumn,
typename Gen,
81 int Dim = utility::ndims<typename ToColumn::data_type>::value
82 - utility::ndims<std::result_of_t<Gen()>>::value>
83 auto generate(from_t<FromColumn> size_from,
84 to_t<ToColumn> fill_to,
86 long gendims = std::numeric_limits<long>::max(),
87 dim_t<Dim> d = dim_t<Dim>{})
90 using GenT = std::function<
91 utility::ndim_type_t<typename ToColumn::data_type, Dim>()>;
92 detail::wrap_generate_fun_for_transform<FromColumn, ToColumn, GenT, Dim>
93 trans_fun{std::move(gen), gendims};
94 return stream::transform(from<FromColumn>, to<ToColumn>, std::move(trans_fun), dim<0>);