Specialised functions - mikera/vectorz-clj GitHub Wiki

vectorz-clj provides some specialised functions in a separate Clojure API that is not part of core.matrix. Normally you should use the core.matrix API directly, but there may be some reasons to use these, e.g.:

  • Type hinted and primitive functions that may perform better than using the general purpose core.matrix API.
  • Experimental features not yet in core.matrix

Here are some Vector Examples:

    (in-ns 'mikera.vectorz.core)

    (def a (vec [1 2 3]))

    (+ a a)                    ;; standard arithmetic operations 
    => #<Vector [2.0,4.0,6.0]>

    (join a (vec [4 5 6]))     ;; vector concatenation
    => #<JoinedVector [1.0,2.0,3.0,4.0,5.0,6.0]>

    (magnitude a)              ;; vector magnitude (length)
    => 3.7416573867739413

    (add! a (vec [2 2 2]))     ;; in-place vector mutation
    a
    => #<Vector [3.0,4.0,5.0]>

    ;; you can even get references to sub-vectors and mutate them
    (let [v (create-length 10)]   ;; create a vector of 10 zeros
      (fill! (subvec v 3 4) 1.0)  ;; fill a subvector with ones
      v)
    => #<Vector [0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0]>