(mul-mat-fn size)

Produces optimized code for a matrix multiplication function for matrices of the given size. The resulting code has no loops or branches.

Source

(defmacro mul-mat-fn "Produces optimized code for a matrix multiplication function for matrices of the given size. The resulting code has no loops or branches." [size] (let [params (repeatedly (* 2 size size) #(with-meta (gensym) {:tag 'double})) [m1 m2] (map vec (partition (* size size) params))] `(fn ~[m1 m2] ~(vec (for [i (range size) j (range size)] (cons `+ (for [k (range size)] `(* ~(nth m1 (+ (* i size) k)) ~(nth m2 (+ (* k size) j))))))))))