Skip to content

Commit

Permalink
Simplify the testing types
Browse files Browse the repository at this point in the history
Add template type functions to combine and merge type lists.
As a result, the GINKGO_DPCPP_SINGLE_MODE only needs to be present once.

Additionally, change the typen name ValueAndIndexType to ComplexAndPODTypes
(because gko::size_type is not an IndexType).
  • Loading branch information
Thomas Grützmacher committed Apr 8, 2024
1 parent 8a8f1ff commit 26f3c87
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 128 deletions.
2 changes: 1 addition & 1 deletion core/test/base/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Array : public ::testing::Test {
gko::array<T> x;
};

TYPED_TEST_SUITE(Array, gko::test::ValueAndIndexTypes, TypenameNameGenerator);
TYPED_TEST_SUITE(Array, gko::test::ComplexAndPODTypes, TypenameNameGenerator);


TYPED_TEST(Array, CanBeCreatedWithoutAnExecutor)
Expand Down
2 changes: 1 addition & 1 deletion core/test/base/iterator_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class PermuteIterator : public ::testing::Test {
using value_type = ValueType;
};

TYPED_TEST_SUITE(PermuteIterator, gko::test::ValueAndIndexTypes,
TYPED_TEST_SUITE(PermuteIterator, gko::test::ComplexAndPODTypes,
TypenameNameGenerator);


Expand Down
256 changes: 136 additions & 120 deletions core/test/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,154 +32,170 @@

namespace gko {
namespace test {
namespace detail {


using ValueTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float, std::complex<float>>;
#else
::testing::Types<float, double, std::complex<float>, std::complex<double>>;
#endif
template <typename LeftList, typename RightList, typename... Result>
struct combine_types {};

using ComplexValueTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<std::complex<float>>;
#else
::testing::Types<std::complex<float>, std::complex<double>>;
#endif
template <template <typename...> class OuterWrapper, typename FirstLeft,
typename... RemainingLeftArgs, typename... RightArgs,
typename... Result>
struct combine_types<OuterWrapper<FirstLeft, RemainingLeftArgs...>,
OuterWrapper<RightArgs...>, Result...>
: combine_types<OuterWrapper<RemainingLeftArgs...>,
OuterWrapper<RightArgs...>, Result...,
std::tuple<FirstLeft, RightArgs>...> {};

using RealValueTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float>;
#else
::testing::Types<float, double>;
#endif
template <template <typename...> class OuterWrapper, typename... RightArgs,
typename... Result>
struct combine_types<OuterWrapper<>, OuterWrapper<RightArgs...>, Result...> {
using type = OuterWrapper<Result...>;
};

template <typename ExistingCombinationList, typename NewElementList,
typename... Result>
struct add_combination {};

template <template <typename...> class OuterWrapper,
typename... CurrentCombinationArgs,
typename... RemainingOldCombinations, typename... NewElementArgs,
typename... Result>
struct add_combination<OuterWrapper<std::tuple<CurrentCombinationArgs...>,
RemainingOldCombinations...>,
OuterWrapper<NewElementArgs...>, Result...>
: add_combination<
OuterWrapper<RemainingOldCombinations...>,
OuterWrapper<NewElementArgs...>, Result...,
std::tuple<CurrentCombinationArgs..., NewElementArgs>...> {};

template <template <typename...> class OuterWrapper, typename... NewElementArgs,
typename... Result>
struct add_combination<OuterWrapper<>, OuterWrapper<NewElementArgs...>,
Result...> {
using type = OuterWrapper<Result...>;
};

using IndexTypes = ::testing::Types<gko::int32, gko::int64>;
template <typename NewElementList, typename ExistingCombinationList,
typename... Result>
struct add_combination_left {};

template <template <typename...> class OuterWrapper, typename... NewElementArgs,
typename... CurrentCombinationArgs,
typename... RemainingOldCombinations, typename... Result>
struct add_combination_left<OuterWrapper<NewElementArgs...>,
OuterWrapper<std::tuple<CurrentCombinationArgs...>,
RemainingOldCombinations...>,
Result...>
: add_combination_left<
OuterWrapper<NewElementArgs...>,
OuterWrapper<RemainingOldCombinations...>, Result...,
std::tuple<NewElementArgs, CurrentCombinationArgs...>...> {};

template <template <typename...> class OuterWrapper, typename... NewElementArgs,
typename... Result>
struct add_combination_left<OuterWrapper<NewElementArgs...>, OuterWrapper<>,
Result...> {
using type = OuterWrapper<Result...>;
};

template <typename FirstList, typename SecondList>
struct merge_type_list {};

using LocalGlobalIndexTypes =
::testing::Types<std::tuple<int32, int32>, std::tuple<int32, int64>,
std::tuple<int64, int64>>;
template <template <typename...> class OuterWrapper, typename... Args1,
typename... Args2>
struct merge_type_list<OuterWrapper<Args1...>, OuterWrapper<Args2...>> {
using type = OuterWrapper<Args1..., Args2...>;
};


using PODTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float, gko::int32, gko::int64>;
#else
::testing::Types<float, double, gko::int32, gko::int64>;
#endif
template <template <typename...> class NewOuterWrapper,
typename OldOuterWrapper>
struct change_outer_wrapper {};

template <template <typename...> class NewOuterWrapper,
template <typename...> class OldOuterWrapper, typename... Args>
struct change_outer_wrapper<NewOuterWrapper, OldOuterWrapper<Args...>> {
using type = NewOuterWrapper<Args...>;
};

using ValueAndIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float, std::complex<float>, gko::int32, gko::int64,
gko::size_type>;
#else
::testing::Types<float, double, std::complex<float>, std::complex<double>,
gko::int32, gko::int64, gko::size_type>;
#endif

template <template <typename...> class NewInnerWrapper, typename ListType>
struct add_internal_wrapper {};

using RealValueAndIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<float, gko::int32, gko::int64, gko::size_type>;
#else
::testing::Types<float, double, gko::int32, gko::int64, gko::size_type>;
#endif
template <template <typename...> class NewInnerWrapper,
template <typename...> class OuterWrapper, typename... Args>
struct add_internal_wrapper<NewInnerWrapper, OuterWrapper<Args...>> {
using type = OuterWrapper<NewInnerWrapper<Args>...>;
};


using ValueIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<std::tuple<float, gko::int32>,
std::tuple<std::complex<float>, gko::int32>,
std::tuple<float, gko::int64>,
std::tuple<std::complex<float>, gko::int64>>;
#else
::testing::Types<
std::tuple<float, gko::int32>, std::tuple<double, gko::int32>,
std::tuple<std::complex<float>, gko::int32>,
std::tuple<std::complex<double>, gko::int32>,
std::tuple<float, gko::int64>, std::tuple<double, gko::int64>,
std::tuple<std::complex<float>, gko::int64>,
std::tuple<std::complex<double>, gko::int64>>;
#endif
} // namespace detail


using RealValueIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<std::tuple<float, gko::int32>,
std::tuple<float, gko::int64>>;
#else
::testing::Types<
std::tuple<float, gko::int32>, std::tuple<double, gko::int32>,
std::tuple<float, gko::int64>, std::tuple<double, gko::int64>>;
#endif
template <typename LeftList, typename RightList>
using combine_types_t =
typename detail::combine_types<LeftList, RightList>::type;

template <typename ExistingCombinationList, typename NewElementList>
using add_combination_t =
typename detail::add_combination<ExistingCombinationList,
NewElementList>::type;

using ComplexValueIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<std::tuple<std::complex<float>, gko::int32>,
std::tuple<std::complex<float>, gko::int64>>;
#else
::testing::Types<std::tuple<std::complex<float>, gko::int32>,
std::tuple<std::complex<double>, gko::int32>,
std::tuple<std::complex<float>, gko::int64>,
std::tuple<std::complex<double>, gko::int64>>;
#endif
template <typename NewElementList, typename ExistingCombinationList>
using add_combination_left_t =
typename detail::add_combination_left<NewElementList,
ExistingCombinationList>::type;

template <typename FirstList, typename SecondList>
using merge_type_list_t =
typename detail::merge_type_list<FirstList, SecondList>::type;

template <template <typename...> class NewInnerWrapper, typename ListType>
using add_internal_wrapper_t =
typename detail::add_internal_wrapper<NewInnerWrapper, ListType>::type;

template <template <typename...> class NewOuterWrapper, typename ListType>
using change_outer_wrapper_t =
typename detail::change_outer_wrapper<NewOuterWrapper, ListType>::type;


using TwoValueIndexType =
using RealValueTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<
std::tuple<float, float, gko::int32>,
std::tuple<std::complex<float>, std::complex<float>, gko::int32>,
std::tuple<float, float, gko::int64>,
std::tuple<std::complex<float>, std::complex<float>, gko::int64>>;
::testing::Types<float>;
#else
::testing::Types<
std::tuple<float, float, gko::int32>,
std::tuple<float, double, gko::int32>,
std::tuple<double, double, gko::int32>,
std::tuple<double, float, gko::int32>,
std::tuple<std::complex<float>, std::complex<float>, gko::int32>,
std::tuple<std::complex<float>, std::complex<double>, gko::int32>,
std::tuple<std::complex<double>, std::complex<double>, gko::int32>,
std::tuple<std::complex<double>, std::complex<float>, gko::int32>,
std::tuple<float, float, gko::int64>,
std::tuple<float, double, gko::int64>,
std::tuple<double, double, gko::int64>,
std::tuple<double, float, gko::int64>,
std::tuple<std::complex<float>, std::complex<float>, gko::int64>,
std::tuple<std::complex<float>, std::complex<double>, gko::int64>,
std::tuple<std::complex<double>, std::complex<double>, gko::int64>,
std::tuple<std::complex<double>, std::complex<float>, gko::int64>>;
::testing::Types<float, double>;
#endif

using ComplexValueTypes = add_internal_wrapper_t<std::complex, RealValueTypes>;

using ValueTypes = merge_type_list_t<RealValueTypes, ComplexValueTypes>;

using IndexTypes = ::testing::Types<int32, int64>;

using LocalGlobalIndexTypes =
::testing::Types<std::tuple<int32, int32>, std::tuple<int32, int64>,
std::tuple<int64, int64>>;

using PODTypes =
merge_type_list_t<merge_type_list_t<RealValueTypes, IndexTypes>,
::testing::Types<size_type>>;

using ComplexAndPODTypes = merge_type_list_t<ComplexValueTypes, PODTypes>;

using ValueIndexTypes = combine_types_t<ValueTypes, IndexTypes>;

using RealValueIndexTypes = combine_types_t<RealValueTypes, IndexTypes>;

using ComplexValueIndexTypes = combine_types_t<ComplexValueTypes, IndexTypes>;

using TwoValueIndexType = add_combination_t<
merge_type_list_t<combine_types_t<RealValueTypes, RealValueTypes>,
combine_types_t<ComplexValueTypes, ComplexValueTypes>>,
IndexTypes>;

using ValueLocalGlobalIndexTypes =
#if GINKGO_DPCPP_SINGLE_MODE
::testing::Types<std::tuple<float, gko::int32, int32>,
std::tuple<float, gko::int32, int64>,
std::tuple<float, gko::int64, int64>,
std::tuple<std::complex<float>, gko::int32, int32>,
std::tuple<std::complex<float>, gko::int32, int64>,
std::tuple<std::complex<float>, gko::int64, int64>>;
#else
::testing::Types<std::tuple<float, gko::int32, int32>,
std::tuple<float, gko::int32, int64>,
std::tuple<float, gko::int64, int64>,
std::tuple<double, gko::int32, int32>,
std::tuple<double, gko::int32, int64>,
std::tuple<double, gko::int64, int64>,
std::tuple<std::complex<float>, gko::int32, int32>,
std::tuple<std::complex<float>, gko::int32, int64>,
std::tuple<std::complex<float>, gko::int64, int64>,
std::tuple<std::complex<double>, gko::int32, int32>,
std::tuple<std::complex<double>, gko::int32, int64>,
std::tuple<std::complex<double>, gko::int64, int64>>;
#endif
add_combination_left_t<ValueTypes, LocalGlobalIndexTypes>;


template <typename Precision, typename OutputType>
Expand Down
1 change: 1 addition & 0 deletions core/test/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ginkgo_create_test(utils_test)
ginkgo_create_test(array_generator_test)
ginkgo_create_test(assertions_test)
ginkgo_create_test(matrix_generator_test)
Expand Down
Loading

0 comments on commit 26f3c87

Please sign in to comment.