8000 PERF: Speed up check_constraint checks by bashtage · Pull Request #20641 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

PERF: Speed up check_constraint checks #20641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions numpy/random/_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
0