8000 Merge pull request #20641 from bashtage/perf-random-common · numpy/numpy@0d2673c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d2673c

Browse files
authored
Merge pull request #20641 from bashtage/perf-random-common
PERF: Speed up check_constraint checks
2 parents 6d5bc23 + b571bc1 commit 0d2673c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

numpy/random/_common.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from cpython cimport PyFloat_AsDouble
55
import sys
66
import numpy as np
77
cimport numpy as np
8+
cimport numpy.math as npmath
89

910
from libc.stdint cimport uintptr_t
1011

@@ -398,10 +399,10 @@ cdef int check_array_constraint(np.ndarray val, object name, constraint_type con
398399
cdef int check_constraint(double val, object name, constraint_type cons) except -1:
399400
cdef bint is_nan
400401
if cons == CONS_NON_NEGATIVE:
401-
if not np.isnan(val) and np.signbit(val):
402+
if not npmath.isnan(val) and npmath.signbit(val):
402403
raise ValueError(name + " < 0")
403404
elif cons == CONS_POSITIVE or cons == CONS_POSITIVE_NOT_NAN:
404-
if cons == CONS_POSITIVE_NOT_NAN and np.isnan(val):
405+
if cons == CONS_POSITIVE_NOT_NAN and npmath.isnan(val):
405406
raise ValueError(name + " must not be NaN")
406407
elif val <= 0:
407408
raise ValueError(name + " <= 0")

0 commit comments

Comments
 (0)
0