Skip to content

Commit 9093aee

Browse files
authored
Merge branch 'master' into simplify-kaiser
2 parents ba80a1f + 4046985 commit 9093aee

File tree

14 files changed

+79
-71
lines changed

14 files changed

+79
-71
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
- name: Setup miniconda
119119
id: setup_miniconda
120120
continue-on-error: true
121-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
121+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
122122
with:
123123
miniforge-version: latest
124124
use-mamba: 'true'
@@ -128,7 +128,7 @@ jobs:
128128

129129
- name: ReSetup miniconda
130130
if: steps.setup_miniconda.outcome == 'failure'
131-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
131+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
132132
with:
133133
miniforge-version: latest
134134
use-mamba: 'true'

.github/workflows/check-mkl-interfaces.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: Setup miniconda
9292
id: setup_miniconda
9393
continue-on-error: true
94-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
94+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
9595
with:
9696
miniforge-version: latest
9797
use-mamba: 'true'
@@ -101,7 +101,7 @@ jobs:
101101

102102
- name: ReSetup miniconda
103103
if: steps.setup_miniconda.outcome == 'failure'
104-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
104+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
105105
with:
106106
miniforge-version: latest
107107
use-mamba: 'true'
@@ -196,7 +196,7 @@ jobs:
196196
- name: Setup miniconda
197197
id: setup_miniconda
198198
continue-on-error: true
199-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
199+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
200200
with:
201201
miniforge-version: latest
202202
use-mamba: 'true'
@@ -206,7 +206,7 @@ jobs:
206206

207207
- name: ReSetup miniconda
208208
if: steps.setup_miniconda.outcome == 'failure'
209-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
209+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
210210
with:
211211
miniforge-version: latest
212212
use-mamba: 'true'

.github/workflows/conda-package.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
test-env-name: 'test'
2323
rerun-tests-on-failure: 'true'
2424
rerun-tests-max-attempts: 2
25-
rerun-tests-timeout: 35
25+
rerun-tests-timeout: 40
2626

2727
jobs:
2828
build:
@@ -64,7 +64,7 @@ jobs:
6464
- name: Setup miniconda
6565
id: setup_miniconda
6666
continue-on-error: true
67-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
67+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
6868
with:
6969
miniforge-version: latest
7070
use-mamba: 'true'
@@ -74,7 +74,7 @@ jobs:
7474

7575
- name: ReSetup miniconda
7676
if: steps.setup_miniconda.outcome == 'failure'
77-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
77+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
7878
with:
7979
miniforge-version: latest
8080
use-mamba: 'true'
@@ -157,7 +157,7 @@ jobs:
157157
- name: Setup miniconda
158158
id: setup_miniconda
159159
continue-on-error: true
160-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
160+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
161161
with:
162162
miniforge-version: latest
163163
use-mamba: 'true'
@@ -167,7 +167,7 @@ jobs:
167167

168168
- name: ReSetup miniconda
169169
if: steps.setup_miniconda.outcome == 'failure'
170-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
170+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
171171
with:
172172
miniforge-version: latest
173173
use-mamba: 'true'
@@ -296,7 +296,7 @@ jobs:
296296
- name: Setup miniconda
297297
id: setup_miniconda
298298
continue-on-error: true
299-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
299+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
300300
with:
301301
miniforge-version: latest
302302
use-mamba: 'true'
@@ -306,7 +306,7 @@ jobs:
306306

307307
- name: ReSetup miniconda
308308
if: steps.setup_miniconda.outcome == 'failure'
309-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
309+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
310310
with:
311311
miniforge-version: latest
312312
use-mamba: 'true'
@@ -445,7 +445,7 @@ jobs:
445445
- name: Setup miniconda
446446
id: setup_miniconda
447447
continue-on-error: true
448-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
448+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
449449
with:
450450
miniforge-version: latest
451451
use-mamba: 'true'
@@ -455,7 +455,7 @@ jobs:
455455

456456
- name: ReSetup miniconda
457457
if: steps.setup_miniconda.outcome == 'failure'
458-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
458+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
459459
with:
460460
miniforge-version: latest
461461
use-mamba: 'true'
@@ -529,7 +529,7 @@ jobs:
529529
- name: Setup miniconda
530530
id: setup_miniconda
531531
continue-on-error: true
532-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
532+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
533533
with:
534534
miniforge-version: latest
535535
use-mamba: 'true'
@@ -539,7 +539,7 @@ jobs:
539539

540540
- name: ReSetup miniconda
541541
if: steps.setup_miniconda.outcome == 'failure'
542-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
542+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
543543
with:
544544
miniforge-version: latest
545545
use-mamba: 'true'
@@ -674,7 +674,7 @@ jobs:
674674
- name: Setup miniconda
675675
id: setup_miniconda
676676
continue-on-error: true
677-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
677+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
678678
with:
679679
miniforge-version: latest
680680
use-mamba: 'true'
@@ -684,7 +684,7 @@ jobs:
684684

