Skip to content
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
95 changes: 62 additions & 33 deletions bsplines2d/_class02_bsplines_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Common
import numpy as np
import scipy as scp
import scipy.interpolate as scpinterp


Expand All @@ -16,41 +17,69 @@
from . import _class02_bsplines_operators_rect


if hasattr(scpinterp._bspl, 'evaluate_spline'):
evaluate_spline = scpinterp._bspl.evaluate_spline
# Should work for scipy >= 1.15.0
# see https://github.com/ToFuProject/bsplines2d/pull/147
if (
hasattr(scpinterp, '_bsplines')
and hasattr(scpinterp._bsplines, '_dierckx')
and hasattr(scpinterp._bsplines._dierckx, 'evaluate_spline')
):

else:
msg = (
"\n\n"
"bsplines2d using a new version of scipy"
" with no scpinterp._bspl.evaluate_spline()\n"
"Instead using scpinterp._bspl.evaluate_ndspline()\n"
"Prototypal and not thoroughly tested!\n"
)
warnings.warn(msg)

def evaluate_spline(t, c, k, xp, nu, extrapolate, out):
ndim = 1
c1 = c.reshape(c.shape[:ndim] + (-1,))
num_c_tr = c1.shape[-1]
strides_c1 = [stride // c.dtype.itemsize for stride in c.strides]
indices_k1d = np.unravel_index(
np.arange((k+1)**ndim),
(k+1,)*ndim,
)[0][:, None]
return scpinterp._bspl.evaluate_ndbspline(
xp[:, None],
t[None, :],
np.array([t.size], dtype=np.int32),
np.array([k], dtype=np.int32),
np.array([nu], dtype=np.int32),
extrapolate,
c.ravel(),
num_c_tr,
np.array(strides_c1, dtype=np.intp),
indices_k1d,
out,
if scp.__version__.startswith('1.15'):
evaluate_spline = scpinterp._bsplines._dierckx.evaluate_spline
else:
def evaluate_spline(t, c, k, xp, nu, extrapolate, out):
out[...] = scpinterp._bsplines._dierckx.evaluate_spline(
t, # 1d contiguous array of floats
c, # 2d contiguous array of floats
k, # int
xp, # 1d contiguous array of floats
nu, # int
extrapolate, # bool
)
return

elif hasattr(scpinterp, '_bspl'):

if hasattr(scpinterp._bspl, 'evaluate_spline'):
evaluate_spline = scpinterp._bspl.evaluate_spline

else:
msg = (
"\n\n"
"bsplines2d using a new version of scipy"
" with no scpinterp._bspl.evaluate_spline()\n"
"Instead using scpinterp._bspl.evaluate_ndspline()\n"
"Prototypal and not thoroughly tested!\n"
)
warnings.warn(msg)

def evaluate_spline(t, c, k, xp, nu, extrapolate, out):
ndim = 1
c1 = c.reshape(c.shape[:ndim] + (-1,))
num_c_tr = c1.shape[-1]
strides_c1 = [stride // c.dtype.itemsize for stride in c.strides]
indices_k1d = np.unravel_index(
np.arange((k+1)**ndim),
(k+1,)*ndim,
)[0][:, None]
return scpinterp._bspl.evaluate_ndbspline(
xp[:, None],
t[None, :],
np.array([t.size], dtype=np.int32),
np.array([k], dtype=np.int32),
np.array([nu], dtype=np.int32),
extrapolate,
c.ravel(),
num_c_tr,
np.array(strides_c1, dtype=np.intp),
indices_k1d,
out,
)

else:
msg = f"scipy {scp.__version__} has no evaluate_spline"
raise Exception(msg)


# ################################################################
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ keywords = [
# scipy 1.15.3 and 1.16.0 have no wheel for python 3.14
requires-python = ">=3.10,<3.14"
dependencies = [
"scipy<1.16.0", # until https://github.com/ToFuProject/bsplines2d/issues/126 solved
"scipy", # see https://github.com/ToFuProject/bsplines2d/pull/147
"contourpy",
'datastock>=0.0.56',
]
Expand Down
Loading