Skip to content

Commit

Permalink
Python 3.13 support (#174)
Browse files Browse the repository at this point in the history
* Build python 3.13
* Added tests for python 3.13
* Added python 3.13 marker
* Fixed some type conversion problems
* Changed compiler directive
* Update to cython
* Update cutils.pyx
  • Loading branch information
philipp-horstenkamp authored Oct 29, 2024
1 parent ebd6556 commit 2a56505
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
- name: Install cibuildwheel
run: |
pip install --upgrade pip
pip install cibuildwheel==2.15.0
pip install cibuildwheel==2.21.3
- name: Build wheels
env:
CIBW_BUILD: 'cp38-* cp39-* cp310-* cp311-* cp312-*'
CIBW_BUILD: 'cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*'
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_SKIP: pp* *-musllinux_* *-manylinux_i686 # skip PyPy, musllinux, 32-bit Linux
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false # Allow one of the matrix builds to fail without failing others
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- name: Checkout
Expand Down
18 changes: 9 additions & 9 deletions KDEpy/cutils_ext/cutils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from libc.math cimport floor
# for nor correctly handle negative indices

# cdivision(True) -> If set to False, Cython will adjust the remainder and
# quotient operators C types to match those of Python ints (which differ
# quotient operators C types to match those of Python ints (which differ
# when the operands have opposite signs) and raise a ZeroDivisionError
# when the right operand is 0
@cython.boundscheck(False)
Expand Down Expand Up @@ -213,7 +213,7 @@ def iterate_data_ND(double[:, :] data, double[:] result, long[:] grid_num,
grid_num : number of grid points in each dimension
obs_tot : total number of observations (grid points)
binary_flgs : array of shape (dims, 2**dims), counting in binary
this is used to to go every corner point efficiently
this is used to go every corner point efficiently
"""
cdef int obs, result_index, i, dims, corners, j, flg, corner, integer_xi
cdef double corner_value, fraction
Expand All @@ -223,7 +223,7 @@ def iterate_data_ND(double[:, :] data, double[:] result, long[:] grid_num,
obs, dims = data.shape[0], data.shape[1]

# For every dimension, there are two directions to find corners in
corners = 2**dims
corners = int(2**dims)

# Loop through every data point
for i in range(obs):
Expand All @@ -246,11 +246,11 @@ def iterate_data_ND(double[:, :] data, double[:] result, long[:] grid_num,
# Since we use flags to indicate x_1 or x_1 + 1, the following
# code does the job:
result_index = int(x_i[0])
result_index += 0**binary_flgs[corner, 0]
result_index += int(0**binary_flgs[corner, 0])
for j in range(1, dims):
result_index *= grid_num[j]
integer_xi = <int> floor(x_i[j])
result_index += (integer_xi + 0**binary_flgs[corner, j])
result_index += (integer_xi + int(0**binary_flgs[corner, j]))

# (2) The value is found by
# PROD_{i=0} (1 - frac(x[i))**flg * frac(x[i]) ** (1 - flg)
Expand Down Expand Up @@ -281,7 +281,7 @@ def iterate_data_ND_weighted(double[:, :] data, double[:] weights, double[:] res
cdef double[:] x_i

obs, dims = data.shape[0], data.shape[1]
corners = 2**dims
corners = int(2**dims)

for i in range(obs):
x_i = data[i, :]
Expand All @@ -290,11 +290,11 @@ def iterate_data_ND_weighted(double[:, :] data, double[:] weights, double[:] res
for corner in range(corners):

result_index = int(x_i[0])
result_index += 0**binary_flgs[corner, 0]
result_index += int(0**binary_flgs[corner, 0])
for j in range(1, dims):
result_index *= grid_num[j]
integer_xi = <int> floor(x_i[j])
result_index += (integer_xi + 0**binary_flgs[corner, j])
result_index += (integer_xi + int(0**binary_flgs[corner, j]))

corner_value = 1.0
for j in range(dims):
Expand Down Expand Up @@ -412,4 +412,4 @@ def grid_is_sorted(double[:, :] grid):
if not grid_is_sorted(grid[row_start_index:, 1:]):
return False

return True
return True
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

[project.urls]
Expand All @@ -43,5 +44,5 @@ lint = [
]

[build-system]
requires = ["setuptools>=45", "wheel", "cython>=0.29,<1.0.0", "oldest-supported-numpy"]
requires = ["setuptools>=45", "wheel", "cython>=3.0,<4.0", "oldest-supported-numpy"]
build-backend = "setuptools.build_meta"
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/pypa/sampleproject
"""

from Cython.Build import cythonize
import numpy as np
from Cython.Distutils import build_ext
from setuptools import Extension, setup
Expand All @@ -15,5 +16,7 @@
packages=["KDEpy"],
cmdclass={"build_ext": build_ext},
include_dirs=[np.get_include()],
ext_modules=[Extension("KDEpy._cutils", ["KDEpy/cutils_ext/cutils.pyx"])],
ext_modules=cythonize(
[Extension("KDEpy._cutils", ["KDEpy/cutils_ext/cutils.pyx"])],
),
)

0 comments on commit 2a56505

Please sign in to comment.