array-api-shape-check 0.1.3__py3-none-any.whl → 1.0.0__py3-none-any.whl

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,8 +1,9 @@
1
+ import inspect
1
2
  import re
2
3
  from collections import defaultdict
3
4
  from collections.abc import Sequence
4
5
  from itertools import groupby
5
- from typing import Any
6
+ from typing import Any, cast
6
7
 
7
8
  import attrs
8
9
  import numpy as np
@@ -34,8 +35,7 @@ class SubscriptInfoFromShapeItemUnchecked(SubscriptInfoFromSubcriptItem):
34
35
  def __repr__(self) -> str:
35
36
  if self.is_variable:
36
37
  return f"*{self.name}:{self.shape_current}"
37
- else:
38
- return f"{self.name}:{self.shape_current[0]}"
38
+ return f"{self.name}:{self.shape_current[0]}"
39
39
 
40
40
 
41
41
  @attrs.frozen(kw_only=True)
@@ -46,8 +46,7 @@ class SubscriptInfoFromShapeItemUnique(SubscriptInfoFromSubcriptItem):
46
46
  def __repr__(self) -> str:
47
47
  if self.is_variable:
48
48
  return f"*{self.name}:{self.shape_broadcasted}"
49
- else:
50
- return f"{self.name}:{self.shape_broadcasted[0]}"
49
+ return f"{self.name}:{self.shape_broadcasted[0]}"
51
50
 
52
51
 
53
52
  @attrs.frozen(kw_only=True)
@@ -60,10 +59,9 @@ class SubscriptInfoFromShapeItem(SubscriptInfoFromShapeItemUnchecked):
60
59
  if self.shape_current != self.shape_broadcasted:
61
60
  return f"*{self.name}:{self.shape_current}->{self.shape_broadcasted}"
62
61
  return f"*{self.name}:{self.shape_current}"
63
- else:
64
- if self.shape_current != self.shape_broadcasted:
65
- return f"{self.name}:{self.shape_current[0]}->{self.shape_broadcasted[0]}"
66
- return f"{self.name}:{self.shape_current[0]}"
62
+ if self.shape_current != self.shape_broadcasted:
63
+ return f"{self.name}:{self.shape_current[0]}->{self.shape_broadcasted[0]}"
64
+ return f"{self.name}:{self.shape_current[0]}"
67
65
 
68
66
 
69
67
  @attrs.frozen(kw_only=True)
@@ -82,7 +80,7 @@ class InconsistentNdimError(ValueError):
82
80
  reason: str
83
81
 
84
82
 
85
- class InconsistentNdimErrorMultipleSolutions(InconsistentNdimError):
83
+ class InconsistentNdimErrorMultipleSolutions(InconsistentNdimError): # noqa: N818
86
84
  def __init__(
87
85
  self, ndims: Sequence[int], reason: str, shapes: Sequence[int] | None = None
88
86
  ) -> None:
@@ -97,7 +95,7 @@ class InconsistentNdimErrorMultipleSolutions(InconsistentNdimError):
97
95
  )
98
96
 
99
97
 
100
- class InconsistentNdimErrorNoSolutions(InconsistentNdimError):
98
+ class InconsistentNdimErrorNoSolutions(InconsistentNdimError): # noqa: N818
101
99
  def __init__(
102
100
  self, ndims: Sequence[int], reason: str, shapes: Sequence[int] | None = None
103
101
  ) -> None:
@@ -121,8 +119,6 @@ class InconsistentShapeError(ValueError):
121
119
 
122
120
 
123
121
  def _get_operand_names(*operands: Any) -> list[str | None]:
124
- import inspect
125
-
126
122
  frame = inspect.currentframe()
127
123
  if frame is None:
128
124
  return [None] * len(operands)
@@ -236,6 +232,10 @@ def parse_variable_ndim(subscripts: str, ndims: Sequence[int], /) -> dict[str, i
236
232
  ------
237
233
  ValueError
238
234
  If the subscript is invalid.
235
+ InconsistentNdimErrorMultipleSolutions
236
+ If the variable dimensions cannot be uniquely determined.
237
+ InconsistentNdimErrorNoSolutions
238
+ If the variable dimensions have no valid solution.
239
239
 
240
240
  Examples
241
241
  --------
@@ -306,18 +306,19 @@ def _parse_shapes(
306
306
  )
307
307
  shapes: tuple[tuple[int, ...], ...] = ()
308
308
  for operand in operands:
309
- shape: tuple[int, ...] # type: ignore
310
309
  if isinstance(operand, tuple):
311
- shape = operand
310
+ if None in operand:
311
+ raise ValueError("Operand shape cannot contain None")
312
+ shape = cast("tuple[int, ...]", operand)
312
313
  elif hasattr(operand, "shape"):
313
314
  if None in operand.shape:
314
315
  raise ValueError("Operand shape cannot contain None")
315
- shape = operand.shape
316
+ shape = cast("tuple[int, ...]", operand.shape)
316
317
  else:
317
318
  raise TypeError(
318
319
  f"Invalid operand: expected an array or a shape tuple, but got {type(operand)}"
319
320
  )
320
- shapes += (shape,) # type: ignore
321
+ shapes += (shape,)
321
322
  del operands
322
323
  ndims = [len(shape) for shape in shapes]
323
324
  try:
@@ -336,7 +337,7 @@ def _parse_shapes(
336
337
  shape_current=shape[: name_to_ndim[item.name]],
337
338
  ),
338
339
  )
