Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -35,6 +35,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
### Deprecated

* `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)

### Removed

Expand Down
9 changes: 8 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from dpnp.dpnp_algo.dpnp_elementwise_common import (
DPNPBinaryFunc,
DPNPBinaryFuncOutKw,
DPNPUnaryFunc,
DPNPUnaryTwoOutputsFunc,
)
Expand Down Expand Up @@ -210,7 +211,13 @@
# -- Options for todo extension ----------------------------------------------
def _can_document_member(member, *args, **kwargs):
if isinstance(
member, (DPNPBinaryFunc, DPNPUnaryFunc, DPNPUnaryTwoOutputsFunc)
member,
(
DPNPBinaryFunc,
DPNPBinaryFuncOutKw,
DPNPUnaryFunc,
DPNPUnaryTwoOutputsFunc,
),
):
return True
return orig(member, *args, **kwargs)
Expand Down
20 changes: 20 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import warnings
from functools import wraps

import dpctl.tensor as dpt
import dpctl.tensor._copy_utils as dtc
import dpctl.tensor._tensor_impl as dti
Expand All @@ -48,6 +51,7 @@
"DPNPI0",
"DPNPAngle",
"DPNPBinaryFunc",
"DPNPBinaryFuncOutKw",
"DPNPFix",
"DPNPImag",
"DPNPReal",
Expand Down Expand Up @@ -729,6 +733,22 @@ def outer(
)


class DPNPBinaryFuncOutKw(DPNPBinaryFunc):
"""DPNPBinaryFunc that deprecates positional `out` argument."""

@wraps(DPNPBinaryFunc.__call__)
def __call__(self, *args, **kwargs):
if len(args) > self.nin:
warnings.warn(
"Passing more than 2 positional arguments is deprecated. "
"If you meant to use the third argument as an output, "
"use the `out` keyword argument instead.",
DeprecationWarning,
stacklevel=2,
)
return super().__call__(*args, **kwargs)


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

Expand Down
25 changes: 23 additions & 2 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
DPNPI0,
DPNPAngle,
DPNPBinaryFunc,
DPNPBinaryFuncOutKw,
DPNPFix,
DPNPImag,
DPNPReal,
Expand Down Expand Up @@ -3202,6 +3203,16 @@ def interp(x, xp, fp, left=None, right=None, period=None):

Default: ``"K"``.

Warning
-------
Passing more than 2 positional arguments is deprecated.
If you meant to use the third argument as an output,
use the `out` keyword argument instead.

For example, ``dpnp.maximum(a, b, c)`` will emit a ``DeprecationWarning``.
Always pass the output array as the keyword argument instead, that is
``dpnp.maximum(a, b, out=c)``.

Returns
-------
out : dpnp.ndarray
Expand Down Expand Up @@ -3255,7 +3266,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):

"""

maximum = DPNPBinaryFunc(
maximum = DPNPBinaryFuncOutKw(
"maximum",
ti._maximum_result_type,
ti._maximum,
Expand Down Expand Up @@ -3297,6 +3308,16 @@ def interp(x, xp, fp, left=None, right=None, period=None):
An array containing the element-wise minima. The data type of
the returned array is determined by the Type Promotion Rules.

Warning
-------
Passing more than 2 positional arguments is deprecated.
If you meant to use the third argument as an output,
use the `out` keyword argument instead.

For example, ``dpnp.minimum(a, b, c)`` will emit a ``DeprecationWarning``.
Always pass the output array as the keyword argument instead, that is
``dpnp.minimum(a, b, out=c)``.

Limitations
-----------
Parameters `where` and `subok` are supported with their default values.
Expand Down Expand Up @@ -3343,7 +3364,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
array(-inf)
"""

minimum = DPNPBinaryFunc(
minimum = DPNPBinaryFuncOutKw(
"minimum",
ti._minimum_result_type,
ti._minimum,
Expand Down
1 change: 1 addition & 0 deletions dpnp/tests/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_invalid_shape(self, func, shape):
with pytest.raises(ValueError):
getattr(dpnp, func)(a, b, out=out)

@pytest.mark.filterwarnings("ignore::DeprecationWarning")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to pass out=out to mitigate that issue rather than muting warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy.minimum(q,w,out=())
ValueError: The 'out' tuple must have exactly one entry per ufunc output

numpy.minimum(q,w,out=(1,2))
ValueError: The 'out' tuple must have exactly one entry per ufunc output

@pytest.mark.parametrize("xp", [dpnp, numpy])
@pytest.mark.parametrize(
"out",
Expand Down
12 changes: 12 additions & 0 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2910,3 +2910,15 @@ def test_elemenwise_outer_scalar():
expected = dpnp.add.outer(x, y)
result = dpnp.add.outer(x, s)
assert dpnp.allclose(result, expected)


@testing.with_requires("numpy>=2.4")
@pytest.mark.parametrize("xp", [dpnp, numpy])
@pytest.mark.parametrize("func", ["minimum", "maximum"])
def test_minimum_maximum_out_deprecated(xp, func):
a = xp.array([1, 3, 2])
b = xp.array([2, 2, 2])
out = xp.empty_like(a)

with pytest.warns(DeprecationWarning, match="deprecated"):
_ = getattr(xp, func)(a, b, out)
5 changes: 4 additions & 1 deletion dpnp/tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,10 @@ def test_invalid_stream(self, stream):
"asarray_chkfinite",
"asanyarray",
"ascontiguousarray",
"asfarray",
pytest.param(
"asfarray",
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
"asfortranarray",
],
)
Expand Down
5 changes: 4 additions & 1 deletion dpnp/tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ def test_copy_operation(usm_type):
"asarray_chkfinite",
"asanyarray",
"ascontiguousarray",
"asfarray",
pytest.param(
"asfarray",
marks=pytest.mark.filterwarnings("ignore::DeprecationWarning"),
),
"asfortranarray",
],
)
Expand Down
Loading