Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
* remove unnecessary includes
* pull common type aliases into CommonTestFixture
* fix some test bounds

Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
Co-authored-by: Fritz Göbel <fritz.goebel@kit.edu>
  • Loading branch information
3 people committed Sep 28, 2022
1 parent 3dadd5c commit e8b73a2
Show file tree
Hide file tree
Showing 35 changed files with 312 additions and 445 deletions.
1 change: 1 addition & 0 deletions core/test/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define GKO_CORE_TEST_UTILS_HPP_


#include <cmath>
#include <complex>
#include <initializer_list>
#include <limits>
Expand Down
4 changes: 2 additions & 2 deletions test/base/kernel_launch_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ struct to_device_type_impl<move_only_type&> {
} // namespace gko


#if GINKGO_DPCPP_SINGLE_MODE
#if GINKGO_COMMON_SINGLE_MODE
using value_type = float;
#else
using value_type = double;
#endif
#endif // GINKGO_COMMON_SINGLE_MODE
using Mtx = gko::matrix::Dense<value_type>;

class KernelLaunch : public CommonTestFixture {
Expand Down
5 changes: 0 additions & 5 deletions test/components/absolute_array_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class AbsoluteArray : public CommonTestFixture {
protected:
#if GINKGO_COMMON_SINGLE_MODE
using value_type = float;
#else
using value_type = double;
#endif
using complex_type = std::complex<value_type>;
AbsoluteArray()
: total_size(6344),
Expand Down
12 changes: 1 addition & 11 deletions test/components/prefix_sum_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/array.hpp>


#include "cuda/test/utils.hpp"
#include "core/test/utils.hpp"
#include "test/utils/executor.hpp"


Expand All @@ -63,16 +63,6 @@ class PrefixSum : public CommonTestFixture {
dvals = vals;
}

void test(gko::size_type size)
{
gko::kernels::reference::components::prefix_sum(ref, vals.get_data(),
size);
gko::kernels::EXEC_NAMESPACE::components::prefix_sum(
exec, dvals.get_data(), size);

GKO_ASSERT_ARRAY_EQ(vals, dvals);
}

std::default_random_engine rand;
gko::size_type total_size;
gko::array<index_type> vals;
Expand Down
2 changes: 0 additions & 2 deletions test/factorization/ic_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Ic : public CommonTestFixture {
protected:
using value_type = gko::default_precision;
using index_type = gko::int32;
using Csr = gko::matrix::Csr<value_type, index_type>;

Ic() : rand_engine(6794)
Expand Down
2 changes: 0 additions & 2 deletions test/factorization/ilu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Ilu : public CommonTestFixture {
protected:
using value_type = gko::default_precision;
using index_type = gko::int32;
using Csr = gko::matrix::Csr<value_type, index_type>;

Ilu() : rand_engine(1337)
Expand Down
2 changes: 0 additions & 2 deletions test/factorization/par_ilut_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ class ParIlut : public CommonTestFixture {
using index_type =
typename std::tuple_element<1, decltype(ValueIndexType())>::type;
using Dense = gko::matrix::Dense<value_type>;
using ComplexDense = gko::matrix::Dense<std::complex<value_type>>;
using Coo = gko::matrix::Coo<value_type, index_type>;
using Csr = gko::matrix::Csr<value_type, index_type>;
using ComplexCsr = gko::matrix::Csr<std::complex<value_type>, index_type>;

ParIlut()
#ifdef GINKGO_FAST_TESTS
Expand Down
65 changes: 30 additions & 35 deletions test/matrix/coo_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Coo : public CommonTestFixture {
protected:
#if GINKGO_COMMON_SINGLE_MODE
using vtype = float;
#else
using vtype = double;
#endif // GINKGO_COMMON_SINGLE_MODE
using Mtx = gko::matrix::Coo<vtype>;
using Vec = gko::matrix::Dense<vtype>;
using ComplexVec = gko::matrix::Dense<std::complex<vtype>>;
using Mtx = gko::matrix::Coo<value_type>;
using Vec = gko::matrix::Dense<value_type>;
using ComplexVec = gko::matrix::Dense<std::complex<value_type>>;

Coo() : rand_engine(42) {}

Expand All @@ -71,7 +66,7 @@ class Coo : public CommonTestFixture {
{
return gko::test::generate_random_matrix<MtxType>(
num_rows, num_cols, std::uniform_int_distribution<>(1, num_cols),
std::normal_distribution<vtype>(-1.0, 1.0), rand_engine, ref);
std::normal_distribution<value_type>(-1.0, 1.0), rand_engine, ref);
}

void set_up_apply_data(int num_vectors = 1)
Expand Down Expand Up @@ -117,7 +112,7 @@ TEST_F(Coo, SimpleApplyIsEquivalentToRef)
mtx->apply(y.get(), expected.get());
dmtx->apply(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -127,14 +122,14 @@ TEST_F(Coo, SimpleApplyDoesntOverwritePadding)
auto dresult_padded =
Vec::create(exec, dresult->get_size(), dresult->get_stride() + 1);
dresult_padded->copy_from(dresult.get());
vtype padding_val{1234.0};
value_type padding_val{1234.0};
exec->copy_from(exec->get_master().get(), 1, &padding_val,
dresult_padded->get_values() + 1);

mtx->apply(y.get(), expected.get());
dmtx->apply(dy.get(), dresult_padded.get());

GKO_ASSERT_MTX_NEAR(dresult_padded, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult_padded, expected, r<value_type>::value);
ASSERT_EQ(exec->copy_val_to_host(dresult_padded->get_values() + 1), 1234.0);
}

Expand All @@ -147,7 +142,7 @@ TEST_F(Coo, SimpleApplyIsEquivalentToRefUnsorted)
mtx->apply(y.get(), expected.get());
dmtx->apply(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -158,7 +153,7 @@ TEST_F(Coo, AdvancedApplyIsEquivalentToRef)
mtx->apply(alpha.get(), y.get(), beta.get(), expected.get());
dmtx->apply(dalpha.get(), dy.get(), dbeta.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -168,14 +163,14 @@ TEST_F(Coo, AdvancedApplyDoesntOverwritePadding)
auto dresult_padded =
Vec::create(exec, dresult->get_size(), dresult->get_stride() + 1);
dresult_padded->copy_from(dresult.get());
vtype padding_val{1234.0};
value_type padding_val{1234.0};
exec->copy_from(exec->get_master().get(), 1, &padding_val,
dresult_padded->get_values() + 1);

mtx->apply(alpha.get(), y.get(), beta.get(), expected.get());
dmtx->apply(dalpha.get(), dy.get(), dbeta.get(), dresult_padded.get());

GKO_ASSERT_MTX_NEAR(dresult_padded, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult_padded, expected, r<value_type>::value);
ASSERT_EQ(exec->copy_val_to_host(dresult_padded->get_values() + 1), 1234.0);
}

Expand All @@ -187,7 +182,7 @@ TEST_F(Coo, SimpleApplyAddIsEquivalentToRef)
mtx->apply2(y.get(), expected.get());
dmtx->apply2(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -198,7 +193,7 @@ TEST_F(Coo, AdvancedApplyAddIsEquivalentToRef)
mtx->apply2(alpha.get(), y.get(), expected.get());
dmtx->apply2(dalpha.get(), dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -209,7 +204,7 @@ TEST_F(Coo, SimpleApplyToDenseMatrixIsEquivalentToRef)
mtx->apply(y.get(), expected.get());
dmtx->apply(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -220,7 +215,7 @@ TEST_F(Coo, AdvancedApplyToDenseMatrixIsEquivalentToRef)
mtx->apply(alpha.get(), y.get(), beta.get(), expected.get());
dmtx->apply(dalpha.get(), dy.get(), dbeta.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -231,7 +226,7 @@ TEST_F(Coo, SimpleApplyAddToDenseMatrixIsEquivalentToRef)
mtx->apply2(y.get(), expected.get());
dmtx->apply2(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -243,7 +238,7 @@ TEST_F(Coo, SimpleApplyAddToDenseMatrixIsEquivalentToRefUnsorted)
mtx->apply2(y.get(), expected.get());
dmtx->apply2(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -254,7 +249,7 @@ TEST_F(Coo, SimpleApplyAddToLargeDenseMatrixIsEquivalentToRef)
mtx->apply2(y.get(), expected.get());
dmtx->apply2(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -265,7 +260,7 @@ TEST_F(Coo, AdvancedApplyAddToDenseMatrixIsEquivalentToRef)
mtx->apply2(alpha.get(), y.get(), expected.get());
dmtx->apply2(dalpha.get(), dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -276,7 +271,7 @@ TEST_F(Coo, AdvancedApplyAddToLargeDenseMatrixIsEquivalentToRef)
mtx->apply2(y.get(), expected.get());
dmtx->apply2(dy.get(), dresult.get());

GKO_ASSERT_MTX_NEAR(dresult, expected, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dresult, expected, r<value_type>::value);
}


Expand All @@ -291,7 +286,7 @@ TEST_F(Coo, ApplyToComplexIsEquivalentToRef)
mtx->apply(complex_b.get(), complex_x.get());
dmtx->apply(dcomplex_b.get(), dcomplex_x.get());

GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<value_type>::value);
}


Expand All @@ -306,7 +301,7 @@ TEST_F(Coo, AdvancedApplyToComplexIsEquivalentToRef)
mtx->apply(alpha.get(), complex_b.get(), beta.get(), complex_x.get());
dmtx->apply(dalpha.get(), dcomplex_b.get(), dbeta.get(), dcomplex_x.get());

GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<value_type>::value);
}


Expand All @@ -321,15 +316,15 @@ TEST_F(Coo, ApplyAddToComplexIsEquivalentToRef)
mtx->apply2(alpha.get(), complex_b.get(), complex_x.get());
dmtx->apply2(dalpha.get(), dcomplex_b.get(), dcomplex_x.get());

GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dcomplex_x, complex_x, r<value_type>::value);
}


TEST_F(Coo, ConvertToDenseIsEquivalentToRef)
{
set_up_apply_data();
auto dense_mtx = gko::matrix::Dense<vtype>::create(ref);
auto ddense_mtx = gko::matrix::Dense<vtype>::create(exec);
auto dense_mtx = gko::matrix::Dense<value_type>::create(ref);
auto ddense_mtx = gko::matrix::Dense<value_type>::create(exec);

mtx->convert_to(dense_mtx.get());
dmtx->convert_to(ddense_mtx.get());
Expand All @@ -341,9 +336,9 @@ TEST_F(Coo, ConvertToDenseIsEquivalentToRef)
TEST_F(Coo, ConvertToCsrIsEquivalentToRef)
{
set_up_apply_data();
auto dense_mtx = gko::matrix::Dense<vtype>::create(ref);
auto csr_mtx = gko::matrix::Csr<vtype>::create(ref);
auto dcsr_mtx = gko::matrix::Csr<vtype>::create(exec);
auto dense_mtx = gko::matrix::Dense<value_type>::create(ref);
auto csr_mtx = gko::matrix::Csr<value_type>::create(ref);
auto dcsr_mtx = gko::matrix::Csr<value_type>::create(exec);

mtx->convert_to(dense_mtx.get());
dense_mtx->convert_to(csr_mtx.get());
Expand Down Expand Up @@ -371,7 +366,7 @@ TEST_F(Coo, InplaceAbsoluteMatrixIsEquivalentToRef)
mtx->compute_absolute_inplace();
dmtx->compute_absolute_inplace();

GKO_ASSERT_MTX_NEAR(mtx, dmtx, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(mtx, dmtx, r<value_type>::value);
}


Expand All @@ -382,5 +377,5 @@ TEST_F(Coo, OutplaceAbsoluteMatrixIsEquivalentToRef)
auto abs_mtx = mtx->compute_absolute();
auto dabs_mtx = dmtx->compute_absolute();

GKO_ASSERT_MTX_NEAR(abs_mtx, dabs_mtx, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(abs_mtx, dabs_mtx, r<value_type>::value);
}
14 changes: 4 additions & 10 deletions test/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Csr : public CommonTestFixture {
protected:
using itype = int;
#if GINKGO_COMMON_SINGLE_MODE
using vtype = float;
#else
using vtype = double;
#endif
using Mtx = gko::matrix::Csr<vtype, itype>;
using Vec = gko::matrix::Dense<vtype>;
using Mtx = gko::matrix::Csr<value_type, index_type>;
using Vec = gko::matrix::Dense<value_type>;

Csr() : rand_engine(15) {}

Expand Down Expand Up @@ -100,7 +94,7 @@ TEST_F(Csr, ScaleIsEquivalentToRef)
x->scale(alpha.get());
dx->scale(dalpha.get());

GKO_ASSERT_MTX_NEAR(dx, x, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dx, x, r<value_type>::value);
}


Expand All @@ -111,7 +105,7 @@ TEST_F(Csr, InvScaleIsEquivalentToRef)
x->inv_scale(alpha.get());
dx->inv_scale(dalpha.get());

GKO_ASSERT_MTX_NEAR(dx, x, r<vtype>::value);
GKO_ASSERT_MTX_NEAR(dx, x, r<value_type>::value);
}


Expand Down
Loading

0 comments on commit e8b73a2

Please sign in to comment.