@@ -9,15 +9,11 @@ from libc.stdlib cimport malloc, free
9
9
import numpy as np
10
10
cimport numpy as cnp
11
11
from numpy cimport ndarray, int64_t, float64_t, float32_t
12
+ from numpy.math cimport signbit, isnan, sqrtl as sqrt
13
+ # sqrtl is square root specialized to "long double"
12
14
cnp.import_array()
13
15
14
16
15
- cdef extern from " src/headers/cmath" namespace " std" :
16
- bint isnan(float64_t) nogil
17
- bint notnan(float64_t) nogil
18
- int signbit(float64_t) nogil
19
- float64_t sqrt(float64_t x) nogil
20
-
21
17
cimport pandas._libs.util as util
22
18
from pandas._libs.util cimport numeric
23
19
@@ -384,21 +380,21 @@ def roll_count(ndarray[float64_t] values, int64_t win, int64_t minp,
384
380
count_x = 0.0
385
381
for j in range (s, e):
386
382
val = values[j]
387
- if notnan (val):
383
+ if not isnan (val):
388
384
count_x += 1.0
389
385
390
386
else :
391
387
392
388
# calculate deletes
393
389
for j in range (start[i - 1 ], s):
394
390
val = values[j]
395
- if notnan (val):
391
+ if not isnan (val):
396
392
count_x -= 1.0
397
393
398
394
# calculate adds
399
395
for j in range (end[i - 1 ], e):
400
396
val = values[j]
401
- if notnan (val):
397
+ if not isnan (val):
402
398
count_x += 1.0
403
399
404
400
if count_x >= minp:
@@ -429,15 +425,15 @@ cdef inline void add_sum(float64_t val, int64_t *nobs, float64_t *sum_x) nogil:
429
425
""" add a value from the sum calc """
430
426
431
427
# Not NaN
432
- if notnan (val):
428
+ if not isnan (val):
433
429
nobs[0 ] = nobs[0 ] + 1
434
430
sum_x[0 ] = sum_x[0 ] + val
435
431
436
432
437
433
cdef inline void remove_sum(float64_t val, int64_t * nobs, float64_t * sum_x) nogil:
438
434
""" remove a value from the sum calc """
439
435
440
- if notnan (val):
436
+ if not isnan (val):
441
437
nobs[0 ] = nobs[0 ] - 1
442
438
sum_x[0 ] = sum_x[0 ] - val
443
439
@@ -545,7 +541,7 @@ cdef inline void add_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
545
541
""" add a value from the mean calc """
546
542
547
543
# Not NaN
548
- if notnan (val):
544
+ if not isnan (val):
549
545
nobs[0 ] = nobs[0 ] + 1
550
546
sum_x[0 ] = sum_x[0 ] + val
551
547
if signbit(val):
@@ -556,7 +552,7 @@ cdef inline void remove_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
556
552
Py_ssize_t * neg_ct) nogil:
557
553
""" remove a value from the mean calc """
558
554
559
- if notnan (val):
555
+ if not isnan (val):
560
556
nobs[0 ] = nobs[0 ] - 1
561
557
sum_x[0 ] = sum_x[0 ] - val
562
558
if signbit(val):
@@ -683,7 +679,7 @@ cdef inline void remove_var(float64_t val, float64_t *nobs, float64_t *mean_x,
683
679
cdef:
684
680
float64_t delta
685
681
686
- if notnan (val):
682
+ if not isnan (val):
687
683
nobs[0 ] = nobs[0 ] - 1
688
684
if nobs[0 ]:
689
685
# a part of Welford's method for the online variance-calculation
@@ -772,7 +768,7 @@ def roll_var(ndarray[float64_t] values, int64_t win, int64_t minp,
772
768
val = values[i]
773
769
prev = values[i - win]
774
770
775
- if notnan (val):
771
+ if not isnan (val):
776
772
if prev == prev:
777
773
778
774
# Adding one observation and removing another one
@@ -837,7 +833,7 @@ cdef inline void add_skew(float64_t val, int64_t *nobs,
837
833
""" add a value from the skew calc """
838
834
839
835
# Not NaN
840
- if notnan (val):
836
+ if not isnan (val):
841
837
nobs[0 ] = nobs[0 ] + 1
842
838
843
839
# seriously don't ask me why this is faster
@@ -852,7 +848,7 @@ cdef inline void remove_skew(float64_t val, int64_t *nobs,
852
848
""" remove a value from the skew calc """
853
849
854
850
# Not NaN
855
- if notnan (val):
851
+ if not isnan (val):
856
852
nobs[0 ] = nobs[0 ] - 1
857
853
858
854
# seriously don't ask me why this is faster
@@ -979,7 +975,7 @@ cdef inline void add_kurt(float64_t val, int64_t *nobs,
979
975
""" add a value from the kurotic calc """
980
976
981
977
# Not NaN
982
- if notnan (val):
978
+ if not isnan (val):
983
979
nobs[0 ] = nobs[0 ] + 1
984
980
985
981
# seriously don't ask me why this is faster
@@ -995,7 +991,7 @@ cdef inline void remove_kurt(float64_t val, int64_t *nobs,
995
991
""" remove a value from the kurotic calc """
996
992
997
993
# Not NaN
998
- if notnan (val):
994
+ if not isnan (val):
999
995
nobs[0 ] = nobs[0 ] - 1
1000
996
1001
997
# seriously don't ask me why this is faster
@@ -1116,7 +1112,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
1116
1112
# setup
1117
1113
for j in range (s, e):
1118
1114
val = values[j]
1119
- if notnan (val):
1115
+ if not isnan (val):
1120
1116
nobs += 1
1121
1117
err = skiplist_insert(sl, val) != 1
1122
1118
if err:
@@ -1127,7 +1123,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
1127
1123
# calculate adds
1128
1124
for j in range (end[i - 1 ], e):
1129
1125
val = values[j]
1130
- if notnan (val):
1126
+ if not isnan (val):
1131
1127
nobs += 1
1132
1128
err = skiplist_insert(sl, val) != 1
1133
1129
if err:
@@ -1136,7 +1132,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
1136
1132
# calculate deletes
1137
1133
for j in range (start[i - 1 ], s):
1138
1134
val = values[j]
1139
- if notnan (val):
1135
+ if not isnan (val):
1140
1136
skiplist_remove(sl, val)
1141
1137
nobs -= 1
1142
1138
@@ -1510,7 +1506,7 @@ def roll_quantile(ndarray[float64_t, cast=True] values, int64_t win,
1510
1506
# setup
1511
1507
for j in range (s, e):
1512
1508
val = values[j]
1513
- if notnan (val):
1509
+ if not isnan (val):
1514
1510
nobs += 1
1515
1511
skiplist_insert(skiplist, val)
1516
1512
@@ -1519,14 +1515,14 @@ def roll_quantile(ndarray[float64_t, cast=True] values, int64_t win,
1519
1515
# calculate adds
1520
1516
for j in range (end[i - 1 ], e):
1521
1517
val = values[j]
1522
- if notnan (val):
1518
+ if not isnan (val):
1523
1519
nobs += 1
1524
1520
skiplist_insert(skiplist, val)
1525
1521
1526
1522
# calculate deletes
1527
1523
for j in range (start[i - 1 ], s):
1528
1524
val = values[j]
1529
- if notnan (val):
1525
+ if not isnan (val):
1530
1526
skiplist_remove(skiplist, val)
1531
1527
nobs -= 1
1532
1528
@@ -1885,7 +1881,7 @@ cdef inline void remove_weighted_var(float64_t val,
1885
1881
cdef:
1886
1882
float64_t temp, q, r
1887
1883
1888
- if notnan (val):
1884
+ if not isnan (val):
1889
1885
nobs[0 ] = nobs[0 ] - 1
1890
1886
1891
1887
if nobs[0 ]:
@@ -1955,7 +1951,7 @@ def roll_weighted_var(float64_t[:] values, float64_t[:] weights,
1955
1951
w = weights[i % win_n]
1956
1952
pre_w = weights[(i - win_n) % win_n]
1957
1953
1958
- if notnan (val):
1954
+ if not isnan (val):
1959
1955
if pre_val == pre_val:
1960
1956
remove_weighted_var(pre_val, pre_w, & t,
1961
1957
& sum_w, & mean, & nobs)
0 commit comments