hn.today

Rapl: Enjoyable, composable, hackable N-dimensional arrays for Rust

github.com8 points1 comments
Screenshot of Rapl: Enjoyable, composable, hackable N-dimensional arrays for Rust

rapl is a Rust crate for N-dimensional arrays that blends NumPy-style ergonomics with ideas from APL/BQN. Ranks are encoded in types so shape mistakes surface at compile time, yet the API is rank-generic: the same operations apply to vectors, matrices, batched tensors and runtime-dynamic arrays. Elements are type-generic (not limited to floats), supporting strings, tuples and user types; arithmetic requires numeric types but slicing, mapping, folding and outer products work for any element. The design emphasizes a tiny, readable core of composable primitives, minimal dependencies, no unsafe code, and “hackability” over raw performance - rapl is intended for exploration, prototyping and teaching rather than production high-performance workloads.

The crate exposes O(1) views (slicing, windows, broadcasts), reshape and permute_axes that preserve storage, and an explicit to_owned_array() for copies. It provides reductions, scans, cell operations, a general contract/tensordot facility, batched matmul, outer products, right-hand broadcasting like NumPy, native complex numbers and an in-crate FFT. Examples include windowed pooling, convolutions built from windows plus contraction, AlexNet with handwritten backprop, multi-head attention, Game of Life, Ising simulations and FFT-based edge detection. A plotting helper draws Ndarrs to SVG/PNG with shape-driven defaults.

Read on github.com1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.