685685
- name: ReSetup miniconda
686686
if: steps.setup_miniconda.outcome == 'failure'
687-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
687+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
688688
with:
689689
miniforge-version: latest
690690
use-mamba: 'true'

.github/workflows/cron-run-tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Setup miniconda
6464
id: setup_miniconda
6565
continue-on-error: true
66-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
66+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
6767
with:
6868
miniforge-version: latest
6969
use-mamba: 'true'
@@ -74,7 +74,7 @@ jobs:
7474

7575
- name: ReSetup miniconda
7676
if: steps.setup_miniconda.outcome == 'failure'
77-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
77+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
7878
with:
7979
miniforge-version: latest
8080
use-mamba: 'true'

.github/workflows/generate_coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- name: Setup miniconda
7878
id: setup_miniconda
7979
continue-on-error: true
80-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
80+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
8181
with:
8282
miniforge-version: latest
8383
use-mamba: 'true'
@@ -87,7 +87,7 @@ jobs:
8787

8888
- name: ReSetup miniconda
8989
if: steps.setup_miniconda.outcome == 'failure'
90-
uses: conda-incubator/setup-miniconda@505e6394dae86d6a5c7fbb6e3fb8938e3e863830 # v3.1.1
90+
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0
9191
with:
9292
miniforge-version: latest
9393
use-mamba: 'true'

.github/workflows/openssf-scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ jobs:
6868

6969
# Upload the results to GitHub's code scanning dashboard.
7070
- name: "Upload to code-scanning"
71-
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
71+
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
7272
with:
7373
sarif_file: results.sarif

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Fixed
1414

15+
* 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)
1516

1617
## [0.18.0] - 06/04/2025
1718

dpnp/linalg/dpnp_utils_linalg.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,10 @@ def _norm_int_axis(x, ord, axis, keepdims):
11871187
if ord == dpnp.inf:
11881188
if x.shape[axis] == 0:
11891189
x = dpnp.moveaxis(x, axis, -1)
1190-
return dpnp.zeros_like(x, shape=x.shape[:-1])
1190+
res_shape = x.shape[:-1]
1191+
if keepdims:
1192+
res_shape += (1,)
1193+
return dpnp.zeros_like(x, shape=res_shape)
11911194
return dpnp.abs(x).max(axis=axis, keepdims=keepdims)
11921195
if ord == -dpnp.inf:
11931196
return dpnp.abs(x).min(axis=axis, keepdims=keepdims)
@@ -1226,7 +1229,10 @@ def _norm_tuple_axis(x, ord, row_axis, col_axis, keepdims):
12261229
flag = x.shape[row_axis] == 0 or x.shape[col_axis] == 0
12271230
if flag and ord in [1, 2, dpnp.inf]:
12281231
x = dpnp.moveaxis(x, axis, (-2, -1))
1229-
return dpnp.zeros_like(x, shape=x.shape[:-2])
1232+
res_shape = x.shape[:-2]
1233+
if keepdims:
1234+
res_shape += (1, 1)
1235+
return dpnp.zeros_like(x, shape=res_shape)
12301236
if row_axis == col_axis:
12311237
raise ValueError("Duplicate axes given.")
12321238
if ord == 2:

dpnp/tests/test_linalg.py

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
get_integer_float_dtypes,
2424
has_support_aspect64,
2525
is_cpu_device,
26-
is_cuda_device,
2726
numpy_version,
2827
requires_intel_mkl_version,
2928
)
@@ -2104,11 +2103,14 @@ def test_empty(self, shape, ord, axis, keepdims):
21042103
assert_raises(ValueError, dpnp.linalg.norm, ia, **kwarg)
21052104
assert_raises(ValueError, numpy.linalg.norm, a, **kwarg)
21062105
else:
2107-
# TODO: when similar changes in numpy are available, instead
2108-
# of assert_equal with zero, we should compare with numpy
2109-
# ord in [None, 1, 2]
2110-
assert_equal(dpnp.linalg.norm(ia, **kwarg), 0.0)
2111-
assert_raises(ValueError, numpy.linalg.norm, a, **kwarg)
2106+
if numpy_version() >= "2.3.0":
2107+
result = dpnp.linalg.norm(ia, **kwarg)
2108+
expected = numpy.linalg.norm(a, **kwarg)
2109+
assert_dtype_allclose(result, expected)
2110+
else:
2111+
assert_equal(
2112+
dpnp.linalg.norm(ia, **kwarg), 0.0, strict=False
2113+
)
21122114
else:
21132115
result = dpnp.linalg.norm(ia, **kwarg)
21142116
expected = numpy.linalg.norm(a, **kwarg)
@@ -2296,49 +2298,40 @@ def test_matrix_norm(self, ord, keepdims):
22962298
expected = numpy.linalg.matrix_norm(a, ord=ord, keepdims=keepdims)
22972299
assert_dtype_allclose(result, expected)
22982300

