Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Allowed input array of `uint64` dtype in `dpnp.bincount` [#2361](https://github.com/IntelPython/dpnp/pull/2361)
* The vector norms `ord={None, 1, 2, inf}` and the matrix norms `ord={None, 1, 2, inf, "fro", "nuc"}` now consistently return zero for empty arrays, which are arrays with at least one axis of size zero. This change affects `dpnp.linalg.norm`, `dpnp.linalg.vector_norm`, and `dpnp.linalg.matrix_norm`. Previously, dpnp would either raise errors or return zero depending on the parameters provided [#2371](https://github.com/IntelPython/dpnp/pull/2371)
* Improved performance of `dpnp.nansum`, `dpnp.nanprod`, `dpnp.nancumsum`, and `dpnp.nancumprod` by reusing `dpnp.nan_to_num` function in implementation of the functions [#2339](https://github.com/IntelPython/dpnp/pull/2339)
* Updated `dpnp.fix` docstring to indicate that the output data-type will be a floating point dtype but not necessarily the default floating point dtype [#2392](https://github.com/IntelPython/dpnp/pull/2392)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,8 +1750,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
-------
out : dpnp.ndarray
An array with the rounded values and with the same dimensions as the input.
The returned array will have the default floating point data type for the
device where `a` is allocated.
The returned array will have a floating point data type that input can cast
to it safely considering device capabilities.
If `out` is ``None`` then a float array is returned with the rounded values.
Otherwise the result is stored there and the return value `out` is
a reference to that array.
Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@ def cov(
Default: ``None``.
dtype : {None, str, dtype object}, optional
Data-type of the result. By default, the return data-type will have
at least floating point type based on the capabilities of the device on
which the input arrays reside.
the default floating point data-type of the device on which the input
arrays reside.

Default: ``None``.

Expand Down
6 changes: 6 additions & 0 deletions dpnp/tests/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ def test_float_nan(self, dt):
expected = numpy.nextafter(numpy.nan, a)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
def test_f16_strides(self, val):
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
Expand All @@ -702,6 +703,7 @@ def test_f16_strides(self, val):
expected = numpy.nextafter(a[1:], -hinf)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
def test_f16_array_inf(self, val):
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
Expand All @@ -716,6 +718,7 @@ def test_f16_array_inf(self, val):
expected = numpy.nextafter(-hinf, a)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize(
"sign1, sign2",
[
Expand All @@ -734,6 +737,7 @@ def test_f16_inf(self, sign1, sign2):
expected = numpy.nextafter(hinf1, hinf2)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
def test_f16_array_nan(self, val):
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
Expand All @@ -748,6 +752,7 @@ def test_f16_array_nan(self, val):
expected = numpy.nextafter(nan, a)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize(
"val1, val2",
[
Expand All @@ -765,6 +770,7 @@ def test_f16_inf_nan(self, val1, val2):
expected = numpy.nextafter(v1, v2)
assert_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize(
"val, scalar",
[
Expand Down
61 changes: 22 additions & 39 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@
from .third_party.cupy import testing


def _get_output_data_type(dtype):
"""Return a data type specified by input `dtype` and device capabilities."""
dtype_float16 = any(
dpnp.issubdtype(dtype, t) for t in (dpnp.bool, dpnp.int8, dpnp.uint8)
)
dtype_float32 = any(
dpnp.issubdtype(dtype, t) for t in (dpnp.int16, dpnp.uint16)
)
if dtype_float16:
out_dtype = dpnp.float16 if has_support_aspect16() else dpnp.float32
elif dtype_float32:
out_dtype = dpnp.float32
elif dpnp.issubdtype(dtype, dpnp.complexfloating):
out_dtype = dpnp.complex64
if has_support_aspect64() and dtype != dpnp.complex64:
out_dtype = dpnp.complex128
else:
out_dtype = dpnp.float32
if has_support_aspect64() and dtype != dpnp.float32:
out_dtype = dpnp.float64

return out_dtype


@pytest.mark.parametrize("deg", [True, False])
class TestAngle:
def test_angle_bool(self, deg):
Expand Down Expand Up @@ -775,6 +751,16 @@ def test_errors(self):


class TestFix:
def get_numpy_output_dtype(self, dtype):
# this is used to determine the output dtype of numpy array
# which is on cpu so no need for checking has_support_aspect64
if has_support_aspect16() and dpnp.can_cast(dtype, dpnp.float16):
return dpnp.float16
if dpnp.can_cast(dtype, dpnp.float32):
return dpnp.float32
if dpnp.can_cast(dtype, dpnp.float64):
return dpnp.float64

@pytest.mark.parametrize(
"dt", get_all_dtypes(no_none=True, no_complex=True)
)
Expand All @@ -794,28 +780,25 @@ def test_complex(self, xp, dt):
xp.fix(a)

@pytest.mark.parametrize(
"a_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
"dt", get_all_dtypes(no_none=True, no_complex=True)
)
def test_out(self, a_dt):
a = get_abs_array(
[[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]], a_dt
)
ia = dpnp.array(a)

out_dt = _get_output_data_type(a.dtype)
out = numpy.zeros_like(a, dtype=out_dt)
iout = dpnp.array(out)
def test_out(self, dt):
data = [[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]
a = get_abs_array(data, dtype=dt)
# numpy output has the same dtype as input
# dpnp output always has a floating point dtype
dt_out = self.get_numpy_output_dtype(a.dtype)
out = numpy.zeros_like(a, dtype=dt_out)
ia, iout = dpnp.array(a), dpnp.array(out)

result = dpnp.fix(ia, out=iout)
expected = numpy.fix(a, out=out)
assert_array_equal(result, expected)

@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
@pytest.mark.parametrize("dt", [bool, numpy.float16])
def test_out_float16(self, dt):
a = numpy.array(
[[1.0, 1.1], [1.5, 1.8], [-1.0, -1.1], [-1.5, -1.8]], dtype=dt
)
def test_out_float16(self):
data = [[1.0, 1.1], [1.5, 1.8], [-1.0, -1.1], [-1.5, -1.8]]
a = numpy.array(data, dtype=numpy.float16)
out = numpy.zeros_like(a, dtype=numpy.float16)
ia, iout = dpnp.array(a), dpnp.array(out)

Expand Down
Loading