Check shapes of input arrays easily
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file array_api_shape_check-0.1.3.tar.gz.
File metadata
- Download URL: array_api_shape_check-0.1.3.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
345d56dcf9155dff338c248e558841d45dbeb3ba5456322335af6fd094b80606
|
|
| MD5 |
5347f904209cc6b41ec9970f517787c8
|
|
| BLAKE2b-256 |
67818732832017719199207b556cb1b65452b3a56985f7dcc0c77bf0803eb4cc
|
Provenance
The following attestation bundles were made for array_api_shape_check-0.1.3.tar.gz:
Publisher:
ci.yml on 34j/array-api-shape-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
array_api_shape_check-0.1.3.tar.gz -
Subject digest:
345d56dcf9155dff338c248e558841d45dbeb3ba5456322335af6fd094b80606 - Sigstore transparency entry: 1521809430
- Sigstore integration time:
-
Permalink:
34j/array-api-shape-check@f87c862420435e07dfc3593979f399e73dd4ba94 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f87c862420435e07dfc3593979f399e73dd4ba94 -
Trigger Event:
push
-
Statement type:
File details
Details for the file array_api_shape_check-0.1.3-py3-none-any.whl.
File metadata
- Download URL: array_api_shape_check-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
778feb8ef2e71aa436de940a7bec3c5d82f5aa0a17daf57dfb4a339a3770104b
|
|
| MD5 |
91ba85d12099001d8943d6e2d24cb24e
|
|
| BLAKE2b-256 |
830738fc496989e7eac9cb63f52988a6653bedf9a3a11fbdce80b4282d54d131
|
Provenance
The following attestation bundles were made for array_api_shape_check-0.1.3-py3-none-any.whl:
Publisher:
ci.yml on 34j/array-api-shape-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
array_api_shape_check-0.1.3-py3-none-any.whl -
Subject digest:
778feb8ef2e71aa436de940a7bec3c5d82f5aa0a17daf57dfb4a339a3770104b - Sigstore transparency entry: 1521809442
- Sigstore integration time:
-
Permalink:
34j/array-api-shape-check@f87c862420435e07dfc3593979f399e73dd4ba94 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f87c862420435e07dfc3593979f399e73dd4ba94 -
Trigger Event:
push
-
Statement type: