Skip to content

Commit

Permalink
base such as composition/combination with half and corr. test
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Oct 29, 2024
1 parent e870b38 commit 3037d52
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 19 deletions.
8 changes: 6 additions & 2 deletions core/base/block_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ namespace {
template <typename Fn>
auto dispatch_dense(Fn&& fn, LinOp* v)
{
return run<matrix::Dense, float, double, std::complex<float>,
std::complex<double>>(v, std::forward<Fn>(fn));
return run<matrix::Dense, float, double,
#if GINKGO_ENABLE_HALF
half, std::complex<half>,
#endif
std::complex<float>, std::complex<double>>(v,
std::forward<Fn>(fn));
}


Expand Down
2 changes: 1 addition & 1 deletion core/base/combination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void Combination<ValueType>::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
2 changes: 1 addition & 1 deletion core/base/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void Composition<ValueType>::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
2 changes: 1 addition & 1 deletion core/base/dense_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void DenseCache<ValueType>::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
Expand Down
2 changes: 1 addition & 1 deletion core/base/perturbation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void Perturbation<ValueType>::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
3 changes: 2 additions & 1 deletion core/test/base/combination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Combination : public ::testing::Test {
std::vector<std::shared_ptr<gko::LinOp>> coefficients;
};

TYPED_TEST_SUITE(Combination, gko::test::ValueTypes, TypenameNameGenerator);
TYPED_TEST_SUITE(Combination, gko::test::ValueTypesWithHalf,
TypenameNameGenerator);


TYPED_TEST(Combination, CanBeEmpty)
Expand Down
3 changes: 2 additions & 1 deletion core/test/base/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Composition : public ::testing::Test {
std::vector<std::shared_ptr<gko::LinOp>> operators;
};

TYPED_TEST_SUITE(Composition, gko::test::ValueTypes, TypenameNameGenerator);
TYPED_TEST_SUITE(Composition, gko::test::ValueTypesWithHalf,
TypenameNameGenerator);


TYPED_TEST(Composition, CanBeEmpty)
Expand Down
3 changes: 2 additions & 1 deletion core/test/base/dense_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions reference/test/base/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class Composition : public ::testing::Test {
std::shared_ptr<Mtx> product;
};

TYPED_TEST_SUITE(Composition, gko::test::ValueTypes, TypenameNameGenerator);
TYPED_TEST_SUITE(Composition, gko::test::ValueTypesWithHalf,
TypenameNameGenerator);


TYPED_TEST(Composition, CopiesOnSameExecutor)
Expand Down Expand Up @@ -142,7 +143,7 @@ TYPED_TEST(Composition, AppliesSingleToMixedVector)
cmp = [ -9 -2 ]
[ 27 26 ]
*/
using Mtx = gko::matrix::Dense<gko::next_precision<TypeParam>>;
using Mtx = gko::matrix::Dense<gko::next_precision_with_half<TypeParam>>;
using value_type = typename Mtx::value_type;
auto cmp = gko::Composition<TypeParam>::create(this->product);
auto x = gko::initialize<Mtx>({1.0, 2.0}, this->exec);
Expand Down Expand Up @@ -182,7 +183,8 @@ TYPED_TEST(Composition, AppliesSingleToMixedComplexVector)
cmp = [ -9 -2 ]
[ 27 26 ]
*/
using value_type = gko::next_precision<gko::to_complex<TypeParam>>;
using value_type =
gko::next_precision_with_half<gko::to_complex<TypeParam>>;
using Mtx = gko::matrix::Dense<value_type>;
auto cmp = gko::Composition<TypeParam>::create(this->product);
auto x = gko::initialize<Mtx>(
Expand Down Expand Up @@ -222,7 +224,7 @@ TYPED_TEST(Composition, AppliesSingleLinearCombinationToMixedVector)
cmp = [ -9 -2 ]
[ 27 26 ]
*/
using value_type = gko::next_precision<TypeParam>;
using value_type = gko::next_precision_with_half<TypeParam>;
using Mtx = gko::matrix::Dense<value_type>;
auto cmp = gko::Composition<TypeParam>::create(this->product);
auto alpha = gko::initialize<Mtx>({3.0}, this->exec);
Expand Down Expand Up @@ -267,7 +269,8 @@ TYPED_TEST(Composition, AppliesSingleLinearCombinationToMixedComplexVector)
cmp = [ -9 -2 ]
[ 27 26 ]
*/
using MixedDense = gko::matrix::Dense<gko::next_precision<TypeParam>>;
using MixedDense =
gko::matrix::Dense<gko::next_precision_with_half<TypeParam>>;
using MixedDenseComplex = gko::to_complex<MixedDense>;
using value_type = typename MixedDenseComplex::value_type;
auto cmp = gko::Composition<TypeParam>::create(this->product);
Expand Down
13 changes: 8 additions & 5 deletions reference/test/base/perturbation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Perturbation : public ::testing::Test {
std::shared_ptr<gko::LinOp> scalar;
};

TYPED_TEST_SUITE(Perturbation, gko::test::ValueTypes, TypenameNameGenerator);
TYPED_TEST_SUITE(Perturbation, gko::test::ValueTypesWithHalf,
TypenameNameGenerator);


TYPED_TEST(Perturbation, CopiesOnSameExecutor)
Expand Down Expand Up @@ -101,7 +102,7 @@ TYPED_TEST(Perturbation, AppliesToMixedVector)
cmp = I + 2 * [ 2 ] * [ 3 2 ]
[ 1 ]
*/
using Mtx = gko::matrix::Dense<gko::next_precision<TypeParam>>;
using Mtx = gko::matrix::Dense<gko::next_precision_with_half<TypeParam>>;
using value_type = typename Mtx::value_type;
auto cmp = gko::Perturbation<TypeParam>::create(this->scalar, this->basis,
this->projector);
Expand Down Expand Up @@ -143,7 +144,8 @@ TYPED_TEST(Perturbation, AppliesToMixedComplexVector)
cmp = I + 2 * [ 2 ] * [ 3 2 ]
[ 1 ]
*/
using value_type = gko::to_complex<gko::next_precision<TypeParam>>;
using value_type =
gko::to_complex<gko::next_precision_with_half<TypeParam>>;
using Mtx = gko::matrix::Dense<value_type>;
auto cmp = gko::Perturbation<TypeParam>::create(this->scalar, this->basis,
this->projector);
Expand Down Expand Up @@ -185,7 +187,7 @@ TYPED_TEST(Perturbation, AppliesLinearCombinationToMixedVector)
cmp = I + 2 * [ 2 ] * [ 3 2 ]
[ 1 ]
*/
using value_type = gko::next_precision<TypeParam>;
using value_type = gko::next_precision_with_half<TypeParam>;
using Mtx = gko::matrix::Dense<value_type>;
auto cmp = gko::Perturbation<TypeParam>::create(this->scalar, this->basis,
this->projector);
Expand Down Expand Up @@ -232,7 +234,8 @@ TYPED_TEST(Perturbation, AppliesLinearCombinationToMixedComplexVector)
cmp = I + 2 * [ 2 ] * [ 3 2 ]
[ 1 ]
*/
using MixedDense = gko::matrix::Dense<gko::next_precision<TypeParam>>;
using MixedDense =
gko::matrix::Dense<gko::next_precision_with_half<TypeParam>>;
using MixedDenseComplex = gko::to_complex<MixedDense>;
using value_type = typename MixedDenseComplex::value_type;
auto cmp = gko::Perturbation<TypeParam>::create(this->scalar, this->basis,
Expand Down

0 comments on commit 3037d52

Please sign in to comment.