$ show v923z/micropython-ulab
micropython-ulab is a C library that provides a subset of NumPy and SciPy functionality for MicroPython and CircuitPython on microcontrollers. It implements a multi-dimensional ndarray type with broadcasting, universal functions, linear algebra (Cholesky, eig, inv, QR), FFT, signal processing (sosfilt), numerical integration, optimization, random number generation, and file I/O. The library is designed for performance and memory frugality, using compile-time feature flags (ulab.h) to trim flash usage. Key entry points include ulab.numpy (array creation, math, stats, linalg, fft, io), ulab.scipy (integrate, linalg, optimize, signal, special), and utils (buffer conversion, spectrogram). The architecture is modular with separate C modules for each functional area, a reusable user module for custom extensions, and extensive test coverage for 1Dā4D arrays and complex numbers. The library is actively maintained with frequent releases, but some SciPy functions remain incomplete and the codebase has repetitive dtype-dispatch macros that increase maintenance burden.
The LLM identified 4 files worth highlighting for reuse:
Provides a self-contained template for adding custom C functions to ulab without modifying core modules. Engineers can copy this file, implement their own functions with the same pattern (type check, create array, iterate, return), and register them. Demonstrates the library's extensibility pattern and is easily reusable for other MicroPython module extensions.
Central configuration header with preprocessor defines to enable/disable all major features (dimensions, operators, submodules). Each define controls a specific subset (e.g., ULAB_NUMPY_HAS_LINALG_MODULE, NDARRAY_HAS_BINARY_OP_ADD). This pattern allows fine-grained control over flash usage and can be extracted as a template for configurable embedded libraries.
A shell script that automates running ulab tests on both unix port and hardware (pyboard) with feature detection, skip lists per target, and expected-output comparison. It supports multiple dimension configurations and emitters. This test harness pattern is reusable for other MicroPython/CircuitPython projects requiring cross-platform validation.
A collection of pure Python modules (e.g., numpy.core.fromnumeric, scipy.signal.filter_design) that implement subset of numpy/scipy functions not yet ported to C. These allow developers to write code that works both with ulab on microcontrollers and standard CPython. The pattern of providing Python fallbacks for missing C implementations is reusable for partial library ports.