From a15d56f915f8f102a29fbda9eba4a0623a0bf4da Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Tue, 1 Sep 2020 17:07:06 +0200 Subject: [PATCH 01/15] add template_convertor and remove_complex for class --- common/base/math.hpp.inc | 6 +- core/test/base/math.cpp | 40 +++++++++++ include/ginkgo/core/base/math.hpp | 109 +++++++++++++++++++++++++++--- 3 files changed, 146 insertions(+), 9 deletions(-) diff --git a/common/base/math.hpp.inc b/common/base/math.hpp.inc index 3ba49b585c3..576ab32859c 100644 --- a/common/base/math.hpp.inc +++ b/common/base/math.hpp.inc @@ -54,10 +54,14 @@ struct is_complex_impl> : public std::integral_constant {}; +template +struct is_complex_or_scalar_impl> : std::is_scalar {}; + + template struct truncate_type_impl> { using type = thrust::complex::type>; }; -} // namespace detail \ No newline at end of file +} // namespace detail diff --git a/core/test/base/math.cpp b/core/test/base/math.cpp index c63cd4ae8e9..0e54c87f788 100644 --- a/core/test/base/math.cpp +++ b/core/test/base/math.cpp @@ -53,6 +53,10 @@ static_assert( "imag must return a real type"); +template +class DummyClass {}; + + template void test_real_is_finite() { @@ -135,4 +139,40 @@ TEST(Conjugate, DoubleComplex) } +TEST(RemoveComplexClass, Float) +{ + using origin = DummyClass; + using expect = DummyClass; + bool check = std::is_same>::value; + ASSERT_TRUE(check); +} + + +TEST(RemoveComplexClass, Double) +{ + using origin = DummyClass; + using expect = DummyClass; + bool check = std::is_same>::value; + ASSERT_TRUE(check); +} + + +TEST(RemoveComplexClass, FloatComplex) +{ + using origin = DummyClass, int>; + using expect = DummyClass; + bool check = std::is_same>::value; + ASSERT_TRUE(check); +} + + +TEST(RemoveComplexClass, DoubleComplex) +{ + using origin = DummyClass, int>; + using expect = DummyClass; + bool check = std::is_same>::value; + ASSERT_TRUE(check); +} + + } // namespace diff --git a/include/ginkgo/core/base/math.hpp b/include/ginkgo/core/base/math.hpp index 9f9dabb8f75..564635556cf 100644 --- a/include/ginkgo/core/base/math.hpp +++ b/include/ginkgo/core/base/math.hpp @@ -141,6 +141,65 @@ struct is_complex_impl> : public std::integral_constant {}; +template +struct is_complex_or_scalar_impl : std::is_scalar {}; + +template +struct is_complex_or_scalar_impl> : std::is_scalar {}; + + +/** + * template_convertor is converting the template parameters of a class by + * convertor. + * + * @tparam convertor which convert one type to another type + * @tparam T type + */ +template