After two years of development, RSTSR has reached a milestone: an efficient-on-CPU, native Rust, n-dimensional tensor scientific-computing library that is highly compatible with the NumPy interface.
We believe NumPy's interface design for n-dimensional tensors is excellent. With RSTSR we show that native Rust scientific computing can be as easy to write and read as NumPy, while being more efficient, safer, and better suited to parallel computing.
- Project: GitHub - RESTGroup/rstsr: An n-dimensional rust tensor toolkit ยท GitHub
- API documentation: rstsr - Rust
For details, see the RSTSR v0.10 blog post: RSTSR 3rd Report | RSTSR: An n-Dimensional Rust Tensor Toolkit
For NumPy users, RSTSR provides a NumPy-RSTSR Cheatsheet to get you up to speed quickly.
Fully Compatible with the Python Array API 2025 Standard
As a native Rust library, RSTSR implements almost every interface of the Python Array API 2025 standard. RSTSR is no longer merely "inspired by" the Array API โ it is a non-Python library that genuinely implements the Array API standard.
The Python Array API 2025 standard covers nearly all of NumPy's commonly used and important functionality, including:
- Creation: zeros, ones, full, arange, linspace, eye, meshgrid, etc.;
- Indexing: basic indexing/slicing, advanced/fancy indexing, element indexing;
- Shape manipulation: reshape, transpose, swapaxes, moveaxis, expand_dims, squeeze, etc.;
- Broadcasting: broadcast_to, broadcast_arrays, etc.; broadcasting also applies to tensor arithmetic and other operations;
- Arithmetic: addition, subtraction, multiplication, division, trigonometric functions, etc.;
- Binary operations: such as logical and comparison operations;
- Linear algebra: matmul, vecdot, eigh, svd, etc.;
- Statistical operations: sum, mean, var, std, min, max, etc.;
- Other tensor operations: concatenate, stack, split, repeat, tile, etc.
rstsr-faer-py, a thin Python wrapper built on RSTSR v0.10.0 with the Faer backend, is available on PyPI. Against the Array API 2025 test suite it scores 1336 Pass / 17 Fail / 33 Skip (NumPy 2.5, for comparison, scores 1339 Pass / 42 Fail / 5 Skip). Of these, 14 failures / 33 skips come from the test suite itself and from the RSTSR Faer backend not implementing FFT; the remaining 3 failures are a floating-point overflow in SVD that is rare in practical situations. This shows that, apart from FFT, RSTSR correctly implements every Array API 2025 interface.
Although we do not literally implement every Array API 2025 interface, that is because a small number are difficult or impossible to implement due to the nature of the Rust language. So even where a solution exists in Python, we do not provide a one-to-one native Rust implementation. The excluded features are:
- The operator overloads
__ipow__,__imatmul__that Python permits but Rust lacks (though they can be achieved with functions); - Dynamic-typed lists, which Python allows but are very hard to express in statically typed Rust. The affected functions are
concatandstack(so long as the tensors share the same dtype, RSTSR can still usert::concatandrt::stack).
Key Features of RSTSR
- Use
%as the matrix-multiplication operator: a distinctive feature of RSTSR. You can write&a % &binstead ofa.matmul(&b), making matrix multiplication more concise. - Excellent parallelism management: for multithreaded BLAS backends, our rayon-based thread control guarantees that whether RSTSR's general computation or matrix linear algebra is called inside or outside rayon parallel threads, the parallel device is fully utilized without ever exceeding the thread count specified by the user.
- Support for both row-major and column-major: RSTSR defaults to row-major memory layout, but also allows column-major layout, which is already used extensively in the real-world REST electronic-structure program.
- Multiple BLAS backends: RSTSR can use Faer's default multithreaded backend, or OpenBLAS, Intel MKL, BLIS, KML, and other BLAS backends; CPU performance is on par with NumPy. Matrix linear algebra operations such as solve, svd, and eigh are supported.
- Extensible backends: generics support multiple backends. Users need not modify RSTSR's source code, and the data need not reside in memory (GPU, disk, or network storage can hold it) โ implementing the new backend trait interfaces is enough to perform mathematical computation with a custom backend.
- Multiple data types: RSTSR supports ordinary floating-point types as well as arbitrary data structures (including types such as strings that require
alloc). In electronic-structure programs, f64 and c64 are the most common dtypes; we support them and provide special optimizations for them. - Zero-overhead reshape: under a reasonable tensor layout (not necessarily fully contiguous in memory), RSTSR can implement reshape as a view, with no extra memory overhead.
- Einstein summation support: with the external TBLIS tensor-contraction library, RSTSR can perform tensor contractions using the same Einstein-summation syntax as NumPy. See
rt::tblis::einsum. - Efficient Vecdot support: in electronic structure โ particularly some dense density-functional matrix computations โ tensor contractions of the form
"pi, pi -> p"are very common and are indeed a significant memory-bandwidth bottleneck. Our implementation ofrt::vecdotis not naive: its multi-core parallel performance is excellent, it is much faster than a plain elementwise multiply followed by a sum, and it uses less memory.