Skip to content

Commit 4297fef

Browse files
Merge pull request #1804 from IntelPython/fix-issues-for-numpy-2.1.0
Fix issues for numpy 2.1.0
2 parents 1e52918 + 5e6271d commit 4297fef

File tree

8 files changed

+50
-28
lines changed

8 files changed

+50
-28
lines changed

.github/workflows/conda-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ jobs:
490490
run: |
491491
CHANNELS="${{ env.CHANNELS }}"
492492
. $CONDA/etc/profile.d/conda.sh
493-
conda create -n ${{ env.EXAMPLES_ENV_NAME }} -y pytest python=${{ matrix.python }} $CHANNELS
494-
conda install -n ${{ env.EXAMPLES_ENV_NAME }} -y cmake">=3.22" $CHANNELS || exit 1
493+
conda create -n ${{ env.EXAMPLES_ENV_NAME }} -y pytest python=${{ matrix.python }} setuptools"<72.2.0" $CHANNELS
494+
conda install -n ${{ env.EXAMPLES_ENV_NAME }} -y cmake $CHANNELS || exit 1
495495
conda install -n ${{ env.EXAMPLES_ENV_NAME }} -y ninja $CHANNELS || exit 1
496496
conda install -n ${{ env.EXAMPLES_ENV_NAME }} -y pybind11 cython scikit-build $CHANNELS || exit 1
497497
conda install -n ${{ env.EXAMPLES_ENV_NAME }} -y mkl-dpcpp mkl-devel-dpcpp dpcpp_cpp_rt $CHANNELS || exit 1

.github/workflows/generate-coverage.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
env:
1717
ONEAPI_ROOT: /opt/intel/oneapi
18-
GTEST_ROOT: /home/runner/work/googletest-1.13.0/install
18+
GTEST_ROOT: /home/runner/work/googletest-1.15.2/install
1919
# Use oneAPI compiler 2023 to work around an issue
2020
USE_2023: 0
2121

@@ -52,16 +52,16 @@ jobs:
5252
- name: Setup Python
5353
uses: actions/setup-python@v5
5454
with:
55-
python-version: '3.11'
55+
python-version: '3.12'
5656
architecture: x64
5757