339
- shape = shape[name_to_ndim[item.name] :]
340
+ shape = shape[name_to_ndim[item.name] :] # noqa: PLW2901
340
341
  info_all += (info_array_new,)
341
342
  return info_all
342
343
 
@@ -373,6 +374,8 @@ def check_shapes(
373
374
  ------
374
375
  ValueError
375
376
  If the subscript is invalid.
377
+ InconsistentShapeError
378
+ If the operand shapes are inconsistent.
376
379
 
377
380
  Examples
378
381
  --------
@@ -450,7 +453,7 @@ def check_shapes(
450
453
  name=item.name,
451
454
  is_variable=item.is_variable,
452
455
  shape_current=item.shape_current,
453
- shape_broadcasted=shape_broadcasted.get(item.name), # type: ignore
456
+ shape_broadcasted=shape_broadcasted[item.name],
454
457
  ),
455
458
  )
456
459
  info_all_new += (info_array_new,)
@@ -459,7 +462,7 @@ def check_shapes(
459
462
  SubscriptInfoFromShapeItemUnique(
460
463
  name=item.name,
461
464
  is_variable=item.is_variable,
462
- shape_broadcasted=shape_broadcasted.get(item.name), # type: ignore
465
+ shape_broadcasted=shape_broadcasted[item.name],
463
466
  )
464
467
  for info_array in info_all_new
465
468
  for item in info_array
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: array-api-shape-check
3
- Version: 0.1.3
3
+ Version: 1.0.0
4
4
  Summary: Check shapes of input arrays easily
5
- Author-email: 34j <34j.95a2p@simplelogin.com>
5
+ Author: 34j
6
6
  License-Expression: MIT
7
7
  Project-URL: Bug Tracker, https://github.com/34j/array-api-shape-check/issues
8
8
  Project-URL: Changelog, https://github.com/34j/array-api-shape-check/blob/main/CHANGELOG.md
@@ -0,0 +1,8 @@
1
+ array_api_shape_check/__init__.py,sha256=8i9ZV_x6HXtVd0g7N3ec190lQ1LUC2s93A9p-J3C9WI,940
2
+ array_api_shape_check/_main.py,sha256=VXDxm8ds6mjq9qiJ4BFNWJWXxjBZKMXZ7WafYvuICt4,16965
3
+ array_api_shape_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ array_api_shape_check-1.0.0.dist-info/licenses/LICENSE,sha256=Otwb96xcK4QBqXXVdBKpLZVnc4mJuFTa8rsMUEpphMM,1061
5
+ array_api_shape_check-1.0.0.dist-info/METADATA,sha256=6cj-qjtOx_MV44WBn5-mLIY2XnChx71cQNG8V_74jQY,6179
6
+ array_api_shape_check-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ array_api_shape_check-1.0.0.dist-info/top_level.txt,sha256=pirw2DeaWnDU_rSg3CZ1MsE-tJWEvndYSQG0illDMkI,22
8
+ array_api_shape_check-1.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- array_api_shape_check/__init__.py,sha256=8i9ZV_x6HXtVd0g7N3ec190lQ1LUC2s93A9p-J3C9WI,940
2
- array_api_shape_check/_main.py,sha256=LqwDK6OD9ldcUaXmmbG5aBXzOW0gEJuu1iAe9rs2BiY,16652
3
- array_api_shape_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- array_api_shape_check-0.1.3.dist-info/licenses/LICENSE,sha256=Otwb96xcK4QBqXXVdBKpLZVnc4mJuFTa8rsMUEpphMM,1061
5
- array_api_shape_check-0.1.3.dist-info/METADATA,sha256=of_gXs9JcFp-b0KQwa9Sbf8GIXPvChmU5VGfvBWyYOQ,6213
6
- array_api_shape_check-0.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
- array_api_shape_check-0.1.3.dist-info/top_level.txt,sha256=pirw2DeaWnDU_rSg3CZ1MsE-tJWEvndYSQG0illDMkI,22
8
- array_api_shape_check-0.1.3.dist-info/RECORD,,