Skip to content

Commit ab08787

Browse files
Merge master into impl-piecewise
2 parents e72041d + f244f40 commit ab08787

File tree

15 files changed

+90
-9
lines changed

15 files changed

+90
-9
lines changed

.github/workflows/openssf-scorecard.yml

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

7373
# Upload the results to GitHub's code scanning dashboard.
7474
- name: "Upload to code-scanning"
75-
uses: github/codeql-action/upload-sarif@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3.29.11
75+
uses: github/codeql-action/upload-sarif@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.30.1
7676
with:
7777
sarif_file: results.sarif

.github/workflows/pre-commit-autoupdate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2121

2222
- name: Set up python
23-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
23+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
2424
with:
2525
python-version: '3.13'
2626

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
ref: ${{ github.sha }}
3737

3838
- name: Set up python
39-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
39+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
4040
with:
4141
python-version: '3.13'
4242

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5858
* Fixed `dpnp.unique` with 1d input array and `axis=0`, `equal_nan=True` keywords passed where the produced result doesn't collapse the NaNs [#2530](https://github.com/IntelPython/dpnp/pull/2530)
5959
* Resolved issue when `dpnp.ndarray` constructor is called with `dpnp.ndarray.data` as `buffer` keyword [#2533](https://github.com/IntelPython/dpnp/pull/2533)
6060
* Fixed `dpnp.linalg.cond` to always return a real dtype [#2547](https://github.com/IntelPython/dpnp/pull/2547)
61+
* Resolved the issue in `dpnp.random` functions to allow any value of `size` where each element is castable to `Py_ssize_t` type [#2578](https://github.com/IntelPython/dpnp/pull/2578)
6162

6263
### Security
6364

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,26 @@ cpdef inline tuple _object_to_tuple(object obj):
390390
if obj is None:
391391
return ()
392392

393-
if cpython.PySequence_Check(obj):
394-
return tuple(obj)
393+
# dpnp.ndarray unconditionally succeeds in PySequence_Check as it implements __getitem__
394+
if cpython.PySequence_Check(obj) and not dpnp.is_supported_array_type(obj):
395+
if isinstance(obj, numpy.ndarray):
396+
obj = numpy.atleast_1d(obj)
397+
398+
nd = len(obj)
399+
shape = []
400+
401+
for i in range(0, nd):
402+
if cpython.PyBool_Check(obj[i]):
403+
raise TypeError("DPNP object_to_tuple(): no item in size can be bool")
404+
405+
# Assumes each item is castable to Py_ssize_t,
406+
# otherwise TypeError will be raised
407+
shape.append(<Py_ssize_t> obj[i])
408+
return tuple(shape)
395409

396410
if dpnp.isscalar(obj):
411+
if cpython.PyBool_Check(obj):
412+
raise TypeError("DPNP object_to_tuple(): 'obj' can't be bool")
397413
return (obj, )
398414

399415
raise ValueError("DPNP object_to_tuple(): 'obj' should be 'None', collections.abc.Sequence, or 'int'")

dpnp/tests/helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ def has_support_aspect64(device=None):
404404
return dev.has_aspect_fp64
405405

406406

407+
def is_arl_or_mtl(device=None):
408+
"""
409+
Return True if a test is running on Arrow Lake or Meteor Lake GPU device,
410+
False otherwise.
411+
"""
412+
return _get_dev_mask(device) == 0x7D00
413+
414+
407415
def is_cpu_device(device=None):
408416
"""
409417
Return True if a test is running on CPU device, False otherwise.

dpnp/tests/test_linalg.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
get_float_complex_dtypes,
2424
get_integer_float_dtypes,
2525
has_support_aspect64,
26-
is_cpu_device,
26+
is_arl_or_mtl,
27+
is_win_platform,
2728
numpy_version,
2829
)
2930
from .third_party.cupy import testing
@@ -109,6 +110,8 @@ def test_usm_ndarray_linalg_batch(func, gen_kwargs, func_kwargs):
109110
)
110111
for _ in range(2)
111112
]
113+
elif func == "cholesky" and is_win_platform() and is_arl_or_mtl():
114+
pytest.skip("SAT-8206")
112115
else:
113116
dpt_args = [
114117
dpt.asarray(generate_random_numpy_array(shape, **gen_kwargs))
@@ -158,6 +161,8 @@ class TestCholesky:
158161
def test_cholesky(self, array, dtype):
159162
a = numpy.array(array, dtype=dtype)
160163
ia = dpnp.array(a)
164+
if ia.ndim > 2 and is_win_platform() and is_arl_or_mtl():
165+
pytest.skip("SAT-8206")
161166
result = dpnp.linalg.cholesky(ia)
162167
expected = numpy.linalg.cholesky(a)
163168
assert_dtype_allclose(result, expected)
@@ -177,6 +182,8 @@ def test_cholesky(self, array, dtype):
177182
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
178183
def test_cholesky_upper(self, array, dtype):
179184
ia = dpnp.array(array, dtype=dtype)
185+
if ia.ndim > 2 and is_win_platform() and is_arl_or_mtl():
186+
pytest.skip("SAT-8206")
180187
result = dpnp.linalg.cholesky(ia, upper=True)
181188

182189
if ia.ndim > 2:
@@ -219,6 +226,8 @@ def test_cholesky_upper(self, array, dtype):
219226
def test_cholesky_upper_numpy(self, array, dtype):
220227
a = numpy.array(array, dtype=dtype)
221228
ia = dpnp.array(a)
229+
if ia.ndim > 2 and is_win_platform() and is_arl_or_mtl():
230+
pytest.skip("SAT-8206")
222231
result = dpnp.linalg.cholesky(ia, upper=True)
223232
expected = numpy.linalg.cholesky(a, upper=True)
224233
assert_dtype_allclose(result, expected)

dpnp/tests/test_random_state.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
is_cpu_device,
2222
is_gpu_device,
2323
)
24+
from .third_party.cupy import testing
2425

2526
# aspects of default device:
2627
_def_device = dpctl.SyclQueue().sycl_device
@@ -1115,3 +1116,31 @@ def test_invalid_dtype(self, dtype):
11151116
def test_invalid_usm_type(self, usm_type):
11161117
# dtype must be float32 or float64
11171118
assert_raises(ValueError, RandomState().uniform, usm_type=usm_type)
1119+
1120+
def test_size_castable_to_integer(self):
1121+
M = numpy.int64(31)
1122+
N = numpy.int64(31)
1123+
K = 63 # plain Python int
1124+
1125+
sizes = [(M, K), (M, N), (K, N)]
1126+
for size in sizes:
1127+
result = RandomState().uniform(size=size)
1128+
assert result.shape == size
1129+
1130+
@testing.with_requires("numpy>=2.3.2")
1131+
@pytest.mark.parametrize("xp", [numpy, dpnp])
1132+
@pytest.mark.parametrize(
1133+
"size",
1134+
[True, [True], dpnp.bool(True), numpy.array(True), numpy.array([True])],
1135+
)
1136+
def test_bool_size(self, xp, size):
1137+
rs = xp.random.RandomState()
1138+
assert_raises(TypeError, rs.uniform, size=size)
1139+
1140+
@pytest.mark.parametrize("size", [numpy.array(1), numpy.array([2])])
1141+
def test_numpy_ndarray_size(self, size):
1142+
result = RandomState().uniform(size=size)
1143+
assert result.shape == size
1144+
1145+
def test_dpnp_ndarray_size(self):
1146+
assert_raises(ValueError, RandomState().uniform, size=dpnp.array(1))

dpnp/tests/test_strides.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def test_erf(dtype):
182182
assert_dtype_allclose(result, expected)
183183

184184

185+
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
185186
@pytest.mark.parametrize("dtype", get_float_complex_dtypes())
186187
@pytest.mark.parametrize("stride", [2, -1, -3])
187188
def test_reciprocal(dtype, stride):

dpnp/tests/test_sycl_queue.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
from dpnp.dpnp_array import dpnp_array
1313
from dpnp.dpnp_utils import get_usm_allocations
1414

15-
from .helper import generate_random_numpy_array, get_all_dtypes, is_win_platform
15+
from .helper import (
16+
generate_random_numpy_array,
17+
get_all_dtypes,
18+
is_arl_or_mtl,
19+
is_win_platform,
20+
)
1621

1722
list_of_backend_str = ["cuda", "host", "level_zero", "opencl"]
1823

@@ -1501,6 +1506,8 @@ def test_cholesky(self, data, is_empty, device):
15011506
else:
15021507
dtype = dpnp.default_float_type(device)
15031508
x = dpnp.array(data, dtype=dtype, device=device)
1509+
if x.ndim > 2 and is_win_platform() and is_arl_or_mtl():
1510+
pytest.skip("SAT-8206")
15041511

15051512
result = dpnp.linalg.cholesky(x)
15061513
assert_sycl_queue_equal(result.sycl_queue, x.sycl_queue)

0 commit comments

Comments
 (0)