Skip to content

Commit

Permalink
Add cartesian_product_t tests (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Nov 27, 2024
1 parent 3bf7b3a commit 49a69d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
25 changes: 9 additions & 16 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,19 @@ using convert_type_seq_to_discrete_domain_t = typename ConvertTypeSeqToDiscreteD

// Computes the cartesian product of DiscreteDomain types
// Example usage : "using DDom = cartesian_prod_t<DDom1,DDom2,DDom3>;"
template <typename... DDom>
template <typename... DDoms>
struct cartesian_prod;

template <typename... DDim1, typename... DDim2>
struct cartesian_prod<ddc::DiscreteDomain<DDim1...>, ddc::DiscreteDomain<DDim2...>>
template <typename... DDims1, typename... DDims2, typename... DDomsTail>
struct cartesian_prod<DiscreteDomain<DDims1...>, DiscreteDomain<DDims2...>, DDomsTail...>
{
using type = ddc::DiscreteDomain<DDim1..., DDim2...>;
using type = typename cartesian_prod<DiscreteDomain<DDims1..., DDims2...>, DDomsTail...>::type;
};

template <typename DDom>
struct cartesian_prod<DDom>
template <typename... DDims>
struct cartesian_prod<DiscreteDomain<DDims...>>
{
using type = DDom;
using type = DiscreteDomain<DDims...>;
};

template <>
Expand All @@ -414,15 +414,8 @@ struct cartesian_prod<>
using type = ddc::DiscreteDomain<>;
};

template <typename DDom1, typename DDom2, typename... Tail>
struct cartesian_prod<DDom1, DDom2, Tail...>
{
using type =
typename cartesian_prod<typename cartesian_prod<DDom1, DDom2>::type, Tail...>::type;
};

template <typename... DDom>
using cartesian_prod_t = typename cartesian_prod<DDom...>::type;
template <typename... DDoms>
using cartesian_prod_t = typename cartesian_prod<DDoms...>::type;

// 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 <class... DDimsA, class... DDimsB>
Expand Down
8 changes: 8 additions & 0 deletions tests/discrete_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,11 @@ TEST(DiscreteDomainTest, Transpose3DConstructor)
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
}

TEST(DiscreteDomainTest, CartesianProduct)
{
EXPECT_TRUE((std::is_same_v<ddc::cartesian_prod_t<>, ddc::DiscreteDomain<>>));
EXPECT_TRUE((std::is_same_v<ddc::cartesian_prod_t<DDomX>, DDomX>));
EXPECT_TRUE((std::is_same_v<ddc::cartesian_prod_t<DDomX, DDomY, DDomZ>, DDomXYZ>));
EXPECT_TRUE((std::is_same_v<ddc::cartesian_prod_t<DDomZY, DDomX>, DDomZYX>));
}

0 comments on commit 49a69d5

Please sign in to comment.