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

remove_dims_of_t and replace_dims_of_t #559

Merged
merged 8 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ KOKKOS_FUNCTION constexpr auto remove_dims_of(DDomA const& DDom_a) noexcept
return detail::convert_type_seq_to_discrete_domain<type_seq_r>(DDom_a);
}

// Remove dimensions from a domain type
template <typename DDom, typename... DDims>
using remove_dims_of_t = decltype(remove_dims_of<DDims...>(std::declval<DDom>()));

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
Expand Down Expand Up @@ -485,6 +489,14 @@ KOKKOS_FUNCTION constexpr auto replace_dim_of(
DDimsB...>(ddc::select<DDimsA>(DDom_a), DDom_b)...);
}

// Replace dimensions from a domain type
template <typename DDom, typename DDim1, typename DDim2>
using replace_dim_of_t
= decltype(replace_dim_of<
DDim1,
DDim2>(std::declval<DDom>(), std::declval<DiscreteDomain<DDim2>>()));


template <class... QueryDDims, class... DDims>
KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
DiscreteDomain<DDims...> const& domain) noexcept
Expand Down
25 changes: 11 additions & 14 deletions include/ddc/kernels/splines/spline_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ class SplineBuilder
* Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and a dimension of interest Y,
* this is DiscreteDomain<X,Z>
*/
using batch_domain_type =
typename ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_remove_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<interpolation_discrete_dimension_type>>>;
using batch_domain_type = 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
Expand All @@ -104,11 +103,10 @@ class SplineBuilder
* Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and a dimension of interest Y
* (associated to a B-splines tag BSplinesY), this is DiscreteDomain<X,BSplinesY,Z>.
*/
using batched_spline_domain_type =
typename ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<interpolation_discrete_dimension_type>,
ddc::detail::TypeSeq<bsplines_type>>>;
using batched_spline_domain_type = ddc::replace_dim_of_t<
batched_interpolation_domain_type,
interpolation_discrete_dimension_type,
bsplines_type>;

private:
/**
Expand All @@ -133,11 +131,10 @@ class SplineBuilder
* Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and a dimension of interest Y,
* this is DiscreteDomain<X,Deriv<Y>,Z>
*/
using batched_derivs_domain_type =
typename ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<interpolation_discrete_dimension_type>,
ddc::detail::TypeSeq<deriv_type>>>;
using batched_derivs_domain_type = 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;
Expand Down
19 changes: 8 additions & 11 deletions include/ddc/kernels/splines/spline_builder_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ class SplineBuilder2D
* Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
* this is DiscreteDomain<Z>.
*/
using batch_domain_type
= ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_remove_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<
interpolation_discrete_dimension_type1,
interpolation_discrete_dimension_type2>>>;
using batch_domain_type = 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
Expand Down Expand Up @@ -163,11 +161,10 @@ class SplineBuilder2D
* Example: For batched_interpolation_domain_type = DiscreteDomain<X,Y,Z> and dimensions of interest X and Y,
* this is DiscreteDomain<X, Deriv<Y>, Z>.
*/
using batched_derivs_domain_type2
= ddc::detail::convert_type_seq_to_discrete_domain<ddc::type_seq_replace_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<interpolation_discrete_dimension_type2>,
ddc::detail::TypeSeq<deriv_type2>>>;
using batched_derivs_domain_type2 = ddc::replace_dim_of_t<
batched_interpolation_domain_type,
interpolation_discrete_dimension_type2,
deriv_type2>;

/**
* @brief The type of the whole Derivs domain (cartesian product of the 2D Deriv domain
Expand Down
15 changes: 6 additions & 9 deletions include/ddc/kernels/splines/spline_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::type_seq_remove_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<evaluation_discrete_dimension_type>>>;
using batch_domain_type = ddc::
remove_dims_of_t<batched_evaluation_domain_type, evaluation_discrete_dimension_type>;

/**
* @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::type_seq_replace_t<
ddc::detail::TypeSeq<IDimX...>,
ddc::detail::TypeSeq<evaluation_discrete_dimension_type>,
ddc::detail::TypeSeq<bsplines_type>>>;
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;
Expand Down
10 changes: 4 additions & 6 deletions include/ddc/kernels/splines/spline_evaluator_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::type_seq_remove_t<
ddc::detail::TypeSeq<IDimX...>,
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
Expand Down
13 changes: 8 additions & 5 deletions tests/discrete_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DDimX>(dom_x);
ddc::remove_dims_of_t<DDomX, DDimX> const subdomain1 = ddc::remove_dims_of(dom_x, dom_x);
ddc::remove_dims_of_t<DDomX, DDimX> const subdomain2 = ddc::remove_dims_of<DDimX>(dom_x);
EXPECT_EQ(subdomain1, ddc::DiscreteDomain<>());
EXPECT_EQ(subdomain2, ddc::DiscreteDomain<>());
}
Expand All @@ -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<DDimZ, DDimY>(dom_x_y);
ddc::remove_dims_of_t<DDomX, DDimZ, DDimY> const subdomain1
= ddc::remove_dims_of(dom_x_y, dom_z_y);
ddc::remove_dims_of_t<DDomX, DDimZ, DDimY> const subdomain2
= ddc::remove_dims_of<DDimZ, DDimY>(dom_x_y);
EXPECT_EQ(subdomain1, dom_x);
EXPECT_EQ(subdomain2, dom_x);
}
Expand All @@ -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<DDimY, DDimZ>(dom_x_y, dom_z);
ddc::replace_dim_of_t<DDomXY, DDimY, DDimZ> const subdomain
= ddc::replace_dim_of<DDimY, DDimZ>(dom_x_y, dom_z);
EXPECT_EQ(subdomain, dom_x_z);
}

Expand Down