Skip to content

Commit

Permalink
Merge pull request numba#9105 from gmarkall/numpy_1.25
Browse files Browse the repository at this point in the history
NumPy 1.25 support (PR numba#9011) continued
  • Loading branch information
esc committed Aug 1, 2023
2 parents cd1842e + 33befe0 commit 19a0196
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 88 deletions.
61 changes: 30 additions & 31 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
name: macOS
vmImage: macos-11
matrix:
py38_np121:
py38_np122:
PYTHON: '3.8'
NUMPY: '1.21'
NUMPY: '1.22'
CONDA_ENV: 'azure_ci'
TEST_START_INDEX: 0
py311_np124:
py311_np125:
PYTHON: '3.11'
NUMPY: '1.24'
NUMPY: '1.25'
CONDA_ENV: 'azure_ci'
TEST_THREADING: 'tbb'
TEST_START_INDEX: 1
Expand All @@ -29,46 +29,35 @@ jobs:
name: Linux
vmImage: ubuntu-20.04
matrix:
py38_np121_vanilla:
PYTHON: '3.8'
NUMPY: '1.21'
CONDA_ENV: azure_ci
VANILLA_INSTALL: yes
TEST_START_INDEX: 2
py38_np122_tbb:
PYTHON: '3.8'
NUMPY: '1.22'
CONDA_ENV: azure_ci
TEST_THREADING: 'tbb'
TEST_START_INDEX: 3
TEST_START_INDEX: 2
py38_np122_omp:
PYTHON: '3.8'
NUMPY: '1.22'
CONDA_ENV: azure_ci
TEST_THREADING: omp
TEST_START_INDEX: 4
TEST_START_INDEX: 3
py38_np122_workqueue:
PYTHON: '3.8'
NUMPY: '1.22'
CONDA_ENV: azure_ci
TEST_THREADING: workqueue
TEST_START_INDEX: 5
TEST_START_INDEX: 4
py38_np123_svml:
PYTHON: '3.8'
NUMPY: '1.23'
CONDA_ENV: azure_ci
TEST_SVML: yes
TEST_START_INDEX: 6
TEST_START_INDEX: 5
py38_np124:
PYTHON: '3.8'
NUMPY: '1.24'
CONDA_ENV: azure_ci
TEST_START_INDEX: 7
py39_np121:
PYTHON: '3.9'
NUMPY: '1.21'
CONDA_ENV: azure_ci
TEST_START_INDEX: 8
TEST_START_INDEX: 6
py39_np122_cov_doc:
PYTHON: '3.9'
NUMPY: '1.22'
Expand All @@ -77,47 +66,57 @@ jobs:
RUN_FLAKE8: yes
RUN_MYPY: yes
BUILD_DOC: yes
TEST_START_INDEX: 9
TEST_START_INDEX: 7
py39_np123_typeguard:
PYTHON: '3.9'
NUMPY: '1.23'
CONDA_ENV: azure_ci
RUN_TYPEGUARD: yes
TEST_START_INDEX: 10
TEST_START_INDEX: 8
py39_np124:
PYTHON: '3.9'
NUMPY: '1.24'
CONDA_ENV: azure_ci
TEST_START_INDEX: 11
py310_np121:
PYTHON: '3.10'
NUMPY: '1.21'
TEST_START_INDEX: 9
py39_np125:
PYTHON: '3.9'
NUMPY: '1.25'
CONDA_ENV: azure_ci
TEST_START_INDEX: 12
TEST_START_INDEX: 10
py310_np122:
PYTHON: '3.10'
NUMPY: '1.22'
CONDA_ENV: azure_ci
TEST_START_INDEX: 13
TEST_START_INDEX: 11
py310_np123:
PYTHON: '3.10'
NUMPY: '1.23'
CONDA_ENV: azure_ci
TEST_START_INDEX: 14
TEST_START_INDEX: 12
py310_np124:
PYTHON: '3.10'
NUMPY: '1.24'
CONDA_ENV: azure_ci
TEST_START_INDEX: 15
TEST_START_INDEX: 13
py310_np125:
PYTHON: '3.10'
NUMPY: '1.25'
CONDA_ENV: azure_ci
TEST_START_INDEX: 14
py311_np123:
PYTHON: '3.11'
NUMPY: '1.23'
CONDA_ENV: azure_ci
TEST_START_INDEX: 16
TEST_START_INDEX: 15
py311_np124:
PYTHON: '3.11'
NUMPY: '1.24'
CONDA_ENV: azure_ci
TEST_START_INDEX: 16
py311_np125:
PYTHON: '3.11'
NUMPY: '1.25'
CONDA_ENV: azure_ci
TEST_START_INDEX: 17

- template: buildscripts/azure/azure-windows.yml
Expand Down
8 changes: 4 additions & 4 deletions buildscripts/azure/azure-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
vmImage: ${{ parameters.vmImage }}
strategy:
matrix:
py38_np121:
py38_np122:
PYTHON: '3.8'
NUMPY: '1.21'
NUMPY: '1.22.3'
CONDA_ENV: 'testenv'
TEST_START_INDEX: 18
py311_np124:
py311_np125:
PYTHON: '3.11'
NUMPY: '1.24'
NUMPY: '1.25'
CONDA_ENV: 'testenv'
TEST_START_INDEX: 19

Expand Down
2 changes: 1 addition & 1 deletion buildscripts/condarecipe.local/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ requirements:
run:
- python >=3.8
# NumPy 1.22.0, 1.22.1, 1.22.2 are all broken for ufuncs, see #7756
- numpy >=1.21, !=1.22.0, !=1.22.1, !=1.22.2
- numpy >=1.22.3
- importlib_metadata # [py<39]
# On channel https://anaconda.org/numba/
- llvmlite >=0.41.0dev0,<0.41
Expand Down
4 changes: 2 additions & 2 deletions buildscripts/gpuci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi;
# Test with different NumPy versions with each toolkit (it's not worth testing
# the Cartesian product of versions here, we just need to test with different
# CUDA and NumPy versions).
declare -A CTK_NUMPY_VMAP=( ["11.2"]="1.21" ["11.3"]="1.22" ["11.5"]="1.23" ["11.8"]="1.24")
declare -A CTK_NUMPY_VMAP=( ["11.2"]="1.22" ["11.3"]="1.23" ["11.5"]="1.24" ["11.8"]="1.25")
NUMPY_VER="${CTK_NUMPY_VMAP[$CUDA_TOOLKIT_VER]}"

################################################################################
Expand All @@ -51,7 +51,7 @@ nvidia-smi
gpuci_logger "Create testing env"
. /opt/conda/etc/profile.d/conda.sh
gpuci_mamba_retry create -n numba_ci -y \
"python=${PYTHON_VER}" \
"python=3.10" \
"cudatoolkit=${CUDA_TOOLKIT_VER}" \
"rapidsai::cubinlinker" \
"conda-forge::ptxcompiler" \
Expand Down
6 changes: 1 addition & 5 deletions buildscripts/incremental/setup_conda_environment.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ cmd /C conda info
set CONDA_INSTALL=cmd /C conda install -q -y
set PIP_INSTALL=pip install -q

@rem Use conda-forge for NumPy 1.24 - at the time of writing it is not available
@rem on the defaults channel.
if %NUMPY%==1.24 (set NUMPY_CHANNEL_PKG="conda-forge::numpy") else (set NUMPY_CHANNEL_PKG="numpy")

@echo on

@rem Deactivate any environment
call deactivate
@rem Display root environment (for debugging)
conda list
@rem Scipy, CFFI, jinja2 and IPython are optional dependencies, but exercised in the test suite
conda create -n %CONDA_ENV% -q -y python=%PYTHON% %NUMPY_CHANNEL_PKG%=%NUMPY% cffi pip scipy jinja2 ipython gitpython pyyaml
conda create -n %CONDA_ENV% -q -y python=%PYTHON% numpy=%NUMPY% cffi pip scipy jinja2 ipython gitpython pyyaml

call activate %CONDA_ENV%
@rem Install latest llvmlite build
Expand Down
11 changes: 1 addition & 10 deletions buildscripts/incremental/setup_conda_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,14 @@ source deactivate
# Display root environment (for debugging)
conda list

# Use conda-forge for NumPy 1.24 - at the time of writing it is not available
# on the defaults channel.

if [ "${NUMPY}" == "1.24" ]; then
NUMPY_CHANNEL_PKG=conda-forge::numpy
else
NUMPY_CHANNEL_PKG=numpy
fi

# If VANILLA_INSTALL is yes, then only Python, NumPy and pip are installed, this
# is to catch tests/code paths that require an optional package and are not
# guarding against the possibility that it does not exist in the environment.
# Create a base env first and then add to it...
# NOTE: gitpython is needed for CI testing to do the test slicing
# NOTE: pyyaml is used to ensure that the Azure CI config is valid

conda create -n $CONDA_ENV -q -y ${EXTRA_CHANNELS} python=$PYTHON $NUMPY_CHANNEL_PKG=$NUMPY pip gitpython pyyaml
conda create -n $CONDA_ENV -q -y ${EXTRA_CHANNELS} python=$PYTHON numpy=$NUMPY pip gitpython pyyaml

# Activate first
set +v
Expand Down
2 changes: 2 additions & 0 deletions docs/source/user/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ information.
+----------++--------------+---------------------------+----------------------------+------------------------------+-------------------+-----------------------------+
| Numba | Release date | Python | NumPy | llvmlite | LLVM | TBB |
+===========+==============+===========================+============================+==============================+===================+=============================+
| 0.58.0 | UNRELEASED | 3.8.x <= version < 3.12 | 1.21 <= version < 1.26 | 0.41.x | 14.x | 2021.6 <= version |
+-----------+--------------+---------------------------+----------------------------+------------------------------+-------------------+-----------------------------+
| 0.57.1 | 2023-06-21 | 3.8.x <= version < 3.12 | 1.21 <= version < 1.25 | 0.40.x | 14.x | 2021.6 <= version |
+-----------+--------------+---------------------------+----------------------------+------------------------------+-------------------+-----------------------------+
| 0.57.0 | 2023-05-01 | 3.8.x <= version < 3.12 | 1.21 <= version < 1.25 | 0.40.x | 14.x | 2021.6 <= version |
Expand Down
5 changes: 5 additions & 0 deletions docs/upcoming_changes/9011.np_support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Add support for NumPy 1.25
==========================

Extend Numba to support new and changed features released in NumPy 1.25.
23 changes: 16 additions & 7 deletions numba/core/typing/npdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AbstractTemplate, infer_global, infer,
infer_getattr, signature)
from numba.np import npdatetime_helpers
from numba.np.numpy_support import numpy_version


