Skip to content

Changes to support NumPy 2.0 #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/build_pip.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}'
Expand Down
2 changes: 1 addition & 1 deletion mkl_fft/_float_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mkl_fft/_numpy_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions mkl_fft/_pydfti.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion mkl_fft/_scipy_fft_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions mkl_fft/src/mklfft.c.src
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions mkl_fft/src/mklfft.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")]
)
]

Expand Down