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
- Related post in native language (zh-hans): RSTSR v0.10:Rust 原生、全面兼容 Python Array API 标准的科学计算高维张量库 - 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.
Application of RSTSR in Real Electronic-Structure Projects
The n-dimensional tensor library RSTSR was designed to better handle the storage and computation of n-dimensional tensors in electronic-structure calculations. RSTSR is developed as part of the REST (Rust-based Electronic Structure Toolkit) electronic-structure program platform.
A typical real-world example is that, in the REST electronic-structure program, we have implemented an efficient second-order analytical gradient for hybrid functionals (REST PR !154).
The Hessian second-order analytical gradient yields important chemical properties, including molecular vibrational frequencies and thermodynamic energies; its derivatives give infrared and Raman spectra. It has significant value in spectroscopy and thermochemistry, and can serve higher-level tasks such as drug design and materials design. We can show that, under the RI-JK approximation, the REST program's skeleton derivative reaches very high performance — matching or even exceeding other similar electronic-structure programs — with FLOPS utilization above 40% in the CP-HF solve, alongside excellent results in both algorithmic implementation and code optimization[1]. All of this is built on RSTSR's efficient tensor computation.
Zhu, A. J.; Zhang, I. Y. Efficient Implementation of Hartree-Fock Hessian Skeleton Derivative with Resolution-of-Identity Approximation in REST. International Conference on Theoretical and High Performance Computational Chemistry (ICT-HPCC) 2026. ↩︎
1 post - 1 participant