5858
- name: Cache Gtest
5959
id: cache-gtest
6060
uses: actions/cache@v4
6161
with:
6262
path: |
63-
/home/runner/work/googletest-1.13.0/install
64-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/home/runner/work/googletest-1.13.0/install/include/gtest/*') }}
63+
/home/runner/work/googletest-1.15.2/install
64+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/home/runner/work/googletest-1.15.2/install/include/gtest/*') }}
6565
restore-keys: |
6666
${{ runner.os }}-build-${{ env.cache-name }}-
6767
${{ runner.os }}-build-
@@ -72,12 +72,12 @@ jobs:
7272
shell: bash -l {0}
7373
run: |
7474
cd /home/runner/work
75-
wget https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz
76-
tar xf v1.13.0.tar.gz
77-
cd googletest-1.13.0
75+
wget https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz
76+
tar xf v1.15.2.tar.gz
77+
cd googletest-1.15.2
7878
mkdir build
7979
cd build
80-
cmake .. -DCMAKE_INSTALL_PREFIX=/home/runner/work/googletest-1.13.0/install
80+
cmake .. -DCMAKE_INSTALL_PREFIX=/home/runner/work/googletest-1.15.2/install
8181
make && make install
8282
8383
- name: Checkout repo
@@ -92,7 +92,7 @@ jobs:
9292
- name: Install dpctl dependencies
9393
shell: bash -l {0}
9494
run: |
95-
pip install numpy"<1.26.0" cython setuptools pytest pytest-cov scikit-build cmake coverage[toml] versioneer[toml]==0.29
95+
pip install numpy cython setuptools pytest pytest-cov scikit-build cmake coverage[toml] versioneer[toml]==0.29
9696
9797
- name: Build dpctl with coverage
9898
shell: bash -l {0}

.github/workflows/os-llvm-sycl-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
- name: Setup Python
101101
uses: actions/setup-python@v5
102102
with:
103-
python-version: '3.11'
103+
python-version: '3.12'
104104
architecture: x64
105105

106106
- name: Install dpctl dependencies

dpctl/tensor/_ctors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,11 @@ def _get_arange_length(start, stop, step):
765765

766766

767767
def _to_scalar(obj, sc_ty):
768-
"A way to convert object to NumPy scalar type"
769-
zd_arr = np.asarray(obj).astype(sc_ty, casting="unsafe")
768+
"""A way to convert object to NumPy scalar type.
769+
Raises OverflowError if obj can not be represented
770+
using the requested scalar type.
771+
"""
772+
zd_arr = np.asarray(obj, dtype=sc_ty)
770773
return zd_arr[tuple()]
771774

772775

dpctl/tensor/_dlpack.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,10 @@ def from_dlpack(x, /, *, device=None, copy=None):
10831083
except TypeError:
10841084
# exporter does not support max_version keyword
10851085
got_type_error = True
1086-
except (BufferError, NotImplementedError):
1087-
# Either dl_device, or copy can be satisfied
1086+
except (BufferError, NotImplementedError, ValueError) as e:
1087+
# Either dl_device, or copy cannot be satisfied
10881088
got_buffer_error = True
1089+
saved_exception = e
10891090
except Exception as e:
10901091
got_other_error = True
10911092
saved_exception = e
@@ -1144,6 +1145,8 @@ def from_dlpack(x, /, *, device=None, copy=None):
11441145
raise BufferError(
11451146
"Importing data via DLPack requires copying, but copy=False was provided"
11461147
)
1148+
if dl_device is None:
1149+
raise saved_exception
11471150
# must copy via host
11481151
if dl_device[0] != device_OneAPI:
11491152
raise BufferError(f"Can not import to requested device {dl_device}")

dpctl/tests/test_sycl_kernel_submit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def test_create_program_from_source(ctype_str, dtype, ctypes_ctor):
6666

6767
n_elems = 1024 * 512
6868
lws = 128
69+
if dtype.kind in "ui":
70+
n_elems = min(n_elems, dpt.iinfo(dtype).max)
71+
n_elems = (n_elems // lws) * lws
6972
a = dpt.arange(n_elems, dtype=dtype, sycl_queue=q)
7073
b = dpt.arange(n_elems, stop=0, step=-1, dtype=dtype, sycl_queue=q)
7174
c = dpt.zeros(n_elems, dtype=dtype, sycl_queue=q)

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,17 +1791,22 @@ def test_full_strides():
17911791
assert np.array_equal(dpt.asnumpy(X), Xnp)
17921792

17931793

1794-
def test_full_gh_1230():
1795-
q = get_queue_or_skip()
1796-
dtype = "i4"
1794+
@pytest.mark.parametrize("dt", ["i1", "u1", "i2", "u2", "i4", "u4", "i8", "u8"])
1795+
def test_full_gh_1230(dt):
1796+
get_queue_or_skip()
1797+
dtype = dpt.dtype(dt)
17971798
dt_maxint = dpt.iinfo(dtype).max
1798-
X = dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
1799-
X_np = dpt.asnumpy(X)
1800-
assert X.dtype == dpt.dtype(dtype)
1801-
assert np.array_equal(X_np, np.full_like(X_np, dt_maxint + 1))
18021799

1803-
with pytest.raises(OverflowError):
1804-
dpt.full(1, dpt.iinfo(dpt.uint64).max + 1, sycl_queue=q)
1800+
if (dtype.itemsize < 8) and (np.lib.NumpyVersion(np.__version__) < "2.0.0"):
1801+
try:
1802+
X = dpt.full(1, fill_value=(dt_maxint + 1), dtype=dt)
1803+
except OverflowError:
1804+
pytest.skip("Expected OverflowError raised")
1805+
Y = dpt.full_like(X, fill_value=dpt.iinfo(dt).min)
1806+
assert dpt.all(X == Y)
1807+
else:
1808+
with pytest.raises(OverflowError):
1809+
dpt.full(1, dt_maxint + 1, dtype=dt)
18051810

18061811

18071812
@pytest.mark.parametrize(

dpctl/tests/test_usm_ndarray_linalg.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,20 @@ def test_matmul_simple(dtype):
8989
skip_if_dtype_not_supported(dtype, q)
9090

9191
n, m = 235, 17
92-
m1 = dpt.ones((m, n), dtype=dtype)
93-
m2 = dpt.ones((n, m), dtype=dtype)
92+
m1 = dpt.zeros((m, n), dtype=dtype)
93+
m2 = dpt.zeros((n, m), dtype=dtype)
94+
95+
dt = m1.dtype
96+
if dt.kind in "ui":
97+
n1 = min(n, dpt.iinfo(dt).max)
98+
else:
99+
n1 = n
100+
m1[:, :n1] = dpt.ones((m, n1), dtype=dt)
101+
m2[:n1, :] = dpt.ones((n1, m), dtype=dt)
94102

95103
for k in [1, 2, 3, 4, 7, 8, 9, 15, 16, 17]:
96104
r = dpt.matmul(m1[:k, :], m2[:, :k])
97-
assert dpt.all(r == dpt.full((k, k), n, dtype=dtype))
105+
assert dpt.all(r == dpt.full((k, k), fill_value=n1, dtype=dt))
98106

99107

100108
@pytest.mark.parametrize("dtype", _numeric_types)

0 commit comments

Comments
 (0)