array-api-shape-check
Documentation: https://array-api-shape-check.readthedocs.io
Source Code: https://github.com/34j/array-api-shape-check
Check shapes of input arrays easily.
Installation
Install this via pip (or your favourite package manager):
pip install array-api-shape-check
Usage
>>> from array_api_shape_check import check_shapes
>>> info = check_shapes("ij,*k*l,*li", (1, 4), (5, 6, 7), (1, 7, 3))
>>> info.all
((i:1->3, j:4), (*k:(5,), *l:(6, 7)), (*l:(1, 7)->(6, 7), i:3))
>>> info.unique
{'i': i:3, 'j': j:4, 'k': *k:(5,), 'l': *l:(6, 7)}
Internally check_shapes() calls parse_variable_ndim(), which determines the number of dimensions for variable subscripts by least squares. If this is successful, checks if each subscript is consistent, then finnaly raises error for all inconsistencies at once.
Diving into the details of the first item:
>>> item = info.all[0][0]
>>> item.name # the name of the subscript
'i'
>>> item.is_variable # whether the subscript is variable (starts with "*")
False
>>> item.shape_current # the current shape of the subscript
(1,)
>>> item.shape_broadcasted # the broadcasted shape of the subscript
(3,)
Not enough information to determine variable subscript ndims:
>>> import pytest
>>> from array_api_shape_check import InconsistentNdimErrorMultipleSolutions, InconsistentNdimErrorNoSolutions, InconsistentShapeError
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="number of variables"):
... check_shapes("*i*j", (1, 1))
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="rank"):
... check_shapes("*i*j,*i*j", (1, 1), (1, 1))
No solution to determine variable subscript ndims:
>>> with pytest.raises(InconsistentNdimErrorNoSolutions, match="residuals"):
... check_shapes("*i,*i", (1, 1), (1, 1, 1))
>>> with pytest.raises(InconsistentNdimErrorNoSolutions, match="negative"):
... check_shapes("*ij", ())
Does not match:
>>> with pytest.raises(InconsistentShapeError):
... check_shapes("ij,*k*l,*li", (3, 4), (5, 6), (1, 7, 3))
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Copier and the browniebroke/pypackage-template project template.
Metadata
Release files for array-api-shape-check 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| array_api_shape_check-1.0.0.tar.gz | 9.7 kB | With provenance | Details for array_api_shape_check-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| array_api_shape_check-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for array_api_shape_check-1.0.0-py3-none-any.whl |
Total release size: 18.3 kB
Release files / array_api_shape_check-1.0.0.tar.gz
| Download URL | array_api_shape_check-1.0.0.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d50590424760e011044b1c4e60058abf3c3524fe3ec88e7065f67d7d946a56ad
|
|
BLAKE2b-256 checksum How to use checksums |
6ca4cd7bb168fca1c01e6e1e888f78c6f9248371f205676d03b1f6c05b52f847
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logRelease files / array_api_shape_check-1.0.0-py3-none-any.whl
| Download URL | array_api_shape_check-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ddc5f6cd682a91c0b74520fb8af4e89ed607d4d729aea8659dcacaf01ac6eb51
|
|
BLAKE2b-256 checksum How to use checksums |
9eb747a4dfb670bd816c15185272c94d29c3dc4ebc0cfe739b7dcb0b1d4d9985
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logSecurity for array-api-shape-check 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for array_api_shape_check-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.