array-api-shape-check 0.1.1__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.1/src/array_api_shape_check.egg-info → array_api_shape_check-0.1.2}/PKG-INFO +2 -2
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/README.md +1 -1
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/pyproject.toml +1 -1
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/src/array_api_shape_check/__init__.py +1 -1
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/src/array_api_shape_check/_main.py +17 -13
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2/src/array_api_shape_check.egg-info}/PKG-INFO +2 -2
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/LICENSE +0 -0
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/setup.cfg +0 -0
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/src/array_api_shape_check/py.typed +0 -0
- {array_api_shape_check-0.1.1 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/SOURCES.txt +0 -0
- {array_api_shape_check-0.1.1 → 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.1 → array_api_shape_check-0.1.2}/src/array_api_shape_check.egg-info/requires.txt +0 -0
- {array_api_shape_check-0.1.1 → 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.1 → 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.
|
|
@@ -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.
|
{array_api_shape_check-0.1.1 → 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,7 +366,7 @@ 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)}
|
|
367
370
|
|
|
368
371
|
Internally `check_shapes()` calls `parse_variable_ndim()`,
|
|
369
372
|
which determines the number of dimensions for variable subscripts by least squares.
|
|
@@ -448,7 +451,8 @@ def check_shapes(
|
|
|
448
451
|
for item in info_array
|
|
449
452
|
}
|
|
450
453
|
result = SubscriptInfoFromShape(
|
|
451
|
-
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)},
|
|
452
456
|
)
|
|
453
457
|
|
|
454
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.
|
|
File without changes
|
|
File without changes
|
{array_api_shape_check-0.1.1 → 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
|