From 3037d5216702b4cd88a2c6e05fea5ff375da318d Mon Sep 17 00:00:00 2001 From: "Yu-Hsiang M. Tsai" Date: Fri, 25 Oct 2024 16:29:56 +0200 Subject: [PATCH] base such as composition/combination with half and corr. test --- core/base/block_operator.cpp | 8 ++++++-- core/base/combination.cpp | 2 +- core/base/composition.cpp | 2 +- core/base/dense_cache.cpp | 2 +- core/base/perturbation.cpp | 2 +- core/test/base/combination.cpp | 3 ++- core/test/base/composition.cpp | 3 ++- core/test/base/dense_cache.cpp | 3 ++- reference/test/base/composition.cpp | 13 ++++++++----- reference/test/base/perturbation.cpp | 13 ++++++++----- 10 files changed, 32 insertions(+), 19 deletions(-) diff --git a/core/base/block_operator.cpp b/core/base/block_operator.cpp index f53375301a8..68c00aeee70 100644 --- a/core/base/block_operator.cpp +++ b/core/base/block_operator.cpp @@ -19,8 +19,12 @@ namespace { template auto dispatch_dense(Fn&& fn, LinOp* v) { - return run, - std::complex>(v, std::forward(fn)); + return run, +#endif + std::complex, std::complex>(v, + std::forward(fn)); } diff --git a/core/base/combination.cpp b/core/base/combination.cpp index 3b30b77d38c..53af6742f6e 100644 --- a/core/base/combination.cpp +++ b/core/base/combination.cpp @@ -168,7 +168,7 @@ void Combination::apply_impl(const LinOp* alpha, const LinOp* b, #define GKO_DECLARE_COMBINATION(_type) class Combination<_type> -GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_COMBINATION); +GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_WITH_HALF(GKO_DECLARE_COMBINATION); } // namespace gko diff --git a/core/base/composition.cpp b/core/base/composition.cpp index 82c8152300b..f6a7df21e45 100644 --- a/core/base/composition.cpp +++ b/core/base/composition.cpp @@ -222,7 +222,7 @@ void Composition::apply_impl(const LinOp* alpha, const LinOp* b, #define GKO_DECLARE_COMPOSITION(_type) class Composition<_type> -GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_COMPOSITION); +GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_WITH_HALF(GKO_DECLARE_COMPOSITION); } // namespace gko diff --git a/core/base/dense_cache.cpp b/core/base/dense_cache.cpp index 6adbb6107c9..48900a586e8 100644 --- a/core/base/dense_cache.cpp +++ b/core/base/dense_cache.cpp @@ -33,7 +33,7 @@ void DenseCache::init_from( #define GKO_DECLARE_DENSE_CACHE(_type) class DenseCache<_type> -GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_DENSE_CACHE); +GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_WITH_HALF(GKO_DECLARE_DENSE_CACHE); } // namespace detail diff --git a/core/base/perturbation.cpp b/core/base/perturbation.cpp index 686c54e5b2d..1fa06ded65e 100644 --- a/core/base/perturbation.cpp +++ b/core/base/perturbation.cpp @@ -182,7 +182,7 @@ void Perturbation::apply_impl(const LinOp* alpha, const LinOp* b, #define GKO_DECLARE_PERTURBATION(_type) class Perturbation<_type> -GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_PERTURBATION); +GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_WITH_HALF(GKO_DECLARE_PERTURBATION); } // namespace gko diff --git a/core/test/base/combination.cpp b/core/test/base/combination.cpp index 73c30ffe11c..63c73cfa168 100644 --- a/core/test/base/combination.cpp +++ b/core/test/base/combination.cpp @@ -43,7 +43,8 @@ class Combination : public ::testing::Test { std::vector> coefficients; }; -TYPED_TEST_SUITE(Combination, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(Combination, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(Combination, CanBeEmpty) diff --git a/core/test/base/composition.cpp b/core/test/base/composition.cpp index 122755b8f92..58c86894fc8 100644 --- a/core/test/base/composition.cpp +++ b/core/test/base/composition.cpp @@ -41,7 +41,8 @@ class Composition : public ::testing::Test { std::vector> operators; }; -TYPED_TEST_SUITE(Composition, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(Composition, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(Composition, CanBeEmpty) diff --git a/core/test/base/dense_cache.cpp b/core/test/base/dense_cache.cpp index 526187610a4..54d904617db 100644 --- a/core/test/base/dense_cache.cpp +++ b/core/test/base/dense_cache.cpp @@ -31,7 +31,8 @@ class DenseCache : public ::testing::Test { }; -TYPED_TEST_SUITE(DenseCache, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(DenseCache, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(DenseCache, CanDefaultConstruct) diff --git a/reference/test/base/composition.cpp b/reference/test/base/composition.cpp index f736edb53f9..d17b8602ce8 100644 --- a/reference/test/base/composition.cpp +++ b/reference/test/base/composition.cpp @@ -75,7 +75,8 @@ class Composition : public ::testing::Test { std::shared_ptr product; }; -TYPED_TEST_SUITE(Composition, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(Composition, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(Composition, CopiesOnSameExecutor) @@ -142,7 +143,7 @@ TYPED_TEST(Composition, AppliesSingleToMixedVector) cmp = [ -9 -2 ] [ 27 26 ] */ - using Mtx = gko::matrix::Dense>; + using Mtx = gko::matrix::Dense>; using value_type = typename Mtx::value_type; auto cmp = gko::Composition::create(this->product); auto x = gko::initialize({1.0, 2.0}, this->exec); @@ -182,7 +183,8 @@ TYPED_TEST(Composition, AppliesSingleToMixedComplexVector) cmp = [ -9 -2 ] [ 27 26 ] */ - using value_type = gko::next_precision>; + using value_type = + gko::next_precision_with_half>; using Mtx = gko::matrix::Dense; auto cmp = gko::Composition::create(this->product); auto x = gko::initialize( @@ -222,7 +224,7 @@ TYPED_TEST(Composition, AppliesSingleLinearCombinationToMixedVector) cmp = [ -9 -2 ] [ 27 26 ] */ - using value_type = gko::next_precision; + using value_type = gko::next_precision_with_half; using Mtx = gko::matrix::Dense; auto cmp = gko::Composition::create(this->product); auto alpha = gko::initialize({3.0}, this->exec); @@ -267,7 +269,8 @@ TYPED_TEST(Composition, AppliesSingleLinearCombinationToMixedComplexVector) cmp = [ -9 -2 ] [ 27 26 ] */ - using MixedDense = gko::matrix::Dense>; + using MixedDense = + gko::matrix::Dense>; using MixedDenseComplex = gko::to_complex; using value_type = typename MixedDenseComplex::value_type; auto cmp = gko::Composition::create(this->product); diff --git a/reference/test/base/perturbation.cpp b/reference/test/base/perturbation.cpp index b6be9ab1563..50a5fe7db20 100644 --- a/reference/test/base/perturbation.cpp +++ b/reference/test/base/perturbation.cpp @@ -33,7 +33,8 @@ class Perturbation : public ::testing::Test { std::shared_ptr scalar; }; -TYPED_TEST_SUITE(Perturbation, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(Perturbation, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(Perturbation, CopiesOnSameExecutor) @@ -101,7 +102,7 @@ TYPED_TEST(Perturbation, AppliesToMixedVector) cmp = I + 2 * [ 2 ] * [ 3 2 ] [ 1 ] */ - using Mtx = gko::matrix::Dense>; + using Mtx = gko::matrix::Dense>; using value_type = typename Mtx::value_type; auto cmp = gko::Perturbation::create(this->scalar, this->basis, this->projector); @@ -143,7 +144,8 @@ TYPED_TEST(Perturbation, AppliesToMixedComplexVector) cmp = I + 2 * [ 2 ] * [ 3 2 ] [ 1 ] */ - using value_type = gko::to_complex>; + using value_type = + gko::to_complex>; using Mtx = gko::matrix::Dense; auto cmp = gko::Perturbation::create(this->scalar, this->basis, this->projector); @@ -185,7 +187,7 @@ TYPED_TEST(Perturbation, AppliesLinearCombinationToMixedVector) cmp = I + 2 * [ 2 ] * [ 3 2 ] [ 1 ] */ - using value_type = gko::next_precision; + using value_type = gko::next_precision_with_half; using Mtx = gko::matrix::Dense; auto cmp = gko::Perturbation::create(this->scalar, this->basis, this->projector); @@ -232,7 +234,8 @@ TYPED_TEST(Perturbation, AppliesLinearCombinationToMixedComplexVector) cmp = I + 2 * [ 2 ] * [ 3 2 ] [ 1 ] */ - using MixedDense = gko::matrix::Dense>; + using MixedDense = + gko::matrix::Dense>; using MixedDenseComplex = gko::to_complex; using value_type = typename MixedDenseComplex::value_type; auto cmp = gko::Perturbation::create(this->scalar, this->basis,