diff --git a/core/test/utils/array_generator_test.cpp b/core/test/utils/array_generator_test.cpp index ae66e4686da..ca96761ea4e 100644 --- a/core/test/utils/array_generator_test.cpp +++ b/core/test/utils/array_generator_test.cpp @@ -18,11 +18,12 @@ template class ArrayGenerator : public ::testing::Test { protected: using value_type = T; + using check_type = double; ArrayGenerator() : exec(gko::ReferenceExecutor::create()) { array = gko::test::generate_random_array( - 500, std::normal_distribution>(20.0, 5.0), + 500, std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42), exec); } @@ -30,15 +31,17 @@ class ArrayGenerator : public ::testing::Test { gko::array array; template - ValueType get_nth_moment(int n, ValueType c, InputIterator sample_start, - InputIterator sample_end, Closure closure_op) + check_type get_nth_moment(int n, ValueType c, InputIterator sample_start, + InputIterator sample_end, Closure closure_op) { using std::pow; - ValueType res = 0; - ValueType num_elems = 0; + check_type res = 0; + check_type num_elems = 0; while (sample_start != sample_end) { auto tmp = *(sample_start++); - res += pow(closure_op(tmp) - c, n); + res += pow(static_cast(closure_op(tmp)) - + static_cast(c), + n); num_elems += 1; } return res / num_elems; @@ -62,7 +65,8 @@ class ArrayGenerator : public ::testing::Test { } }; -TYPED_TEST_SUITE(ArrayGenerator, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(ArrayGenerator, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(ArrayGenerator, OutputHasCorrectSize) diff --git a/core/test/utils/matrix_generator_test.cpp b/core/test/utils/matrix_generator_test.cpp index 43756bc1709..61710540e24 100644 --- a/core/test/utils/matrix_generator_test.cpp +++ b/core/test/utils/matrix_generator_test.cpp @@ -20,31 +20,32 @@ template class MatrixGenerator : public ::testing::Test { protected: using value_type = T; + using check_type = double; using real_type = gko::remove_complex; using mtx_type = gko::matrix::Dense; MatrixGenerator() : exec(gko::ReferenceExecutor::create()), mtx(gko::test::generate_random_matrix( - 500, 100, std::normal_distribution(50, 5), - std::normal_distribution(20.0, 5.0), + 500, 100, std::normal_distribution<>(50, 5), + std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42), exec)), dense_mtx(gko::test::generate_random_dense_matrix( - 500, 100, std::normal_distribution(20.0, 5.0), + 500, 100, std::normal_distribution<>(20.0, 5.0), std::default_random_engine(41), exec)), l_mtx(gko::test::generate_random_lower_triangular_matrix( - 4, true, std::normal_distribution(50, 5), - std::normal_distribution(20.0, 5.0), + 4, true, std::normal_distribution<>(50, 5), + std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42), exec)), u_mtx(gko::test::generate_random_upper_triangular_matrix( - 4, true, std::normal_distribution(50, 5), - std::normal_distribution(20.0, 5.0), + 4, true, std::normal_distribution<>(50, 5), + std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42), exec)), lower_bandwidth(2), upper_bandwidth(3), band_mtx(gko::test::generate_random_band_matrix( 100, lower_bandwidth, upper_bandwidth, - std::normal_distribution(20.0, 5.0), + std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42), exec)), nnz_per_row_sample(500, 0), values_sample(0), @@ -96,15 +97,17 @@ class MatrixGenerator : public ::testing::Test { template - ValueType get_nth_moment(int n, ValueType c, InputIterator sample_start, - InputIterator sample_end, Closure closure_op) + check_type get_nth_moment(int n, ValueType c, InputIterator sample_start, + InputIterator sample_end, Closure closure_op) { using std::pow; - ValueType res = 0; - ValueType num_elems = 0; + check_type res = 0; + check_type num_elems = 0; while (sample_start != sample_end) { auto tmp = *(sample_start++); - res += pow(closure_op(tmp) - c, n); + res += pow(static_cast(closure_op(tmp)) - + static_cast(c), + n); num_elems += 1; } return res / num_elems; @@ -128,7 +131,8 @@ class MatrixGenerator : public ::testing::Test { } }; -TYPED_TEST_SUITE(MatrixGenerator, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(MatrixGenerator, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(MatrixGenerator, OutputHasCorrectSize) @@ -247,7 +251,7 @@ TYPED_TEST(MatrixGenerator, CanGenerateTridiagMatrix) { using T = typename TestFixture::value_type; using Dense = typename TestFixture::mtx_type; - auto dist = std::normal_distribution>(0, 1); + auto dist = std::normal_distribution<>(0, 1); auto engine = std::default_random_engine(42); auto lower = gko::test::detail::get_rand_value(dist, engine); auto diag = gko::test::detail::get_rand_value(dist, engine); @@ -271,18 +275,23 @@ TYPED_TEST(MatrixGenerator, CanGenerateTridiagInverseMatrix) { using T = typename TestFixture::value_type; using Dense = typename TestFixture::mtx_type; - auto dist = std::normal_distribution>(0, 1); + auto dist = std::normal_distribution<>(0, 1); auto engine = std::default_random_engine(42); auto lower = gko::test::detail::get_rand_value(dist, engine); auto upper = gko::test::detail::get_rand_value(dist, engine); // make diagonally dominant - auto diag = std::abs(gko::test::detail::get_rand_value(dist, engine)) + - std::abs(lower) + std::abs(upper); + auto diag = gko::abs(gko::test::detail::get_rand_value(dist, engine)) + + gko::abs(lower) + gko::abs(upper); + gko::size_type size = 50; + if (std::is_same_v, gko::half>) { + // half precision can only handle the inverse of small matrix. + size = 5; + } auto mtx = gko::test::generate_tridiag_matrix( - 50, {lower, diag, upper}, this->exec); + size, {lower, diag, upper}, this->exec); auto inv_mtx = gko::test::generate_tridiag_inverse_matrix( - 50, {lower, diag, upper}, this->exec); + size, {lower, diag, upper}, this->exec); auto result = Dense::create(this->exec, mtx->get_size()); inv_mtx->apply(mtx, result); diff --git a/core/test/utils/matrix_utils_test.cpp b/core/test/utils/matrix_utils_test.cpp index 3c67571e1b2..f742d4561a2 100644 --- a/core/test/utils/matrix_utils_test.cpp +++ b/core/test/utils/matrix_utils_test.cpp @@ -30,8 +30,8 @@ class MatrixUtils : public ::testing::Test { MatrixUtils() : exec(gko::ReferenceExecutor::create()), data(gko::test::generate_random_matrix_data( - 500, 500, std::normal_distribution(50, 5), - std::normal_distribution(20.0, 5.0), + 500, 500, std::normal_distribution<>(50, 5), + std::normal_distribution<>(20.0, 5.0), std::default_random_engine(42))), rectangular_data(gko::dim<2>(500, 100)) {} @@ -41,7 +41,8 @@ class MatrixUtils : public ::testing::Test { mtx_data rectangular_data; }; -TYPED_TEST_SUITE(MatrixUtils, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(MatrixUtils, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(MatrixUtils, MakeSymmetricThrowsError) @@ -241,7 +242,7 @@ TYPED_TEST(MatrixUtils, MakeHpdMatrixCorrectly) TYPED_TEST(MatrixUtils, MakeHpdMatrixWithRatioCorrectly) { using T = typename TestFixture::value_type; - gko::remove_complex ratio = 1.00001; + gko::remove_complex ratio = 1.01; auto cpy_data = this->data; gko::utils::make_hpd(this->data, ratio); @@ -276,7 +277,7 @@ TYPED_TEST(MatrixUtils, MakeSpdMatrixCorrectly) TYPED_TEST(MatrixUtils, MakeSpdMatrixWithRatioCorrectly) { using T = typename TestFixture::value_type; - gko::remove_complex ratio = 1.00001; + gko::remove_complex ratio = 1.01; auto cpy_data = this->data; gko::utils::make_spd(this->data, ratio); diff --git a/core/test/utils/unsort_matrix_test.cpp b/core/test/utils/unsort_matrix_test.cpp index 5d2f88f982a..40ec65b08db 100644 --- a/core/test/utils/unsort_matrix_test.cpp +++ b/core/test/utils/unsort_matrix_test.cpp @@ -119,7 +119,7 @@ class UnsortMatrix : public ::testing::Test { std::unique_ptr coo_empty; }; -TYPED_TEST_SUITE(UnsortMatrix, gko::test::ValueIndexTypes, +TYPED_TEST_SUITE(UnsortMatrix, gko::test::ValueIndexTypesWithHalf, PairTypenameNameGenerator); diff --git a/core/test/utils/value_generator_test.cpp b/core/test/utils/value_generator_test.cpp index 633565a66ef..57473c41b6e 100644 --- a/core/test/utils/value_generator_test.cpp +++ b/core/test/utils/value_generator_test.cpp @@ -20,19 +20,22 @@ template class ValueGenerator : public ::testing::Test { protected: using value_type = T; + using check_type = double; ValueGenerator() {} template - ValueType get_nth_moment(int n, ValueType c, InputIterator sample_start, - InputIterator sample_end, Closure closure_op) + check_type get_nth_moment(int n, ValueType c, InputIterator sample_start, + InputIterator sample_end, Closure closure_op) { using std::pow; - ValueType res = 0; - ValueType num_elems = 0; + check_type res = 0; + check_type num_elems = 0; while (sample_start != sample_end) { auto tmp = *(sample_start++); - res += pow(closure_op(tmp) - c, n); + res += pow(static_cast(closure_op(tmp)) - + static_cast(c), + n); num_elems += 1; } return res / num_elems; @@ -56,7 +59,8 @@ class ValueGenerator : public ::testing::Test { } }; -TYPED_TEST_SUITE(ValueGenerator, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(ValueGenerator, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(ValueGenerator, OutputHasCorrectAverageAndDeviation) diff --git a/reference/test/utils/assertions_test.cpp b/reference/test/utils/assertions_test.cpp index 98f1ec68e0d..9c6b544172e 100644 --- a/reference/test/utils/assertions_test.cpp +++ b/reference/test/utils/assertions_test.cpp @@ -17,7 +17,8 @@ namespace { template class MatricesNear : public ::testing::Test {}; -TYPED_TEST_SUITE(MatricesNear, gko::test::ValueTypes, TypenameNameGenerator); +TYPED_TEST_SUITE(MatricesNear, gko::test::ValueTypesWithHalf, + TypenameNameGenerator); TYPED_TEST(MatricesNear, CanPassAnyMatrixType)