Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
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)
* Extended `dpnp.fft.fftfreq` and `dpnp.fft.rfftfreq` functions to support `dtype` keyword per Python Array API spec 2024.12 [#2384](https://github.com/IntelPython/dpnp/pull/2384)
* Updated `dpnp.fix` to return output with the same data-type of input [#2392](https://github.com/IntelPython/dpnp/pull/2392)

### Fixed

Expand Down
40 changes: 40 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"DPNPI0",
"DPNPAngle",
"DPNPBinaryFunc",
"DPNPFix",
"DPNPImag",
"DPNPReal",
"DPNPRound",
Expand Down Expand Up @@ -511,6 +512,45 @@ def __call__(self, x, deg=False, out=None, order="K"):
return res


class DPNPFix(DPNPUnaryFunc):
"""Class that implements dpnp.real unary element-wise functions."""

def __init__(
self,
name,
result_type_resolver_fn,
unary_dp_impl_fn,
docs,
):
super().__init__(
name,
result_type_resolver_fn,
unary_dp_impl_fn,
docs,
)

def __call__(self, x, out=None, order="K"):
if not dpnp.is_supported_array_type(x):
pass # pass to raise error in main implementation
elif dpnp.issubdtype(x.dtype, dpnp.inexact):
pass # for inexact types, pass to calculate in the backend
elif out is not None and (
not dpnp.is_supported_array_type(out) or out.dtype != x.dtype
):
pass # pass to raise error in main implementation
else:
# for exact types, return the input
if out is None:
return dpnp.asarray(x, copy=True)

if isinstance(out, dpt.usm_ndarray):
out = dpnp_array._create_from_usm_ndarray(out)
out[...] = x
return out

return super().__call__(x, out=out, order=order)


class DPNPI0(DPNPUnaryFunc):
"""Class that implements dpnp.i0 unary element-wise functions."""

Expand Down
26 changes: 11 additions & 15 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
DPNPI0,
DPNPAngle,
DPNPBinaryFunc,
DPNPFix,
DPNPImag,
DPNPReal,
DPNPRound,
Expand Down Expand Up @@ -1728,14 +1729,14 @@ def ediff1d(ary, to_end=None, to_begin=None):
Round to nearest integer towards zero.

Round an array of floats element-wise to nearest integer towards zero.
The rounded values are returned as floats.
The rounded values have the same data-type as the input.

For full documentation refer to :obj:`numpy.fix`.

Parameters
----------
x : {dpnp.ndarray, usm_ndarray}
An array of floats to be rounded.
Input array, expected to have a real-valued data type.
out : {None, dpnp.ndarray, usm_ndarray}, optional
Output array to populate.
Array must have the correct shape and the expected data type.
Expand All @@ -1749,19 +1750,12 @@ def ediff1d(ary, to_end=None, to_begin=None):
Returns
-------
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.
If `out` is ``None`` then a float array is returned with the rounded values.
An array with the same dimensions and data-type as the input.
If `out` is ``None`` then a new array is returned
with the rounded values.
Otherwise the result is stored there and the return value `out` is
a reference to that array.

Limitations
-----------
Parameters `where` and `subok` are supported with their default values.
Keyword argument `kwargs` is currently unsupported.
Otherwise ``NotImplementedError`` exception will be raised.

See Also
--------
:obj:`dpnp.round` : Round to given number of decimals.
Expand All @@ -1782,7 +1776,7 @@ def ediff1d(ary, to_end=None, to_begin=None):
array([ 2., 2., -2., -2.])
"""

fix = DPNPUnaryFunc(
fix = DPNPFix(
"fix",
ufi._fix_result_type,
ufi._fix,
Expand Down Expand Up @@ -1934,8 +1928,10 @@ def ediff1d(ary, to_end=None, to_begin=None):

Notes
-----
Some spreadsheet programs calculate the "floor-towards-zero", in other words floor(-2.5) == -2.
DPNP instead uses the definition of floor where floor(-2.5) == -3.
Some spreadsheet programs calculate the "floor-towards-zero", where
``floor(-2.5) == -2``. DPNP instead uses the definition of :obj:`dpnp.floor`
where ``floor(-2.5) == -3``. The "floor-towards-zero" function is called
:obj:`dpnp.fix` in DPNP.

Examples
--------
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
Loading
Loading