diff --git a/include/ddc/non_uniform_point_sampling.hpp b/include/ddc/non_uniform_point_sampling.hpp index 3fb79d3ec..ffcd931e8 100644 --- a/include/ddc/non_uniform_point_sampling.hpp +++ b/include/ddc/non_uniform_point_sampling.hpp @@ -134,30 +134,27 @@ class NonUniformPointSampling : detail::NonUniformPointSamplingBase } }; - /** Construct an Impl and associated discrete_domain_type from an iterator + /** Construct an Impl and associated discrete_domain_type from a range * containing the points coordinates along the `DDim` dimension. * - * @param non_uniform_points a vector containing the coordinates of the points of the domain. + * @param non_uniform_points a range (std::vector, std::array, ...) containing the coordinates of the points of the domain. */ template static std::tuple, DiscreteDomain> - init(InputRange const non_uniform_points) + init(InputRange const& non_uniform_points) { - auto a = non_uniform_points.begin(); - auto b = non_uniform_points.end(); - auto n = std::distance(non_uniform_points.begin(), non_uniform_points.end()); - assert(a < b); - assert(n > 0); + assert(!non_uniform_points.empty()); + DiscreteVector const n(non_uniform_points.size()); typename DDim::template Impl disc(non_uniform_points); - DiscreteDomain domain {disc.front(), DiscreteVector {n}}; + DiscreteDomain domain(disc.front(), n); return std::make_tuple(std::move(disc), std::move(domain)); } - /** Construct 4 non-uniform `DiscreteDomain` and an Impl from 3 iterators containing the points coordinates along the `DDim` dimension. + /** Construct 4 non-uniform `DiscreteDomain` and an Impl from 3 ranges containing the points coordinates along the `DDim` dimension. * - * @param domain_r an iterator containing the coordinates of the points of the main domain along the DDim position - * @param pre_ghost_r an iterator containing the positions of the ghost points before the main domain the DDim position - * @param post_ghost_r an iterator containing the positions of the ghost points after the main domain the DDim position + * @param domain_r a range containing the coordinates of the points of the main domain along the DDim position + * @param pre_ghost_r a range containing the positions of the ghost points before the main domain the DDim position + * @param post_ghost_r a range containing the positions of the ghost points after the main domain the DDim position */ template static std::tuple< @@ -171,16 +168,11 @@ class NonUniformPointSampling : detail::NonUniformPointSamplingBase InputRange const& pre_ghost_r, InputRange const& post_ghost_r) { - using discrete_domain_type = DiscreteDomain; - auto n = DiscreteVector {std::distance(domain_r.begin(), domain_r.end())}; - - assert(domain_r.begin() < domain_r.end()); - assert(n > 1); + assert(!domain_r.empty()); - auto n_ghosts_before - = DiscreteVector {std::distance(pre_ghost_r.begin(), pre_ghost_r.end())}; - auto n_ghosts_after - = DiscreteVector {std::distance(post_ghost_r.begin(), post_ghost_r.end())}; + DiscreteVector const n(domain_r.size()); + DiscreteVector const n_ghosts_before(pre_ghost_r.size()); + DiscreteVector const n_ghosts_after(post_ghost_r.size()); std::vector full_domain; @@ -190,14 +182,10 @@ class NonUniformPointSampling : detail::NonUniformPointSamplingBase typename DDim::template Impl disc(full_domain); - discrete_domain_type ghosted_domain - = discrete_domain_type(disc.front(), n + n_ghosts_before + n_ghosts_after); - discrete_domain_type pre_ghost - = discrete_domain_type(ghosted_domain.front(), n_ghosts_before); - discrete_domain_type main_domain - = discrete_domain_type(ghosted_domain.front() + n_ghosts_before, n); - discrete_domain_type post_ghost - = discrete_domain_type(main_domain.back() + 1, n_ghosts_after); + DiscreteDomain ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after); + DiscreteDomain pre_ghost(ghosted_domain.front(), n_ghosts_before); + DiscreteDomain main_domain(ghosted_domain.front() + n_ghosts_before, n); + DiscreteDomain post_ghost(main_domain.back() + 1, n_ghosts_after); return std::make_tuple( std::move(disc), std::move(main_domain), diff --git a/tests/non_uniform_point_sampling.cpp b/tests/non_uniform_point_sampling.cpp index 8ab4aaa8c..2fefd641f 100644 --- a/tests/non_uniform_point_sampling.cpp +++ b/tests/non_uniform_point_sampling.cpp @@ -94,8 +94,8 @@ TEST(NonUniformPointSampling, Formatting) TEST(NonUniformPointSampling, Coordinate) { - ddc::init_discrete_space(vector_points_x); - ddc::init_discrete_space(vector_points_y); + ddc::init_discrete_space(DDimX::init(vector_points_x)); + ddc::init_discrete_space(DDimY::init(vector_points_y)); EXPECT_EQ(ddc::coordinate(point_ix), point_rx); EXPECT_EQ(ddc::coordinate(point_iy), point_ry); EXPECT_EQ(ddc::coordinate(point_ixy), point_rxy);