|
NumericAL
A header-only C++20 lexer built on REAL
|
A pure, header-only C++20 numerical computing library: tensors, Einstein summation, dense linear algebra, matrix functions and FFT, generic over its scalar type and depending on nothing but the C++ standard library. Its answers are the same to the bit on any number of threads, and its Python binding follows NumPy and SciPy. It is one of the Algorithmic Libraries of the SciForge ecosystem, beside REAL.
NumericAL computes with concrete numeric structures (vectors, matrices, tensors) and knows nothing of expressions or of any symbolic layer; the tools built on top of it own that.
Documentation: https://reche23.github.io/NumericAL/, with the guides, the Python and C++ references, a page of differences from NumPy and SciPy, and the Doxygen reference of every header under api/.
linalg and most of scipy.linalg), tensors and einsum, the FFT, matrix functions, and the element-wise functions and reductions over them, in float32, float64 and their complex types, with bool for comparisons and int64 for integers (not yet through the linear algebra); a BLAS and LAPACK ABI (numerical_blas)..T, transpose, a permuting einsum) and a basic slice (t[1:500], t[::2], t[::-1]) are views that read the elements where they lie. A Tensor is immutable (t[i] = x raises TypeError), so unlike a NumPy view, a view never writes through to its base.One cp310 abi3 wheel serves CPython 3.10 and later; the free-threaded 3.14t and 3.15t take their own and run without the GIL. For C++, add include/ to the include path, or after cmake --install, in your CMakeLists.txt:
add_subdirectory and FetchContent give the same target; numerical.get_include() gives the headers of an installed Python package.
C++ (this is cmake/smoke/main.cpp, which CI builds against the installed package):
Python, where every function takes a Tensor or anything asarray reads (a NumPy array, a nested list, a number):
A Tensor passes to NumPy, PyTorch, JAX or CuPy without a copy (np.asarray(t), np.from_dlpack(t)).
numpy.linalg and most of scipy.linalg: LU, Cholesky, LDLᵀ, QR (with pivoting), the symmetric, Hermitian and general eigenproblems, the SVD, Schur and generalized Schur (QZ) forms, least squares, banded, Toeplitz and triangular solvers, on stacks of matrices as NumPy's (linear algebra).expm, logm, sqrtm, funm, fractional powers, the Sylvester, Lyapunov and Riccati solvers.einsum, NumPy's broadcasting, element-wise functions, reductions, comparisons and masks, the array API namespace (__array_namespace__) and numerical.linalg (tensors and dtypes).numpy.fft and the cosine and sine transforms of scipy.fft, any length.numerical_blas** (experimental): 39 BLAS and LAPACK routines under their Fortran names, carried by the Linux wheels, to preload under a program linked against BLAS (BLAS and LAPACK).The C++ library lists every class and the algorithm it runs.
A result is the same, to the bit, on any number of threads, and on any x86-64 processor with AVX2 or AVX-512 for one build; between other kernels (portable, NEON, AMX) it may differ in the last bits. Every decomposition is backward stable, held by differential fuzzers against NumPy and SciPy on adversarial matrices; a NaN or an infinity in a matrix raises LinAlgError. Compiled outside the wheels and the sdist, which set both:
-ffp-contract=on;-mllvm -force-ordered-reductions=false too.Reproducibility and threads says why, and how to cap the threads and choose the kernel; Accuracy gives the bound each function is held to.
Each push is built and tested with GCC 14 and Clang 21 (Linux x86-64, under ASan and UBSan too), GCC 13 (Linux arm64), MSVC 2022 (Windows x64) and Apple Clang 16 (macOS arm64, locally). CMake 3.16 or newer; Python 3.10 or newer for the binding. SciForge's quality bar holds: 100 % coverage, Clang and GCC, lint, format, MISRA-oriented analysis and sanitizers green. CONTRIBUTING.md gives the build and the gates.
On an M1 Pro against Accelerate, at order 1024, matrix products, solve and inverse are as fast or faster (0.94×), Cholesky, QR and eigh within 1.0–1.2×, svd and lstsq 1.3–1.4×; small problems (order 64–256) take 1.5–3× Accelerate's time. Against OpenBLAS on x86-64 (i9-10900X, i9-9900K) large problems (order 512 and 1024) take 1.1–2.5×, eigh 2.6–2.9×. make bench-linalg times NumericAL against the BLAS and LAPACK NumPy ships, each library alone in its process, every answer checked first. The tables, the method and where the gaps are: BENCHMARKS.md.
CHANGELOG.md lists what each release adds, changes and fixes.
MIT — see [LICENSE](LICENSE). Several algorithms follow LAPACK's routines closely; its BSD license, which their redistribution carries, is in [NOTICE](NOTICE).
René Chenard