diff options
| author | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2021-12-22 09:49:10 +0000 |
|---|---|---|
| committer | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2021-12-22 09:49:10 +0000 |
| commit | b571bc10752b80b5338eed2d37045858784dae1a (patch) | |
| tree | e7f6de4371aee479525c42306cffc6632255dad8 | |
| parent | 7acb0fd4123673dc38aa5634b47f93770e61cfab (diff) | |
| download | numpy-b571bc10752b80b5338eed2d37045858784dae1a.tar.gz | |
PERF: Speed up check_constraint checks
Remove python api calls from check_constraint
xref #20636
| -rw-r--r-- | numpy/random/_common.pyx | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/numpy/random/_common.pyx b/numpy/random/_common.pyx index 4c34c503c..86828e200 100644 --- a/numpy/random/_common.pyx +++ b/numpy/random/_common.pyx @@ -5,6 +5,7 @@ from cpython cimport PyFloat_AsDouble import sys import numpy as np cimport numpy as np +cimport numpy.math as npmath from libc.stdint cimport uintptr_t @@ -398,10 +399,10 @@ cdef int check_array_constraint(np.ndarray val, object name, constraint_type con cdef int check_constraint(double val, object name, constraint_type cons) except -1: cdef bint is_nan if cons == CONS_NON_NEGATIVE: - if not np.isnan(val) and np.signbit(val): + if not npmath.isnan(val) and npmath.signbit(val): raise ValueError(name + " < 0") elif cons == CONS_POSITIVE or cons == CONS_POSITIVE_NOT_NAN: - if cons == CONS_POSITIVE_NOT_NAN and np.isnan(val): + if cons == CONS_POSITIVE_NOT_NAN and npmath.isnan(val): raise ValueError(name + " must not be NaN") elif val <= 0: raise ValueError(name + " <= 0") |
