Skip to content

Commit 7f53e6e

Browse files
authored
Merge pull request scipy#22158 from lesteve/dierckx-less-strict-input-check
MAINT: accept ndarray subclasses in interpolate._dierckx
2 parents 2a345ee + 055664d commit 7f53e6e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

scipy/interpolate/src/_dierckxmodule.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
static int
1616
check_array(PyObject *obj, npy_intp ndim, int typenum) {
1717

18-
int cond = (PyArray_CheckExact(obj) &&
18+
int cond = (PyArray_Check(obj) &&
1919
(PyArray_TYPE((PyArrayObject*)obj) == typenum) &&
2020
(PyArray_NDIM((PyArrayObject*)obj) == ndim) &&
2121
PyArray_CHKFLAGS((PyArrayObject*)obj, NPY_ARRAY_ALIGNED | NPY_ARRAY_C_CONTIGUOUS)

scipy/interpolate/tests/test_bsplines.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,28 @@ def worker_fn(_, b):
647647
_run_concurrent_barrier(10, worker_fn, b)
648648

649649

650+
def test_memmap(self, tmpdir):
651+
# Make sure that memmaps can be used as t and c atrributes after the
652+
# spline has been constructed. This is similar to what happens in a
653+
# scikit-learn context, where joblib can create read-only memmap to
654+
# share objects between workers. For more details, see
655+
# https://github.com/scipy/scipy/issues/22143
656+
b = _make_random_spline()
657+
xx = np.linspace(0, 1, 10)
658+
659+
expected = b(xx)
660+
661+
t_mm = np.memmap(
662+
str(tmpdir.join('t.dat')), mode='w+', dtype=b.t.dtype, shape=b.t.shape)
663+
t_mm[:] = b.t
664+
c_mm = np.memmap(
665+
str(tmpdir.join('c.dat')), mode='w+', dtype=b.c.dtype, shape=b.c.shape)
666+
c_mm[:] = b.c
667+
b.t = t_mm
668+
b.c = c_mm
669+
670+
xp_assert_close(b(xx), expected)
671+
650672
class TestInsert:
651673

652674
@pytest.mark.parametrize('xval', [0.0, 1.0, 2.5, 4, 6.5, 7.0])

0 commit comments

Comments
 (0)