# timedelta64-only operations
Expand Down Expand Up @@ -144,13 +145,22 @@ class TimedeltaTrueDiv(TimedeltaDivOp):
class TimedeltaFloorDiv(TimedeltaDivOp):
key = operator.floordiv

@infer_global(operator.eq)
class TimedeltaCmpEq(TimedeltaCmpOp):
key = operator.eq
if numpy_version >= (1, 25):
@infer_global(operator.eq)
class TimedeltaCmpEq(TimedeltaOrderedCmpOp):
key = operator.eq

@infer_global(operator.ne)
class TimedeltaCmpNe(TimedeltaCmpOp):
key = operator.ne
@infer_global(operator.ne)
class TimedeltaCmpNe(TimedeltaOrderedCmpOp):
key = operator.ne
else:
@infer_global(operator.eq)
class TimedeltaCmpEq(TimedeltaCmpOp):
key = operator.eq

@infer_global(operator.ne)
class TimedeltaCmpNe(TimedeltaCmpOp):
key = operator.ne

@infer_global(operator.lt)
class TimedeltaCmpLt(TimedeltaOrderedCmpOp):
Expand Down Expand Up @@ -228,7 +238,6 @@ def generic(self, args, kws):
left, right = args
if isinstance(left, types.NPDatetime) and isinstance(right,
types.NPDatetime):
# All units compatible...
unit = npdatetime_helpers.get_best_unit(left.unit, right.unit)
return signature(types.NPTimedelta(unit), left, right)

