Skip to content

Commit 0cd520e

Browse files
authoredMay 27, 2024··
Merge pull request #100 from IntelPython/support-numpy-2
Changes to support NumPy 2.0
2 parents 276b142 + bbdef36 commit 0cd520e

File tree

9 files changed

+87
-26
lines changed

9 files changed

+87
-26
lines changed
 

‎.github/workflows/build_pip.yaml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Editable build using pip and pre-release NumPy
2+
3+
on: push
4+
5+
permissions: read-all
6+
7+
env:
8+
PACKAGE_NAME: mkl_fft
9+
MODULE_NAME: mkl_fft
10+
TEST_ENV_NAME: test_mkl_fft
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
shell: bash -el {0}
18+
19+
strategy:
20+
matrix:
21+
python: ['3.9', '3.10', '3.11', '3.12']
22+
use_pre: ["", "--pre"]
23+
24+
steps:
25+
- name: Install jq
26+
shell: bash -l {0}
27+
run: |
28+
sudo apt-get install jq
29+
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- uses: conda-incubator/setup-miniconda@v3
35+
with:
36+
use-mamba: true
37+
miniforge-variant: Mambaforge
38+
miniforge-version: latest
39+
channels: conda-forge
40+
activate-environment: test
41+
python-version: ${{ matrix.python }}
42+
43+
- name: Install MKL
44+
run: |
45+
conda install mkl-devel mkl-service
46+
python -c "import sys; print(sys.executable)"
47+
which python
48+
python -c "import mkl; print(mkl.__file__)"
49+
50+
- name: Build conda package
51+
run: |
52+
pip install --no-cache-dir cython pytest hypothesis
53+
pip install --no-cache-dir numpy ${{ matrix.use_pre }}
54+
echo "CONDA_PREFFIX is '${CONDA_PREFIX}'"
55+
export MKLROOT=${CONDA_PREFIX}
56+
pip install -e . --no-build-isolation --verbose --no-deps
57+
python -m pytest -v mkl_fft/tests

‎.github/workflows/conda-package.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python: ['3.10']
17+
python: ['3.9', '3.10']
1818
steps:
1919
- uses: actions/checkout@v4
2020
with:
@@ -62,7 +62,7 @@ jobs:
6262

6363
strategy:
6464
matrix:
65-
python: ['3.10']
65+
python: ['3.9', '3.10']
6666
experimental: [false]
6767
runner: [ubuntu-latest]
6868
continue-on-error: ${{ matrix.experimental }}
@@ -120,11 +120,11 @@ jobs:
120120
pytest -v --pyargs $MODULE_NAME
121121
122122
build_windows:
123-
runs-on: windows-latest
123+
runs-on: windows-2019
124124

125125
strategy:
126126
matrix:
127-
python: ['3.10']
127+
python: ['3.9', '3.10']
128128
env:
129129
conda-bld: C:\Miniconda\conda-bld\win-64\
130130
steps:
@@ -165,9 +165,9 @@ jobs:
165165
shell: cmd /C CALL {0}
166166
strategy:
167167
matrix:
168-
python: ['3.10']
168+
python: ['3.9', '3.10']
169169
experimental: [false]
170-
runner: [windows-latest]
170+
runner: [windows-2019]
171171
continue-on-error: ${{ matrix.experimental }}
172172
env:
173173
workdir: '${{ github.workspace }}'

‎mkl_fft/_float_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __downcast_float128_array(x):
5959
xdt = x.dtype
6060
if xdt == np.longdouble and not xdt == np.float64:
6161
return np.asarray(x, dtype=np.float64)
62-
elif xdt == np.longcomplex and not xdt == np.complex_:
62+
elif xdt == np.clongdouble and not xdt == np.complex_:
6363
return np.asarray(x, dtype=np.complex_)
6464
if not isinstance(x, np.ndarray):
6565
__x = np.asarray(x)

‎mkl_fft/_numpy_fft.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
__all__ = ['fft', 'ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn',
5757
'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn']
5858

59-
from numpy.core import (array, asarray, asanyarray, shape, conjugate, take, sqrt, prod)
59+
from numpy import (array, asarray, asanyarray, shape, conjugate, take, sqrt, prod)
6060

6161
import numpy
6262
from . import _pydfti as mkl_fft

