Skip to content

Commit

Permalink
Merge branch 'topic/default/check-py3.12-numpy2.0' into 'branch/default'
Browse files Browse the repository at this point in the history
Check Python 3.12 and Numpy 2.0

See merge request fluiddyn/transonic!141
  • Loading branch information
paugier committed Jul 24, 2024
2 parents 39c0474 + b1ba32d commit c3dd7c3
Show file tree
Hide file tree
Showing 8 changed files with 1,324 additions and 1,289 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v2
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.23.0
pixi-version: v0.26.1
cache: false
- name: Tests
run: |
Expand Down
8 changes: 4 additions & 4 deletions data_tests/saved__backend__/cython/type_hint_notemplate.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cimport numpy as np
ctypedef fused __compute__Array_TypeIint_complex128I_NDimI1_3I:
np.ndarray[np.complex128_t, ndim=1]
np.ndarray[np.complex128_t, ndim=3]
np.ndarray[np.int_t, ndim=1]
np.ndarray[np.int_t, ndim=3]
np.ndarray[np.int32_t, ndim=1]
np.ndarray[np.int32_t, ndim=3]

ctypedef fused __compute__TypeIint_complex128I:
cython.int
Expand All @@ -18,7 +18,7 @@ ctypedef fused __compute__UnionArray_TypeIint_complex128I_NDimI1_3I_Array_float3
np.ndarray[np.complex128_t, ndim=3]
np.ndarray[np.float32_t, ndim=2]
np.ndarray[np.float32_t, ndim=4]
np.ndarray[np.int_t, ndim=1]
np.ndarray[np.int_t, ndim=3]
np.ndarray[np.int32_t, ndim=1]
np.ndarray[np.int32_t, ndim=3]

cpdef compute(__compute__Array_TypeIint_complex128I_NDimI1_3I a, __compute__Array_TypeIint_complex128I_NDimI1_3I b, __compute__TypeIint_complex128I c, __compute__UnionArray_TypeIint_complex128I_NDimI1_3I_Array_float32_NDimI1_3Ip1 d, cython.str e)
1,152 changes: 578 additions & 574 deletions pdm.lock

Large diffs are not rendered by default.

1,414 changes: 721 additions & 693 deletions pixi.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/transonic/backends/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@


def normalize_type_name_for_array(name):
if name == "bool_":

if name in ("bool_", "bool"):
return "np.uint8"
if name == "int":
return "np.int32"
if any(name.endswith(str(number)) for number in (8, 16, 32, 64, 128)):
return "np." + name
if name in ("int", "float", "complex"):
if name in ("float", "complex"):
return "np." + name
return name

Expand Down
2 changes: 1 addition & 1 deletion src/transonic_cl/cythonize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from distutils.core import setup
from setuptools import setup

import numpy as np
from Cython.Build import cythonize
Expand Down
16 changes: 8 additions & 8 deletions src/transonic_cl/run_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def main():
args = [sys.executable, "-m", "transonic_cl.cythonize", name]

name_lock.touch()
try:
completed_process = subprocess.run(
args, stdout=stdout, stderr=stderr, universal_newlines=True
)
except Exception:
pass
finally:
name_lock.unlink()
completed_process = subprocess.run(
args, stdout=stdout, stderr=stderr, text=True, check=False
)
name_lock.unlink()

if completed_process.returncode:
print(completed_process.stderr)
raise subprocess.CalledProcessError(completed_process.returncode, args)
if backend == "pythran" and "-o" in args and path_tmp.exists():
path_tmp.rename(path_out)
elif backend == "cython":
Expand Down
10 changes: 5 additions & 5 deletions tests/backends/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ def compare(result, dtype, ndim, memview, mem_layout=None, positive_indices=None

def test_memview():
memview = "memview"
compare("np.int_t[:, ::1]", int, "2d", memview, "C")
compare("np.int_t[:, :, :]", int, "3d", memview, "strided")
compare("np.int32_t[:, ::1]", int, "2d", memview, "C")
compare("np.int32_t[:, :, :]", int, "3d", memview, "strided")
compare("np.int32_t[::1, :]", np.int32, "2d", memview, "F")


def test_array():
memview = None
compare('np.ndarray[np.int_t, ndim=2, mode="c"]', int, "2d", memview, "C")
compare("np.ndarray[np.int_t, ndim=3]", int, "3d", memview, "strided")
compare('np.ndarray[np.int32_t, ndim=2, mode="c"]', int, "2d", memview, "C")
compare("np.ndarray[np.int32_t, ndim=3]", int, "3d", memview, "strided")
compare(
'np.ndarray[np.int32_t, ndim=2, mode="f"]', np.int32, "2d", memview, "F"
)
compare(
"np.ndarray[np.int_t, ndim=2, negative_indices=False]",
"np.ndarray[np.int32_t, ndim=2, negative_indices=False]",
int,
"2d",
memview,
Expand Down

0 comments on commit c3dd7c3

Please sign in to comment.