Skip to content

Commit f732df9

Browse files
committed
add reference tests for zero NaN behavior
1 parent c234e8c commit f732df9

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

reference/test/matrix/csr_kernels.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -518,6 +518,22 @@ TYPED_TEST(Csr, AppliesLinearCombinationToDenseVector)
518518
}
519519

520520

521+
TYPED_TEST(Csr, AppliesLinearCombinationToDenseVectorWithZeroBetaNaN)
522+
{
523+
using Vec = typename TestFixture::Vec;
524+
using T = typename TestFixture::value_type;
525+
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
526+
auto beta = gko::initialize<Vec>({0.0}, this->exec);
527+
auto x = gko::initialize<Vec>({2.0, 1.0, 4.0}, this->exec);
528+
auto y = gko::initialize<Vec>({gko::nan<T>(), gko::nan<T>()}, this->exec);
529+
530+
this->mtx->apply(alpha, x, beta, y);
531+
532+
EXPECT_EQ(y->at(0), T{-13.0});
533+
EXPECT_EQ(y->at(1), T{-5.0});
534+
}
535+
536+
521537
TYPED_TEST(Csr, MixedAppliesLinearCombinationToDenseVector1)
522538
{
523539
// Both vectors have the same value type which differs from the matrix

reference/test/matrix/dense_kernels.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ TYPED_TEST(Dense, AppliesLinearCombinationToDense)
230230
}
231231

232232

233+
TYPED_TEST(Dense, AppliesLinearCombinationToDenseWithZeroBetaNan)
234+
{
235+
using Mtx = typename TestFixture::Mtx;
236+
using T = typename TestFixture::value_type;
237+
auto alpha = gko::initialize<Mtx>({-1.0}, this->exec);
238+
auto beta = gko::initialize<Mtx>({0.0}, this->exec);
239+
this->mtx3->fill(gko::nan<T>());
240+
241+
this->mtx2->apply(alpha, this->mtx1, beta, this->mtx3);
242+
243+
EXPECT_EQ(this->mtx3->at(0, 0), T{0.5});
244+
EXPECT_EQ(this->mtx3->at(0, 1), T{0.5});
245+
EXPECT_EQ(this->mtx3->at(0, 2), T{0.5});
246+
EXPECT_EQ(this->mtx3->at(1, 0), T{-1.0});
247+
EXPECT_EQ(this->mtx3->at(1, 1), T{-1.0});
248+
EXPECT_EQ(this->mtx3->at(1, 2), T{-1.0});
249+
}
250+
251+
233252
TYPED_TEST(Dense, AppliesLinearCombinationToMixedDense)
234253
{
235254
using MixedMtx = typename TestFixture::MixedMtx;

reference/test/matrix/ell_kernels.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -244,6 +244,21 @@ TYPED_TEST(Ell, AppliesLinearCombinationToDenseVector)
244244
}
245245

246246

247+
TYPED_TEST(Ell, AppliesLinearCombinationToDenseVectorWithZeroBetaNaN)
248+
{
249+
using T = typename TestFixture::value_type;
250+
using Vec = typename TestFixture::Vec;
251+
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
252+
auto beta = gko::initialize<Vec>({0.0}, this->exec);
253+
auto x = gko::initialize<Vec>({2.0, 1.0, 4.0}, this->exec);
254+
auto y = gko::initialize<Vec>({gko::nan<T>(), gko::nan<T>()}, this->exec);
255+
256+
this->mtx1->apply(alpha, x, beta, y);
257+
258+
GKO_ASSERT_MTX_NEAR(y, l({-13.0, -5.0}), 0.0);
259+
}
260+
261+
247262
TYPED_TEST(Ell, MixedAppliesLinearCombinationToDenseVector1)
248263
{
249264
// Both vectors have the same value type which differs from the matrix

reference/test/matrix/sellp_kernels.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -114,6 +114,21 @@ TYPED_TEST(Sellp, AppliesLinearCombinationToDenseVector)
114114
}
115115

116116

117+
TYPED_TEST(Sellp, AppliesLinearCombinationToDenseVectorWithZeroBetaNaN)
118+
{
119+
using T = typename TestFixture::value_type;
120+
using Vec = typename TestFixture::Vec;
121+
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
122+
auto beta = gko::initialize<Vec>({0.0}, this->exec);
123+
auto x = gko::initialize<Vec>({2.0, 1.0, 4.0}, this->exec);
124+
auto y = gko::initialize<Vec>({gko::nan<T>(), gko::nan<T>()}, this->exec);
125+
126+
this->mtx1->apply(alpha, x, beta, y);
127+
128+
GKO_ASSERT_MTX_NEAR(y, l({-13.0, -5.0}), 0.0);
129+
}
130+
131+
117132
TYPED_TEST(Sellp, AppliesLinearCombinationToMixedDenseVector)
118133
{
119134
using value_type = gko::next_precision<typename TestFixture::value_type>;

reference/test/matrix/sparsity_csr_kernels.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -190,6 +190,22 @@ TYPED_TEST(SparsityCsr, AppliesLinearCombinationToDenseVector)
190190
}
191191

192192

193+
TYPED_TEST(SparsityCsr, AppliesLinearCombinationToDenseVectorWithZeroBetaNaN)
194+
{
195+
using Vec = typename TestFixture::Vec;
196+
using T = typename TestFixture::value_type;
197+
auto alpha = gko::initialize<Vec>({-1.0}, this->exec);
198+
auto beta = gko::initialize<Vec>({0.0}, this->exec);
199+
auto x = gko::initialize<Vec>({2.0, 1.0, 4.0}, this->exec);
200+
auto y = gko::initialize<Vec>({gko::nan<T>(), gko::nan<T>()}, this->exec);
201+
202+
this->mtx->apply(alpha, x, beta, y);
203+
204+
EXPECT_EQ(y->at(0), T{-7.0});
205+
EXPECT_EQ(y->at(1), T{-1.0});
206+
}
207+
208+
193209
TYPED_TEST(SparsityCsr, AppliesLinearCombinationToMixedDenseVector)
194210
{
195211
using T = gko::next_precision<typename TestFixture::value_type>;

0 commit comments

Comments
 (0)