What is the most efficient and idiomatic way to combine two or more large vectors together? This is what I have been doing. In my application I'm using matrices, so each operation is a bit more expensive than adding two doubles. Using range
to drive the fold feels a bit clumsy.
(require '[clojure.core.reducers :as r])
(def a (mapv (fn [_] (rand 100)) (range 100000)))
(def b (mapv (fn [_] (rand 100)) (range 100000)))
(r/foldcat (r/map #(+ (a %) (b %)) (range (count a))))
Also calculating that range
could end up being the most costly bit on multi-core CPUs since it's the only non-parallel part and involve sequences.
mapv
instead ofvmap
? – guilespimapv
. I am using core.matrix ( vectorz-clj ). Typically I have one vector of 3x3 matrices and another of vector3's and I need to multiply them together in a pairwise manner, like the pattern I presented here. This is for a large computational dynamics problem. There may be 100k elements in each vector, so parallelism is greatly desired. Also I'm using clojure for prototyping because I can develop and experiment much more efficiently in Clojure. So I do want to keep things simple and take advantage of conveniences like core.reducers – Michael Alexander Ewert