array-api-shape-check 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {array_api_shape_check-0.1.0/src/array_api_shape_check.egg-info → array_api_shape_check-0.1.2}/PKG-INFO +3 -9
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/README.md +2 -8
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/pyproject.toml +1 -1
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check/__init__.py +1 -1
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check/_main.py +35 -20
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2/src/array_api_shape_check.egg-info}/PKG-INFO +3 -9
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/LICENSE +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/setup.cfg +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check/py.typed +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/SOURCES.txt +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/dependency_links.txt +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/requires.txt +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/top_level.txt +0 -0
- {array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/tests/test_main.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: array-api-shape-check
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Check shapes of input arrays easily
|
|
5
5
|
Author-email: 34j <34j.95a2p@simplelogin.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -82,7 +82,7 @@ Install this via pip (or your favourite package manager):
|
|
|
82
82
|
>>> info.all
|
|
83
83
|
((i:1->3, j:4), (*k:(5,), *l:(6, 7)), (*l:(1, 7)->(6, 7), i:3))
|
|
84
84
|
>>> info.unique
|
|
85
|
-
|
|
85
|
+
{'i': i:3, 'j': j:4, 'k': *k:(5,), 'l': *l:(6, 7)}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
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.
|
|
@@ -107,13 +107,7 @@ Not enough information to determine variable subscript ndims:
|
|
|
107
107
|
>>> import pytest
|
|
108
108
|
>>> from array_api_shape_check import InconsistentNdimErrorMultipleSolutions, InconsistentNdimErrorNoSolutions, InconsistentShapeError
|
|
109
109
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="number of variables"):
|
|
110
|
-
... check_shapes(
|
|
111
|
-
... "*i*j",
|
|
112
|
-
... (
|
|
113
|
-
... 1,
|
|
114
|
-
... 1,
|
|
115
|
-
... ),
|
|
116
|
-
... )
|
|
110
|
+
... check_shapes("*i*j", (1, 1))
|
|
117
111
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="rank"):
|
|
118
112
|
... check_shapes("*i*j,*i*j", (1, 1), (1, 1))
|
|
119
113
|
```
|
|
@@ -54,7 +54,7 @@ Install this via pip (or your favourite package manager):
|
|
|
54
54
|
>>> info.all
|
|
55
55
|
((i:1->3, j:4), (*k:(5,), *l:(6, 7)), (*l:(1, 7)->(6, 7), i:3))
|
|
56
56
|
>>> info.unique
|
|
57
|
-
|
|
57
|
+
{'i': i:3, 'j': j:4, 'k': *k:(5,), 'l': *l:(6, 7)}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
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.
|
|
@@ -79,13 +79,7 @@ Not enough information to determine variable subscript ndims:
|
|
|
79
79
|
>>> import pytest
|
|
80
80
|
>>> from array_api_shape_check import InconsistentNdimErrorMultipleSolutions, InconsistentNdimErrorNoSolutions, InconsistentShapeError
|
|
81
81
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="number of variables"):
|
|
82
|
-
... check_shapes(
|
|
83
|
-
... "*i*j",
|
|
84
|
-
... (
|
|
85
|
-
... 1,
|
|
86
|
-
... 1,
|
|
87
|
-
... ),
|
|
88
|
-
... )
|
|
82
|
+
... check_shapes("*i*j", (1, 1))
|
|
89
83
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="rank"):
|
|
90
84
|
... check_shapes("*i*j,*i*j", (1, 1), (1, 1))
|
|
91
85
|
```
|
{array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check/_main.py
RENAMED
|
@@ -23,7 +23,7 @@ class SubscriptInfoFromSubcriptItem:
|
|
|
23
23
|
@attrs.frozen(kw_only=True)
|
|
24
24
|
class SubscriptInfoFromSubcript:
|
|
25
25
|
all: tuple[tuple[SubscriptInfoFromSubcriptItem, ...], ...]
|
|
26
|
-
unique:
|
|
26
|
+
unique: dict[str, SubscriptInfoFromSubcriptItem]
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
@attrs.frozen(kw_only=True)
|
|
@@ -70,7 +70,7 @@ class SubscriptInfoFromShapeItem(SubscriptInfoFromShapeItemUnchecked):
|
|
|
70
70
|
class SubscriptInfoFromShape:
|
|
71
71
|
all: tuple[tuple[SubscriptInfoFromShapeItem, ...], ...]
|
|
72
72
|
"""The subscript info grouped by order, then by operand"""
|
|
73
|
-
unique:
|
|
73
|
+
unique: dict[str, SubscriptInfoFromShapeItemUnique]
|
|
74
74
|
"""The unique subscripts,
|
|
75
75
|
ignoring order and shapes not broadcasted,
|
|
76
76
|
sorted lexicographically by name"""
|
|
@@ -157,8 +157,11 @@ def parse_subscripts(subscripts: str, /) -> SubscriptInfoFromSubcript:
|
|
|
157
157
|
|
|
158
158
|
Examples
|
|
159
159
|
--------
|
|
160
|
-
>>> parse_subscripts("ij,*k*l,*li")
|
|
161
|
-
|
|
160
|
+
>>> info = parse_subscripts("ij,*k*l,*li")
|
|
161
|
+
>>> info.all
|
|
162
|
+
((i, j), (*k, *l), (*l, i))
|
|
163
|
+
>>> info.unique
|
|
164
|
+
{'i': i, 'j': j, 'k': *k, 'l': *l}
|
|
162
165
|
|
|
163
166
|
"""
|
|
164
167
|
# If . other than ...
|
|
@@ -181,9 +184,9 @@ def parse_subscripts(subscripts: str, /) -> SubscriptInfoFromSubcript:
|
|
|
181
184
|
is_variable = False
|
|
182
185
|
info_all += (info_array,)
|
|
183
186
|
|
|
184
|
-
info_unique
|
|
185
|
-
x for info_array in info_all for x in info_array
|
|
186
|
-
|
|
187
|
+
info_unique = tuple(
|
|
188
|
+
sorted({x for info_array in info_all for x in info_array}, key=lambda x: x.name)
|
|
189
|
+
)
|
|
187
190
|
# raise if there are subscripts with same name but different is_variable
|
|
188
191
|
names = set()
|
|
189
192
|
for info in info_unique:
|
|
@@ -193,9 +196,7 @@ def parse_subscripts(subscripts: str, /) -> SubscriptInfoFromSubcript:
|
|
|
193
196
|
)
|
|
194
197
|
names.add(info.name)
|
|
195
198
|
|
|
196
|
-
return SubscriptInfoFromSubcript(
|
|
197
|
-
all=info_all, unique=tuple(sorted(info_unique, key=lambda x: x.name))
|
|
198
|
-
)
|
|
199
|
+
return SubscriptInfoFromSubcript(all=info_all, unique={item.name: item for item in info_unique})
|
|
199
200
|
|
|
200
201
|
|
|
201
202
|
def parse_variable_ndim(subscripts: str, ndims: Sequence[int], /) -> dict[str, int]:
|
|
@@ -253,7 +254,9 @@ def parse_variable_ndim(subscripts: str, ndims: Sequence[int], /) -> dict[str, i
|
|
|
253
254
|
)
|
|
254
255
|
|
|
255
256
|
# decide dimensions by solving linear equations
|
|
256
|
-
info_variable_unique = [
|
|
257
|
+
info_variable_unique = [
|
|
258
|
+
subscript for subscript in info.unique.values() if subscript.is_variable
|
|
259
|
+
]
|
|
257
260
|
if len(info_variable_unique) > len(info.all):
|
|
258
261
|
raise InconsistentNdimErrorMultipleSolutions("number of variables")
|
|
259
262
|
rhs = np.asarray(ndims, dtype=int)
|
|
@@ -363,19 +366,30 @@ def check_shapes(
|
|
|
363
366
|
>>> info.all
|
|
364
367
|
((i:1->3, j:4), (*k:(5,), *l:(6, 7)), (*l:(1, 7)->(6, 7), i:3))
|
|
365
368
|
>>> info.unique
|
|
366
|
-
|
|
369
|
+
{'i': i:3, 'j': j:4, 'k': *k:(5,), 'l': *l:(6, 7)}
|
|
370
|
+
|
|
371
|
+
Internally `check_shapes()` calls `parse_variable_ndim()`,
|
|
372
|
+
which determines the number of dimensions for variable subscripts by least squares.
|
|
373
|
+
If this is successful, checks if each subscript is consistent,
|
|
374
|
+
then finnaly raises error for all inconsistencies at once.
|
|
375
|
+
|
|
376
|
+
Diving into the details of the first item:
|
|
377
|
+
|
|
378
|
+
>>> item = info.all[0][0]
|
|
379
|
+
>>> item.name # the name of the subscript
|
|
380
|
+
'i'
|
|
381
|
+
>>> item.is_variable # whether the subscript is variable (starts with "*")
|
|
382
|
+
False
|
|
383
|
+
>>> item.shape_current # the current shape of the subscript
|
|
384
|
+
(1,)
|
|
385
|
+
>>> item.shape_broadcasted # the broadcasted shape of the subscript
|
|
386
|
+
(3,)
|
|
367
387
|
|
|
368
388
|
Not enough information to determine variable subscript ndims:
|
|
369
389
|
|
|
370
390
|
>>> import pytest
|
|
371
391
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="number of variables"):
|
|
372
|
-
... check_shapes(
|
|
373
|
-
... "*i*j",
|
|
374
|
-
... (
|
|
375
|
-
... 1,
|
|
376
|
-
... 1,
|
|
377
|
-
... ),
|
|
378
|
-
... )
|
|
392
|
+
... check_shapes("*i*j", (1, 1))
|
|
379
393
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="rank"):
|
|
380
394
|
... check_shapes("*i*j,*i*j", (1, 1), (1, 1))
|
|
381
395
|
|
|
@@ -437,7 +451,8 @@ def check_shapes(
|
|
|
437
451
|
for item in info_array
|
|
438
452
|
}
|
|
439
453
|
result = SubscriptInfoFromShape(
|
|
440
|
-
all=info_all_new,
|
|
454
|
+
all=info_all_new,
|
|
455
|
+
unique={item.name: item for item in sorted(info_unique, key=lambda x: x.name)},
|
|
441
456
|
)
|
|
442
457
|
|
|
443
458
|
if errors:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: array-api-shape-check
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Check shapes of input arrays easily
|
|
5
5
|
Author-email: 34j <34j.95a2p@simplelogin.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -82,7 +82,7 @@ Install this via pip (or your favourite package manager):
|
|
|
82
82
|
>>> info.all
|
|
83
83
|
((i:1->3, j:4), (*k:(5,), *l:(6, 7)), (*l:(1, 7)->(6, 7), i:3))
|
|
84
84
|
>>> info.unique
|
|
85
|
-
|
|
85
|
+
{'i': i:3, 'j': j:4, 'k': *k:(5,), 'l': *l:(6, 7)}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
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.
|
|
@@ -107,13 +107,7 @@ Not enough information to determine variable subscript ndims:
|
|
|
107
107
|
>>> import pytest
|
|
108
108
|
>>> from array_api_shape_check import InconsistentNdimErrorMultipleSolutions, InconsistentNdimErrorNoSolutions, InconsistentShapeError
|
|
109
109
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="number of variables"):
|
|
110
|
-
... check_shapes(
|
|
111
|
-
... "*i*j",
|
|
112
|
-
... (
|
|
113
|
-
... 1,
|
|
114
|
-
... 1,
|
|
115
|
-
... ),
|
|
116
|
-
... )
|
|
110
|
+
... check_shapes("*i*j", (1, 1))
|
|
117
111
|
>>> with pytest.raises(InconsistentNdimErrorMultipleSolutions, match="rank"):
|
|
118
112
|
... check_shapes("*i*j,*i*j", (1, 1), (1, 1))
|
|
119
113
|
```
|
|
File without changes
|
|
File without changes
|
{array_api_shape_check-0.1.0 → array_api_shape_check-0.1.2}/src/array_api_shape_check/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|