| @@ -1505,52 +1505,8 @@ def roll_kurt(ndarray[double_t] input, |
|
|
| 1505 |
1505 |
#------------------------------------------------------------------------------- |
| 1506 |
1506 |
# Rolling median, min, max |
| 1507 |
1507 |
|
| 1508 |
|
-ctypedef double_t (* skiplist_f)(object sl, int n, int p) |
| 1509 |
|
- |
| 1510 |
|
-cdef _roll_skiplist_op(ndarray arg, int win, int minp, skiplist_f op): |
| 1511 |
|
- cdef ndarray[double_t] input = arg |
| 1512 |
|
- cdef double val, prev, midpoint |
| 1513 |
|
- cdef IndexableSkiplist skiplist |
| 1514 |
|
- cdef Py_ssize_t nobs = 0, i |
| 1515 |
|
- |
| 1516 |
|
- cdef Py_ssize_t N = len(input) |
| 1517 |
|
- cdef ndarray[double_t] output = np.empty(N, dtype=float) |
| 1518 |
|
- |
| 1519 |
|
- skiplist = IndexableSkiplist(win) |
| 1520 |
|
- |
| 1521 |
|
- minp = _check_minp(win, minp, N) |
| 1522 |
|
- |
| 1523 |
|
-for i from 0 <= i < minp - 1: |
| 1524 |
|
- val = input[i] |
| 1525 |
|
- |
| 1526 |
|
-# Not NaN |
| 1527 |
|
-if val == val: |
| 1528 |
|
- nobs += 1 |
| 1529 |
|
- skiplist.insert(val) |
| 1530 |
|
- |
| 1531 |
|
- output[i] = NaN |
| 1532 |
|
- |
| 1533 |
|
-for i from minp - 1 <= i < N: |
| 1534 |
|
- val = input[i] |
| 1535 |
|
- |
| 1536 |
|
-if i > win - 1: |
| 1537 |
|
- prev = input[i - win] |
| 1538 |
|
- |
| 1539 |
|
-if prev == prev: |
| 1540 |
|
- skiplist.remove(prev) |
| 1541 |
|
- nobs -= 1 |
| 1542 |
|
- |
| 1543 |
|
-if val == val: |
| 1544 |
|
- nobs += 1 |
| 1545 |
|
- skiplist.insert(val) |
| 1546 |
|
- |
| 1547 |
|
- output[i] = op(skiplist, nobs, minp) |
| 1548 |
|
- |
| 1549 |
|
-return output |
| 1550 |
|
- |
| 1551 |
1508 |
from skiplist cimport * |
| 1552 |
1509 |
|
| 1553 |
|
- |
| 1554 |
1510 |
@cython.boundscheck(False) |
| 1555 |
1511 |
@cython.wraparound(False) |
| 1556 |
1512 |
def roll_median_c(ndarray[float64_t] arg, int win, int minp): |