Liking cljdoc? Tell your friends :D

hiphip.long

Utilities for long arrays

Utilities for long arrays
raw docstring

+type+clj

source

acloneclj

(aclone xs)

aclone that doesn't require type hinting.

aclone that doesn't require type hinting.
sourceraw docstring

afill!cljmacro

(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)
sourceraw docstring

agetclj

(aget xs idx)

aset that doesn't require type hinting

aset that doesn't require type hinting
sourceraw docstring

aincclj

(ainc xs idx val)

Increment the value of xs at idx by val

Increment the value of xs at idx by val
sourceraw docstring

alengthclj

(alength xs)

alength that doesn't require type hinting

alength that doesn't require type hinting
sourceraw docstring

amakecljmacro

(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))
sourceraw docstring

amapcljmacro

(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))
sourceraw docstring

amaxclj

(amax xs)

Maximum over an array.

Maximum over an array.
sourceraw docstring

amax-indexclj

(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.
sourceraw docstring

amax-indicesclj

(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.)
sourceraw docstring

ameancljmacro

(amean xs)

Mean over an array.

Mean over an array.
sourceraw docstring

aminclj

(amin xs)

Minimum over an array.

Minimum over an array.
sourceraw docstring

amin-indexclj

(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.
sourceraw docstring

amin-indicesclj

(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.)
sourceraw docstring

apartition!cljmacro

(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.
sourceraw docstring

apartition-indices!cljmacro

(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.
sourceraw docstring

aproductcljmacro

(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)
sourceraw docstring

areducecljmacro

(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)))
sourceraw docstring

aselect!cljmacro

(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.
sourceraw docstring

aselect-indices!cljmacro

(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.
sourceraw docstring

asetclj

(aset xs idx val)

aset that doesn't require type hinting

aset that doesn't require type hinting
sourceraw docstring

asort!cljmacro

(asort! xs)
(asort! xs start stop)

Sorts an array in-place.

Sorts an array in-place.
sourceraw docstring

asort-indices!cljmacro

(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.
sourceraw docstring

asort-max!clj

(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.
sourceraw docstring

asort-min!clj

(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.
sourceraw docstring

asumcljmacro

(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)))
sourceraw docstring

doarrcljmacro

(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))
sourceraw docstring

dot-productcljmacro

(dot-product xs ys)

Dot product of two arrays.

Dot product of two arrays.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close