kwgoodman/bottleneck — Issue #37: bn.anynan() and bn.allnan()
Author: kwgoodman
Created: 2012-02-27 17:15:17+00:00
State: open

bn.anynan(arr, axis) and bn.allnan(arr, axis) might be useful functions to have in bottleneck.

Here's some proof of concept code for anynan:

@cython.boundscheck(False)
@cython.wraparound(False)
def anynan_axis1(np.ndarray[np.float64_t, ndim=2] a):
cdef:
int n0, n1, i, j, f
np.npy_intp *dim
np.float64_t aij
np.ndarray[np.uint8_t, ndim=1, cast=True] y
dim = PyArray_DIMS(a)
n0 = dim[0]
n1 = dim[1]
cdef np.npy_intp *dims = [n0]
y = PyArray_EMPTY(1, dims, NPY_BOOL, 0)
for i in range(n0):
f = 1
for j in range(n1):
aij = a[i, j]
if aij != aij:
y[i] = 1
f = 0
break
if f == 1:
y[i] = 0
return y

We'd have to teach the templating function loop_cdef() to create rmpty bool return arrays.