Get the latest tech news
Blazing Matrix Products
matrix products Why not use BLAS? Because I am interested in Brutalist array programming, and the absence of a high-performance native matrix product in BQN was a compelling opportunity for exploration1. Of course wrapping dgemm is always an option: blasFFI ← (⊣•FFI·(1-˜+`׬)∘=⟜⊏⊸⊔⊢)´ ⟨ "/lib/libcblas.so"∾˜•BQN 1⊑•Sh "nix-instantiate"‿"--eval-only"‿"--expr"‿"(import <nixpkgs> {}).blas.outPath" " & cblas_dgemm u32 u32 u32 i32 i32 i32 f64 *f64 i32 *f64 i32 f64 &f64 i32" ⟩ Dgemm ← {BlasFFI 101‿111‿111‿m‿n‿k‿1‿𝕨‿k‿𝕩‿n‿0‿(m‿n⥊0)∾⊢´m‿k‿·‿n←𝕨∾○≢𝕩} In case you're wondering, this function has roughly the same overhead as NumPy's dot.
The first step towards higher performance is employing blocking to optimize cache access patterns. As a bonus, here's a convenient function to compute powers of a square matrix 𝕩(particularly useful in graph theory) using blocks of size 𝕨, which pads the matrices with zeros as needed: It works for any square matrix, regardless of dimension: if it is odd, we pad with an extra row and column, and then take back the original.
Or read this on Hacker News