Runtime shape and dtype checking for NumPy, JAX, PyTorch, and CuPy arrays, powered by beartype.
https://beartype.github.io/bearshape/ β// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Health 86/100 with only 13 stars
// how to help
// readme
bearshape
Runtime shape and dtype checking for NumPy, JAX, PyTorch, CuPy, and tree-structured containers, powered by beartype.
from beartype import beartype
from bearshape import N, C
from bearshape.numpy import F32
@beartype
def normalize(x: F32[N, C]) -> F32[N, C]:
return x / x.sum(axis=1, keepdims=True)
bearshape turns annotations such as F32[N, C], F32Like[~B, C],
F32[Value("size")], and Tree[F32[N], T] into runtime-validated contracts.
Named dimensions are shared within a function call, so mismatched shapes fail at
the boundary instead of later in array code.
Installation and candidate status
These docs describe the unpublished 0.1.0rc1 candidate, requiring Python
3.11+ (tested on 3.11β3.14) and beartype 0.23.1. pip install bearshape
currently installs the older
PyPI release. To try the candidate from a
checkout in a Python 3.11+ virtual environment:
python -m pip install . numpy "beartype==0.23.1"