58
58
cdef inline int int_max(int a, int b): return a if a >= b else b
59
59
cdef inline int int_min(int a, int b): return a if a <= b else b
60
60
61
- cdef bint is_monotonic_start_end_bounds (
61
+ cdef bint is_monotonic_increasing_start_end_bounds (
62
62
ndarray[int64_t, ndim= 1 ] start, ndarray[int64_t, ndim= 1 ] end
63
63
):
64
64
return is_monotonic(start, False )[0 ] and is_monotonic(end, False )[0 ]
@@ -143,9 +143,11 @@ def roll_sum(ndarray[float64_t] values, ndarray[int64_t] start,
143
143
int64_t s, e
144
144
int64_t nobs = 0 , i, j, N = len (values)
145
145
ndarray[float64_t] output
146
- bint is_monotonic_bounds
146
+ bint is_monotonic_increasing_bounds
147
147
148
- is_monotonic_bounds = is_monotonic_start_end_bounds(start, end)
148
+ is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
149
+ start, end
150
+ )
149
151
output = np.empty(N, dtype = float )
150
152
151
153
with nogil:
@@ -154,7 +156,7 @@ def roll_sum(ndarray[float64_t] values, ndarray[int64_t] start,
154
156
s = start[i]
155
157
e = end[i]
156
158
157
- if i == 0 or not is_monotonic_bounds :
159
+ if i == 0 or not is_monotonic_increasing_bounds :
158
160
159
161
# setup
160
162
@@ -173,9 +175,10 @@ def roll_sum(ndarray[float64_t] values, ndarray[int64_t] start,
173
175
174
176
output[i] = calc_sum(minp, nobs, sum_x)
175
177
176
- if not is_monotonic_bounds:
177
- for j in range (s, e):
178
- remove_sum(values[j], & nobs, & sum_x, & compensation_remove)
178
+ if not is_monotonic_increasing_bounds:
179
+ nobs = 0
180
+ sum_x = 0.0
181
+ compensation_remove = 0.0
179
182
180
183
return output
181
184
@@ -244,9 +247,11 @@ def roll_mean(ndarray[float64_t] values, ndarray[int64_t] start,
244
247
int64_t s, e
245
248
Py_ssize_t nobs = 0 , i, j, neg_ct = 0 , N = len (values)
246
249
ndarray[float64_t] output
247
- bint is_monotonic_bounds
250
+ bint is_monotonic_increasing_bounds
248
251
249
- is_monotonic_bounds = is_monotonic_start_end_bounds(start, end)
252
+ is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
253
+ start, end
254
+ )
250
255
output = np.empty(N, dtype = float )
251
256
252
257
with nogil:
@@ -255,7 +260,7 @@ def roll_mean(ndarray[float64_t] values, ndarray[int64_t] start,
255
260
s = start[i]
256
261
e = end[i]
257
262
258
- if i == 0 or not is_monotonic_bounds :
263
+ if i == 0 or not is_monotonic_increasing_bounds :
259
264
260
265
# setup
261
266
for j in range (s, e):
@@ -276,10 +281,11 @@ def roll_mean(ndarray[float64_t] values, ndarray[int64_t] start,
276
281
277
282
output[i] = calc_mean(minp, nobs, neg_ct, sum_x)
278
283
279
- if not is_monotonic_bounds:
280
- for j in range (s, e):
281
- val = values[j]
282
- remove_mean(val, & nobs, & sum_x, & neg_ct, & compensation_remove)
284
+ if not is_monotonic_increasing_bounds:
285
+ nobs = 0
286
+ neg_ct = 0
287
+ sum_x = 0.0
288
+ compensation_remove = 0.0
283
289
return output
284
290
285
291
# ----------------------------------------------------------------------
@@ -367,10 +373,12 @@ def roll_var(ndarray[float64_t] values, ndarray[int64_t] start,
367
373
int64_t s, e
368
374
Py_ssize_t i, j, N = len (values)
369
375
ndarray[float64_t] output
370
- bint is_monotonic_bounds
376
+ bint is_monotonic_increasing_bounds
371
377
372
378
minp = max (minp, 1 )
373
- is_monotonic_bounds = is_monotonic_start_end_bounds(start, end)
379
+ is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
380
+ start, end
381
+ )
374
382
output = np.empty(N, dtype = float )
375
383
376
384
with nogil:
@@ -382,7 +390,7 @@ def roll_var(ndarray[float64_t] values, ndarray[int64_t] start,
382
390
383
391
# Over the first window, observations can only be added
384
392
# never removed
385
- if i == 0 or not is_monotonic_bounds :
393
+ if i == 0 or not is_monotonic_increasing_bounds :
386
394
387
395
for j in range (s, e):
388
396
add_var(values[j], & nobs, & mean_x, & ssqdm_x, & compensation_add)
@@ -403,10 +411,11 @@ def roll_var(ndarray[float64_t] values, ndarray[int64_t] start,
403
411
404
412
output[i] = calc_var(minp, ddof, nobs, ssqdm_x)
405
413
406
- if not is_monotonic_bounds:
407
- for j in range (s, e):
408
- remove_var(values[j], & nobs, & mean_x, & ssqdm_x,
409
- & compensation_remove)
414
+ if not is_monotonic_increasing_bounds:
415
+ nobs = 0.0
416
+ mean_x = 0.0
417
+ ssqdm_x = 0.0
418
+ compensation_remove = 0.0
410
419
411
420
return output
412
421
@@ -486,10 +495,12 @@ def roll_skew(ndarray[float64_t] values, ndarray[int64_t] start,
486
495
int64_t nobs = 0 , i, j, N = len (values)
487
496
int64_t s, e
488
497
ndarray[float64_t] output
489
- bint is_monotonic_bounds
498
+ bint is_monotonic_increasing_bounds
490
499
491
500
minp = max (minp, 3 )
492
- is_monotonic_bounds = is_monotonic_start_end_bounds(start, end)
501
+ is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
502
+ start, end
503
+ )
493
504
output = np.empty(N, dtype = float )
494
505
495
506
with nogil:
@@ -501,7 +512,7 @@ def roll_skew(ndarray[float64_t] values, ndarray[int64_t] start,
501
512
502
513
# Over the first window, observations can only be added
503
514
# never removed
504
- if i == 0 or not is_monotonic_bounds :
515
+ if i == 0 or not is_monotonic_increasing_bounds :
505
516
506
517
for j in range (s, e):
507
518
val = values[j]
@@ -524,10 +535,11 @@ def roll_skew(ndarray[float64_t] values, ndarray[int64_t] start,
524
535
525
536
output[i] = calc_skew(minp, nobs, x, xx, xxx)
526
537
527
- if not is_monotonic_bounds:
528
- for j in range (s, e):
529
- val = values[j]
530
- remove_skew(val, & nobs, & x, & xx, & xxx)
538
+ if not is_monotonic_increasing_bounds:
539
+ nobs = 0
540
+ x = 0.0
541
+ xx = 0.0
542
+ xxx = 0.0
531
543
532
544
return output
533
545
@@ -611,10 +623,12 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
611
623
float64_t x = 0 , xx = 0 , xxx = 0 , xxxx = 0
612
624
int64_t nobs = 0 , i, j, s, e, N = len (values)
613
625
ndarray[float64_t] output
614
- bint is_monotonic_bounds
626
+ bint is_monotonic_increasing_bounds
615
627
616
628
minp = max (minp, 4 )
617
- is_monotonic_bounds = is_monotonic_start_end_bounds(start, end)
629
+ is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
630
+ start, end
631
+ )
618
632
output = np.empty(N, dtype = float )
619
633
620
634
with nogil:
@@ -626,7 +640,7 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
626
640
627
641
# Over the first window, observations can only be added
628
642
# never removed
629
- if i == 0 or not is_monotonic_bounds :
643
+ if i == 0 or not is_monotonic_increasing_bounds :
630
644
631
645
for j in range (s, e):
632
646
add_kurt(values[j], & nobs, & x, & xx, & xxx, & xxxx)
@@ -646,9 +660,12 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
646
660
647
661
output[i] = calc_kurt(minp, nobs, x, xx, xxx, xxxx)
648
662
649
- if not is_monotonic_bounds:
650
- for j in range (s, e):
651
- remove_kurt(values[j], & nobs, & x, & xx, & xxx, & xxxx)
663
+ if not is_monotonic_increasing_bounds:
664
+ nobs = 0
665
+ x = 0.0
666
+ xx = 0.0
667
+ xxx = 0.0
668
+ xxxx = 0.0
652
669
653
670
return output
654
671
0 commit comments