diff --git a/cuda/test/matrix/ell_kernels.cpp b/cuda/test/matrix/ell_kernels.cpp index dff573a284f..e24f7083728 100644 --- a/cuda/test/matrix/ell_kernels.cpp +++ b/cuda/test/matrix/ell_kernels.cpp @@ -58,6 +58,7 @@ class Ell : public ::testing::Test { protected: using Mtx = gko::matrix::Ell<>; using Vec = gko::matrix::Dense<>; + using Vec2 = gko::matrix::Dense; using ComplexVec = gko::matrix::Dense>; Ell() : rand_engine(42) {} @@ -92,22 +93,35 @@ class Ell : public ::testing::Test { stride); mtx->copy_from(gen_mtx(num_rows, num_cols)); expected = gen_mtx(num_rows, num_vectors); + expected2 = Vec2::create(ref); + expected2->copy_from(expected.get()); y = gen_mtx(num_cols, num_vectors); + y2 = Vec2::create(ref); + y2->copy_from(y.get()); alpha = gko::initialize({2.0}, ref); + alpha2 = gko::initialize({2.0}, ref); beta = gko::initialize({-1.0}, ref); + beta2 = gko::initialize({-1.0}, ref); dmtx = Mtx::create(cuda); dmtx->copy_from(mtx.get()); dresult = Vec::create(cuda); dresult->copy_from(expected.get()); + dresult2 = Vec2::create(cuda); + dresult2->copy_from(expected2.get()); dy = Vec::create(cuda); dy->copy_from(y.get()); + dy2 = Vec2::create(cuda); + dy2->copy_from(y2.get()); dalpha = Vec::create(cuda); dalpha->copy_from(alpha.get()); + dalpha2 = Vec2::create(cuda); + dalpha2->copy_from(alpha2.get()); dbeta = Vec::create(cuda); dbeta->copy_from(beta.get()); + dbeta2 = Vec2::create(cuda); + dbeta2->copy_from(beta2.get()); } - std::shared_ptr ref; std::shared_ptr cuda; @@ -115,15 +129,23 @@ class Ell : public ::testing::Test { std::unique_ptr mtx; std::unique_ptr expected; + std::unique_ptr expected2; std::unique_ptr y; + std::unique_ptr y2; std::unique_ptr alpha; + std::unique_ptr alpha2; std::unique_ptr beta; + std::unique_ptr beta2; std::unique_ptr dmtx; std::unique_ptr dresult; + std::unique_ptr dresult2; std::unique_ptr dy; + std::unique_ptr dy2; std::unique_ptr dalpha; + std::unique_ptr dalpha2; std::unique_ptr dbeta; + std::unique_ptr dbeta2; }; @@ -138,6 +160,39 @@ TEST_F(Ell, SimpleApplyIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyIsEquivalentToRef) { set_up_apply_data(); @@ -149,6 +204,39 @@ TEST_F(Ell, AdvancedApplyIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyWithStrideIsEquivalentToRef) { set_up_apply_data(532, 231, 1, 300, 600); @@ -160,6 +248,39 @@ TEST_F(Ell, SimpleApplyWithStrideIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithStrideIsEquivalentToRef) { set_up_apply_data(532, 231, 1, 300, 600); @@ -170,6 +291,39 @@ TEST_F(Ell, AdvancedApplyWithStrideIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyWithStrideToDenseMatrixIsEquivalentToRef) { set_up_apply_data(532, 231, 3, 300, 600); @@ -181,6 +335,39 @@ TEST_F(Ell, SimpleApplyWithStrideToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef) { set_up_apply_data(532, 231, 3, 300, 600); @@ -192,6 +379,39 @@ TEST_F(Ell, AdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyByAtomicIsEquivalentToRef) { set_up_apply_data(10, 10000); diff --git a/hip/test/matrix/ell_kernels.hip.cpp b/hip/test/matrix/ell_kernels.hip.cpp index e9a875eb544..77253125abe 100644 --- a/hip/test/matrix/ell_kernels.hip.cpp +++ b/hip/test/matrix/ell_kernels.hip.cpp @@ -58,6 +58,7 @@ class Ell : public ::testing::Test { protected: using Mtx = gko::matrix::Ell<>; using Vec = gko::matrix::Dense<>; + using Vec2 = gko::matrix::Dense; using ComplexVec = gko::matrix::Dense>; Ell() : rand_engine(42) {} @@ -92,19 +93,33 @@ class Ell : public ::testing::Test { stride); mtx->copy_from(gen_mtx(num_rows, num_cols)); expected = gen_mtx(num_rows, num_vectors); + expected2 = Vec2::create(ref); + expected2->copy_from(expected.get()); y = gen_mtx(num_cols, num_vectors); + y2 = Vec2::create(ref); + y2->copy_from(y.get()); alpha = gko::initialize({2.0}, ref); + alpha2 = gko::initialize({2.0}, ref); beta = gko::initialize({-1.0}, ref); + beta2 = gko::initialize({-1.0}, ref); dmtx = Mtx::create(hip); dmtx->copy_from(mtx.get()); dresult = Vec::create(hip); dresult->copy_from(expected.get()); + dresult2 = Vec2::create(hip); + dresult2->copy_from(expected2.get()); dy = Vec::create(hip); dy->copy_from(y.get()); + dy2 = Vec2::create(hip); + dy2->copy_from(y2.get()); dalpha = Vec::create(hip); dalpha->copy_from(alpha.get()); + dalpha2 = Vec2::create(hip); + dalpha2->copy_from(alpha2.get()); dbeta = Vec::create(hip); dbeta->copy_from(beta.get()); + dbeta2 = Vec2::create(hip); + dbeta2->copy_from(beta2.get()); } @@ -115,15 +130,23 @@ class Ell : public ::testing::Test { std::unique_ptr mtx; std::unique_ptr expected; + std::unique_ptr expected2; std::unique_ptr y; + std::unique_ptr y2; std::unique_ptr alpha; + std::unique_ptr alpha2; std::unique_ptr beta; + std::unique_ptr beta2; std::unique_ptr dmtx; std::unique_ptr dresult; + std::unique_ptr dresult2; std::unique_ptr dy; + std::unique_ptr dy2; std::unique_ptr dalpha; + std::unique_ptr dalpha2; std::unique_ptr dbeta; + std::unique_ptr dbeta2; }; @@ -138,6 +161,39 @@ TEST_F(Ell, SimpleApplyIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyIsEquivalentToRef) { set_up_apply_data(); @@ -149,6 +205,39 @@ TEST_F(Ell, AdvancedApplyIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyWithStrideIsEquivalentToRef) { set_up_apply_data(532, 231, 1, 300, 600); @@ -160,6 +249,39 @@ TEST_F(Ell, SimpleApplyWithStrideIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithStrideIsEquivalentToRef) { set_up_apply_data(532, 231, 1, 300, 600); @@ -170,6 +292,39 @@ TEST_F(Ell, AdvancedApplyWithStrideIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 1, 300, 600); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyWithStrideToDenseMatrixIsEquivalentToRef) { set_up_apply_data(532, 231, 3, 300, 600); @@ -181,6 +336,39 @@ TEST_F(Ell, SimpleApplyWithStrideToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithStrideToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef) { set_up_apply_data(532, 231, 3, 300, 600); @@ -192,6 +380,39 @@ TEST_F(Ell, AdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithStrideToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(532, 231, 3, 300, 600); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyByAtomicIsEquivalentToRef) { set_up_apply_data(10, 10000); diff --git a/omp/test/matrix/ell_kernels.cpp b/omp/test/matrix/ell_kernels.cpp index 281292e9684..01f1a31121d 100644 --- a/omp/test/matrix/ell_kernels.cpp +++ b/omp/test/matrix/ell_kernels.cpp @@ -57,6 +57,7 @@ class Ell : public ::testing::Test { protected: using Mtx = gko::matrix::Ell<>; using Vec = gko::matrix::Dense<>; + using Vec2 = gko::matrix::Dense; using ComplexVec = gko::matrix::Dense>; Ell() : rand_engine(42) {} @@ -90,19 +91,33 @@ class Ell : public ::testing::Test { mtx = Mtx::create(ref, gko::dim<2>{}, max_nonzeros_per_row, stride); mtx->copy_from(gen_mtx(532, 231, 1)); expected = gen_mtx(532, num_vectors, 1); + expected2 = Vec2::create(ref); + expected2->copy_from(expected.get()); y = gen_mtx(231, num_vectors, 1); + y2 = Vec2::create(ref); + y2->copy_from(y.get()); alpha = gko::initialize({2.0}, ref); + alpha2 = gko::initialize({2.0}, ref); beta = gko::initialize({-1.0}, ref); + beta2 = gko::initialize({-1.0}, ref); dmtx = Mtx::create(omp); dmtx->copy_from(mtx.get()); dresult = Vec::create(omp); dresult->copy_from(expected.get()); + dresult2 = Vec2::create(omp); + dresult2->copy_from(expected2.get()); dy = Vec::create(omp); dy->copy_from(y.get()); + dy2 = Vec2::create(omp); + dy2->copy_from(y2.get()); dalpha = Vec::create(omp); dalpha->copy_from(alpha.get()); + dalpha2 = Vec2::create(omp); + dalpha2->copy_from(alpha2.get()); dbeta = Vec::create(omp); dbeta->copy_from(beta.get()); + dbeta2 = Vec2::create(omp); + dbeta2->copy_from(beta2.get()); } std::shared_ptr ref; @@ -112,15 +127,23 @@ class Ell : public ::testing::Test { std::unique_ptr mtx; std::unique_ptr expected; + std::unique_ptr expected2; std::unique_ptr y; + std::unique_ptr y2; std::unique_ptr alpha; + std::unique_ptr alpha2; std::unique_ptr beta; + std::unique_ptr beta2; std::unique_ptr dmtx; std::unique_ptr dresult; + std::unique_ptr dresult2; std::unique_ptr dy; + std::unique_ptr dy2; std::unique_ptr dalpha; + std::unique_ptr dalpha2; std::unique_ptr dbeta; + std::unique_ptr dbeta2; }; @@ -135,6 +158,39 @@ TEST_F(Ell, SimpleApplyIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyIsEquivalentToRef) { set_up_apply_data(); @@ -146,6 +202,39 @@ TEST_F(Ell, AdvancedApplyIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef1) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef2) +{ + set_up_apply_data(); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyIsEquivalentToRef3) +{ + set_up_apply_data(); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyWithPaddingIsEquivalentToRef) { set_up_apply_data(300, 600); @@ -157,6 +246,39 @@ TEST_F(Ell, SimpleApplyWithPaddingIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithPaddingIsEquivalentToRef1) +{ + set_up_apply_data(300, 600); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithPaddingIsEquivalentToRef2) +{ + set_up_apply_data(300, 600); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithPaddingIsEquivalentToRef3) +{ + set_up_apply_data(300, 600); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithPaddingIsEquivalentToRef) { set_up_apply_data(300, 600); @@ -167,6 +289,39 @@ TEST_F(Ell, AdvancedApplyWithPaddingIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithPaddingIsEquivalentToRef1) +{ + set_up_apply_data(300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithPaddingIsEquivalentToRef2) +{ + set_up_apply_data(300, 600); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithPaddingIsEquivalentToRef3) +{ + set_up_apply_data(300, 600); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, SimpleApplyToDenseMatrixIsEquivalentToRef) { set_up_apply_data(0, 0, 3); @@ -178,6 +333,39 @@ TEST_F(Ell, SimpleApplyToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyToDenseMatrixIsEquivalentToRef) { set_up_apply_data(0, 0, 3); @@ -189,7 +377,40 @@ TEST_F(Ell, AdvancedApplyToDenseMatrixIsEquivalentToRef) } -TEST_F(Ell, SimpleApplyWithPaddinToDenseMatrixIsEquivalentToRef) +TEST_F(Ell, MixedAdvancedApplyToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(0, 0, 3); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, SimpleApplyWithPaddingToDenseMatrixIsEquivalentToRef) { set_up_apply_data(300, 600, 3); @@ -200,6 +421,39 @@ TEST_F(Ell, SimpleApplyWithPaddinToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedSimpleApplyWithPaddingToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(y2.get(), expected2.get()); + dmtx->apply(dy2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithPaddingToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(y2.get(), expected.get()); + dmtx->apply(dy2.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedSimpleApplyWithPaddingToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(y.get(), expected2.get()); + dmtx->apply(dy.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, AdvancedApplyWithPaddingToDenseMatrixIsEquivalentToRef) { set_up_apply_data(300, 600, 3); @@ -210,6 +464,39 @@ TEST_F(Ell, AdvancedApplyWithPaddingToDenseMatrixIsEquivalentToRef) } +TEST_F(Ell, MixedAdvancedApplyWithPaddingToDenseMatrixIsEquivalentToRef1) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(alpha2.get(), y2.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithPaddingToDenseMatrixIsEquivalentToRef2) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(alpha2.get(), y2.get(), beta.get(), expected.get()); + dmtx->apply(dalpha2.get(), dy2.get(), dbeta.get(), dresult.get()); + + GKO_ASSERT_MTX_NEAR(dresult, expected, 1e-14); +} + + +TEST_F(Ell, MixedAdvancedApplyWithPaddingToDenseMatrixIsEquivalentToRef3) +{ + set_up_apply_data(300, 600, 3); + + mtx->apply(alpha.get(), y.get(), beta2.get(), expected2.get()); + dmtx->apply(dalpha.get(), dy.get(), dbeta2.get(), dresult2.get()); + + GKO_ASSERT_MTX_NEAR(dresult2, expected2, 1e-14); +} + + TEST_F(Ell, ApplyToComplexIsEquivalentToRef) { set_up_apply_data(300, 600); diff --git a/reference/test/matrix/ell_kernels.cpp b/reference/test/matrix/ell_kernels.cpp index 91b29752be9..6c27f971bbd 100644 --- a/reference/test/matrix/ell_kernels.cpp +++ b/reference/test/matrix/ell_kernels.cpp @@ -119,6 +119,53 @@ TYPED_TEST(Ell, AppliesToDenseVector) } +TYPED_TEST(Ell, 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; + using Vec = typename gko::matrix::Dense; + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = Vec::create(this->exec, gko::dim<2>{2, 1}); + + this->mtx1->apply(x.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({13.0, 5.0}), 0.0); +} + + +TYPED_TEST(Ell, MixedAppliesToDenseVector2) +{ + // Input vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = Vec2::create(this->exec, gko::dim<2>{2, 1}); + + this->mtx1->apply(x.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({13.0, 5.0}), 0.0); +} + + +TYPED_TEST(Ell, MixedAppliesToDenseVector3) +{ + // Output vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense>; + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = Vec1::create(this->exec, gko::dim<2>{2, 1}); + + this->mtx1->apply(x.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({13.0, 5.0}), 0.0); +} + + TYPED_TEST(Ell, AppliesToDenseMatrix) { using Vec = typename TestFixture::Vec; @@ -141,6 +188,80 @@ TYPED_TEST(Ell, AppliesToDenseMatrix) } +TYPED_TEST(Ell, 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; + using Vec = gko::matrix::Dense; + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + // clang-format on + auto y = Vec::create(this->exec, gko::dim<2>{2}); + + this->mtx1->apply(x.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{13.0, 3.5}, + { 5.0, -7.5}}), 0.0); + // clang-format on +} + + +TYPED_TEST(Ell, MixedAppliesToDenseMatrix2) +{ + // Input vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + // clang-format on + auto y = Vec2::create(this->exec, gko::dim<2>{2}); + + this->mtx1->apply(x.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{13.0, 3.5}, + { 5.0, -7.5}}), 0.0); + // clang-format on +} + + +TYPED_TEST(Ell, MixedAppliesToDenseMatrix3) +{ + // Output vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + // clang-format on + auto y = Vec1::create(this->exec, gko::dim<2>{2}); + + this->mtx1->apply(x.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{13.0, 3.5}, + { 5.0, -7.5}}), 0.0); + // clang-format on +} + + TYPED_TEST(Ell, AppliesLinearCombinationToDenseVector) { using Vec = typename TestFixture::Vec; @@ -155,6 +276,59 @@ TYPED_TEST(Ell, AppliesLinearCombinationToDenseVector) } +TYPED_TEST(Ell, 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; + using Vec = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = gko::initialize({1.0, 2.0}, this->exec); + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({-11.0, -1.0}), 0.0); +} + + +TYPED_TEST(Ell, MixedAppliesLinearCombinationToDenseVector2) +{ + // Input vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = gko::initialize({1.0, 2.0}, this->exec); + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({-11.0, -1.0}), 0.0); +} + + +TYPED_TEST(Ell, MixedAppliesLinearCombinationToDenseVector3) +{ + // Output vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + auto x = gko::initialize({2.0, 1.0, 4.0}, this->exec); + auto y = gko::initialize({1.0, 2.0}, this->exec); + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + GKO_ASSERT_MTX_NEAR(y, l({-11.0, -1.0}), 0.0); +} + + TYPED_TEST(Ell, AppliesLinearCombinationToDenseMatrix) { using Vec = typename TestFixture::Vec; @@ -181,6 +355,92 @@ TYPED_TEST(Ell, AppliesLinearCombinationToDenseMatrix) } +TYPED_TEST(Ell, 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; + using Vec = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + auto y = gko::initialize( + {I{1.0, 0.5}, + I{2.0, -1.5}}, this->exec); + // clang-format on + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{-11.0, -2.5}, + { -1.0, 4.5}}), 0.0); + // clang-format on +} + + +TYPED_TEST(Ell, MixedAppliesLinearCombinationToDenseMatrix2) +{ + // Input vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + auto y = gko::initialize( + {I{1.0, 0.5}, + I{2.0, -1.5}}, this->exec); + // clang-format on + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{-11.0, -2.5}, + { -1.0, 4.5}}), 0.0); + // clang-format on +} + + +TYPED_TEST(Ell, MixedAppliesLinearCombinationToDenseMatrix3) +{ + // Output vector has same value type as matrix + using T = typename TestFixture::value_type; + using next_T = gko::next_precision; + using Vec1 = typename TestFixture::Vec; + using Vec2 = gko::matrix::Dense; + auto alpha = gko::initialize({-1.0}, this->exec); + auto beta = gko::initialize({2.0}, this->exec); + // clang-format off + auto x = gko::initialize( + {I{2.0, 3.0}, + I{1.0, -1.5}, + I{4.0, 2.5}}, this->exec); + auto y = gko::initialize( + {I{1.0, 0.5}, + I{2.0, -1.5}}, this->exec); + // clang-format on + + this->mtx1->apply(alpha.get(), x.get(), beta.get(), y.get()); + + // clang-format off + GKO_ASSERT_MTX_NEAR(y, + l({{-11.0, -2.5}, + { -1.0, 4.5}}), 0.0); + // clang-format on +} + + TYPED_TEST(Ell, ApplyFailsOnWrongInnerDimension) { using Vec = typename TestFixture::Vec;