On Mon, Mar 5, 2012 at 12:12 PM, Keith Goodman <kwgood...@gmail.com> wrote: > On Mon, Mar 5, 2012 at 12:06 PM, Neal Becker <ndbeck...@gmail.com> wrote: >> But doesn't this one fail on empty array? > > Yes. I'm optimizing for fun, not for corner cases. This should work > for size zero and NaNs: > > @cython.boundscheck(False) > @cython.wraparound(False) > def allequal(np.ndarray[np.float64_t, ndim=1] a): > cdef: > np.float64_t a0 > Py_ssize_t i, n=a.size > if n == 0: > return False # Or would you like True? > a0 = a[0] > for i in range(n): > if a[i] != a0: > return False > return True
Sorry for all the posts. I'll go back to being quiet. Seems like np.allclose returns True for empty arrays: I[2] a = np.array([]) I[3] np.allclose(np.array([]), np.array([])) O[3] True The original allequal cython code did the same: I[4] allequal(a) O[4] True _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion