Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
test-env-name: 'test'
rerun-tests-on-failure: 'true'
rerun-tests-max-attempts: 2
rerun-tests-timeout: 35
rerun-tests-timeout: 40

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* Fixed a bug for calculating the norm (`dpnp.linalg.norm`) of empty arrays when `keepdims=True` is passed [#2477](https://github.com/IntelPython/dpnp/pull/2477)

## [0.18.0] - 06/04/2025

Expand Down
13 changes: 11 additions & 2 deletions dpnp/linalg/dpnp_utils_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,11 @@ def _norm_int_axis(x, ord, axis, keepdims):
if ord == dpnp.inf:
if x.shape[axis] == 0:
x = dpnp.moveaxis(x, axis, -1)
return dpnp.zeros_like(x, shape=x.shape[:-1])
res_shape = x.shape[:-1]
result = dpnp.zeros_like(x, shape=res_shape)
if keepdims:
result = result.reshape(res_shape + (1,))
return result
return dpnp.abs(x).max(axis=axis, keepdims=keepdims)
if ord == -dpnp.inf:
return dpnp.abs(x).min(axis=axis, keepdims=keepdims)
Expand Down Expand Up @@ -1222,11 +1226,16 @@ def _norm_tuple_axis(x, ord, row_axis, col_axis, keepdims):

"""

# pylint: disable=too-many-branches
axis = (row_axis, col_axis)
flag = x.shape[row_axis] == 0 or x.shape[col_axis] == 0
if flag and ord in [1, 2, dpnp.inf]:
x = dpnp.moveaxis(x, axis, (-2, -1))
return dpnp.zeros_like(x, shape=x.shape[:-2])
res_shape = x.shape[:-2]
result = dpnp.zeros_like(x, shape=res_shape)
if keepdims:
result = result.reshape(res_shape + (1, 1))
return result
if row_axis == col_axis:
raise ValueError("Duplicate axes given.")
if ord == 2:
Expand Down
14 changes: 8 additions & 6 deletions dpnp/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
get_integer_float_dtypes,
has_support_aspect64,
is_cpu_device,
is_cuda_device,
numpy_version,
requires_intel_mkl_version,
)
Expand Down Expand Up @@ -2104,11 +2103,14 @@ def test_empty(self, shape, ord, axis, keepdims):
assert_raises(ValueError, dpnp.linalg.norm, ia, **kwarg)
assert_raises(ValueError, numpy.linalg.norm, a, **kwarg)
else:
# TODO: when similar changes in numpy are available, instead
# of assert_equal with zero, we should compare with numpy
# ord in [None, 1, 2]
assert_equal(dpnp.linalg.norm(ia, **kwarg), 0.0)
assert_raises(ValueError, numpy.linalg.norm, a, **kwarg)
if numpy_version() >= "2.3.0":
result = dpnp.linalg.norm(ia, **kwarg)
expected = numpy.linalg.norm(a, **kwarg)
assert_dtype_allclose(result, expected)
else:
assert_equal(
dpnp.linalg.norm(ia, **kwarg), 0.0, strict=False
)
else:
result = dpnp.linalg.norm(ia, **kwarg)
expected = numpy.linalg.norm(a, **kwarg)
Expand Down
6 changes: 4 additions & 2 deletions dpnp/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
assert_dtype_allclose,
generate_random_numpy_array,
get_all_dtypes,
get_complex_dtypes,
is_win_platform,
numpy_version,
)
from .third_party.cupy import testing
Expand Down Expand Up @@ -845,6 +843,8 @@ def test_dtype_matrix(self, dt_in1, dt_in2, dt_out, shape1, shape2):
assert_raises(TypeError, dpnp.matmul, ia, ib, out=iout)
assert_raises(TypeError, numpy.matmul, a, b, out=out)

# TODO: include numpy-2.3 when numpy-issue-29164 is resolved
@testing.with_requires("numpy<2.3")
@pytest.mark.parametrize("dtype", _selected_dtypes)
@pytest.mark.parametrize("order1", ["C", "F", "A"])
@pytest.mark.parametrize("order2", ["C", "F", "A"])
Expand Down Expand Up @@ -882,6 +882,8 @@ def test_order(self, dtype, order1, order2, order, shape1, shape2):
assert result.flags.f_contiguous == expected.flags.f_contiguous
assert_dtype_allclose(result, expected)

# TODO: include numpy-2.3 when numpy-issue-29164 is resolved
@testing.with_requires("numpy<2.3")
@pytest.mark.parametrize("dtype", _selected_dtypes)
@pytest.mark.parametrize(
"stride",
Expand Down
5 changes: 4 additions & 1 deletion dpnp/tests/testing/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def _assert(assert_func, result, expected, *args, **kwargs):
]
# For numpy < 2.0, some tests will fail for dtype mismatch
dev = dpctl.select_default_device()
if numpy.__version__ >= "2.0.0" and dev.has_aspect_fp64:
if (
numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0"
and dev.has_aspect_fp64
):
strict = kwargs.setdefault("strict", True)
if flag:
if strict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ def test_unique_inverse(self, xp, dtype, attr):
a = testing.shaped_random((100, 100), xp, dtype)
return getattr(xp.unique_inverse(a), attr)

@testing.with_requires("numpy>=2.0")
# TODO: include numpy-2.3 when dpnp-issue-2476 is addressed
@testing.with_requires("numpy>=2.0", "numpy<2.3")
@testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True)
@testing.numpy_cupy_array_equal()
def test_unique_values(self, xp, dtype):
Expand Down
2 changes: 2 additions & 0 deletions dpnp/tests/third_party/cupy/math_tests/test_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def test_cupy_matmul(self, xp, dtype1, dtype2):
)
class TestMatmulOut(unittest.TestCase):

# TODO: include numpy-2.3 when numpy-issue-29164 is resolved
@testing.with_requires("numpy<2.3")
# no_int8=True is added to avoid overflow
@testing.for_all_dtypes(name="dtype1", no_int8=True)
@testing.for_all_dtypes(name="dtype2", no_int8=True)
Expand Down
Loading