Window function implementations for datajure. Each function takes a column (dtype reader/vector) and returns a column of the same length. These are called per-partition by the expr compiler when processing :win AST nodes in window mode (:by + :set).
Window function implementations for datajure. Each function takes a column (dtype reader/vector) and returns a column of the same length. These are called per-partition by the expr compiler when processing :win AST nodes in window mode (:by + :set).
Maps op keywords to binary functions for use in win-scan.
Maps op keywords to binary functions for use in win-scan.
(win-cummax col)Cumulative maximum. nil values skipped. Leading nils remain nil. [nil nil 5.0 8.0] -> [nil nil 5.0 8.0]
Cumulative maximum. nil values skipped. Leading nils remain nil. [nil nil 5.0 8.0] -> [nil nil 5.0 8.0]
(win-cummean col)Cumulative mean. nil values skipped. [10 20 30] -> [10.0 15.0 20.0]
Cumulative mean. nil values skipped. [10 20 30] -> [10.0 15.0 20.0]
(win-cummin col)Cumulative minimum. nil values skipped. Leading nils remain nil. [nil nil 5.0 3.0] -> [nil nil 5.0 3.0]
Cumulative minimum. nil values skipped. Leading nils remain nil. [nil nil 5.0 3.0] -> [nil nil 5.0 3.0]
(win-cumsum col)Cumulative sum. nil values treated as 0. [10 20 30] -> [10 30 60] [nil 20 30] -> [0.0 20.0 50.0]
Cumulative sum. nil values treated as 0. [10 20 30] -> [10 30 60] [nil 20 30] -> [0.0 20.0 50.0]
(win-delta col)Difference from previous element: x[i] - x[i-1]. Returns nil for the first element (no predecessor). [10 20 30] -> [nil 10 10]
Difference from previous element: x[i] - x[i-1]. Returns nil for the first element (no predecessor). [10 20 30] -> [nil 10 10]
(win-dense-rank col)SQL DENSE_RANK(): 1-based, dense tie method, based on current row order. No gaps after ties. Pre-sorted [30 20 20 10] -> [1 2 2 3]
SQL DENSE_RANK(): 1-based, dense tie method, based on current row order. No gaps after ties. Pre-sorted [30 20 20 10] -> [1 2 2 3]
(win-differ col)Boolean: true where value differs from predecessor. First element always returns true (q convention — no predecessor to match). [A A B B A] -> [true false true false true]
Boolean: true where value differs from predecessor. First element always returns true (q convention — no predecessor to match). [A A B B A] -> [true false true false true]
(win-ema col period-or-alpha)Exponential moving average. Parameter dispatch:
Exponential moving average. Parameter dispatch: - If period-or-alpha >= 1: treated as period, alpha = 2 / (1 + period) - If period-or-alpha < 1: treated directly as smoothing factor alpha Seeded at first non-nil value. nil values carry forward last EMA. Leading nils remain nil. ema 2 [10 20 30] -> [10.0 16.67 25.56]
(win-fills col)Forward-fill nil values with the last non-nil value. Leading nils (before the first non-nil) remain nil. Matches q's fills convention. [1 nil nil 4 nil] -> [1 1 1 4 4]
Forward-fill nil values with the last non-nil value. Leading nils (before the first non-nil) remain nil. Matches q's fills convention. [1 nil nil 4 nil] -> [1 1 1 4 4]
(win-lag col offset)Lag by offset positions. Returns nil for positions without enough history. [10 20 30 40], offset=1 -> [nil 10 20 30]
Lag by offset positions. Returns nil for positions without enough history. [10 20 30 40], offset=1 -> [nil 10 20 30]
(win-lead col offset)Lead by offset positions. Returns nil for positions without enough future. [10 20 30 40], offset=1 -> [20 30 40 nil]
Lead by offset positions. Returns nil for positions without enough future. [10 20 30 40], offset=1 -> [20 30 40 nil]
(win-mavg col width)Moving average over width rows (expanding at start). nil values skipped. Matches q's mavg convention. 3 mavg [10 20 30 40 50] -> [10.0 15.0 20.0 30.0 40.0]
Moving average over width rows (expanding at start). nil values skipped. Matches q's mavg convention. 3 mavg [10 20 30 40 50] -> [10.0 15.0 20.0 30.0 40.0]
(win-mdev col width)Moving standard deviation over width rows (expanding at start). Population std dev (ddof=0), matching q's mdev. nil values skipped. 3 mdev [10 20 30 40 50] -> [0.0 5.0 8.165 8.165 8.165]
Moving standard deviation over width rows (expanding at start). Population std dev (ddof=0), matching q's mdev. nil values skipped. 3 mdev [10 20 30 40 50] -> [0.0 5.0 8.165 8.165 8.165]
(win-mmax col width)Moving maximum over width rows (expanding at start). nil values skipped. 3 mmax [30 10 50 20 40] -> [30.0 30.0 50.0 50.0 50.0]
Moving maximum over width rows (expanding at start). nil values skipped. 3 mmax [30 10 50 20 40] -> [30.0 30.0 50.0 50.0 50.0]
(win-mmin col width)Moving minimum over width rows (expanding at start). nil values skipped. 3 mmin [30 10 50 20 40] -> [30.0 10.0 10.0 10.0 20.0]
Moving minimum over width rows (expanding at start). nil values skipped. 3 mmin [30 10 50 20 40] -> [30.0 10.0 10.0 10.0 20.0]
(win-msum col width)Moving sum over width rows (expanding at start). nil values skipped. 3 msum [10 20 30 40 50] -> [10.0 30.0 60.0 90.0 120.0]
Moving sum over width rows (expanding at start). nil values skipped. 3 msum [10 20 30 40 50] -> [10.0 30.0 60.0 90.0 120.0]
(win-rank col)SQL RANK(): 1-based, min tie method, based on current row order. Ties (equal values) get the same rank, next rank skips. Pre-sorted [30 20 20 10] -> [1 2 2 4]
SQL RANK(): 1-based, min tie method, based on current row order. Ties (equal values) get the same rank, next rank skips. Pre-sorted [30 20 20 10] -> [1 2 2 4]
(win-ratio col)Ratio to previous element: x[i] / x[i-1]. Returns nil for the first element (no predecessor). [10 20 30] -> [nil 2.0 1.5]
Ratio to previous element: x[i] / x[i-1]. Returns nil for the first element (no predecessor). [10 20 30] -> [nil 2.0 1.5]
(win-rleid col)Run-length encoding group ID. Increments when value changes. [A A A B B A A] -> [1 1 1 2 2 3 3]
Run-length encoding group ID. Increments when value changes. [A A A B B A A] -> [1 1 1 2 2 3 3]
(win-row-number col)SQL ROW_NUMBER(): 1-based sequential numbering by current row order.
SQL ROW_NUMBER(): 1-based sequential numbering by current row order.
(win-scan op-kw col)Generalized cumulative scan: applies a binary op left-to-right across col (like Clojure's reductions). Nil values are skipped (last good value carried). Leading nils remain nil until first non-nil value is found.
op-kw must be one of :+ :* :max :min. Killer use case: cumulative compounding wealth index via :*
Examples: win-scan :+ [1 2 3 4] -> [1 3 6 10] win-scan :* [1.1 1.2 1.3] -> [1.1 1.32 1.716] win-scan :max [30 10 50 20] -> [30 30 50 50]
Generalized cumulative scan: applies a binary op left-to-right across col (like Clojure's reductions). Nil values are skipped (last good value carried). Leading nils remain nil until first non-nil value is found. op-kw must be one of :+ :* :max :min. Killer use case: cumulative compounding wealth index via :* Examples: win-scan :+ [1 2 3 4] -> [1 3 6 10] win-scan :* [1.1 1.2 1.3] -> [1.1 1.32 1.716] win-scan :max [30 10 50 20] -> [30 30 50 50]
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |