Fast vector math in Clojure / Incanter

后端 未结 5 524
感情败类
感情败类 2021-01-30 09:40

I\'m currently looking into Clojure and Incanter as an alternative to R. (Not that I dislike R, but it just interesting to try out new languages.) I like Incanter and find the s

5条回答
  •  梦谈多话
    2021-01-30 09:57

    Here's a solution with transients - appealing but slow.

    (use 'incanter.stats)
    (set! *warn-on-reflection* true)
    (def x (doall (sample-normal 1e7)))
    
    (time
     (def y
          (loop [xs x
                 xs+ (rest x)
                 result (transient [])]
            (if (empty? xs+)
              (persistent! result)
              (recur (rest xs) (rest xs+)
                     (conj! result (- (double (first xs+))
                                      (double (first xs)))))))))
    

提交回复
热议问题