‎mkl_fft/_pydfti.pyx

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
# imports
3030
import sys
3131
import numpy as np
32-
from numpy.core._multiarray_tests import internal_overlap
32+
if np.lib.NumpyVersion(np.__version__) >= "2.0.0a0":
33+
from numpy._core._multiarray_tests import internal_overlap
34+
else:
35+
from numpy.core._multiarray_tests import internal_overlap
3336
from threading import local as threading_local
3437

3538
# cimports
@@ -133,11 +136,6 @@ cdef extern from "src/mklfft.h":
133136
int double_cdouble_mkl_ifftnd_out(cnp.ndarray, cnp.ndarray, double)
134137
char * mkl_dfti_error(int)
135138

136-
# Initialize numpy
137-
cdef int numpy_import_status = cnp.import_array()
138-
if numpy_import_status < 0:
139-
raise ImportError("Failed to import NumPy as dependency of mkl_fft")
140-
141139

142140
cdef int _datacopied(cnp.ndarray arr, object orig):
143141
"""
@@ -217,7 +215,7 @@ cdef cnp.ndarray __process_arguments(object x, object n, object axis,
217215
cnp.NPY_ELEMENTSTRIDES | cnp.NPY_ENSUREARRAY | cnp.NPY_NOTSWAPPED,
218216
NULL)
219217

220-
if <void *> x_arr is NULL:
218+
if (<void *> x_arr) is NULL:
221219
raise ValueError("An input argument x is not an array-like object")
222220

223221
if _datacopied(x_arr, x):

‎mkl_fft/_scipy_fft_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from . import _float_utils
2929
import mkl
3030

31-
from numpy.core import (take, sqrt, prod)
31+
from numpy import (take, sqrt, prod)
3232
import contextvars
3333
import contextlib
3434
import operator

‎mkl_fft/src/mklfft.c.src

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2020, Intel Corporation
2+
Copyright (c) 2017-2024, Intel Corporation
33

44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions are met:
@@ -25,9 +25,9 @@
2525
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
29-
28+
#define PY_SSIZE_T_CLEAN
3029
#include "Python.h"
30+
#define NO_IMPORT_ARRAY
3131
#include "numpy/arrayobject.h"
3232
#include "mklfft.h"
3333
#include "multi_iter.h"
@@ -81,13 +81,17 @@ static NPY_INLINE void get_basic_array_data(
8181
npy_intp *x_size)
8282
{
8383
npy_intp asize = 0;
84+
npy_intp elsz = 0;
85+
int x_ndim = 0;
8486
assert(x != NULL);
8587

86-
*x_rank = PyArray_NDIM(x);
88+
x_ndim = PyArray_NDIM(x);
89+
*x_rank = x_ndim;
8790
*x_shape = PyArray_SHAPE(x);
8891
*x_strides = PyArray_STRIDES(x);
89-
*x_itemsize = PyArray_ITEMSIZE(x);
90-
asize = ar_size(*x_shape, *x_rank);
92+
elsz = PyArray_ITEMSIZE(x);
93+
*x_itemsize = elsz;
94+
asize = ar_size(*x_shape, x_ndim);
9195
*x_size = asize;
9296
}
9397

‎mkl_fft/src/mklfft.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727
#include "mkl.h"
28+
#include "numpy/arrayobject.h"
2829

2930
typedef struct DftiCache {
3031
DFTI_DESCRIPTOR_HANDLE hand;

‎setup.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2017-2023, Intel Corporation
2+
# Copyright (c) 2017-2024, Intel Corporation
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions are met:
@@ -49,10 +49,10 @@
4949
Programming Language :: C
5050
Programming Language :: Python
5151
Programming Language :: Python :: 3
52-
Programming Language :: Python :: 3.7
53-
Programming Language :: Python :: 3.8
5452
Programming Language :: Python :: 3.9
5553
Programming Language :: Python :: 3.10
54+
Programming Language :: Python :: 3.11
55+
Programming Language :: Python :: 3.12
5656
Programming Language :: Python :: Implementation :: CPython
5757
Topic :: Software Development
5858
Topic :: Scientific/Engineering
@@ -104,7 +104,8 @@ def extensions():
104104
extra_compile_args = [
105105
'-DNDEBUG',
106106
# '-ggdb', '-O0', '-Wall', '-Wextra', '-DDEBUG',
107-
]
107+
],
108+
define_macros=[("NPY_NO_DEPRECATED_API", None), ("PY_ARRAY_UNIQUE_SYMBOL", "mkl_fft_ext")]
108109
)
109110
]
110111

0 commit comments

Comments
 (0)
Please sign in to comment.