diff --git a/src/taoensso/tufte/stats.cljc b/src/taoensso/tufte/stats.cljc index 4ae847e..fff4714 100644 --- a/src/taoensso/tufte/stats.cljc +++ b/src/taoensso/tufte/stats.cljc @@ -20,43 +20,6 @@ #?(:clj (let [c (Class/forName "[J")] (defn longs? "Returns true iff given long array" [x] (instance? c x)))) #?(:clj (let [c (Class/forName "[D")] (defn doubles? "Returns true iff given double array" [x] (instance? c x)))) -;;;; Tuples - -(do - (deftype Tup2 [x y ]) - (deftype Tup3 [x y z])) - -(defn multi-reduce - "Like `reduce` but supports separate simultaneous accumulators - as a micro-optimisation when reducing a large collection multiple - times." - ;; Faster than using volatiles - ([f init coll] (reduce f init coll)) - ([f1 init1 f2 init2 coll] - (let [^Tup2 tuple - (reduce - (fn [^Tup2 tuple in] - (Tup2. - (f1 (.-x tuple) in) - (f2 (.-y tuple) in))) - (Tup2. init1 init2) - coll)] - - [(.-x tuple) (.-y tuple)])) - - ([f1 init1 f2 init2 f3 init3 coll] - (let [^Tup3 tuple - (reduce - (fn [^Tup3 tuple in] - (Tup3. - (f1 (.-x tuple) in) - (f2 (.-y tuple) in) - (f2 (.-z tuple) in))) - (Tup3. init1 init2 init3) - coll)] - - [(.-x tuple) (.-y tuple) (.-z tuple)]))) - ;;;; Sorted nums (deftype SortedLongs [^longs a] @@ -360,7 +323,7 @@ xsum (double (reduce rf-sum 0.0 snums)) xbar (/ xsum nx) [^double xvar-sum ^double xmad-sum] - (multi-reduce + (enc/reduce-multi (partial rf-sum-variance xbar) 0.0 (partial rf-sum-abs-deviation xbar) 0.0 snums)] diff --git a/test/taoensso/stats_tests.cljc b/test/taoensso/stats_tests.cljc index 566a264..6e372fa 100644 --- a/test/taoensso/stats_tests.cljc +++ b/test/taoensso/stats_tests.cljc @@ -31,9 +31,6 @@ (is (= (vec (stats/sorted-nums [1.0 3 2])) [1.0 2.0 3.0])) (is (= (vec (stats/sorted-nums [1 3.0 2.0])) [1 2 3]))])]) -(deftest multi-reduce - [(is (= (stats/multi-reduce + 0 - 0 (range 1e4)) [49995000 -49995000]))]) - (deftest weighted-nth [(is (= (#'stats/weighted-nth 0.5 [1 3]) 2.0)) (is (= (#'stats/weighted-nth 0.5 [1 10]) 5.5))