Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -50,6 +50,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
* `dpnp.asfarray` is deprecated. Use `dpnp.asarray` with an appropriate dtype instead [#2650](https://github.com/IntelPython/dpnp/pull/2650)
* Passing the output array ``out`` positionally to `dpnp.minimum` and `dpnp.maximum` is deprecated. Pass the output with the keyword form, e.g. ``dpnp.minimum(a, b, out=c)`` [#2659](https://github.com/IntelPython/dpnp/pull/2659)
* `dpnp.ndarray.T` property is deprecated for not two-dimensional array to be compatible with the Python array API standard. To achieve a similar behavior when ``a.ndim != 2``, either ``a.transpose()``, or ``a.mT`` (swaps the last two axes only), or ``dpnp.permute_dims(a, range(a.ndim)[::-1])`` can be used [#2681](https://github.com/IntelPython/dpnp/pull/2681)
* `dpnp.fix` is deprecated. Use `dpnp.trunc` instead [#2730](https://github.com/IntelPython/dpnp/pull/2730)

### Removed

Expand Down
24 changes: 24 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"DPNPBinaryFunc",
"DPNPBinaryFuncOutKw",
"DPNPBinaryTwoOutputsFunc",
"DPNPDeprecatedUnaryFunc",
"DPNPImag",
"DPNPReal",
"DPNPRound",
Expand Down Expand Up @@ -230,6 +231,29 @@ def _unpack_out_kw(self, out):
return out


class DPNPDeprecatedUnaryFunc(DPNPUnaryFunc):
"""
Class that implements a deprecated unary element-wise function.

Parameters
----------
deprecated_msg : {str, None}
Warning message to emit. If None, no warning is issued.

"""

def __init__(self, *args, deprecated_msg=None, **kwargs):
super().__init__(*args, **kwargs)
self._deprecated_msg = deprecated_msg

def __call__(self, *args, **kwargs):
if self._deprecated_msg:
warnings.warn(
self._deprecated_msg, DeprecationWarning, stacklevel=2
)
return super().__call__(*args, **kwargs)


class DPNPUnaryTwoOutputsFunc(UnaryElementwiseFunc):
"""
Class that implements unary element-wise functions with two output arrays.
Expand Down
10 changes: 9 additions & 1 deletion dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
DPNPBinaryFunc,
DPNPBinaryFuncOutKw,
DPNPBinaryTwoOutputsFunc,
DPNPDeprecatedUnaryFunc,
DPNPImag,
DPNPReal,
DPNPRound,
Expand Down Expand Up @@ -1853,6 +1854,12 @@ def ediff1d(ary, to_end=None, to_begin=None):
:obj:`dpnp.floor` : Return the floor of the input, element-wise.
:obj:`dpnp.ceil` : Return the ceiling of the input, element-wise.

Warning
-------
This function is deprecated. It is recommended to use
:obj:`dpnp.trunc` instead, as it provides the same functionality of
truncating decimal values to their integer parts.

Examples
--------
>>> import dpnp as np
Expand All @@ -1867,13 +1874,14 @@ def ediff1d(ary, to_end=None, to_begin=None):
"""

# reuse trunc backend implementation for fix
fix = DPNPUnaryFunc(
fix = DPNPDeprecatedUnaryFunc(
"fix",
ti._trunc_result_type,
ti._trunc,
_FIX_DOCSTRING,
mkl_fn_to_call="_mkl_trunc_to_call",
mkl_impl_fn="_trunc",
deprecated_msg=("dpnp.fix is deprecated in favor of dpnp.trunc"),
)


Expand Down
26 changes: 24 additions & 2 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,18 @@ def test_out_dtype(self, func):

@pytest.mark.parametrize("xp", [numpy, dpnp])
@pytest.mark.parametrize(
"func", ["abs", "fix", "round", "add", "frexp", "divmod"]
"func",
[
"abs",
pytest.param(
"fix",
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
"round",
"add",
"frexp",
"divmod",
],
)
def test_out_wrong_tuple_len(self, xp, func):
if func == "round" and xp is numpy:
Expand Down Expand Up @@ -2543,7 +2554,18 @@ def test_projection(self, dtype):
assert dpnp.allclose(result, expected)


@pytest.mark.parametrize("func", ["ceil", "floor", "trunc", "fix"])
@pytest.mark.parametrize(
"func",
[
"ceil",
"floor",
"trunc",
pytest.param(
"fix",
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
],
)
class TestRoundingFuncs:
@testing.with_requires("numpy>=2.1.0")
@pytest.mark.parametrize(
Expand Down
6 changes: 5 additions & 1 deletion dpnp/tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ def test_meshgrid(device):
pytest.param("exp2", [0.0, 1.0, 2.0]),
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
pytest.param("fabs", [-1.2, 1.2]),
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
pytest.param(
"fix",
[2.1, 2.9, -2.1, -2.9],
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("gradient", [1.0, 2.0, 4.0, 7.0, 11.0, 16.0]),
Expand Down
6 changes: 5 additions & 1 deletion dpnp/tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,11 @@ def test_meshgrid(usm_type_x, usm_type_y):
pytest.param("exp2", [0.0, 1.0, 2.0]),
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
pytest.param("fabs", [-1.2, 1.2]),
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
pytest.param(
"fix",
[2.1, 2.9, -2.1, -2.9],
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
pytest.param("gradient", [1, 2, 4, 7, 11, 16]),
Expand Down
1 change: 1 addition & 0 deletions dpnp/tests/third_party/cupy/math_tests/test_rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_trunc(self):
self.check_unary("trunc")
self.check_unary_complex_unsupported("trunc")

@pytest.mark.filterwarnings("ignore::DeprecationWarning")
@testing.with_requires("numpy>=2.1")
def test_fix(self):
self.check_unary("fix")
Expand Down
Loading