Expand Down
32 changes: 32 additions & 0 deletions numba/cpython/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,38 @@ def int_ne_impl(context, builder, sig, args):
return impl_ret_untracked(context, builder, sig.return_type, res)


def int_signed_unsigned_cmp(op):
def impl(context, builder, sig, args):
(left, right) = args
# This code is translated from the NumPy source.
# What we're going to do is divide the range of a signed value at zero.
# If the signed value is less than zero, then we can treat zero as the
# unsigned value since the unsigned value is necessarily zero or larger
# and any signed comparison between a negative value and zero/infinity
# will yield the same result. If the signed value is greater than or
# equal to zero, then we can safely cast it to an unsigned value and do
# the expected unsigned-unsigned comparison operation.
# Original: https://github.com/numpy/numpy/pull/23713
cmp_zero = builder.icmp_signed('<', left, Constant(left.type, 0))
lt_zero = builder.icmp_signed(op, left, Constant(left.type, 0))
ge_zero = builder.icmp_unsigned(op, left, right)
res = builder.select(cmp_zero, lt_zero, ge_zero)
return impl_ret_untracked(context, builder, sig.return_type, res)
return impl


def int_unsigned_signed_cmp(op):
def impl(context, builder, sig, args):
(left, right) = args
# See the function `int_signed_unsigned_cmp` for implementation notes.
cmp_zero = builder.icmp_signed('<', right, Constant(right.type, 0))
lt_zero = builder.icmp_signed(op, Constant(right.type, 0), right)
ge_zero = builder.icmp_unsigned(op, left, right)
res = builder.select(cmp_zero, lt_zero, ge_zero)
return impl_ret_untracked(context, builder, sig.return_type, res)
return impl


