epymorph 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.
Files changed (104) hide show
  1. epymorph/__init__.py +7 -0
  2. epymorph/__main__.py +16 -0
  3. epymorph/adrio/__init__.py +0 -0
  4. epymorph/adrio/acs5.py +1378 -0
  5. epymorph/adrio/adrio.py +953 -0
  6. epymorph/adrio/cdc.py +1826 -0
  7. epymorph/adrio/commuting_flows.py +283 -0
  8. epymorph/adrio/csv.py +499 -0
  9. epymorph/adrio/humidity.py +206 -0
  10. epymorph/adrio/lodes.py +509 -0
  11. epymorph/adrio/numpy.py +160 -0
  12. epymorph/adrio/prism.py +345 -0
  13. epymorph/adrio/processing.py +1221 -0
  14. epymorph/adrio/soda.py +602 -0
  15. epymorph/adrio/us_tiger.py +289 -0
  16. epymorph/adrio/validation.py +382 -0
  17. epymorph/attribute.py +614 -0
  18. epymorph/cache.py +680 -0
  19. epymorph/cli/__init__.py +0 -0
  20. epymorph/cli/cache.py +78 -0
  21. epymorph/cli/main.py +29 -0
  22. epymorph/compartment_model.py +1873 -0
  23. epymorph/data/__init__.py +1 -0
  24. epymorph/data/ipm/__init__.py +22 -0
  25. epymorph/data/ipm/no.py +14 -0
  26. epymorph/data/ipm/pei.py +40 -0
  27. epymorph/data/ipm/seirs.py +50 -0
  28. epymorph/data/ipm/sirh.py +55 -0
  29. epymorph/data/ipm/sirs.py +48 -0
  30. epymorph/data/ipm/sparsemod.py +96 -0
  31. epymorph/data/mm/__init__.py +22 -0
  32. epymorph/data/mm/centroids.py +76 -0
  33. epymorph/data/mm/flat.py +61 -0
  34. epymorph/data/mm/icecube.py +50 -0
  35. epymorph/data/mm/no.py +29 -0
  36. epymorph/data/mm/pei.py +105 -0
  37. epymorph/data/mm/sparsemod.py +73 -0
  38. epymorph/data/pei.py +424 -0
  39. epymorph/data_shape.py +593 -0
  40. epymorph/data_type.py +185 -0
  41. epymorph/data_usage.py +258 -0
  42. epymorph/database.py +1301 -0
  43. epymorph/error.py +195 -0
  44. epymorph/event.py +196 -0
  45. epymorph/geography/__init__.py +0 -0
  46. epymorph/geography/custom.py +93 -0
  47. epymorph/geography/scope.py +457 -0
  48. epymorph/geography/us_census.py +1056 -0
  49. epymorph/geography/us_geography.py +502 -0
  50. epymorph/geography/us_tiger.py +1083 -0
  51. epymorph/initializer.py +786 -0
  52. epymorph/kit.py +107 -0
  53. epymorph/log/__init__.py +0 -0
  54. epymorph/log/file.py +128 -0
  55. epymorph/log/messaging.py +139 -0
  56. epymorph/log/movement.py +228 -0
  57. epymorph/movement_model.py +347 -0
  58. epymorph/parameter_fitting/__init__.py +0 -0
  59. epymorph/parameter_fitting/distribution.py +68 -0
  60. epymorph/parameter_fitting/dynamics.py +19 -0
  61. epymorph/parameter_fitting/filter/__init__.py +0 -0
  62. epymorph/parameter_fitting/filter/base_filter.py +50 -0
  63. epymorph/parameter_fitting/filter/particle.py +32 -0
  64. epymorph/parameter_fitting/filter/particle_filter.py +296 -0
  65. epymorph/parameter_fitting/likelihood.py +54 -0
  66. epymorph/parameter_fitting/output.py +73 -0
  67. epymorph/parameter_fitting/particlefilter_simulation.py +175 -0
  68. epymorph/parameter_fitting/perturbation.py +19 -0
  69. epymorph/parameter_fitting/utils/__init__.py +0 -0
  70. epymorph/parameter_fitting/utils/data_loader.py +97 -0
  71. epymorph/parameter_fitting/utils/epymorph_simulation.py +119 -0
  72. epymorph/parameter_fitting/utils/observations.py +63 -0
  73. epymorph/parameter_fitting/utils/parameter_estimation.py +49 -0
  74. epymorph/parameter_fitting/utils/params_perturb.py +43 -0
  75. epymorph/parameter_fitting/utils/particle_initializer.py +95 -0
  76. epymorph/parameter_fitting/utils/resampler.py +258 -0
  77. epymorph/parameter_fitting/utils/utils.py +101 -0
  78. epymorph/params.py +438 -0
  79. epymorph/py.typed +0 -0
  80. epymorph/rume.py +871 -0
  81. epymorph/simulation.py +991 -0
  82. epymorph/simulator/__init__.py +0 -0
  83. epymorph/simulator/basic/__init__.py +0 -0
  84. epymorph/simulator/basic/basic_simulator.py +171 -0
  85. epymorph/simulator/basic/ipm_exec.py +437 -0
  86. epymorph/simulator/basic/mm_exec.py +244 -0
  87. epymorph/simulator/basic/output.py +213 -0
  88. epymorph/simulator/world.py +149 -0
  89. epymorph/simulator/world_list.py +274 -0
  90. epymorph/strata.py +24 -0
  91. epymorph/sympy_shim.py +57 -0
  92. epymorph/time.py +1197 -0
  93. epymorph/tools/__init__.py +0 -0
  94. epymorph/tools/data.py +297 -0
  95. epymorph/tools/ipm_diagram.py +208 -0
  96. epymorph/tools/out_map.py +551 -0
  97. epymorph/tools/out_plot.py +423 -0
  98. epymorph/tools/out_table.py +582 -0
  99. epymorph/util.py +1036 -0
  100. epymorph-1.0.0.dist-info/METADATA +57 -0
  101. epymorph-1.0.0.dist-info/RECORD +104 -0
  102. epymorph-1.0.0.dist-info/WHEEL +5 -0
  103. epymorph-1.0.0.dist-info/entry_points.txt +2 -0
  104. epymorph-1.0.0.dist-info/top_level.txt +1 -0
