Created
July 19, 2011 18:55
-
-
Save fabianp/1093404 to your computer and use it in GitHub Desktop.
check an array for finite values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cimport numpy as np | |
import numpy as np | |
np.import_array() | |
def chkfinite_double(np.ndarray X): | |
cdef int i, length | |
cdef np.PyArrayObject val | |
cdef np.flatiter iter | |
length = np.PyArray_SIZE(X) | |
iter = np.PyArray_IterNew(X) | |
while np.PyArray_ITER_NOTDONE(iter): | |
val = np.PyArray_GETITEM(X, np.PyArray_ITER_DATA(iter)) | |
if not npy_isfinite(val): | |
raise ValueError('Array cannot contain Inf or NaN') | |
np.PyArray_ITER_NEXT(iter) | |
return True | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyximport | |
pyximport.install() | |
import gistfile1.pyx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment