Skip to content

Commit 4d2e306

Browse files
committed
[reductions] New maximum reducer
1 parent 1dfa062 commit 4d2e306

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/tech/v3/dataset/reductions.clj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ user> (ds-reduce/group-by-column-agg
134134
hamf-proto/Finalize
135135
(finalize [this v] (deref v))))
136136

137+
(defn maximum-rf
138+
([]
139+
Double/NaN)
140+
([eax v]
141+
(if (Double/isNaN eax)
142+
v
143+
(max (double v) (double eax))))
144+
([eax]
145+
eax))
146+
147+
(defn maximum
148+
[colname]
149+
(reducer->column-reducer maximum-rf colname))
137150

138151
(deftype BitmapConsumer [^RoaringBitmap bitmap]
139152
LongConsumer
@@ -494,7 +507,7 @@ _unnamed [4 5]:
494507
k v
495508
(let [vv (finalize-fn v)]
496509
(.lock ll)
497-
(try
510+
(try
498511
(.accept ^Consumer c vv)
499512
(finally
500513
(.unlock ll))))))

test/tech/v3/dataset/reductions_test.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@
370370

371371
))
372372

373+
(deftest maximum-test
374+
(let [ds (ds/->dataset {:x (repeatedly 100 rand)})
375+
ev (last (:x (ds/sort-by-column ds :x)))
376+
out-ds (ds-reduce/aggregate {:max-x (ds-reduce/maximum :x)} ds)]
377+
(is (= 1 (ds/row-count out-ds)))
378+
(is (= (first (:max-x out-ds))
379+
ev))))
380+
373381
(comment
374382

375383
(do
@@ -435,7 +443,7 @@
435443

436444

437445
(dotimes [idx 100]
438-
(time
446+
(time
439447
(ds-reduce/group-by-column-agg
440448
:a
441449
(into {} (for [col (-> one-hot :one-hot-table vals)

0 commit comments

Comments
 (0)