epymorph/data_shape.py ADDED
@@ -0,0 +1,593 @@
1
+ """
2
+ Expression of the shape of numpy data whose dimensions can be relative to a
3
+ simulation context. Provides utilities to declare, check, and adapt data dimensionality.
4
+ """
5
+
6
+ from abc import ABC, abstractmethod
7
+ from dataclasses import dataclass
8
+ from typing import ClassVar, Protocol, TypeVar
9
+
10
+ import numpy as np
11
+ from numpy.typing import NDArray
12
+ from typing_extensions import override
13
+
14
+ from epymorph.error import DimensionError
15
+ from epymorph.util import Matcher
16
+
17
+
18
+ class Dimensions(Protocol):
19
+ """
20
+ Stores the lengths of simulation dimensions which are supported by `DataShapes`.
21
+
22
+ See Also
23
+ --------
24
+ Concrete implementations [epymorph.data_shape.CompleteDimensions][] and
25
+ [epymorph.data_shape.PartialDimensions][] exist to enable cases where
26
+ either all or only some of the dimensions are specified.
27
+ """
28
+
29
+ @property
30
+ @abstractmethod
31
+ def T(self) -> int:
32
+ """The number of days."""
33
+
34
+ @property
35
+ @abstractmethod
36
+ def N(self) -> int:
37
+ """The number of nodes."""
38
+
39
+ @property
40
+ @abstractmethod
41
+ def C(self) -> int:
42
+ """The number of compartments."""
43
+
44
+ @property
45
+ @abstractmethod
46
+ def E(self) -> int:
47
+ """The number of events."""
48
+
49
+ @staticmethod
50
+ def of(
51
+ *,
52
+ T: int | None = None,
53
+ N: int | None = None,
54
+ C: int | None = None,
55
+ E: int | None = None,
56
+ ) -> "Dimensions":
57
+ """
58
+ Construct either a `CompleteDimensions` or `PartialDimensions` instance,
59
+ depending on whether or not the dimensions are fully specified.
60
+
61
+ Parameters
62
+ ----------
63
+ T :
64
+ The number of simulation days, if known.
65
+ N :
66
+ The number of geo nodes, if known.
67
+ C :
68
+ The number of compartments in the disease model, if known.
69
+ E :
70
+ The number of events in the disease model, if known.
71
+
72
+ Returns
73
+ -------
74
+ :
75
+ A new `Dimensions` instance (either complete or partial).
76
+ """
77
+ if T is not None and N is not None and C is not None and E is not None:
78
+ return CompleteDimensions(T=T, N=N, C=C, E=E)
79
+ return PartialDimensions(T=T, N=N, C=C, E=E)
80
+
81
+
82
+ class PartialDimensions(Dimensions):
83
+ """
84
+ A `Dimensions` implementation where some dimensions are unknown.
85
+ If code accesses an unspecified dimension, `DimensionError` is raised.
86
+ """
87
+
88
+ _T: int | None
89
+ _N: int | None
90
+ _C: int | None
91
+ _E: int | None
92
+
93
+ def __init__(
94
+ self,
95
+ *,
96
+ T: int | None = None,
97
+ N: int | None = None,
98
+ C: int | None = None,
99
+ E: int | None = None,
100
+ ):
101
+ self._T = T
102
+ self._N = N
103
+ self._C = C
104
+ self._E = E
105
+
106
+ @property
107
+ @override
108
+ def T(self):
109
+ if self._T is None:
110
+ raise DimensionError("We need dimension T but it was not provided.")
111
+ return self._T
112
+
113
+ @property
114
+ @override
115
+ def N(self):
116
+ if self._N is None:
117
+ raise DimensionError("We need dimension N but it was not provided.")
118
+ return self._N
119
+
120
+ @property
121
+ @override
122
+ def C(self):
123
+ if self._C is None:
124
+ raise DimensionError("We need dimension C but it was not provided.")
125
+ return self._C
126
+
127
+ @property
128
+ @override
129
+ def E(self):
130
+ if self._E is None:
131
+ raise DimensionError("We need dimension E but it was not provided.")
132
+ return self._E
133
+
134
+
135
+ class CompleteDimensions(Dimensions):
136
+ """A Dimensions instance where all dimensions are known."""
137
+
138
+ _T: int
139
+ _N: int
140
+ _C: int
141
+ _E: int
142
+
143
+ def __init__(
144
+ self,
145
+ *,
146
+ T: int,
147
+ N: int,
148
+ C: int,
149
+ E: int,
150
+ ):
151
+ self._T = T
152
+ self._N = N
153
+ self._C = C
154
+ self._E = E
155
+
156
+ @property
157
+ @override
158
+ def T(self):
159
+ return self._T
160
+
161
+ @property
162
+ @override
163
+ def N(self):
164
+ return self._N
165
+
166
+ @property
167
+ @override
168
+ def C(self):
169
+ return self._C
170
+
171
+ @property
172
+ @override
173
+ def E(self):
174
+ return self._E
175
+
176
+
177
+ DataT = TypeVar("DataT", bound=np.generic)
178
+ """The dtype of a numpy array."""
179
+
180
+
181
+ class DataShape(ABC):
182
+ """Description of a data attribute's shape relative to the simulation context."""
183
+
184
+ @abstractmethod
185
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
186
+ """
187
+ Return a tuple with the lengths of the dimensions in this shape.
188
+
189
+ Parameters
190
+ ----------
191
+ dim :
192
+ Information about the simulation context's dimensions.
193
+
194
+ Returns
195
+ -------
196
+ :
197
+ The absolute size of this shape in the given context. If an axis is of
198
+ indeterminate length, it is represented as -1.
199
+ """
200
+
201
+ @abstractmethod
202
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
203
+ """
204
+ Check if the given value matches this shape expression.
205
+
206
+ Parameters
207
+ ----------
208
+ dim :
209
+ Information about the simulation context's dimensions.
210
+ value :
211
+ The numpy array to check.
212
+
213
+ Returns
214
+ -------
215
+ :
216
+ True if the array's shape matches this shape description in the given
217
+ context.
218
+ """
219
+
220
+ @abstractmethod
221
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
222
+ """
223
+ Adapt the given value to this shape.
224
+
225
+ Note that this shape adaptation is more permissive than standard numpy
226
+ broadcasting.
227
+
228
+ Parameters
229
+ ----------
230
+ dim :
231
+ Information about the simulation context's dimensions.
232
+ value :
233
+ The numpy array to reshape.
234
+
235
+ Returns
236
+ -------
237
+ :
238
+ The reshaped array (may be a view).
239
+
240
+ Raises
241
+ ------
242
+ ValueError
243
+ If the array cannot be adapted.
244
+ """
245
+
246
+
247
+ @dataclass(frozen=True)
248
+ class Scalar(DataShape):
249
+ """A scalar value."""
250
+
251
+ @override
252
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
253
+ return ()
254
+
255
+ @override
256
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
257
+ return value.shape == tuple()
258
+
259
+ @override
260
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
261
+ if not self.matches(dim, value):
262
+ raise ValueError("Not able to adapt shape.")
263
+ return value
264
+
265
+ def __str__(self):
266
+ return "S"
267
+
268
+
269
+ @dataclass(frozen=True)
270
+ class Time(DataShape):
271
+ """An array of at least size T: the number of simulation days."""
272
+
273
+ @override
274
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
275
+ return (dim.T,)
276
+
277
+ @override
278
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
279
+ if value.ndim == 1 and value.shape[0] >= dim.T:
280
+ return True
281
+ if value.shape == tuple():
282
+ return True
283
+ return False
284
+
285
+ @override
286
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
287
+ if value.ndim == 1 and value.shape[0] >= dim.T:
288
+ return value[: dim.T]
289
+ if value.shape == tuple():
290
+ return np.broadcast_to(value, shape=(dim.T,))
291
+ raise ValueError("Not able to adapt shape.")
292
+
293
+ def __str__(self):
294
+ return "T"
295
+
296
+
297
+ @dataclass(frozen=True)
298
+ class Node(DataShape):
299
+ """An array of size N: the number of simulation nodes."""
300
+
301
+ @override
302
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
303
+ return (dim.N,)
304
+
305
+ @override
306
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
307
+ if value.ndim == 1 and value.shape[0] == dim.N:
308
+ return True
309
+ if value.shape == tuple():
310
+ return True
311
+ return False
312
+
313
+ @override
314
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
315
+ if value.ndim == 1 and value.shape[0] == dim.N:
316
+ return value
317
+ if value.shape == tuple():
318
+ return np.broadcast_to(value, shape=(dim.N,))
319
+ raise ValueError("Not able to adapt shape.")
320
+
321
+ def __str__(self):
322
+ return "N"
323
+
324
+
325
+ @dataclass(frozen=True)
326
+ class NodeAndNode(DataShape):
327
+ """An array of size NxN: a square of the number of simulation nodes."""
328
+
329
+ @override
330
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
331
+ return (dim.N, dim.N)
332
+
333
+ @override
334
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
335
+ shape = self.to_tuple(dim)
336
+ if value.shape == shape:
337
+ return True
338
+ if value.shape == tuple():
339
+ return True
340
+ return False
341
+
342
+ @override
343
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
344
+ shape = self.to_tuple(dim)
345
+ if value.shape == shape:
346
+ return value
347
+ if value.shape == tuple():
348
+ return np.broadcast_to(value, shape=shape)
349
+ raise ValueError("Not able to adapt shape.")
350
+
351
+ def __str__(self):
352
+ return "NxN"
353
+
354
+
355
+ @dataclass(frozen=True)
356
+ class NodeAndCompartment(DataShape):
357
+ """
358
+ An array of size NxC: the number of simulation nodes by the number of disease
359
+ compartments.
360
+ """
361
+
362
+ @override
363
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
364
+ return (dim.N, dim.C)
365
+
366
+ @override
367
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
368
+ N, C = self.to_tuple(dim)
369
+ if value.shape == (N, C):
370
+ return True
371
+ if value.shape == tuple():
372
+ return True
373
+ if value.shape == (N,):
374
+ return True
375
+ if value.shape == (C,):
376
+ return True
377
+ return False
378
+
379
+ @override
380
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
381
+ N, C = self.to_tuple(dim)
382
+ if value.shape == (N, C):
383
+ return value
384
+ if value.shape == tuple():
385
+ return np.broadcast_to(value, shape=(N, C))
386
+ if value.shape == (N,):
387
+ return np.broadcast_to(value[:, np.newaxis], shape=(N, C))
388
+ if value.shape == (C,):
389
+ return np.broadcast_to(value, shape=(N, C))
390
+ raise ValueError("Not able to adapt shape.")
391
+
392
+ def __str__(self):
393
+ return "NxC"
394
+
395
+
396
+ @dataclass(frozen=True)
397
+ class TimeAndNode(DataShape):
398
+ """
399
+ An array of size at-least-T by exactly-N: T is the number of simulation days
400
+ and N is the number of simulation nodes.
401
+ """
402
+
403
+ @override
404
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
405
+ return (dim.T, dim.N)
406
+
407
+ @override
408
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
409
+ T, N = self.to_tuple(dim)
410
+ if value.ndim == 2 and value.shape[0] >= T and value.shape[1] == N:
411
+ return True
412
+ if value.shape == tuple():
413
+ return True
414
+ if value.shape == (N,):
415
+ return True
416
+ if value.ndim == 1 and value.shape[0] >= T:
417
+ return True
418
+ return False
419
+
420
+ @override
421
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
422
+ T, N = self.to_tuple(dim)
423
+ if value.ndim == 2 and value.shape[0] >= T and value.shape[1] == N:
424
+ return value[:T, :]
425
+ if value.shape == tuple():
426
+ return np.broadcast_to(value, shape=(T, N))
427
+ if value.shape == (N,):
428
+ return np.broadcast_to(value, shape=(T, N))
429
+ if value.ndim == 1 and value.shape[0] >= T:
430
+ return np.broadcast_to(value[:T, np.newaxis], shape=(T, N))
431
+ raise ValueError("Not able to adapt shape.")
432
+
433
+ def __str__(self):
434
+ return "TxN"
435
+
436
+
437
+ @dataclass(frozen=True)
438
+ class NodeAndArbitrary(DataShape):
439
+ """An array of size exactly-N by any dimension: N is the number of geo nodes."""
440
+
441
+ @override
442
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
443
+ return (dim.N, -1)
444
+
445
+ @override
446
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
447
+ if value.ndim == 2 and value.shape[0] == dim.N:
448
+ return True
449
+ return False
450
+
451
+ @override
452
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
453
+ if self.matches(dim, value):
454
+ return value
455
+ raise ValueError("Not able to adapt shape.")
456
+
457
+ def __str__(self):
458
+ return "NxA"
459
+
460
+
461
+ @dataclass(frozen=True)
462
+ class ArbitraryAndNode(DataShape):
463
+ """An array of size any dimension by exactly-N: N is the number of geo nodes."""
464
+
465
+ @override
466
+ def to_tuple(self, dim: Dimensions) -> tuple[int, ...]:
467
+ return (-1, dim.N)
468
+
469
+ @override
470
+ def matches(self, dim: Dimensions, value: NDArray) -> bool:
471
+ if value.ndim == 2 and value.shape[1] == dim.N:
472
+ return True
473
+ return False
474
+
475
+ @override
476
+ def adapt(self, dim: Dimensions, value: NDArray[DataT]) -> NDArray[DataT]:
477
+ if self.matches(dim, value):
478
+ return value
479
+ raise ValueError("Not able to adapt shape.")
480
+
481
+ def __str__(self):
482
+ return "AxN"
483
+
484
+
485
+ @dataclass(frozen=True)
486
+ class Shapes:
487
+ """
488
+ Static instances for all available shapes.
489
+
490
+ Data can be in any of these shapes, where:
491
+
492
+ - Scalar is a single scalar value
493
+ - T is the number of days
494
+ - N is the number of nodes
495
+ - C is the number of IPM compartments
496
+ - A is any length (arbitrary; this dimension is effectively unchecked)
497
+ """
498
+
499
+ # Note: epymorph.simulation.validate_context_for_shape must be updated
500
+ # when adding new axes designations.
501
+
502
+ Scalar: ClassVar = Scalar()
503
+ T: ClassVar = Time()
504
+ N: ClassVar = Node()
505
+ NxC: ClassVar = NodeAndCompartment()
506
+ NxN: ClassVar = NodeAndNode()
507
+ TxN: ClassVar = TimeAndNode()
508
+ NxA: ClassVar = NodeAndArbitrary()
509
+ AxN: ClassVar = ArbitraryAndNode()
510
+
511
+
512
+ def parse_shape(shape: str) -> DataShape:
513
+ """
514
+ Attempt to parse `DataShape` from a shape expression string.
515
+
516
+ Parameters
517
+ ----------
518
+ shape :
519
+ The shape expression string.
520
+
521
+ Returns
522
+ -------
523
+ :
524
+ The `DataShape` instance, if valid.
525
+
526
+ Raises
527
+ ------
528
+ ValueError
529
+ If the string is not a supported shape.
530
+ """
531
+ match shape:
532
+ case "Scalar":
533
+ return Shapes.Scalar
534
+ case "T":
535
+ return Shapes.T
536
+ case "N":
537
+ return Shapes.N
538
+ case "NxC":
539
+ return Shapes.NxC
540
+ case "NxN":
541
+ return Shapes.NxN
542
+ case "TxN":
543
+ return Shapes.TxN
544
+ case "NxA":
545
+ return Shapes.NxA
546
+ case "AxN":
547
+ return Shapes.AxN
548
+ case _:
549
+ raise ValueError(f"'{shape}' is not a valid shape specification.")
550
+
551
+
552
+ class DataShapeMatcher(Matcher[NDArray]):
553
+ """
554
+ A `Matcher` which checks whether an array is adaptable to `shape` under the given
555
+ dimensions (`dim`).
556
+
557
+ Parameters
558
+ ----------
559
+ shape :
560
+ The data shape to match.
561
+ dim :
562
+ Information about the simulation context's dimensions.
563
+ exact :
564
+ If True, do not accept array adaptation, require that the array match exactly.
565
+ """
566
+
567
+ _shape: DataShape
568
+ _dim: Dimensions
569
+ _exact: bool
570
+
571
+ def __init__(self, shape: DataShape, dim: Dimensions, *, exact: bool = False):
572
+ self._shape = shape
573
+ self._dim = dim
574
+ self._exact = exact
575
+
576
+ @override
577
+ def expected(self) -> str:
578
+ return str(self._shape)
579
+
580
+ @override
581
+ def __call__(self, value: NDArray) -> bool:
582
+ if self._exact:
583
+ # If making an exact match, convert the expected shape to a tuple
584
+ # then see that the expected shape matches the value shape.
585
+ # They must have the same number of dimensions.
586
+ # A value of -1 in the expected tuple matches any value,
587
+ # this is to support shapes with Arbitrary dimensions.
588
+ expected = self._shape.to_tuple(self._dim)
589
+ return len(value.shape) == len(expected) and all(
590
+ True if exp == -1 else exp == act
591
+ for exp, act in zip(expected, value.shape)
592
+ )
593
+ return self._shape.matches(self._dim, value)