diff --git a/.github/workflows/build_pip.yaml b/.github/workflows/build_pip.yaml new file mode 100644 index 0000000..6600317 --- /dev/null +++ b/.github/workflows/build_pip.yaml @@ -0,0 +1,57 @@ +name: Editable build using pip and pre-release NumPy + +on: push + +permissions: read-all + +env: + PACKAGE_NAME: mkl_fft + MODULE_NAME: mkl_fft + TEST_ENV_NAME: test_mkl_fft + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} + + strategy: + matrix: + python: ['3.9', '3.10', '3.11', '3.12'] + use_pre: ["", "--pre"] + + steps: + - name: Install jq + shell: bash -l {0} + run: | + sudo apt-get install jq + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v3 + with: + use-mamba: true + miniforge-variant: Mambaforge + miniforge-version: latest + channels: conda-forge + activate-environment: test + python-version: ${{ matrix.python }} + + - name: Install MKL + run: | + conda install mkl-devel mkl-service + python -c "import sys; print(sys.executable)" + which python + python -c "import mkl; print(mkl.__file__)" + + - name: Build conda package + run: | + pip install --no-cache-dir cython pytest hypothesis + pip install --no-cache-dir numpy ${{ matrix.use_pre }} + echo "CONDA_PREFFIX is '${CONDA_PREFIX}'" + export MKLROOT=${CONDA_PREFIX} + pip install -e . --no-build-isolation --verbose --no-deps + python -m pytest -v mkl_fft/tests diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 69cc440..7662542 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ['3.10'] + python: ['3.9', '3.10'] steps: - uses: actions/checkout@v4 with: @@ -62,7 +62,7 @@ jobs: strategy: matrix: - python: ['3.10'] + python: ['3.9', '3.10'] experimental: [false] runner: [ubuntu-latest] continue-on-error: ${{ matrix.experimental }} @@ -120,11 +120,11 @@ jobs: pytest -v --pyargs $MODULE_NAME build_windows: - runs-on: windows-latest + runs-on: windows-2019 strategy: matrix: - python: ['3.10'] + python: ['3.9', '3.10'] env: conda-bld: C:\Miniconda\conda-bld\win-64\ steps: @@ -165,9 +165,9 @@ jobs: shell: cmd /C CALL {0} strategy: matrix: - python: ['3.10'] + python: ['3.9', '3.10'] experimental: [false] - runner: [windows-latest] + runner: [windows-2019] continue-on-error: ${{ matrix.experimental }} env: workdir: '${{ github.workspace }}' diff --git a/mkl_fft/_float_utils.py b/mkl_fft/_float_utils.py index 5091567..f9f063c 100644 --- a/mkl_fft/_float_utils.py +++ b/mkl_fft/_float_utils.py @@ -59,7 +59,7 @@ def __downcast_float128_array(x): xdt = x.dtype if xdt == np.longdouble and not xdt == np.float64: return np.asarray(x, dtype=np.float64) - elif xdt == np.longcomplex and not xdt == np.complex_: + elif xdt == np.clongdouble and not xdt == np.complex_: return np.asarray(x, dtype=np.complex_) if not isinstance(x, np.ndarray): __x = np.asarray(x) diff --git a/mkl_fft/_numpy_fft.py b/mkl_fft/_numpy_fft.py index d1afc58..e32403c 100644 --- a/mkl_fft/_numpy_fft.py +++ b/mkl_fft/_numpy_fft.py @@ -56,7 +56,7 @@ __all__ = ['fft', 'ifft', 'rfft', 'irfft', 'hfft', 'ihfft', 'rfftn', 'irfftn', 'rfft2', 'irfft2', 'fft2', 'ifft2', 'fftn', 'ifftn'] -from numpy.core import (array, asarray, asanyarray, shape, conjugate, take, sqrt, prod) +from numpy import (array, asarray, asanyarray, shape, conjugate, take, sqrt, prod) import numpy from . import _pydfti as mkl_fft diff --git a/mkl_fft/_pydfti.pyx b/mkl_fft/_pydfti.pyx index 1c377c8..0ce8950 100644 --- a/mkl_fft/_pydfti.pyx +++ b/mkl_fft/_pydfti.pyx @@ -29,7 +29,10 @@ # imports import sys import numpy as np -from numpy.core._multiarray_tests import internal_overlap +if np.lib.NumpyVersion(np.__version__) >= "2.0.0a0": + from numpy._core._multiarray_tests import internal_overlap +else: + from numpy.core._multiarray_tests import internal_overlap from threading import local as threading_local # cimports @@ -133,11 +136,6 @@ cdef extern from "src/mklfft.h": int double_cdouble_mkl_ifftnd_out(cnp.ndarray, cnp.ndarray, double) char * mkl_dfti_error(int) -# Initialize numpy -cdef int numpy_import_status = cnp.import_array() -if numpy_import_status < 0: - raise ImportError("Failed to import NumPy as dependency of mkl_fft") - cdef int _datacopied(cnp.ndarray arr, object orig): """ @@ -217,7 +215,7 @@ cdef cnp.ndarray __process_arguments(object x, object n, object axis, cnp.NPY_ELEMENTSTRIDES | cnp.NPY_ENSUREARRAY | cnp.NPY_NOTSWAPPED, NULL) - if <void *> x_arr is NULL: + if (<void *> x_arr) is NULL: raise ValueError("An input argument x is not an array-like object") if _datacopied(x_arr, x): diff --git a/mkl_fft/_scipy_fft_backend.py b/mkl_fft/_scipy_fft_backend.py index 38212b5..fb1f841 100644 --- a/mkl_fft/_scipy_fft_backend.py +++ b/mkl_fft/_scipy_fft_backend.py @@ -28,7 +28,7 @@ from . import _float_utils import mkl -from numpy.core import (take, sqrt, prod) +from numpy import (take, sqrt, prod) import contextvars import contextlib import operator diff --git a/mkl_fft/src/mklfft.c.src b/mkl_fft/src/mklfft.c.src index 94ae9fb..d1fc6d1 100644 --- a/mkl_fft/src/mklfft.c.src +++ b/mkl_fft/src/mklfft.c.src @@ -1,5 +1,5 @@ /* - Copyright (c) 2017-2020, Intel Corporation + Copyright (c) 2017-2024, Intel Corporation Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -25,9 +25,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define NPY_NO_DEPRECATED_API NPY_API_VERSION - +#define PY_SSIZE_T_CLEAN #include "Python.h" +#define NO_IMPORT_ARRAY #include "numpy/arrayobject.h" #include "mklfft.h" #include "multi_iter.h" @@ -81,13 +81,17 @@ static NPY_INLINE void get_basic_array_data( npy_intp *x_size) { npy_intp asize = 0; + npy_intp elsz = 0; + int x_ndim = 0; assert(x != NULL); - *x_rank = PyArray_NDIM(x); + x_ndim = PyArray_NDIM(x); + *x_rank = x_ndim; *x_shape = PyArray_SHAPE(x); *x_strides = PyArray_STRIDES(x); - *x_itemsize = PyArray_ITEMSIZE(x); - asize = ar_size(*x_shape, *x_rank); + elsz = PyArray_ITEMSIZE(x); + *x_itemsize = elsz; + asize = ar_size(*x_shape, x_ndim); *x_size = asize; } diff --git a/mkl_fft/src/mklfft.h b/mkl_fft/src/mklfft.h index af25b65..6e48e5c 100644 --- a/mkl_fft/src/mklfft.h +++ b/mkl_fft/src/mklfft.h @@ -25,6 +25,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "mkl.h" +#include "numpy/arrayobject.h" typedef struct DftiCache { DFTI_DESCRIPTOR_HANDLE hand; diff --git a/setup.py b/setup.py index a6dc76f..9686a7f 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2017-2023, Intel Corporation +# Copyright (c) 2017-2024, Intel Corporation # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -49,10 +49,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 @@ -104,7 +104,8 @@ def extensions(): extra_compile_args = [ '-DNDEBUG', # '-ggdb', '-O0', '-Wall', '-Wextra', '-DDEBUG', - ] + ], + define_macros=[("NPY_NO_DEPRECATED_API", None), ("PY_ARRAY_UNIQUE_SYMBOL", "mkl_fft_ext")] ) ]