|
7 | 7 | from typing import Any, Protocol, runtime_checkable |
8 | 8 |
|
9 | 9 | try: |
10 | | - from typing import ParamSpec, TypeAlias |
| 10 | + from typing import ParamSpec, TypeAlias, Union |
11 | 11 | except ImportError: |
12 | | - from typing_extensions import ParamSpec, TypeAlias |
| 12 | + from typing_extensions import ParamSpec, TypeAlias, Union |
| 13 | + |
| 14 | +import numpy as np |
13 | 15 |
|
14 | 16 | import jax |
15 | 17 | from jax.typing import ArrayLike |
|
20 | 22 | Message: TypeAlias = dict[str, Any] |
21 | 23 | TraceT: TypeAlias = OrderedDict[str, Message] |
22 | 24 |
|
| 25 | +# ArrayLike type has StaticScalar, StrictArrayT has everything except StaticScalars |
| 26 | +StrictArrayT: TypeAlias = Union[np.ndarray, jax.Array] |
| 27 | + |
23 | 28 |
|
24 | 29 | @runtime_checkable |
25 | 30 | class ConstraintT(Protocol): |
@@ -87,20 +92,20 @@ def is_discrete(self) -> bool: ... |
87 | 92 |
|
88 | 93 | @runtime_checkable |
89 | 94 | class TransformT(Protocol): |
90 | | - domain = ConstraintT |
91 | | - codomain = ConstraintT |
| 95 | + domain: ConstraintT = ... |
| 96 | + codomain: ConstraintT = ... |
92 | 97 | _inv: "TransformT" = None |
93 | 98 |
|
94 | | - def __call__(self, x: ArrayLike) -> ArrayLike: ... |
95 | | - def _inverse(self, y: ArrayLike) -> ArrayLike: ... |
| 99 | + def __call__(self, x: jax.Array) -> jax.Array: ... |
| 100 | + def _inverse(self, y: jax.Array) -> jax.Array: ... |
96 | 101 | def log_abs_det_jacobian( |
97 | | - self, x: ArrayLike, y: ArrayLike, intermediates=None |
98 | | - ) -> ArrayLike: ... |
99 | | - def call_with_intermediates(self, x: ArrayLike) -> tuple[ArrayLike, None]: ... |
| 102 | + self, x: jax.Array, y: jax.Array, intermediates=None |
| 103 | + ) -> jax.Array: ... |
| 104 | + def call_with_intermediates(self, x: jax.Array) -> tuple[jax.Array, None]: ... |
100 | 105 | def forward_shape(self, shape: tuple[int, ...]) -> tuple[int, ...]: ... |
101 | 106 | def inverse_shape(self, shape: tuple[int, ...]) -> tuple[int, ...]: ... |
102 | 107 |
|
103 | 108 | @property |
104 | 109 | def inv(self) -> "TransformT": ... |
105 | 110 | @property |
106 | | - def sign(self) -> ArrayLike: ... |
| 111 | + def sign(self) -> jax.Array: ... |
0 commit comments