@@ -55,39 +55,11 @@ cdef:
55
55
56
56
float64_t NaN = < float64_t> np.NaN
57
57
58
- cdef inline int int_max(int a, int b): return a if a >= b else b
59
- cdef inline int int_min(int a, int b): return a if a <= b else b
60
-
61
58
cdef bint is_monotonic_increasing_start_end_bounds(
62
59
ndarray[int64_t, ndim= 1 ] start, ndarray[int64_t, ndim= 1 ] end
63
60
):
64
61
return is_monotonic(start, False )[0 ] and is_monotonic(end, False )[0 ]
65
62
66
- # Cython implementations of rolling sum, mean, variance, skewness,
67
- # other statistical moment functions
68
- #
69
- # Misc implementation notes
70
- # -------------------------
71
- #
72
- # - In Cython x * x is faster than x ** 2 for C types, this should be
73
- # periodically revisited to see if it's still true.
74
- #
75
-
76
- # original C implementation by N. Devillard.
77
- # This code in public domain.
78
- # Function : kth_smallest()
79
- # In : array of elements, # of elements in the array, rank k
80
- # Out : one element
81
- # Job : find the kth smallest element in the array
82
-
83
- # Reference:
84
-
85
- # Author: Wirth, Niklaus
86
- # Title: Algorithms + data structures = programs
87
- # Publisher: Englewood Cliffs: Prentice-Hall, 1976
88
- # Physical description: 366 p.
89
- # Series: Prentice-Hall Series in Automatic Computation
90
-
91
63
# ----------------------------------------------------------------------
92
64
# Rolling sum
93
65
@@ -774,7 +746,6 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
774
746
775
747
def roll_median_c (const float64_t[:] values , ndarray[int64_t] start ,
776
748
ndarray[int64_t] end , int64_t minp ):
777
- # GH 32865. win argument kept for compatibility
778
749
cdef:
779
750
float64_t val, res, prev
780
751
bint err = False
@@ -1167,9 +1138,8 @@ def roll_apply(object obj,
1167
1138
arr = np.asarray(obj)
1168
1139
1169
1140
# ndarray input
1170
- if raw:
1171
- if not arr.flags.c_contiguous:
1172
- arr = arr.copy(' C' )
1141
+ if raw and not arr.flags.c_contiguous:
1142
+ arr = arr.copy(' C' )
1173
1143
1174
1144
counts = roll_sum(np.isfinite(arr).astype(float ), start, end, minp)
1175
1145
@@ -1195,17 +1165,17 @@ def roll_apply(object obj,
1195
1165
# Rolling sum and mean for weighted window
1196
1166
1197
1167
1198
- def roll_weighted_sum (float64_t[:] values , float64_t[:] weights , int minp ):
1168
+ def roll_weighted_sum (const float64_t[:] values , const float64_t[:] weights , int minp ):
1199
1169
return _roll_weighted_sum_mean(values, weights, minp, avg = 0 )
1200
1170
1201
1171
1202
- def roll_weighted_mean (float64_t[:] values , float64_t[:] weights , int minp ):
1172
+ def roll_weighted_mean (const float64_t[:] values , const float64_t[:] weights , int minp ):
1203
1173
return _roll_weighted_sum_mean(values, weights, minp, avg = 1 )
1204
1174
1205
1175
1206
- cdef ndarray[ float64_t] _roll_weighted_sum_mean(float64_t[:] values,
1207
- float64_t[:] weights,
1208
- int minp, bint avg):
1176
+ cdef float64_t[: ] _roll_weighted_sum_mean(const float64_t[:] values,
1177
+ const float64_t[:] weights,
1178
+ int minp, bint avg):
1209
1179
"""
1210
1180
Assume len(weights) << len(values)
1211
1181
"""
@@ -1270,7 +1240,7 @@ cdef ndarray[float64_t] _roll_weighted_sum_mean(float64_t[:] values,
1270
1240
if c < minp:
1271
1241
output[in_i] = NaN
1272
1242
1273
- return np.asarray( output)
1243
+ return output
1274
1244
1275
1245
1276
1246
# ----------------------------------------------------------------------
@@ -1424,7 +1394,7 @@ cdef inline void remove_weighted_var(float64_t val,
1424
1394
mean[0 ] = 0
1425
1395
1426
1396
1427
- def roll_weighted_var (float64_t[:] values , float64_t[:] weights ,
1397
+ def roll_weighted_var (const float64_t[:] values , const float64_t[:] weights ,
1428
1398
int64_t minp , unsigned int ddof ):
1429
1399
"""
1430
1400
Calculates weighted rolling variance using West's online algorithm.
0 commit comments