@@ -115,7 +115,7 @@ METRIC_MAPPING{{name_suffix}} = {
115
115
'pyfunc': PyFuncDistance{{name_suffix}},
116
116
}
117
117
118
- cdef inline cnp.ndarray _buffer_to_ndarray{{name_suffix}}(const {{INPUT_DTYPE_t}}* x, cnp.npy_intp n):
118
+ cdef inline object _buffer_to_ndarray{{name_suffix}}(const {{INPUT_DTYPE_t}}* x, cnp.npy_intp n):
119
119
# Wrap a memory buffer with an ndarray. Warning: this is not robust.
120
120
# In particular, if x is deallocated before the returned array goes
121
121
# out of scope, this could cause memory errors. Since there is not
@@ -620,9 +620,9 @@ cdef class DistanceMetric{{name_suffix}}:
620
620
return dist
621
621
622
622
def _pairwise_dense_dense(self, X, Y):
623
- cdef cnp.ndarray[ {{INPUT_DTYPE_t}}, ndim=2, mode='c' ] Xarr
624
- cdef cnp.ndarray[ {{INPUT_DTYPE_t}}, ndim=2, mode='c' ] Yarr
625
- cdef cnp.ndarray[ DTYPE_t, ndim=2, mode='c' ] Darr
623
+ cdef const {{INPUT_DTYPE_t}}[:, ::1 ] Xarr
624
+ cdef const {{INPUT_DTYPE_t}}[:, ::1 ] Yarr
625
+ cdef DTYPE_t[:, ::1 ] Darr
626
626
627
627
Xarr = np.asarray(X, dtype={{INPUT_DTYPE}}, order='C')
628
628
self._validate_data(Xarr)
@@ -2806,10 +2806,9 @@ cdef class PyFuncDistance{{name_suffix}}(DistanceMetric{{name_suffix}}):
2806
2806
const {{INPUT_DTYPE_t}}* x2,
2807
2807
ITYPE_t size,
2808
2808
) except -1 with gil:
2809
- cdef cnp.ndarray x1arr
2810
- cdef cnp.ndarray x2arr
2811
- x1arr = _buffer_to_ndarray{{name_suffix}}(x1, size)
2812
- x2arr = _buffer_to_ndarray{{name_suffix}}(x2, size)
2809
+ cdef:
2810
+ object x1arr = _buffer_to_ndarray{{name_suffix}}(x1, size)
2811
+ object x2arr = _buffer_to_ndarray{{name_suffix}}(x2, size)
2813
2812
d = self.func(x1arr, x2arr, **self.kwargs)
2814
2813
try:
2815
2814
# Cython generates code here that results in a TypeError
0 commit comments