diff --git a/setup.cfg b/setup.cfg index 387884acef0c..60c8b1f6372a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,14 +6,20 @@ ignore = E201 # By default, tests marked as slow will be deselected. # To run all tests, use -m "slow and not slow". # To run only slow tests, use -m "slow". -addopts = -m "not slow" -p no:warnings --tb=short --strict-markers +addopts = -m "not slow" --tb=short --strict-markers norecursedirs = tests_perf testpaths = tests markers = slow: marks tests as slow (deselect with '-m "not slow"') multi_gpu: marks tests that require a specified number of GPUs - # Added due to -p no:warnings to avoid errors with --strict-markers - filterwarnings: mark to filter warnings during tests +filterwarnings = + # pkg_resources + ignore:pkg_resources is deprecated as an API:DeprecationWarning + # NumPy arccosh + # Undefined behavior depends on the backend: + # NumPy with OpenBLAS for np.array[1.0] does not raise a warning + # while numpy with OneMKL raises RuntimeWarning + ignore:invalid value encountered in arccosh:RuntimeWarning [versioneer] VCS = git diff --git a/tests/test_arraycreation.py b/tests/test_arraycreation.py index 1f98aa2de6ff..ca91ec6f6994 100644 --- a/tests/test_arraycreation.py +++ b/tests/test_arraycreation.py @@ -516,6 +516,7 @@ def test_vander_seq(sequence): assert_allclose(vander_func(numpy, sequence), vander_func(dpnp, sequence)) +@pytest.mark.usefixtures("suppress_complex_warning") @pytest.mark.parametrize( "shape", [(), 0, (0,), (2, 0, 3), (3, 2)], @@ -531,6 +532,7 @@ def test_full(shape, fill_value, dtype, order): assert_array_equal(func(numpy), func(dpnp)) +@pytest.mark.usefixtures("suppress_complex_warning") @pytest.mark.parametrize( "array", [[], 0, [1, 2, 3], [[1, 2], [3, 4]]], @@ -709,9 +711,7 @@ def test_linspace(start, stop, num, dtype, retstep): if numpy.issubdtype(dtype, dpnp.integer): assert_allclose(res_np, res_dp, rtol=1) else: - if dtype is None and not has_support_aspect64(): - dtype = dpnp.float32 - assert_allclose(res_np, res_dp, rtol=1e-06, atol=dpnp.finfo(dtype).eps) + assert_dtype_allclose(res_dp, res_np) @pytest.mark.parametrize( diff --git a/tests/test_arraymanipulation.py b/tests/test_arraymanipulation.py index 69116ef86921..12f14bf41098 100644 --- a/tests/test_arraymanipulation.py +++ b/tests/test_arraymanipulation.py @@ -846,6 +846,7 @@ def test_asfarray(dtype, data): assert_array_equal(result, expected) +@pytest.mark.usefixtures("suppress_complex_warning") @pytest.mark.parametrize("dtype", get_all_dtypes()) @pytest.mark.parametrize("data", [[1.0, 2.0, 3.0]], ids=["[1., 2., 3.]"]) @pytest.mark.parametrize("data_dtype", get_all_dtypes(no_none=True)) diff --git a/tests/test_dparray.py b/tests/test_dparray.py index 874493f4e952..ac9757c580a8 100644 --- a/tests/test_dparray.py +++ b/tests/test_dparray.py @@ -220,6 +220,9 @@ def test_print_dpnp_zero_shape(): assert result == expected +# Numpy will raise an error when converting a.ndim > 0 to a scalar +# TODO: Discuss dpnp behavior according to these future changes +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.parametrize("func", [bool, float, int, complex]) @pytest.mark.parametrize("shape", [tuple(), (1,), (1, 1), (1, 1, 1)]) @pytest.mark.parametrize( @@ -231,6 +234,9 @@ def test_scalar_type_casting(func, shape, dtype): assert func(numpy_array) == func(dpnp_array) +# Numpy will raise an error when converting a.ndim > 0 to a scalar +# TODO: Discuss dpnp behavior according to these future changes +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.parametrize( "method", ["__bool__", "__float__", "__int__", "__complex__"] ) diff --git a/tests/test_histogram.py b/tests/test_histogram.py index 7601d67c54a9..da58a4ac2f8f 100644 --- a/tests/test_histogram.py +++ b/tests/test_histogram.py @@ -38,11 +38,6 @@ class TestDigitize: numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9]), numpy.array([1, 4, 6, 7]), ), - # Infinity values - ( - numpy.array([-numpy.inf, -1, 0, 1, numpy.inf]), - numpy.array([-2, -1, 0, 1, 2]), - ), # Repeated elements (numpy.array([1, 2, 2, 3, 3, 3, 4, 5]), numpy.array([1, 2, 3, 4])), ], @@ -57,6 +52,18 @@ def test_digitize(self, x, bins, dtype, right): expected = numpy.digitize(x, bins, right=right) assert_dtype_allclose(result, expected) + @pytest.mark.parametrize("dtype", get_float_dtypes()) + @pytest.mark.parametrize("right", [True, False]) + def test_digitize_inf(self, dtype, right): + x = numpy.array([-numpy.inf, -1, 0, 1, numpy.inf], dtype=dtype) + bins = numpy.array([-2, -1, 0, 1, 2], dtype=dtype) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp, right=right) + expected = numpy.digitize(x, bins, right=right) + assert_dtype_allclose(result, expected) + @pytest.mark.parametrize( "dtype_x", get_all_dtypes(no_bool=True, no_complex=True) ) @@ -386,7 +393,8 @@ def test_infinite_edge(self, xp, inf_val): # both first and last ranges must be finite with assert_raises_regex( - ValueError, f"autodetected range of \[{min}, {max}\] is not finite" + ValueError, + f"autodetected range of \\[{min}, {max}\\] is not finite", ): xp.histogram(v) diff --git a/tests/test_linalg.py b/tests/test_linalg.py index a45b2826b3ac..ec2a085d4d34 100644 --- a/tests/test_linalg.py +++ b/tests/test_linalg.py @@ -780,7 +780,9 @@ def test_lstsq(self, a_shape, b_shape, dtype): b_dp = inp.array(b_np) result = inp.linalg.lstsq(a_dp, b_dp) - expected = numpy.linalg.lstsq(a_np, b_np) + # if rcond is not set, FutureWarning is given. + # By default Numpy uses None for calculations + expected = numpy.linalg.lstsq(a_np, b_np, rcond=None) for param_dp, param_np in zip(result, expected): assert_dtype_allclose(param_dp, param_np) @@ -794,7 +796,9 @@ def test_lstsq_diff_type(self, a_dtype, b_dtype): a_dp = inp.array(a_np) b_dp = inp.array(b_np) - expected = numpy.linalg.lstsq(a_np, b_np) + # if rcond is not set, FutureWarning is given. + # By default Numpy uses None for calculations + expected = numpy.linalg.lstsq(a_np, b_np, rcond=None) result = inp.linalg.lstsq(a_dp, b_dp) for param_dp, param_np in zip(result, expected): @@ -813,7 +817,9 @@ def test_lstsq_empty(self, m, n, nrhs, dtype): b_dp = inp.array(b_np) result = inp.linalg.lstsq(a_dp, b_dp) - expected = numpy.linalg.lstsq(a_np, b_np) + # if rcond is not set, FutureWarning is given. + # By default Numpy uses None for calculations + expected = numpy.linalg.lstsq(a_np, b_np, rcond=None) for param_dp, param_np in zip(result, expected): assert_dtype_allclose(param_dp, param_np) diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 4a86cdc081ed..4a1ee63c8fc9 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -91,7 +91,7 @@ def test_mode(self): d = dpnp.ones(100) k = dpnp.ones(3) default_mode = dpnp.convolve(d, k, mode="full") - full_mode = dpnp.convolve(d, k, mode="f") + full_mode = dpnp.convolve(d, k, mode="full") assert_array_equal(full_mode, default_mode) # integer mode with assert_raises(ValueError): diff --git a/tests/test_random_state.py b/tests/test_random_state.py index 70940501d2ee..ed56dbdf7307 100644 --- a/tests/test_random_state.py +++ b/tests/test_random_state.py @@ -239,7 +239,6 @@ def test_fallback(self, loc, scale): [ dpnp.float16, float, - dpnp.integer, dpnp.int64, dpnp.int32, dpnp.int, @@ -253,7 +252,6 @@ def test_fallback(self, loc, scale): ids=[ "dpnp.float16", "float", - "dpnp.integer", "dpnp.int64", "dpnp.int32", "dpnp.int", @@ -366,8 +364,8 @@ def test_wrong_dims(self): class TestRandInt: @pytest.mark.parametrize( "dtype", - [int, dpnp.int32, dpnp.int, dpnp.integer], - ids=["int", "dpnp.int32", "dpnp.int", "dpnp.integer"], + [int, dpnp.int32, dpnp.int], + ids=["int", "dpnp.int32", "dpnp.int"], ) @pytest.mark.parametrize( "usm_type", @@ -379,7 +377,7 @@ def test_distr(self, dtype, usm_type): low = 1 high = 10 - if dtype in (dpnp.int, dpnp.integer) and dtype != dpnp.dtype("int32"): + if dtype == dpnp.int and dtype != dpnp.dtype("int32"): pytest.skip( "dtype isn't alias on dpnp.int32 on the target OS, so there will be a fallback" ) @@ -566,11 +564,10 @@ def test_bounds_fallback(self, low, high): @pytest.mark.usefixtures("allow_fall_back_on_numpy") @pytest.mark.parametrize( "dtype", - [dpnp.int64, dpnp.int, dpnp.integer, dpnp.bool, dpnp.bool_, bool], + [dpnp.int64, dpnp.int, dpnp.bool, dpnp.bool_, bool], ids=[ "dpnp.int64", "dpnp.int", - "dpnp.integer", "dpnp.bool", "dpnp.bool_", "bool", @@ -582,7 +579,7 @@ def test_dtype_fallback(self, dtype): high = 37 if not dtype in {dpnp.bool_, bool} else 2 size = (3, 2, 5) - if dtype in (dpnp.int, dpnp.integer) and dtype == dpnp.dtype("int32"): + if dtype == dpnp.int and dtype == dpnp.dtype("int32"): pytest.skip( "dtype is alias on dpnp.int32 on the target OS, so no fallback here" ) @@ -1157,7 +1154,6 @@ def test_fallback(self, low, high): [ dpnp.float16, float, - dpnp.integer, dpnp.int64, dpnp.int, int, @@ -1170,7 +1166,6 @@ def test_fallback(self, low, high): ids=[ "dpnp.float16", "float", - "dpnp.integer", "dpnp.int64", "dpnp.int", "int", @@ -1182,7 +1177,7 @@ def test_fallback(self, low, high): ], ) def test_invalid_dtype(self, dtype): - if dtype in (dpnp.int, dpnp.integer) and dtype == dpnp.dtype("int32"): + if dtype == dpnp.int and dtype == dpnp.dtype("int32"): pytest.skip( "dtype is alias on dpnp.int32 on the target OS, so no error here" ) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 8332f26949ba..3073b8806e5e 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -103,7 +103,7 @@ def vvsort(val, vec, size, xp): {"dtype": dpnp.int32}, ), pytest.param("fromiter", [[1, 2, 3, 4]], {"dtype": dpnp.int64}), - pytest.param("fromstring", ["1, 2"], {"dtype": int, "sep": " "}), + pytest.param("fromstring", ["1 2"], {"dtype": int, "sep": " "}), pytest.param("full", [(2, 2)], {"fill_value": 5}), pytest.param("eye", [4, 2], {}), pytest.param("geomspace", [1, 4, 8], {}), @@ -1686,6 +1686,7 @@ def test_from_dlpack(arr_dtype, shape, device): assert V.strides == W.strides +@pytest.mark.usefixtures("suppress_invalid_numpy_warnings") @pytest.mark.parametrize( "device", valid_devices, @@ -2112,7 +2113,9 @@ def test_lstsq(m, n, nrhs, device): b_dp = dpnp.array(b_np, device=device) result_dp = dpnp.linalg.lstsq(a_dp, b_dp) - result = numpy.linalg.lstsq(a_np, b_np) + # if rcond is not set, FutureWarning is given. + # By default Numpy uses None for calculations + result = numpy.linalg.lstsq(a_np, b_np, rcond=None) for param_dp, param_np in zip(result_dp, result): assert_dtype_allclose(param_dp, param_np) diff --git a/tests/test_umath.py b/tests/test_umath.py index 5a61079335f1..c302cbba3a05 100644 --- a/tests/test_umath.py +++ b/tests/test_umath.py @@ -398,6 +398,7 @@ def test_invalid_out(self, out): class TestReciprocal: + @pytest.mark.usefixtures("suppress_divide_numpy_warnings") @pytest.mark.parametrize("dtype", get_float_complex_dtypes()) def test_reciprocal(self, dtype): np_array, expected = _get_numpy_arrays_1in_1out( diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index f66017ea6e26..77839f9b9338 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -199,7 +199,7 @@ def test_array_creation_from_2d_array(func, args, usm_type_x, usm_type_y): "fromfunction", [(lambda i, j: i + j), (3, 3)], {"dtype": dp.int32} ), pytest.param("fromiter", [[1, 2, 3, 4]], {"dtype": dp.int64}), - pytest.param("fromstring", ["1, 2"], {"dtype": int, "sep": " "}), + pytest.param("fromstring", ["1 2"], {"dtype": int, "sep": " "}), pytest.param("full", [(2, 2)], {"fill_value": 5}), pytest.param("eye", [4, 2], {}), pytest.param("geomspace", [1, 4, 8], {}), diff --git a/tests/third_party/cupy/binary_tests/test_elementwise.py b/tests/third_party/cupy/binary_tests/test_elementwise.py index a26983662566..e756c454f150 100644 --- a/tests/third_party/cupy/binary_tests/test_elementwise.py +++ b/tests/third_party/cupy/binary_tests/test_elementwise.py @@ -7,14 +7,14 @@ class TestElementwise(unittest.TestCase): @testing.for_int_dtypes() @testing.numpy_cupy_array_equal() def check_unary_int(self, name, xp, dtype): - a = xp.array([-3, -2, -1, 0, 1, 2, 3], dtype=dtype) + a = xp.array([-3, -2, -1, 0, 1, 2, 3]).astype(dtype) return getattr(xp, name)(a) @testing.for_int_dtypes() @testing.numpy_cupy_array_equal() def check_binary_int(self, name, xp, dtype): - a = xp.array([-3, -2, -1, 0, 1, 2, 3], dtype=dtype) - b = xp.array([0, 1, 2, 3, 4, 5, 6], dtype=dtype) + a = xp.array([-3, -2, -1, 0, 1, 2, 3]).astype(dtype) + b = xp.array([0, 1, 2, 3, 4, 5, 6]).astype(dtype) return getattr(xp, name)(a, b) def test_bitwise_and(self): diff --git a/tests/third_party/cupy/core_tests/test_ndarray_math.py b/tests/third_party/cupy/core_tests/test_ndarray_math.py index 3233687789ab..81caf2c8ceb0 100644 --- a/tests/third_party/cupy/core_tests/test_ndarray_math.py +++ b/tests/third_party/cupy/core_tests/test_ndarray_math.py @@ -57,7 +57,7 @@ class TestRoundHalfway(unittest.TestCase): @testing.for_float_dtypes() @testing.numpy_cupy_allclose(atol=1e-5) def test_round_halfway_float(self, xp, dtype): - if self.decimals is -3 and dtype == numpy.float32: + if self.decimals == -3 and dtype == numpy.float32: pytest.skip( "Case with decimals=-3 and dtype float32 has divide error less than 1e-5" ) @@ -78,7 +78,7 @@ def test_round_halfway_float(self, xp, dtype): @testing.numpy_cupy_array_equal() def test_round_halfway_int(self, xp, dtype): # generate [..., -1.5, -0.5, 0.5, 1.5, ...] * 10^{-decimals} - if self.decimals is -3 and not has_support_aspect64(): + if self.decimals == -3 and not has_support_aspect64(): pytest.skip( "Case with decimals=-3 and dtype float32 has divide error less than 1e-5" ) @@ -96,7 +96,7 @@ def test_round_halfway_int(self, xp, dtype): @testing.numpy_cupy_array_equal() def test_round_halfway_uint(self, xp, dtype): # generate [0.5, 1.5, ...] * 10^{-decimals} - if self.decimals is -3 and not has_support_aspect64(): + if self.decimals == -3 and not has_support_aspect64(): pytest.skip( "Case with decimals=-3 and dtype float32 has divide error less than 1e-5" ) @@ -105,7 +105,7 @@ def test_round_halfway_uint(self, xp, dtype): a -= 1 scale = 10 ** abs(self.decimals) if self.decimals < 0: - a *= xp.array(scale, dtype=dtype) + a *= xp.array(scale).astype(dtype) a >>= 1 return a.round(self.decimals) diff --git a/tests/third_party/cupy/creation_tests/test_ranges.py b/tests/third_party/cupy/creation_tests/test_ranges.py index 2094f2ffc8e1..92c81061b7a1 100644 --- a/tests/third_party/cupy/creation_tests/test_ranges.py +++ b/tests/third_party/cupy/creation_tests/test_ranges.py @@ -176,9 +176,9 @@ def test_linspace_float_overflow(self, xp): def test_linspace_float_underflow(self, xp): # find minimum subnormal number dtype = cupy.default_float_type() - x = xp.finfo(dtype).min - while x / 2 > 0: - x /= 2 + # use .tiny instead of .min and while to get + # minimum subnormal number directly and avoid RuntimeWarning + x = xp.finfo(dtype).tiny return xp.linspace(0.0, x, 10, dtype=dtype) @testing.with_requires("numpy>=1.16") diff --git a/tests/third_party/cupy/logic_tests/test_comparison.py b/tests/third_party/cupy/logic_tests/test_comparison.py index b7dba2a219b8..eed4c7f9b368 100644 --- a/tests/third_party/cupy/logic_tests/test_comparison.py +++ b/tests/third_party/cupy/logic_tests/test_comparison.py @@ -46,28 +46,28 @@ class TestComparisonOperator(unittest.TestCase): ] @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_array_list_equal() + @testing.numpy_cupy_array_equal() def test_binary_npscalar_array(self, xp, dtype): a = numpy.int16(3) b = testing.shaped_arange((2, 3), xp, dtype) return [op(a, b) for op in self.operators] @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_array_list_equal() + @testing.numpy_cupy_array_equal() def test_binary_pyscalar_array(self, xp, dtype): a = 3.0 b = testing.shaped_arange((2, 3), xp, dtype) return [op(a, b) for op in self.operators] @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_array_list_equal() + @testing.numpy_cupy_array_equal() def test_binary_array_npscalar(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) b = numpy.float32(3.0) return [op(a, b) for op in self.operators] @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_array_list_equal() + @testing.numpy_cupy_array_equal() def test_binary_array_pyscalar(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) b = 3 diff --git a/tests/third_party/cupy/math_tests/test_sumprod.py b/tests/third_party/cupy/math_tests/test_sumprod.py index f36086755e97..b1561260402f 100644 --- a/tests/third_party/cupy/math_tests/test_sumprod.py +++ b/tests/third_party/cupy/math_tests/test_sumprod.py @@ -234,7 +234,18 @@ def _numpy_nanprod_implemented(self): ) def _test(self, xp, dtype): - a = testing.shaped_arange(self.shape, xp, dtype) + shape = self.shape + # Reduce the shape of the input array to avoid overflow warning + # for nanprod with float32, shape=(20, 30, 40), axis=0 and transpose_axes=False + if ( + self.func == "nanprod" + and dtype == xp.float32 + and self.shape == (20, 30, 40) + and self.axis == 0 + and not self.transpose_axes + ): + shape = (10, 20, 30) + a = testing.shaped_arange(shape, xp, dtype) if self.transpose_axes: a = a.transpose(2, 0, 1) if not issubclass(dtype, xp.integer): @@ -245,6 +256,7 @@ def _test(self, xp, dtype): @testing.for_all_dtypes(no_bool=True, no_float16=True) @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) def test_nansum_all(self, xp, dtype): + dtype = xp.float32 if ( not self._numpy_nanprod_implemented() or not self._do_transposed_axis_test()