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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: array-api-shape-check
3
- Version: 0.1.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
- (i:3, j:4, *k:(5,), *l:(6, 7))
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
- (i:3, j:4, *k:(5,), *l:(6, 7))
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.
@@ -4,7 +4,7 @@ requires = [ "setuptools>=77.0.3" ]
4
4
 
5
5
  [project]
6
6
  name = "array-api-shape-check"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Check shapes of input arrays easily"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.1"
1
+ __version__ = "0.1.2"
2
2
  from ._main import (
3
3
  InconsistentNdimError,
4
4
  InconsistentNdimErrorMultipleSolutions,
@@ -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: tuple[SubscriptInfoFromSubcriptItem, ...]
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: tuple[SubscriptInfoFromShapeItemUnique, ...]
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
- SubscriptInfoFromSubcript(all=((i, j), (*k, *l), (*l, i)), unique=(i, j, *k, *l))
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: set[SubscriptInfoFromSubcriptItem] = {
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 = [subscript for subscript in info.unique if subscript.is_variable]
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
- (i:3, j:4, *k:(5,), *l:(6, 7))
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, unique=tuple(sorted(info_unique, key=lambda x: x.name))
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.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
- (i:3, j:4, *k:(5,), *l:(6, 7))
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.