Utilities for float arrays
Utilities for float arrays
(aclone xs)
aclone that doesn't require type hinting.
aclone that doesn't require type hinting.
(afill! bindings form)
Like amap
, but writes the output of form to the first bound array
and returns it.
;; Relace values that are too large (afill! [x xs :let [limit 500]] (if (>= x limit) 42, x))
;; Cube an array! (afill! [x xs] (* x x x))
;; Zero the first 20 elements (afill! [x xs :range [0 20]] 0)
Like `amap`, but writes the output of form to the first bound array and returns it. ;; Relace values that are too large (afill! [x xs :let [limit 500]] (if (>= x limit) 42, x)) ;; Cube an array! (afill! [x xs] (* x x x)) ;; Zero the first 20 elements (afill! [x xs :range [0 20]] 0)
(aget xs idx)
aset that doesn't require type hinting
aset that doesn't require type hinting
(ainc xs idx val)
Increment the value of xs at idx by val
Increment the value of xs at idx by val
(alength xs)
alength that doesn't require type hinting
alength that doesn't require type hinting
(amake [idx len] expr)
Make a new array of length len and fill it with values computed by expr.
;; array of random values between 0 10 (amake [_ 10e3] (rand-int 10))
;; array of squares (amake [i 100] (* i i))
Make a new array of length len and fill it with values computed by expr. ;; array of random values between 0 10 (amake [_ 10e3] (rand-int 10)) ;; array of squares (amake [i 100] (* i i))
(amap bindings form)
Like for, but with hiphip-style array bindings (please see the
hiphip.array
docstring). Builds a new array from values produced
by form at each step, with length equal to the range of the
iteration.
;; Square roots array (amap [x xs] (Math/sqrt x))
;; Take the max of two arrays. (amap [x xs y ys] (max x y))
;; Create an array from the first ten elements, all incremented (amap [x xs :range [0 10]] (inc x))
Like for, but with hiphip-style array bindings (please see the `hiphip.array` docstring). Builds a new array from values produced by form at each step, with length equal to the range of the iteration. ;; Square roots array (amap [x xs] (Math/sqrt x)) ;; Take the max of two arrays. (amap [x xs y ys] (max x y)) ;; Create an array from the first ten elements, all incremented (amap [x xs :range [0 10]] (inc x))
(amax-index xs)
Maximum over an array.
Uses Java for now for maximum efficiency. See benchmarks for our current best performance in pure Clojure.
Maximum over an array. Uses Java for now for maximum efficiency. See benchmarks for our current best performance in pure Clojure.
(amax-indices xs k)
Return an array of indices where the last k elements point at the max k elements of xs in ascending order (and the remaining elements point at the remaining elements of xs, in no particular order.)
Return an array of indices where the last k elements point at the max k elements of xs in ascending order (and the remaining elements point at the remaining elements of xs, in no particular order.)
(amin-index xs)
Minimum over an array.
Uses Java for now for maximum efficiency. See benchmarks for our current best performance in pure Clojure.
Minimum over an array. Uses Java for now for maximum efficiency. See benchmarks for our current best performance in pure Clojure.
(amin-indices xs k)
Return an array of indices where the first k elements point at the min k elements of xs in ascending order (and the remaining elements point at the remaining elements of xs, in no particular order.)
Return an array of indices where the first k elements point at the min k elements of xs in ascending order (and the remaining elements point at the remaining elements of xs, in no particular order.)
(apartition! xs pivot)
(apartition! xs start stop pivot)
Mutate array xs in range [start stop) so that elements less than pivot come first, followed by elements equal to pivot, followed by elements greater than pivot. Returns 1 + the smallest index pointing at an element > pivot after the partitioning.
Mutate array xs in range [start stop) so that elements less than pivot come first, followed by elements equal to pivot, followed by elements greater than pivot. Returns 1 + the smallest index pointing at an element > pivot after the partitioning.
(apartition-indices! indices xs pivot)
(apartition-indices! indices xs start stop pivot)
Like apartition!, but mutate an array of indices instead.
Like apartition!, but mutate an array of indices instead.
(aproduct array)
(aproduct bindings form)
Like (apply * xs)
, but for arrays. Supports for-each
bindings (please see the hiphip.array
docstring) and a body
expression.
;; Net probability of an array of probabilities (aproduct x)
Like `(apply * xs)`, but for arrays. Supports for-each bindings (please see the `hiphip.array` docstring) and a body expression. ;; Net probability of an array of probabilities (aproduct x)
(areduce bindings ret init form)
areduce
, with hiphip-style array bindings (please see the
hiphip.array
docstring). Note: The type of the accumulator will
have the same semantics as those of a variable in a loop.
;; Sum a really, really large array without overflow (areduce [x xs] ret 0 (+' ret x))
;; Frequencies of different elements (areduce [x xs] ret {} (assoc ret x (inc (get ret x 0))))
;; Return all non-composite numbers (areduce [x (asort xs)] ncomp [] (if (some zero? (map #(mod x %) ncomp)) ncomp (conj ncomp x)))
`areduce`, with hiphip-style array bindings (please see the `hiphip.array` docstring). Note: The type of the accumulator will have the same semantics as those of a variable in a loop. ;; Sum a really, really large array without overflow (areduce [x xs] ret 0 (+' ret x)) ;; Frequencies of different elements (areduce [x xs] ret {} (assoc ret x (inc (get ret x 0)))) ;; Return all non-composite numbers (areduce [x (asort xs)] ncomp [] (if (some zero? (map #(mod x %) ncomp)) ncomp (conj ncomp x)))
(aselect! xs k)
(aselect! xs start stop k)
Rearranges xs such that the smallest k elements come first, followed by all greater elements.
Rearranges xs such that the smallest k elements come first, followed by all greater elements.
(aselect-indices! xs k)
(aselect-indices! indices xs k)
(aselect-indices! xs start stop k)
(aselect-indices! indices xs start stop k)
Like aselect!, but mutates an array of indices instead.
Like aselect!, but mutates an array of indices instead.
(aset xs idx val)
aset that doesn't require type hinting
aset that doesn't require type hinting
(asort! xs)
(asort! xs start stop)
Sorts an array in-place.
Sorts an array in-place.
(asort-indices! xs)
(asort-indices! indices xs)
(asort-indices! xs start stop)
(asort-indices! indices xs start stop)
Like asort!, but mutates an array of indices instead.
Like asort!, but mutates an array of indices instead.
(asort-max! xs k)
Rearrange xs so that the last k elements are the top k in ascending order. Faster than sorting the whole array.
Rearrange xs so that the last k elements are the top k in ascending order. Faster than sorting the whole array.
(asort-min! xs k)
Rearrange xs so that the first k elements are the min k in ascending order. Faster than sorting the whole array.
Rearrange xs so that the first k elements are the min k in ascending order. Faster than sorting the whole array.
(asum array)
(asum bindings form)
Like (apply + xs)
, but for arrays. Supports for-each
bindings (please see the hiphip.array
docstring) and a body
expression.
;; Basic usage (asum xs)
;; Sum of the square of each element (asum [x xs] (* x x))
;; Compute a standard deviation (let [mean (amean xs)] (/ (asum [x xs] (Math/pow (- x mean) 2)) (alength xs)))
Like `(apply + xs)`, but for arrays. Supports for-each bindings (please see the `hiphip.array` docstring) and a body expression. ;; Basic usage (asum xs) ;; Sum of the square of each element (asum [x xs] (* x x)) ;; Compute a standard deviation (let [mean (amean xs)] (/ (asum [x xs] (Math/pow (- x mean) 2)) (alength xs)))
(doarr bindings & body)
Like doseq, but with hiphip-style array bindings (please see the
hiphip.array
docstring).
;; Array to ArrayList (let [alist (java.util.ArrayList.)] (doarr [x xs] (.add alist x)) alist)
;; Print the fifty first elements (doarr [x xs :range [0 50]] (println x))
Like doseq, but with hiphip-style array bindings (please see the `hiphip.array` docstring). ;; Array to ArrayList (let [alist (java.util.ArrayList.)] (doarr [x xs] (.add alist x)) alist) ;; Print the fifty first elements (doarr [x xs :range [0 50]] (println x))
(dot-product xs ys)
Dot product of two arrays.
Dot product of two arrays.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close