@@ -15,6 +15,7 @@ cnp.import_array()
15
15
16
16
cdef extern from " src/headers/cmath" namespace " std" :
17
17
bint isnan(double ) nogil
18
+ bint notnan(double ) nogil
18
19
int signbit(double ) nogil
19
20
double sqrt(double x) nogil
20
21
@@ -381,21 +382,21 @@ def roll_count(ndarray[double_t] input, int64_t win, int64_t minp,
381
382
count_x = 0.0
382
383
for j in range (s, e):
383
384
val = input [j]
384
- if val == val :
385
+ if notnan( val) :
385
386
count_x += 1.0
386
387
387
388
else :
388
389
389
390
# calculate deletes
390
391
for j in range (start[i - 1 ], s):
391
392
val = input [j]
392
- if val == val :
393
+ if notnan( val) :
393
394
count_x -= 1.0
394
395
395
396
# calculate adds
396
397
for j in range (end[i - 1 ], e):
397
398
val = input [j]
398
- if val == val :
399
+ if notnan( val) :
399
400
count_x += 1.0
400
401
401
402
if count_x >= minp:
@@ -424,15 +425,15 @@ cdef inline void add_sum(double val, int64_t *nobs, double *sum_x) nogil:
424
425
""" add a value from the sum calc """
425
426
426
427
# Not NaN
427
- if val == val :
428
+ if notnan( val) :
428
429
nobs[0 ] = nobs[0 ] + 1
429
430
sum_x[0 ] = sum_x[0 ] + val
430
431
431
432
432
433
cdef inline void remove_sum(double val, int64_t * nobs, double * sum_x) nogil:
433
434
""" remove a value from the sum calc """
434
435
435
- if val == val :
436
+ if notnan( val) :
436
437
nobs[0 ] = nobs[0 ] - 1
437
438
sum_x[0 ] = sum_x[0 ] - val
438
439
@@ -538,7 +539,7 @@ cdef inline void add_mean(double val, Py_ssize_t *nobs, double *sum_x,
538
539
""" add a value from the mean calc """
539
540
540
541
# Not NaN
541
- if val == val :
542
+ if notnan( val) :
542
543
nobs[0 ] = nobs[0 ] + 1
543
544
sum_x[0 ] = sum_x[0 ] + val
544
545
if signbit(val):
@@ -549,7 +550,7 @@ cdef inline void remove_mean(double val, Py_ssize_t *nobs, double *sum_x,
549
550
Py_ssize_t * neg_ct) nogil:
550
551
""" remove a value from the mean calc """
551
552
552
- if val == val :
553
+ if notnan( val) :
553
554
nobs[0 ] = nobs[0 ] - 1
554
555
sum_x[0 ] = sum_x[0 ] - val
555
556
if signbit(val):
@@ -671,8 +672,7 @@ cdef inline void remove_var(double val, double *nobs, double *mean_x,
671
672
""" remove a value from the var calc """
672
673
cdef double delta
673
674
674
- # Not NaN
675
- if val == val:
675
+ if notnan(val):
676
676
nobs[0 ] = nobs[0 ] - 1
677
677
if nobs[0 ]:
678
678
# a part of Welford's method for the online variance-calculation
@@ -760,7 +760,7 @@ def roll_var(ndarray[double_t] input, int64_t win, int64_t minp,
760
760
val = input [i]
761
761
prev = input [i - win]
762
762
763
- if val == val :
763
+ if notnan( val) :
764
764
if prev == prev:
765
765
766
766
# Adding one observation and removing another one
@@ -822,7 +822,7 @@ cdef inline void add_skew(double val, int64_t *nobs, double *x, double *xx,
822
822
""" add a value from the skew calc """
823
823
824
824
# Not NaN
825
- if val == val :
825
+ if notnan( val) :
826
826
nobs[0 ] = nobs[0 ] + 1
827
827
828
828
# seriously don't ask me why this is faster
@@ -836,7 +836,7 @@ cdef inline void remove_skew(double val, int64_t *nobs, double *x, double *xx,
836
836
""" remove a value from the skew calc """
837
837
838
838
# Not NaN
839
- if val == val :
839
+ if notnan( val) :
840
840
nobs[0 ] = nobs[0 ] - 1
841
841
842
842
# seriously don't ask me why this is faster
@@ -959,7 +959,7 @@ cdef inline void add_kurt(double val, int64_t *nobs, double *x, double *xx,
959
959
""" add a value from the kurotic calc """
960
960
961
961
# Not NaN
962
- if val == val :
962
+ if notnan( val) :
963
963
nobs[0 ] = nobs[0 ] + 1
964
964
965
965
# seriously don't ask me why this is faster
@@ -974,7 +974,7 @@ cdef inline void remove_kurt(double val, int64_t *nobs, double *x, double *xx,
974
974
""" remove a value from the kurotic calc """
975
975
976
976
# Not NaN
977
- if val == val :
977
+ if notnan( val) :
978
978
nobs[0 ] = nobs[0 ] - 1
979
979
980
980
# seriously don't ask me why this is faster
@@ -1089,7 +1089,7 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
1089
1089
1090
1090
# setup
1091
1091
val = input [i]
1092
- if val == val :
1092
+ if notnan( val) :
1093
1093
nobs += 1
1094
1094
err = skiplist_insert(sl, val) != 1
1095
1095
if err:
@@ -1100,14 +1100,14 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
1100
1100
# calculate deletes
1101
1101
for j in range (start[i - 1 ], s):
1102
1102
val = input [j]
1103
- if val == val :
1103
+ if notnan( val) :
1104
1104
skiplist_remove(sl, val)
1105
1105
nobs -= 1
1106
1106
1107
1107
# calculate adds
1108
1108
for j in range (end[i - 1 ], e):
1109
1109
val = input [j]
1110
- if val == val :
1110
+ if notnan( val) :
1111
1111
nobs += 1
1112
1112
err = skiplist_insert(sl, val) != 1
1113
1113
if err:
@@ -1472,7 +1472,7 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
1472
1472
1473
1473
# setup
1474
1474
val = input [i]
1475
- if val == val :
1475
+ if notnan( val) :
1476
1476
nobs += 1
1477
1477
skiplist_insert(skiplist, val)
1478
1478
@@ -1481,14 +1481,14 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
1481
1481
# calculate deletes
1482
1482
for j in range (start[i - 1 ], s):
1483
1483
val = input [j]
1484
- if val == val :
1484
+ if notnan( val) :
1485
1485
skiplist_remove(skiplist, val)
1486
1486
nobs -= 1
1487
1487
1488
1488
# calculate adds
1489
1489
for j in range (end[i - 1 ], e):
1490
1490
val = input [j]
1491
- if val == val :
1491
+ if notnan( val) :
1492
1492
nobs += 1
1493
1493
skiplist_insert(skiplist, val)
1494
1494
0 commit comments