Skip to content

Commit

Permalink
matrix test with half
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Oct 24, 2024
1 parent ac07523 commit e65a57a
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 102 deletions.
40 changes: 20 additions & 20 deletions reference/test/matrix/coo_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Coo : public ::testing::Test {
using Csr = gko::matrix::Csr<value_type, index_type>;
using Mtx = gko::matrix::Coo<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;
using MixedVec = gko::matrix::Dense<gko::next_precision<value_type>>;
using MixedVec =
gko::matrix::Dense<gko::next_precision_with_half<value_type>>;

Coo() : exec(gko::ReferenceExecutor::create()), mtx(Mtx::create(exec))
{
Expand Down Expand Up @@ -72,24 +73,24 @@ class Coo : public ::testing::Test {
std::unique_ptr<Mtx> uns_mtx;
};

TYPED_TEST_SUITE(Coo, gko::test::ValueIndexTypes, PairTypenameNameGenerator);
TYPED_TEST_SUITE(Coo, gko::test::ValueIndexTypesWithHalf,
PairTypenameNameGenerator);


TYPED_TEST(Coo, ConvertsToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Coo = typename TestFixture::Mtx;
using OtherCoo = gko::matrix::Coo<OtherType, IndexType>;
auto tmp = OtherCoo::create(this->exec);
auto res = Coo::create(this->exec);
// If OtherType is more precise: 0, otherwise r
auto residual = r<OtherType>::value < r<ValueType>::value
? gko::remove_complex<ValueType>{0}
: gko::remove_complex<ValueType>{
static_cast<gko::remove_complex<ValueType>>(
r<OtherType>::value)};
auto residual =
r<OtherType>::value < r<ValueType>::value
? gko::remove_complex<ValueType>{0}
: static_cast<gko::remove_complex<ValueType>>(r<OtherType>::value);

this->mtx->convert_to(tmp);
tmp->convert_to(res);
Expand All @@ -102,17 +103,16 @@ TYPED_TEST(Coo, MovesToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Coo = typename TestFixture::Mtx;
using OtherCoo = gko::matrix::Coo<OtherType, IndexType>;
auto tmp = OtherCoo::create(this->exec);
auto res = Coo::create(this->exec);
// If OtherType is more precise: 0, otherwise r
auto residual = r<OtherType>::value < r<ValueType>::value
? gko::remove_complex<ValueType>{0}
: gko::remove_complex<ValueType>{
static_cast<gko::remove_complex<ValueType>>(
r<OtherType>::value)};
auto residual =
r<OtherType>::value < r<ValueType>::value
? gko::remove_complex<ValueType>{0}
: static_cast<gko::remove_complex<ValueType>>(r<OtherType>::value);

this->mtx->move_to(tmp);
tmp->move_to(res);
Expand Down Expand Up @@ -218,7 +218,7 @@ TYPED_TEST(Coo, ConvertsEmptyToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Coo = typename TestFixture::Mtx;
using OtherCoo = gko::matrix::Coo<OtherType, IndexType>;
auto empty = OtherCoo::create(this->exec);
Expand All @@ -235,7 +235,7 @@ TYPED_TEST(Coo, MovesEmptyToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Coo = typename TestFixture::Mtx;
using OtherCoo = gko::matrix::Coo<OtherType, IndexType>;
auto empty = OtherCoo::create(this->exec);
Expand Down Expand Up @@ -706,7 +706,7 @@ TYPED_TEST(Coo, AppliesToComplex)
TYPED_TEST(Coo, AppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using Vec = gko::matrix::Dense<mixed_complex_type>;
auto exec = gko::ReferenceExecutor::create();
Expand Down Expand Up @@ -762,7 +762,7 @@ TYPED_TEST(Coo, AdvancedAppliesToComplex)
TYPED_TEST(Coo, AdvancedAppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using MixedDense = gko::matrix::Dense<mixed_value_type>;
using MixedDenseComplex = gko::matrix::Dense<mixed_complex_type>;
Expand Down Expand Up @@ -820,7 +820,7 @@ TYPED_TEST(Coo, ApplyAddsToComplex)
TYPED_TEST(Coo, ApplyAddsToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using MixedVec = gko::matrix::Dense<mixed_complex_type>;
auto exec = gko::ReferenceExecutor::create();
Expand Down Expand Up @@ -877,7 +877,7 @@ TYPED_TEST(Coo, ApplyAddsScaledToComplex)
TYPED_TEST(Coo, ApplyAddsScaledToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using MixedDense = gko::matrix::Dense<mixed_value_type>;
using MixedDenseComplex = gko::matrix::Dense<mixed_complex_type>;
Expand Down
44 changes: 23 additions & 21 deletions reference/test/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Csr : public ::testing::Test {
using Ell = gko::matrix::Ell<value_type, index_type>;
using Hybrid = gko::matrix::Hybrid<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;
using MixedVec = gko::matrix::Dense<gko::next_precision<value_type>>;
using MixedVec =
gko::matrix::Dense<gko::next_precision_with_half<value_type>>;
using Perm = gko::matrix::Permutation<index_type>;
using ScaledPerm = gko::matrix::ScaledPermutation<value_type, index_type>;

Expand Down Expand Up @@ -347,7 +348,8 @@ class Csr : public ::testing::Test {
index_type invalid_index = gko::invalid_index<index_type>();
};

TYPED_TEST_SUITE(Csr, gko::test::ValueIndexTypes, PairTypenameNameGenerator);
TYPED_TEST_SUITE(Csr, gko::test::ValueIndexTypesWithHalf,
PairTypenameNameGenerator);


TYPED_TEST(Csr, AppliesToDenseVector)
Expand All @@ -368,7 +370,7 @@ TYPED_TEST(Csr, MixedAppliesToDenseVector1)
{
// Both vectors have the same value type which differs from the matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec = typename gko::matrix::Dense<next_T>;
auto x = gko::initialize<Vec>({2.0, 1.0, 4.0}, this->exec);
auto y = Vec::create(this->exec, gko::dim<2>{2, 1});
Expand All @@ -383,7 +385,7 @@ TYPED_TEST(Csr, MixedAppliesToDenseVector2)
{
// Input vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
auto x = gko::initialize<Vec1>({2.0, 1.0, 4.0}, this->exec);
Expand All @@ -399,9 +401,9 @@ TYPED_TEST(Csr, MixedAppliesToDenseVector3)
{
// Output vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<gko::next_precision<T>>;
using Vec2 = gko::matrix::Dense<gko::next_precision_with_half<T>>;
auto x = gko::initialize<Vec2>({2.0, 1.0, 4.0}, this->exec);
auto y = Vec1::create(this->exec, gko::dim<2>{2, 1});

Expand Down Expand Up @@ -432,7 +434,7 @@ TYPED_TEST(Csr, MixedAppliesToDenseMatrix1)
{
// Both vectors have the same value type which differs from the matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec = gko::matrix::Dense<next_T>;
// clang-format off
auto x = gko::initialize<Vec>(
Expand All @@ -456,7 +458,7 @@ TYPED_TEST(Csr, MixedAppliesToDenseMatrix2)
{
// Input vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
// clang-format off
Expand All @@ -481,7 +483,7 @@ TYPED_TEST(Csr, MixedAppliesToDenseMatrix3)
{
// Output vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
// clang-format off
Expand Down Expand Up @@ -522,7 +524,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseVector1)
{
// Both vectors have the same value type which differs from the matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
auto beta = gko::initialize<Vec>({2.0}, this->exec);
Expand All @@ -539,7 +541,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseVector2)
{
// Input vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec1>({-1.0}, this->exec);
Expand All @@ -557,7 +559,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseVector3)
{
// Output vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec2>({-1.0}, this->exec);
Expand Down Expand Up @@ -595,7 +597,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseMatrix1)
{
// Both vectors have the same value type which differs from the matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
auto beta = gko::initialize<Vec>({2.0}, this->exec);
Expand All @@ -619,7 +621,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseMatrix2)
{
// Input vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec1>({-1.0}, this->exec);
Expand All @@ -639,7 +641,7 @@ TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseMatrix3)
{
// Output vector has same value type as matrix
using T = typename TestFixture::value_type;
using next_T = gko::next_precision<T>;
using next_T = gko::next_precision_with_half<T>;
using Vec1 = typename TestFixture::Vec;
using Vec2 = gko::matrix::Dense<next_T>;
auto alpha = gko::initialize<Vec2>({-1.0}, this->exec);
Expand Down Expand Up @@ -788,7 +790,7 @@ TYPED_TEST(Csr, ConvertsToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Csr = typename TestFixture::Mtx;
using OtherCsr = gko::matrix::Csr<OtherType, IndexType>;
auto tmp = OtherCsr::create(this->exec);
Expand All @@ -815,7 +817,7 @@ TYPED_TEST(Csr, MovesToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Csr = typename TestFixture::Mtx;
using OtherCsr = gko::matrix::Csr<OtherType, IndexType>;
auto tmp = OtherCsr::create(this->exec);
Expand Down Expand Up @@ -994,7 +996,7 @@ TYPED_TEST(Csr, ConvertsEmptyToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Csr = typename TestFixture::Mtx;
using OtherCsr = gko::matrix::Csr<OtherType, IndexType>;
auto empty = OtherCsr::create(this->exec);
Expand All @@ -1013,7 +1015,7 @@ TYPED_TEST(Csr, MovesEmptyToPrecision)
{
using ValueType = typename TestFixture::value_type;
using IndexType = typename TestFixture::index_type;
using OtherType = gko::next_precision<ValueType>;
using OtherType = gko::next_precision_with_half<ValueType>;
using Csr = typename TestFixture::Mtx;
using OtherCsr = gko::matrix::Csr<OtherType, IndexType>;
auto empty = OtherCsr::create(this->exec);
Expand Down Expand Up @@ -2050,7 +2052,7 @@ TYPED_TEST(Csr, AppliesToComplex)
TYPED_TEST(Csr, AppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using Vec = gko::matrix::Dense<mixed_complex_type>;
auto exec = gko::ReferenceExecutor::create();
Expand Down Expand Up @@ -2106,7 +2108,7 @@ TYPED_TEST(Csr, AdvancedAppliesToComplex)
TYPED_TEST(Csr, AdvancedAppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using MixedDense = gko::matrix::Dense<mixed_value_type>;
using MixedDenseComplex = gko::matrix::Dense<mixed_complex_type>;
Expand Down
17 changes: 9 additions & 8 deletions reference/test/matrix/dense_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class Dense : public ::testing::Test {
protected:
using value_type = T;
using Mtx = gko::matrix::Dense<value_type>;
using MixedMtx = gko::matrix::Dense<gko::next_precision<value_type>>;
using MixedMtx =
gko::matrix::Dense<gko::next_precision_with_half<value_type>>;
using ComplexMtx = gko::to_complex<Mtx>;
using RealMtx = gko::remove_complex<Mtx>;
Dense()
Expand Down Expand Up @@ -80,7 +81,7 @@ class Dense : public ::testing::Test {
};


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


TYPED_TEST(Dense, CopyRespectsStride)
Expand Down Expand Up @@ -745,7 +746,7 @@ TYPED_TEST(Dense, ConvertsToPrecision)
{
using Dense = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherT = typename gko::next_precision_with_half<T>;
using OtherDense = typename gko::matrix::Dense<OtherT>;
auto tmp = OtherDense::create(this->exec);
auto res = Dense::create(this->exec);
Expand All @@ -767,7 +768,7 @@ TYPED_TEST(Dense, MovesToPrecision)
{
using Dense = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherT = typename gko::next_precision_with_half<T>;
using OtherDense = typename gko::matrix::Dense<OtherT>;
auto tmp = OtherDense::create(this->exec);
auto res = Dense::create(this->exec);
Expand Down Expand Up @@ -1066,7 +1067,7 @@ TYPED_TEST(Dense, AppliesToComplex)
TYPED_TEST(Dense, AppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using Vec = gko::matrix::Dense<mixed_complex_type>;
auto exec = gko::ReferenceExecutor::create();
Expand Down Expand Up @@ -1120,7 +1121,7 @@ TYPED_TEST(Dense, AdvancedAppliesToComplex)
TYPED_TEST(Dense, AdvancedAppliesToMixedComplex)
{
using mixed_value_type =
gko::next_precision<typename TestFixture::value_type>;
gko::next_precision_with_half<typename TestFixture::value_type>;
using mixed_complex_type = gko::to_complex<mixed_value_type>;
using MixedDense = gko::matrix::Dense<mixed_value_type>;
using MixedDenseComplex = gko::matrix::Dense<mixed_complex_type>;
Expand Down Expand Up @@ -2013,7 +2014,7 @@ TYPED_TEST(Dense, ConvertsEmptyToPrecision)
{
using Dense = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherT = typename gko::next_precision_with_half<T>;
using OtherDense = typename gko::matrix::Dense<OtherT>;
auto empty = OtherDense::create(this->exec);
auto res = Dense::create(this->exec);
Expand All @@ -2028,7 +2029,7 @@ TYPED_TEST(Dense, MovesEmptyToPrecision)
{
using Dense = typename TestFixture::Mtx;
using T = typename TestFixture::value_type;
using OtherT = typename gko::next_precision<T>;
using OtherT = typename gko::next_precision_with_half<T>;
using OtherDense = typename gko::matrix::Dense<OtherT>;
auto empty = OtherDense::create(this->exec);
auto res = Dense::create(this->exec);
Expand Down
Loading

0 comments on commit e65a57a

Please sign in to comment.