Skip to content

Commit

Permalink
Merge pull request #42 from IntelPython/support-numpy-2.0
Browse files Browse the repository at this point in the history
Support numpy 2.0
  • Loading branch information
oleksandr-pavlyk authored May 28, 2024
2 parents 50a443a + aac1e22 commit 5ad8a37
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build-with-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
name: Build project with IntelLLVM clang compiler
runs-on: ubuntu-latest

strategy:
matrix:
python: ["3.9", "3.10", "3.11", "3.12"]
use_pre: ["", "--pre"]
env:
ONEAPI_ROOT: /opt/intel/oneapi

Expand All @@ -37,7 +41,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: ${{ matrix.python }}
architecture: x64

- name: Checkout repo
Expand All @@ -48,7 +52,8 @@ jobs:
- name: Install mkl_random dependencies
shell: bash -l {0}
run: |
pip install numpy cython setuptools pytest pytest-cov
pip install cython setuptools pytest pytest-cov
pip install numpy ${{ matrix.use_pre }}
- name: List oneAPI folder content
shell: bash -l {0}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.9", "3.10", "3.11", "3.12"]
python: ["3.9", "3.10"]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -59,11 +59,11 @@ jobs:
path: /usr/share/miniconda/conda-bld/linux-64/${{ env.PACKAGE_NAME }}-*.tar.bz2

build_windows:
runs-on: windows-latest
runs-on: windows-2019

strategy:
matrix:
python: ['3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10']
env:
conda-bld: C:\Miniconda\conda-bld\win-64\
steps:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:

strategy:
matrix:
python: ['3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10']
experimental: [false]
runner: [ubuntu-latest]
continue-on-error: ${{ matrix.experimental }}
Expand Down Expand Up @@ -169,9 +169,9 @@ jobs:

strategy:
matrix:
python: ['3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10']
experimental: [false]
runner: [windows-latest]
runner: [windows-2019]
continue-on-error: ${{ matrix.experimental }}
env:
CHANNELS: -c conda-forge -c intel --override-channels
Expand Down
6 changes: 3 additions & 3 deletions mkl_random/mklrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ cdef class RandomState:
ret = randfunc(low, high - 1, size)

if size is None:
if dtype in (bool, int, np.compat.long):
if dtype in (bool, int):
return dtype(ret)

return ret
Expand Down Expand Up @@ -1893,7 +1893,7 @@ cdef class RandomState:
"""

# Format and Verify input
a = np.array(a, copy=False)
a = np.asarray(a)
if a.ndim == 0:
try:
# __index__ must return an integer by python rules.
Expand Down Expand Up @@ -1942,7 +1942,7 @@ cdef class RandomState:
cdf /= cdf[-1]
uniform_samples = self.random_sample(shape)
idx = cdf.searchsorted(uniform_samples, side='right')
idx = np.array(idx, copy=False) # searchsorted returns a scalar
idx = np.asarray(idx) # searchsorted returns a scalar
else:
idx = self.randint(0, pop_size, size=shape)
else:
Expand Down
3 changes: 1 addition & 2 deletions mkl_random/tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from numpy.testing import (
assert_, assert_raises, assert_equal,
assert_warns, suppress_warnings)
from numpy.compat import asbytes
import sys
import warnings

Expand Down Expand Up @@ -500,7 +499,7 @@ def test_choice_return_shape():
def test_randomdist_bytes(randomdist):
rnd.seed(randomdist.seed, brng=randomdist.brng)
actual = rnd.bytes(10)
desired = asbytes('\xa4\xde\xde{\xb4\x88\xe6\x84*2')
desired = b'\xa4\xde\xde{\xb4\x88\xe6\x84*2'
np.testing.assert_equal(actual, desired)


Expand Down
5 changes: 3 additions & 2 deletions mkl_random/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from numpy.testing import (TestCase, assert_,
assert_array_equal, assert_raises)
import mkl_random as rnd
from numpy.compat import long
import numpy as np

import pytest
Expand Down Expand Up @@ -78,7 +77,9 @@ def test_permutation_longs():
rnd.seed(1234, brng='MT19937')
a = rnd.permutation(12)
rnd.seed(1234, brng='MT19937')
b = rnd.permutation(long(12))
dt_long = np.dtype("long")
twelve_long = dt_long.type(12)
b = rnd.permutation(twelve_long)
assert_array_equal(a, b)


Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
Programming Language :: C
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: Implementation :: CPython
Topic :: Software Development
Topic :: Scientific/Engineering
Expand Down Expand Up @@ -95,7 +95,8 @@ def extensions():

defs = [('_FILE_OFFSET_BITS', '64'),
('_LARGEFILE_SOURCE', '1'),
('_LARGEFILE64_SOURCE', '1')]
('_LARGEFILE64_SOURCE', '1'),
("PY_ARRAY_UNIQUE_SYMBOL", "mkl_random_ext")]

exts = [
Extension(
Expand Down

0 comments on commit 5ad8a37

Please sign in to comment.