From 4c97107378ef956a5e0f246bba30df22525f49f4 Mon Sep 17 00:00:00 2001 From: blegouix Date: Mon, 22 Jul 2024 09:11:55 +0200 Subject: [PATCH 1/6] init --- include/ddc/discrete_domain.hpp | 18 ++++++++++++++++++ include/ddc/kernels/splines/spline_builder.hpp | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/ddc/discrete_domain.hpp b/include/ddc/discrete_domain.hpp index 2449dc40d..6402f4fc6 100644 --- a/include/ddc/discrete_domain.hpp +++ b/include/ddc/discrete_domain.hpp @@ -389,6 +389,18 @@ struct ConvertTypeSeqToDiscreteDomain> template using convert_type_seq_to_discrete_domain = typename ConvertTypeSeqToDiscreteDomain::type; +template +struct ConvertDiscreteDomainToTypeSeq; + +template +struct ConvertDiscreteDomainToTypeSeq> +{ + using type = detail::TypeSeq; +}; + +template +using convert_discrete_domain_to_type_seq = typename ConvertDiscreteDomainToTypeSeq::type; + } // namespace detail // Computes the cartesian product of DiscreteDomain types @@ -418,6 +430,12 @@ struct cartesian_prod template using cartesian_prod_t = typename cartesian_prod::type; +// Remove dimensions from a domain type +template +using remove_dims_of_t = ddc::detail::convert_type_seq_to_discrete_domain, + ddc::detail::TypeSeq>>; + // Computes the substraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b) template KOKKOS_FUNCTION constexpr auto remove_dims_of( diff --git a/include/ddc/kernels/splines/spline_builder.hpp b/include/ddc/kernels/splines/spline_builder.hpp index 4e2e1fb8e..63f165a49 100644 --- a/include/ddc/kernels/splines/spline_builder.hpp +++ b/include/ddc/kernels/splines/spline_builder.hpp @@ -92,10 +92,9 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain */ - using batch_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq>>; + using batch_domain_type = typename ddc::remove_dims_of_t< + batched_interpolation_domain_type, + interpolation_discrete_dimension_type>; /** * @brief The type of the whole spline domain (cartesian product of 1D spline domain From 7d44a0d5362a716978268496ff27e26a71f93df1 Mon Sep 17 00:00:00 2001 From: blegouix Date: Mon, 22 Jul 2024 09:25:18 +0200 Subject: [PATCH 2/6] wip --- include/ddc/discrete_domain.hpp | 12 ++++++++++-- .../ddc/kernels/splines/spline_builder.hpp | 18 ++++++++---------- .../ddc/kernels/splines/spline_builder_2d.hpp | 19 ++++++++----------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/ddc/discrete_domain.hpp b/include/ddc/discrete_domain.hpp index 6402f4fc6..1b0f0dc3f 100644 --- a/include/ddc/discrete_domain.hpp +++ b/include/ddc/discrete_domain.hpp @@ -433,8 +433,8 @@ using cartesian_prod_t = typename cartesian_prod::type; // Remove dimensions from a domain type template using remove_dims_of_t = ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq>>; + ddc::detail::convert_discrete_domain_to_type_seq, + ddc::detail::TypeSeq>>; // Computes the substraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b) template @@ -462,6 +462,14 @@ KOKKOS_FUNCTION constexpr auto remove_dims_of(DDomA const& DDom_a) noexcept return detail::convert_type_seq_to_discrete_domain(DDom_a); } +// Replace dimensions from a domain type +template +using replace_dim_of_t = + typename ddc::detail::convert_type_seq_to_discrete_domain, + ddc::detail::TypeSeq, + ddc::detail::TypeSeq>>; + namespace detail { // Checks if dimension of DDom_a is DDim1. If not, returns restriction to DDim2 of DDom_b. May not be usefull in its own, it helps for replace_dim_of diff --git a/include/ddc/kernels/splines/spline_builder.hpp b/include/ddc/kernels/splines/spline_builder.hpp index 63f165a49..0968f1f33 100644 --- a/include/ddc/kernels/splines/spline_builder.hpp +++ b/include/ddc/kernels/splines/spline_builder.hpp @@ -103,11 +103,10 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y * (associated to a B-splines tag BSplinesY), this is DiscreteDomain. */ - using batched_spline_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq, - ddc::detail::TypeSeq>>; + using batched_spline_domain_type = typename ddc::replace_dim_of_t< + batched_interpolation_domain_type, + interpolation_discrete_dimension_type, + bsplines_type>; private: /** @@ -132,11 +131,10 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain,Z> */ - using batched_derivs_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq, - ddc::detail::TypeSeq>>; + using batched_derivs_domain_type = typename ddc::replace_dim_of_t< + batched_interpolation_domain_type, + interpolation_discrete_dimension_type, + deriv_type>; /// @brief Indicates if the degree of the splines is odd or even. static constexpr bool s_odd = BSplines::degree() % 2; diff --git a/include/ddc/kernels/splines/spline_builder_2d.hpp b/include/ddc/kernels/splines/spline_builder_2d.hpp index d9a9c0964..daa1cdf77 100644 --- a/include/ddc/kernels/splines/spline_builder_2d.hpp +++ b/include/ddc/kernels/splines/spline_builder_2d.hpp @@ -125,12 +125,10 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain. */ - using batch_domain_type - = ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq< - interpolation_discrete_dimension_type1, - interpolation_discrete_dimension_type2>>>; + using batch_domain_type = typename ddc::remove_dims_of_t< + batched_interpolation_domain_type, + interpolation_discrete_dimension_type1, + interpolation_discrete_dimension_type2>; /** * @brief The type of the whole spline domain (cartesian product of 2D spline domain @@ -163,11 +161,10 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain, Z>. */ - using batched_derivs_domain_type2 - = ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq, - ddc::detail::TypeSeq>>; + using batched_derivs_domain_type2 = typename ddc::replace_dim_of_t< + batched_interpolation_domain_type, + interpolation_discrete_dimension_type1, + deriv_type1>; /** * @brief The type of the whole Derivs domain (cartesian product of the 2D Deriv domain From dde000bba922caaf285725c9b4acf08312181271 Mon Sep 17 00:00:00 2001 From: blegouix Date: Mon, 22 Jul 2024 09:41:37 +0200 Subject: [PATCH 3/6] wip --- include/ddc/kernels/splines/spline_builder.hpp | 6 +++--- include/ddc/kernels/splines/spline_builder_2d.hpp | 8 ++++---- include/ddc/kernels/splines/spline_evaluator.hpp | 15 ++++++--------- .../ddc/kernels/splines/spline_evaluator_2d.hpp | 10 ++++------ 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/include/ddc/kernels/splines/spline_builder.hpp b/include/ddc/kernels/splines/spline_builder.hpp index 0968f1f33..44e0046d4 100644 --- a/include/ddc/kernels/splines/spline_builder.hpp +++ b/include/ddc/kernels/splines/spline_builder.hpp @@ -92,7 +92,7 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain */ - using batch_domain_type = typename ddc::remove_dims_of_t< + using batch_domain_type = ddc::remove_dims_of_t< batched_interpolation_domain_type, interpolation_discrete_dimension_type>; @@ -103,7 +103,7 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y * (associated to a B-splines tag BSplinesY), this is DiscreteDomain. */ - using batched_spline_domain_type = typename ddc::replace_dim_of_t< + using batched_spline_domain_type = ddc::replace_dim_of_t< batched_interpolation_domain_type, interpolation_discrete_dimension_type, bsplines_type>; @@ -131,7 +131,7 @@ class SplineBuilder * Example: For batched_interpolation_domain_type = DiscreteDomain and a dimension of interest Y, * this is DiscreteDomain,Z> */ - using batched_derivs_domain_type = typename ddc::replace_dim_of_t< + using batched_derivs_domain_type = ddc::replace_dim_of_t< batched_interpolation_domain_type, interpolation_discrete_dimension_type, deriv_type>; diff --git a/include/ddc/kernels/splines/spline_builder_2d.hpp b/include/ddc/kernels/splines/spline_builder_2d.hpp index daa1cdf77..2ecb26ec5 100644 --- a/include/ddc/kernels/splines/spline_builder_2d.hpp +++ b/include/ddc/kernels/splines/spline_builder_2d.hpp @@ -125,7 +125,7 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain. */ - using batch_domain_type = typename ddc::remove_dims_of_t< + using batch_domain_type = ddc::remove_dims_of_t< batched_interpolation_domain_type, interpolation_discrete_dimension_type1, interpolation_discrete_dimension_type2>; @@ -161,10 +161,10 @@ class SplineBuilder2D * Example: For batched_interpolation_domain_type = DiscreteDomain and dimensions of interest X and Y, * this is DiscreteDomain, Z>. */ - using batched_derivs_domain_type2 = typename ddc::replace_dim_of_t< + using batched_derivs_domain_type2 = ddc::replace_dim_of_t< batched_interpolation_domain_type, - interpolation_discrete_dimension_type1, - deriv_type1>; + interpolation_discrete_dimension_type2, + deriv_type2>; /** * @brief The type of the whole Derivs domain (cartesian product of the 2D Deriv domain diff --git a/include/ddc/kernels/splines/spline_evaluator.hpp b/include/ddc/kernels/splines/spline_evaluator.hpp index 144e884f0..c8f6aa699 100644 --- a/include/ddc/kernels/splines/spline_evaluator.hpp +++ b/include/ddc/kernels/splines/spline_evaluator.hpp @@ -82,20 +82,17 @@ class SplineEvaluator * @brief The type of the batch domain (obtained by removing the dimension of interest * from the whole domain). */ - using batch_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq>>; + using batch_domain_type = ddc:: + remove_dims_of_t; /** * @brief The type of the whole spline domain (cartesian product of 1D spline domain * and batch domain) preserving the order of dimensions. */ - using batched_spline_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq, - ddc::detail::TypeSeq>>; + using batched_spline_domain_type = ddc::replace_dim_of_t< + batched_evaluation_domain_type, + evaluation_discrete_dimension_type, + bsplines_type>; /// @brief The type of the extrapolation rule at the lower boundary. using lower_extrapolation_rule_type = LowerExtrapolationRule; diff --git a/include/ddc/kernels/splines/spline_evaluator_2d.hpp b/include/ddc/kernels/splines/spline_evaluator_2d.hpp index 818f6685f..b3ca7659c 100644 --- a/include/ddc/kernels/splines/spline_evaluator_2d.hpp +++ b/include/ddc/kernels/splines/spline_evaluator_2d.hpp @@ -113,12 +113,10 @@ class SplineEvaluator2D * @brief The type of the batch domain (obtained by removing the dimensions of interest * from the whole domain). */ - using batch_domain_type = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq< - evaluation_discrete_dimension_type1, - evaluation_discrete_dimension_type2>>>; + using batch_domain_type = typename ddc::remove_dims_of_t< + batched_evaluation_domain_type, + evaluation_discrete_dimension_type1, + evaluation_discrete_dimension_type2>; /** * @brief The type of the whole spline domain (cartesian product of 2D spline domain From 40c7f61f17f082da61c9109eb7f91ac7ccc65d1d Mon Sep 17 00:00:00 2001 From: blegouix Date: Mon, 22 Jul 2024 09:46:11 +0200 Subject: [PATCH 4/6] rc --- tests/discrete_domain.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/discrete_domain.cpp b/tests/discrete_domain.cpp index 7274a2d22..7c3b80fab 100644 --- a/tests/discrete_domain.cpp +++ b/tests/discrete_domain.cpp @@ -177,8 +177,8 @@ TEST(DiscreteDomainTest, RangeFor) TEST(DiscreteDomainTest, DiffEmpty) { DDomX const dom_x = DDomX(); - auto const subdomain1 = ddc::remove_dims_of(dom_x, dom_x); - auto const subdomain2 = ddc::remove_dims_of(dom_x); + ddc::remove_dims_of_t const subdomain1 = ddc::remove_dims_of(dom_x, dom_x); + ddc::remove_dims_of_t const subdomain2 = ddc::remove_dims_of(dom_x); EXPECT_EQ(subdomain1, ddc::DiscreteDomain<>()); EXPECT_EQ(subdomain2, ddc::DiscreteDomain<>()); } @@ -188,8 +188,10 @@ TEST(DiscreteDomainTest, Diff) DDomX const dom_x = DDomX(); DDomXY const dom_x_y = DDomXY(); DDomZY const dom_z_y = DDomZY(); - auto const subdomain1 = ddc::remove_dims_of(dom_x_y, dom_z_y); - auto const subdomain2 = ddc::remove_dims_of(dom_x_y); + ddc::remove_dims_of_t const subdomain1 + = ddc::remove_dims_of(dom_x_y, dom_z_y); + ddc::remove_dims_of_t const subdomain2 + = ddc::remove_dims_of(dom_x_y); EXPECT_EQ(subdomain1, dom_x); EXPECT_EQ(subdomain2, dom_x); } @@ -199,7 +201,8 @@ TEST(DiscreteDomainTest, Replace) DDomXY const dom_x_y(lbound_x_y, nelems_x_y); DDomZ const dom_z(lbound_z, nelems_z); DDomXZ const dom_x_z(lbound_x_z, nelems_x_z); - auto const subdomain = ddc::replace_dim_of(dom_x_y, dom_z); + ddc::replace_dim_of_t const subdomain + = ddc::replace_dim_of(dom_x_y, dom_z); EXPECT_EQ(subdomain, dom_x_z); } From bd6992f170b313c69f6de23ba8e5ebc039efee3c Mon Sep 17 00:00:00 2001 From: Baptiste Legouix Date: Thu, 25 Jul 2024 13:37:58 +0200 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Thomas Padioleau --- include/ddc/discrete_domain.hpp | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/include/ddc/discrete_domain.hpp b/include/ddc/discrete_domain.hpp index 1b0f0dc3f..32eddaa01 100644 --- a/include/ddc/discrete_domain.hpp +++ b/include/ddc/discrete_domain.hpp @@ -389,18 +389,6 @@ struct ConvertTypeSeqToDiscreteDomain> template using convert_type_seq_to_discrete_domain = typename ConvertTypeSeqToDiscreteDomain::type; -template -struct ConvertDiscreteDomainToTypeSeq; - -template -struct ConvertDiscreteDomainToTypeSeq> -{ - using type = detail::TypeSeq; -}; - -template -using convert_discrete_domain_to_type_seq = typename ConvertDiscreteDomainToTypeSeq::type; - } // namespace detail // Computes the cartesian product of DiscreteDomain types @@ -431,10 +419,8 @@ template using cartesian_prod_t = typename cartesian_prod::type; // Remove dimensions from a domain type -template -using remove_dims_of_t = ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq>>; +template +using remove_dims_of_t = decltype(remove_dims_of(std::declval())); // Computes the substraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b) template @@ -464,11 +450,7 @@ KOKKOS_FUNCTION constexpr auto remove_dims_of(DDomA const& DDom_a) noexcept // Replace dimensions from a domain type template -using replace_dim_of_t = - typename ddc::detail::convert_type_seq_to_discrete_domain, - ddc::detail::TypeSeq, - ddc::detail::TypeSeq>>; +using replace_dim_of_t = decltype(replace_dim_of(std::declval(), std::declval>())); namespace detail { From 0f313466bcf709c4506861340d5b18365ab08e05 Mon Sep 17 00:00:00 2001 From: blegouix Date: Thu, 25 Jul 2024 17:38:10 +0200 Subject: [PATCH 6/6] fix --- include/ddc/discrete_domain.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/ddc/discrete_domain.hpp b/include/ddc/discrete_domain.hpp index 32eddaa01..508884cea 100644 --- a/include/ddc/discrete_domain.hpp +++ b/include/ddc/discrete_domain.hpp @@ -418,10 +418,6 @@ struct cartesian_prod template using cartesian_prod_t = typename cartesian_prod::type; -// Remove dimensions from a domain type -template -using remove_dims_of_t = decltype(remove_dims_of(std::declval())); - // Computes the substraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b) template KOKKOS_FUNCTION constexpr auto remove_dims_of( @@ -448,9 +444,9 @@ KOKKOS_FUNCTION constexpr auto remove_dims_of(DDomA const& DDom_a) noexcept return detail::convert_type_seq_to_discrete_domain(DDom_a); } -// Replace dimensions from a domain type -template -using replace_dim_of_t = decltype(replace_dim_of(std::declval(), std::declval>())); +// Remove dimensions from a domain type +template +using remove_dims_of_t = decltype(remove_dims_of(std::declval())); namespace detail { @@ -493,6 +489,14 @@ KOKKOS_FUNCTION constexpr auto replace_dim_of( DDimsB...>(ddc::select(DDom_a), DDom_b)...); } +// Replace dimensions from a domain type +template +using replace_dim_of_t + = decltype(replace_dim_of< + DDim1, + DDim2>(std::declval(), std::declval>())); + + template KOKKOS_FUNCTION constexpr DiscreteVector extents( DiscreteDomain const& domain) noexcept