2299-
@pytest.mark.parametrize(
2300-
"xp",
2301-
[
2302-
dpnp,
2303-
pytest.param(
2304-
numpy,
2305-
marks=pytest.mark.skipif(
2306-
numpy_version() < "2.3.0",
2307-
reason="numpy raises an error",
2308-
),
2309-
),
2310-
],
2311-
)
2301+
@testing.with_requires("numpy>=2.3")
23122302
@pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32])
23132303
@pytest.mark.parametrize(
23142304
"shape, axis", [[(2, 0), None], [(2, 0), (0, 1)], [(0, 2), (0, 1)]]
23152305
)
23162306
@pytest.mark.parametrize("ord", [None, "fro", "nuc", 1, 2, dpnp.inf])
2317-
def test_matrix_norm_empty(self, xp, dtype, shape, axis, ord):
2318-
x = xp.zeros(shape, dtype=dtype)
2319-
sc = dtype(0.0) if dtype == dpnp.float32 else 0.0
2320-
assert_equal(xp.linalg.norm(x, axis=axis, ord=ord), sc)
2307+
@pytest.mark.parametrize("keepdims", [True, False])
2308+
def test_matrix_norm_empty(self, dtype, shape, axis, ord, keepdims):
2309+
a = numpy.zeros(shape, dtype=dtype)
2310+
ia = dpnp.array(a)
2311+
result = dpnp.linalg.norm(ia, axis=axis, ord=ord, keepdims=keepdims)
2312+
expected = numpy.linalg.norm(a, axis=axis, ord=ord, keepdims=keepdims)
2313+
assert_dtype_allclose(result, expected)
23212314

2322-
@pytest.mark.parametrize(
2323-
"xp",
2324-
[
2325-
dpnp,
2326-
pytest.param(
2327-
numpy,
2328-
marks=pytest.mark.skipif(
2329-
numpy_version() < "2.3.0",
2330-
reason="numpy raises an error",
2331-
),
2332-
),
2333-
],
2334-
)
2315+
@testing.with_requires("numpy>=2.3")
23352316
@pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32])
23362317
@pytest.mark.parametrize("axis", [None, 0])
23372318
@pytest.mark.parametrize("ord", [None, 1, 2, dpnp.inf])
2338-
def test_vector_norm_empty(self, xp, dtype, axis, ord):
2339-
x = xp.zeros(0, dtype=dtype)
2340-
sc = dtype(0.0) if dtype == dpnp.float32 else 0.0
2341-
assert_equal(xp.linalg.vector_norm(x, axis=axis, ord=ord), sc)
2319+
@pytest.mark.parametrize("keepdims", [True, False])
2320+
def test_vector_norm_empty(self, dtype, axis, ord, keepdims):
2321+
a = numpy.zeros(0, dtype=dtype)
2322+
ia = dpnp.array(a)
2323+
result = dpnp.linalg.vector_norm(
2324+
ia, axis=axis, ord=ord, keepdims=keepdims
2325+
)
2326+
expected = numpy.linalg.vector_norm(
2327+
a, axis=axis, ord=ord, keepdims=keepdims
2328+
)
2329+
assert_dtype_allclose(result, expected)
2330+
if keepdims:
2331+
# norm and vector_norm have different paths in dpnp when keepdims=True,
2332+
# to cover both of them test with norm as well
2333+
result = dpnp.linalg.norm(ia, axis=axis, ord=ord, keepdims=keepdims)
2334+
assert_dtype_allclose(result, expected)
23422335

23432336
@testing.with_requires("numpy>=2.0")
23442337
@pytest.mark.parametrize(

dpnp/tests/test_product.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
assert_dtype_allclose,
1313
generate_random_numpy_array,
1414
get_all_dtypes,
15-
get_complex_dtypes,
16-
is_win_platform,
1715
numpy_version,
1816
)
1917
from .third_party.cupy import testing
@@ -845,6 +843,8 @@ def test_dtype_matrix(self, dt_in1, dt_in2, dt_out, shape1, shape2):
845843
assert_raises(TypeError, dpnp.matmul, ia, ib, out=iout)
846844
assert_raises(TypeError, numpy.matmul, a, b, out=out)
847845

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

885+
# TODO: include numpy-2.3 when numpy-issue-29164 is resolved
886+
@testing.with_requires("numpy<2.3")
885887
@pytest.mark.parametrize("dtype", _selected_dtypes)
886888
@pytest.mark.parametrize(
887889
"stride",

0 commit comments

Comments
 (0)