def int_abs_impl(context, builder, sig, args):
[x] = args
ZERO = Constant(x.type, None)
Expand Down
13 changes: 6 additions & 7 deletions numba/cuda/tests/cudapy/test_gufunc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import numpy.core.umath_tests as ut

from collections import namedtuple
from numba import void, int32, float32, float64
Expand Down Expand Up @@ -42,7 +41,7 @@ def test_gufunc_small(self):
5)

C = gufunc(A, B)
Gold = ut.matrix_multiply(A, B)
Gold = np.matmul(A, B)
self.assertTrue(np.allclose(C, Gold))

def test_gufunc_auto_transfer(self):
Expand All @@ -58,7 +57,7 @@ def test_gufunc_auto_transfer(self):
dB = cuda.to_device(B)

C = gufunc(A, dB).copy_to_host()
Gold = ut.matrix_multiply(A, B)
Gold = np.matmul(A, B)
self.assertTrue(np.allclose(C, Gold))

def test_gufunc(self):
Expand All @@ -72,7 +71,7 @@ def test_gufunc(self):
5)

C = gufunc(A, B)
Gold = ut.matrix_multiply(A, B)
Gold = np.matmul(A, B)
self.assertTrue(np.allclose(C, Gold))

def test_gufunc_hidim(self):
Expand All @@ -84,7 +83,7 @@ def test_gufunc_hidim(self):
B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(4, 25, 4, 5)

C = gufunc(A, B)
Gold = ut.matrix_multiply(A, B)
Gold = np.matmul(A, B)
self.assertTrue(np.allclose(C, Gold))

def test_gufunc_new_axis(self):
Expand All @@ -94,7 +93,7 @@ def test_gufunc_new_axis(self):
X = np.random.randn(10, 3, 3)
Y = np.random.randn(3, 3)

gold = ut.matrix_multiply(X, Y)
gold = np.matmul(X, Y)

res1 = gufunc(X, Y)
np.testing.assert_allclose(gold, res1)
Expand Down Expand Up @@ -122,7 +121,7 @@ def test_gufunc_stream(self):
C = dC.copy_to_host(stream=stream)
stream.synchronize()

Gold = ut.matrix_multiply(A, B)
Gold = np.matmul(A, B)

self.assertTrue(np.allclose(C, Gold))

Expand Down
Loading

0 comments on commit 19a0196

Please sign in to comment.