Skip to content

Commit

Permalink
rename compiled ext to _cutils, explicit import in FFTKDE
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed Sep 20, 2023
1 parent c4cc3a7 commit aa06d5b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 3 additions & 1 deletion KDEpy/FFTKDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from scipy.signal import convolve

from KDEpy.BaseKDE import BaseKDE
from KDEpy.binning import grid_is_sorted, linear_binning
from KDEpy.binning import linear_binning
from KDEpy.utils import cartesian
# noinspection PyProtectedMember, PyUnresolvedReferences
from KDEpy._cutils import grid_is_sorted


class FFTKDE(BaseKDE):
Expand Down
19 changes: 9 additions & 10 deletions KDEpy/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@

import numpy as np

# Import compiled cutils module locally (not declared in __init__)
# Import compiled _cutils module (not declared in __init__)
# and ignore unresolved reference (may not be build in dev environment)
# noinspection PyUnresolvedReferences
from . import cutils
# noinspection PyProtectedMember, PyUnresolvedReferences
from KDEpy import _cutils
from KDEpy.utils import cartesian

grid_is_sorted = cutils.grid_is_sorted

# This parameter was in use when a NumPy implementation and a Cython
# implementation were both used. Now only Cython is used.
Expand Down Expand Up @@ -110,10 +109,10 @@ def linbin_cython(data, grid_points, weights=None):
# Two Cython functions are implemented, one for weighted data and one
# for unweighted data, since creating equal weights is costly w.r.t time
if weights is None:
result = cutils.iterate_data_1D(transformed_data, result)
result = _cutils.iterate_data_1D(transformed_data, result)
return np.asfarray(result[:-1]) / transformed_data.shape[0]
else:
res = cutils.iterate_data_1D_weighted(transformed_data, weights, result)
res = _cutils.iterate_data_1D_weighted(transformed_data, weights, result)
return np.asfarray(res[:-1]) # Remove last, outside of grid


Expand Down Expand Up @@ -358,9 +357,9 @@ def linbin_Ndim(data, grid_points, weights=None):
if weights is not None:
if data_dims >= 3:
binary_flgs = cartesian(([0, 1],) * dims)
result = cutils.iterate_data_ND_weighted(data, weights, result, grid_num, obs_tot, binary_flgs)
result = _cutils.iterate_data_ND_weighted(data, weights, result, grid_num, obs_tot, binary_flgs)
else:
result = cutils.iterate_data_2D_weighted(data, weights, result, grid_num, obs_tot)
result = _cutils.iterate_data_2D_weighted(data, weights, result, grid_num, obs_tot)
result = np.asarray_chkfinite(result, dtype=float)

# Unweighted data has two specific routines too. This is because creating
Expand All @@ -369,9 +368,9 @@ def linbin_Ndim(data, grid_points, weights=None):
else:
if data_dims >= 3:
binary_flgs = cartesian(([0, 1],) * dims)
result = cutils.iterate_data_ND(data, result, grid_num, obs_tot, binary_flgs)
result = _cutils.iterate_data_ND(data, result, grid_num, obs_tot, binary_flgs)
else:
result = cutils.iterate_data_2D(data, result, grid_num, obs_tot)
result = _cutils.iterate_data_2D(data, result, grid_num, obs_tot)
result = np.asarray_chkfinite(result, dtype=float)
result = result / data_obs

Expand Down
5 changes: 4 additions & 1 deletion KDEpy/tests/test_sorted_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import numpy as np
import pytest

from KDEpy.binning import grid_is_sorted # Imported from .pyx to binning.py, then here
# Import compiled _cutils module (not declared in __init__)
# and ignore unresolved reference (may not be build in dev environment)
# noinspection PyProtectedMember, PyUnresolvedReferences
from KDEpy._cutils import grid_is_sorted # Imported from .pyx to binning.py, then here


class TestGridSorted:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
packages=["KDEpy"],
cmdclass={"build_ext": build_ext},
include_dirs=[np.get_include()],
ext_modules=[Extension("KDEpy.cutils", ["KDEpy/cutils_ext/cutils.pyx"])],
ext_modules=[Extension("KDEpy._cutils", ["KDEpy/cutils_ext/cutils.pyx"])],
)

0 comments on commit aa06d5b

Please sign in to comment.