jax-pyrefly-stubs 1.4.0.dev4__tar.gz → 1.5.0.dev1__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.
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/PKG-INFO +7 -6
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/README.md +4 -4
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/__init__.pyi +65 -4
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/_array.pyi +190 -4
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/_shapes.pyi +60 -12
- jax_pyrefly_stubs-1.5.0.dev1/jax-stubs/_src/basearray.pyi +10 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/lax/__init__.pyi +1 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/numpy/__init__.pyi +119 -44
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/random.pyi +3 -2
- jax_pyrefly_stubs-1.5.0.dev1/jax-stubs/sharding.pyi +36 -0
- jax_pyrefly_stubs-1.5.0.dev1/jax-stubs/typing.pyi +14 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/pyproject.toml +3 -2
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/LICENSE +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/lax/linalg.pyi +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/nn/__init__.pyi +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/nn/initializers.pyi +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/numpy/fft.pyi +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/numpy/linalg.pyi +0 -0
- {jax_pyrefly_stubs-1.4.0.dev4 → jax_pyrefly_stubs-1.5.0.dev1}/jax-stubs/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: jax-pyrefly-stubs
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0.dev1
|
|
4
4
|
Summary: JAX type stubs with array-shape tracking, maintained by Pyrefly
|
|
5
5
|
Project-URL: homepage, https://pyrefly.org
|
|
6
6
|
Project-URL: documentation, https://pyrefly.org/en/docs/
|
|
@@ -34,7 +34,8 @@ Classifier: Programming Language :: Python :: 3
|
|
|
34
34
|
Classifier: Typing :: Stubs Only
|
|
35
35
|
Requires-Python: >=3.12
|
|
36
36
|
Requires-Dist: jax
|
|
37
|
-
Requires-Dist: pyrefly-
|
|
37
|
+
Requires-Dist: pyrefly-numpy-stubs==1.5.0.dev1
|
|
38
|
+
Requires-Dist: pyrefly-shape-extensions==1.5.0.dev1
|
|
38
39
|
Description-Content-Type: text/markdown
|
|
39
40
|
|
|
40
41
|
# Pyrefly JAX shape stubs
|
|
@@ -42,10 +43,10 @@ Description-Content-Type: text/markdown
|
|
|
42
43
|
This package is a PEP 561 stub-only distribution. It installs the `jax-stubs`
|
|
43
44
|
stub package so Pyrefly can discover shape-aware stubs for the runtime `jax`
|
|
44
45
|
package without replacing or shadowing JAX itself. It is versioned in lockstep
|
|
45
|
-
with Pyrefly and depends on the matching `pyrefly-shape-extensions`
|
|
46
|
-
Installing it also installs `jax`, which provides
|
|
47
|
-
partial stubs. The `jax` dependency is unpinned,
|
|
48
|
-
JAX version.
|
|
46
|
+
with Pyrefly and depends on the matching `pyrefly-shape-extensions` and
|
|
47
|
+
`pyrefly-numpy-stubs` packages. Installing it also installs `jax`, which provides
|
|
48
|
+
upstream modules used by these partial stubs. The `jax` dependency is unpinned,
|
|
49
|
+
so projects can choose their own JAX version.
|
|
49
50
|
|
|
50
51
|
Shape-typed fixture stubs for a subset of JAX. This is a starting point for
|
|
51
52
|
working with the JAX core team rather than a complete model: it covers array
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
This package is a PEP 561 stub-only distribution. It installs the `jax-stubs`
|
|
4
4
|
stub package so Pyrefly can discover shape-aware stubs for the runtime `jax`
|
|
5
5
|
package without replacing or shadowing JAX itself. It is versioned in lockstep
|
|
6
|
-
with Pyrefly and depends on the matching `pyrefly-shape-extensions`
|
|
7
|
-
Installing it also installs `jax`, which provides
|
|
8
|
-
partial stubs. The `jax` dependency is unpinned,
|
|
9
|
-
JAX version.
|
|
6
|
+
with Pyrefly and depends on the matching `pyrefly-shape-extensions` and
|
|
7
|
+
`pyrefly-numpy-stubs` packages. Installing it also installs `jax`, which provides
|
|
8
|
+
upstream modules used by these partial stubs. The `jax` dependency is unpinned,
|
|
9
|
+
so projects can choose their own JAX version.
|
|
10
10
|
|
|
11
11
|
Shape-typed fixture stubs for a subset of JAX. This is a starting point for
|
|
12
12
|
working with the JAX core team rather than a complete model: it covers array
|
|
@@ -3,14 +3,76 @@
|
|
|
3
3
|
# This source code is licensed under the MIT license found in the
|
|
4
4
|
# LICENSE file in the root directory of this source tree.
|
|
5
5
|
|
|
6
|
+
from collections.abc import Callable, Iterable, Sequence
|
|
6
7
|
from types import SimpleNamespace
|
|
7
|
-
from typing import Any,
|
|
8
|
+
from typing import Any, overload
|
|
8
9
|
|
|
9
10
|
# Override jax.Array with shape-aware version.
|
|
10
11
|
from jax._array import Array as Array
|
|
12
|
+
from jax.stages import Lowered as _Lowered, Traced as _Traced
|
|
13
|
+
|
|
14
|
+
class _Wrapped[**P, R]:
|
|
15
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...
|
|
16
|
+
def lower(self, *args: P.args, **kwargs: P.kwargs) -> _Lowered: ...
|
|
17
|
+
def trace(self, *args: P.args, **kwargs: P.kwargs) -> _Traced: ...
|
|
18
|
+
def eval_shape(self, *args: P.args, **kwargs: P.kwargs) -> Any: ...
|
|
19
|
+
def clear_cache(self) -> None: ...
|
|
20
|
+
|
|
21
|
+
class _JitTransform:
|
|
22
|
+
def __call__[**P, R](self, fun: Callable[P, R], /) -> _Wrapped[P, R]: ...
|
|
11
23
|
|
|
12
24
|
# Override jit and vmap because jax annotations fail with shaped arrays.
|
|
13
|
-
|
|
25
|
+
@overload
|
|
26
|
+
def jit[**P, R](
|
|
27
|
+
fun: Callable[P, R],
|
|
28
|
+
/,
|
|
29
|
+
*,
|
|
30
|
+
in_shardings: Any = ...,
|
|
31
|
+
out_shardings: Any = ...,
|
|
32
|
+
static_argnums: int | Sequence[int] | None = None,
|
|
33
|
+
static_argnames: str | Iterable[str] | None = None,
|
|
34
|
+
donate_argnums: int | Sequence[int] | None = None,
|
|
35
|
+
donate_argnames: str | Iterable[str] | None = None,
|
|
36
|
+
keep_unused: bool = False,
|
|
37
|
+
device: Any = None,
|
|
38
|
+
backend: str | None = None,
|
|
39
|
+
inline: bool | Any = False,
|
|
40
|
+
compiler_options: dict[str, Any] | None = None,
|
|
41
|
+
**kwargs: Any,
|
|
42
|
+
) -> _Wrapped[P, R]: ...
|
|
43
|
+
@overload
|
|
44
|
+
def jit(
|
|
45
|
+
*,
|
|
46
|
+
in_shardings: Any = ...,
|
|
47
|
+
out_shardings: Any = ...,
|
|
48
|
+
static_argnums: int | Sequence[int] | None = None,
|
|
49
|
+
static_argnames: str | Iterable[str] | None = None,
|
|
50
|
+
donate_argnums: int | Sequence[int] | None = None,
|
|
51
|
+
donate_argnames: str | Iterable[str] | None = None,
|
|
52
|
+
keep_unused: bool = False,
|
|
53
|
+
device: Any = None,
|
|
54
|
+
backend: str | None = None,
|
|
55
|
+
inline: bool | Any = False,
|
|
56
|
+
compiler_options: dict[str, Any] | None = None,
|
|
57
|
+
**kwargs: Any,
|
|
58
|
+
) -> _JitTransform: ...
|
|
59
|
+
@overload
|
|
60
|
+
def jit[**P, R](
|
|
61
|
+
*,
|
|
62
|
+
fun: Callable[P, R],
|
|
63
|
+
in_shardings: Any = ...,
|
|
64
|
+
out_shardings: Any = ...,
|
|
65
|
+
static_argnums: int | Sequence[int] | None = None,
|
|
66
|
+
static_argnames: str | Iterable[str] | None = None,
|
|
67
|
+
donate_argnums: int | Sequence[int] | None = None,
|
|
68
|
+
donate_argnames: str | Iterable[str] | None = None,
|
|
69
|
+
keep_unused: bool = False,
|
|
70
|
+
device: Any = None,
|
|
71
|
+
backend: str | None = None,
|
|
72
|
+
inline: bool | Any = False,
|
|
73
|
+
compiler_options: dict[str, Any] | None = None,
|
|
74
|
+
**kwargs: Any,
|
|
75
|
+
) -> _Wrapped[P, R]: ...
|
|
14
76
|
def vmap(fun: Callable[..., Any], *args: Any, **kwargs: Any) -> Callable[..., Any]: ...
|
|
15
77
|
|
|
16
78
|
# Remaining APIs mirror imports in jax/__init__.py,
|
|
@@ -44,7 +106,6 @@ from jax import (
|
|
|
44
106
|
from jax._src.ad_checkpoint import (
|
|
45
107
|
checkpoint as checkpoint,
|
|
46
108
|
checkpoint_policies as checkpoint_policies,
|
|
47
|
-
custom_remat as custom_remat,
|
|
48
109
|
remat as remat,
|
|
49
110
|
)
|
|
50
111
|
from jax._src.api import (
|
|
@@ -136,7 +197,6 @@ from jax._src.mesh import (
|
|
|
136
197
|
use_abstract_mesh as use_abstract_mesh,
|
|
137
198
|
)
|
|
138
199
|
from jax._src.partition_spec import P as P
|
|
139
|
-
from jax._src.pjit import reshard as reshard
|
|
140
200
|
from jax._src.pmap import pmap as pmap
|
|
141
201
|
from jax._src.shard_map import (
|
|
142
202
|
shard_map as shard_map,
|
|
@@ -168,6 +228,7 @@ from jax.ref import (
|
|
|
168
228
|
new_ref as new_ref,
|
|
169
229
|
Ref as Ref,
|
|
170
230
|
)
|
|
231
|
+
from jax.sharding import reshard as reshard
|
|
171
232
|
from jax.version import (
|
|
172
233
|
__version__ as __version__,
|
|
173
234
|
__version_info__ as __version_info__,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
from collections.abc import Iterator
|
|
11
11
|
from types import EllipsisType
|
|
12
|
-
from typing import Any, overload, Protocol, Sequence, SupportsIndex
|
|
12
|
+
from typing import Any, Callable, overload, Protocol, Sequence, SupportsIndex
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
from jax._shapes import (
|
|
@@ -50,7 +50,7 @@ from shape_extensions import (
|
|
|
50
50
|
type _Shape = IntTuple
|
|
51
51
|
type _Axis = int | tuple[int, ...] | None
|
|
52
52
|
type _SingleAxis = int | None
|
|
53
|
-
type _Scalar = bool | int | float | complex | np.number
|
|
53
|
+
type _Scalar = bool | int | float | complex | np.number | np.bool_
|
|
54
54
|
# Note: when using _ArrayLike in an annotation, the Shape passed to it must
|
|
55
55
|
# have a default value of [] for scalars to be handled properly.
|
|
56
56
|
type ArrayLike[Shape: _Shape] = Array[Shape] | np.ndarray[Shape] | _Scalar
|
|
@@ -85,6 +85,8 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
85
85
|
self,
|
|
86
86
|
index: _BasicIndex | _ArrayIndex | tuple[_BasicIndex | _ArrayIndex, ...],
|
|
87
87
|
) -> Array[IntTuple]: ...
|
|
88
|
+
@property
|
|
89
|
+
def at(self) -> _IndexUpdateHelper[Shape]: ...
|
|
88
90
|
# JAX reverses every axis, at any rank, so this is not 2-D only.
|
|
89
91
|
@property
|
|
90
92
|
def T(self) -> Array[reverse_shape(Shape)]: ...
|
|
@@ -118,12 +120,44 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
118
120
|
def real(self) -> Array[Shape]: ...
|
|
119
121
|
@property
|
|
120
122
|
def imag(self) -> Array[Shape]: ...
|
|
123
|
+
@property
|
|
124
|
+
def aval(self) -> Any: ...
|
|
125
|
+
@property
|
|
126
|
+
def weak_type(self) -> bool: ...
|
|
127
|
+
@property
|
|
128
|
+
def traceback(self) -> Any: ...
|
|
129
|
+
@property
|
|
130
|
+
def format(self) -> Any: ...
|
|
121
131
|
def __len__[N: IntVar, Rest: _Shape = []](
|
|
122
132
|
self: Array[[N, *Rest]],
|
|
123
133
|
) -> Int[N]: ...
|
|
124
|
-
def __iter__[N: IntVar, Rest: _Shape
|
|
134
|
+
def __iter__[N: IntVar, Rest: _Shape](
|
|
125
135
|
self: Array[[N, *Rest]], /
|
|
126
136
|
) -> Iterator[Array[Rest]]: ...
|
|
137
|
+
def __reversed__[N: IntVar, Rest: _Shape](
|
|
138
|
+
self: Array[[N, *Rest]], /
|
|
139
|
+
) -> Iterator[Array[Rest]]: ...
|
|
140
|
+
def __contains__(self, key: object) -> bool: ...
|
|
141
|
+
def __bool__(self) -> bool: ...
|
|
142
|
+
def __int__(self: Array[[]], /) -> int: ...
|
|
143
|
+
def __float__(self: Array[[]], /) -> float: ...
|
|
144
|
+
def __complex__(self: Array[[]], /) -> complex: ...
|
|
145
|
+
def __index__(self: Array[[]], /) -> int: ...
|
|
146
|
+
def __round__(self, ndigits: int | None = None) -> Array[Shape]: ...
|
|
147
|
+
def __copy__(self) -> Array[Shape]: ...
|
|
148
|
+
def __deepcopy__(self, memo: Any) -> Array[Shape]: ...
|
|
149
|
+
def __format__(self, format_spec: str) -> str: ...
|
|
150
|
+
def __array__(
|
|
151
|
+
self,
|
|
152
|
+
dtype: np.dtype | None = None,
|
|
153
|
+
context: None = None,
|
|
154
|
+
copy: bool | None = None,
|
|
155
|
+
) -> np.ndarray[Shape]: ...
|
|
156
|
+
def __array_namespace__(self, *, api_version: str | None = None) -> Any: ...
|
|
157
|
+
def __dlpack__(self, *, stream: Any = None) -> Any: ...
|
|
158
|
+
def __dlpack_device__(self) -> tuple[int, int]: ...
|
|
159
|
+
def __buffer__(self, flags: int) -> memoryview: ...
|
|
160
|
+
def __release_buffer__(self, view: memoryview) -> None: ...
|
|
127
161
|
def copy(self) -> Array[Shape]: ...
|
|
128
162
|
def conj(self) -> Array[Shape]: ...
|
|
129
163
|
def conjugate(self) -> Array[Shape]: ...
|
|
@@ -145,6 +179,18 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
145
179
|
) -> Array[Shape]: ...
|
|
146
180
|
def addressable_data(self, index: int) -> Array[IntTuple]: ...
|
|
147
181
|
def copy_to_host_async(self) -> None: ...
|
|
182
|
+
def block_until_ready(self) -> Array[Shape]: ...
|
|
183
|
+
def clone(self) -> Array[Shape]: ...
|
|
184
|
+
def delete(self) -> None: ...
|
|
185
|
+
def is_deleted(self) -> bool: ...
|
|
186
|
+
def is_ready(self) -> bool: ...
|
|
187
|
+
def devices(self) -> set[_Device]: ...
|
|
188
|
+
def platform(self) -> str: ...
|
|
189
|
+
def on_device_size_in_bytes(self) -> int: ...
|
|
190
|
+
def unsafe_buffer_pointer(self) -> int: ...
|
|
191
|
+
def unsafe_raw_buffer(self) -> Any: ...
|
|
192
|
+
def tobytes(self, order: str = "C") -> bytes: ...
|
|
193
|
+
def tolist(self) -> list[Any]: ...
|
|
148
194
|
def __add__[OtherShape: _Shape = []](
|
|
149
195
|
self, other: ArrayLike[OtherShape]
|
|
150
196
|
) -> Array[broadcast(Shape, OtherShape)]: ...
|
|
@@ -181,6 +227,22 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
181
227
|
def __rmod__[OtherShape: _Shape = []](
|
|
182
228
|
self, other: ArrayLike[OtherShape]
|
|
183
229
|
) -> Array[broadcast(Shape, OtherShape)]: ...
|
|
230
|
+
@overload
|
|
231
|
+
def __divmod__(self, other: _Scalar, /) -> tuple[Array[Shape], Array[Shape]]: ...
|
|
232
|
+
@overload
|
|
233
|
+
def __divmod__[OtherShape: _Shape = []](
|
|
234
|
+
self, other: ArrayLike[OtherShape], /
|
|
235
|
+
) -> tuple[
|
|
236
|
+
Array[broadcast(Shape, OtherShape)], Array[broadcast(Shape, OtherShape)]
|
|
237
|
+
]: ...
|
|
238
|
+
@overload
|
|
239
|
+
def __rdivmod__(self, other: _Scalar, /) -> tuple[Array[Shape], Array[Shape]]: ...
|
|
240
|
+
@overload
|
|
241
|
+
def __rdivmod__[OtherShape: _Shape = []](
|
|
242
|
+
self, other: ArrayLike[OtherShape], /
|
|
243
|
+
) -> tuple[
|
|
244
|
+
Array[broadcast(OtherShape, Shape)], Array[broadcast(OtherShape, Shape)]
|
|
245
|
+
]: ...
|
|
184
246
|
def __pow__[OtherShape: _Shape = []](
|
|
185
247
|
self, other: ArrayLike[OtherShape]
|
|
186
248
|
) -> Array[broadcast(Shape, OtherShape)]: ...
|
|
@@ -248,6 +310,9 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
248
310
|
def __matmul__[OtherShape: _Shape = []](
|
|
249
311
|
self, other: ArrayLike[OtherShape]
|
|
250
312
|
) -> Array[matmul_shape(Shape, OtherShape)]: ...
|
|
313
|
+
def __rmatmul__[OtherShape: _Shape = []](
|
|
314
|
+
self, other: ArrayLike[OtherShape]
|
|
315
|
+
) -> Array[matmul_shape(OtherShape, Shape)]: ...
|
|
251
316
|
@overload
|
|
252
317
|
def transpose(self) -> Array[reverse_shape(Shape)]: ...
|
|
253
318
|
@overload
|
|
@@ -297,7 +362,12 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
297
362
|
order: str = ...,
|
|
298
363
|
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
299
364
|
) -> Array[IntTuple]: ...
|
|
300
|
-
def ravel(
|
|
365
|
+
def ravel(
|
|
366
|
+
self,
|
|
367
|
+
order: str = "C",
|
|
368
|
+
*,
|
|
369
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
370
|
+
) -> Array[ravel_shape(Shape)]: ...
|
|
301
371
|
def flatten(
|
|
302
372
|
self,
|
|
303
373
|
order: str = "C",
|
|
@@ -323,6 +393,7 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
323
393
|
axis: Axis = None,
|
|
324
394
|
*,
|
|
325
395
|
total_repeat_length: None = None,
|
|
396
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
326
397
|
) -> Array[repeat_shape(Shape, Repeats, Axis)]: ...
|
|
327
398
|
# TODO(stroxler): Separate dynamic repeat counts from invalid concrete counts and axes.
|
|
328
399
|
@overload
|
|
@@ -332,6 +403,7 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
332
403
|
axis: int | None = None,
|
|
333
404
|
*,
|
|
334
405
|
total_repeat_length: int | None = None,
|
|
406
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
335
407
|
) -> Array[IntTuple]: ...
|
|
336
408
|
@overload
|
|
337
409
|
# Any non-tuple sequence axis is gradual; see `jax/numpy/__init__.pyi`.
|
|
@@ -796,3 +868,117 @@ class Array[Shape: _Shape = _Shape]:
|
|
|
796
868
|
size: int | None = None,
|
|
797
869
|
fill_value: Any = 0,
|
|
798
870
|
) -> Array[IntTuple]: ...
|
|
871
|
+
|
|
872
|
+
class _IndexUpdateRef[Shape: _Shape, SliceShape: _Shape]:
|
|
873
|
+
def set(
|
|
874
|
+
self,
|
|
875
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
876
|
+
*,
|
|
877
|
+
mode: str | None = None,
|
|
878
|
+
indices_are_sorted: bool = False,
|
|
879
|
+
unique_indices: bool = False,
|
|
880
|
+
wrap_negative_indices: bool = True,
|
|
881
|
+
**kwargs: Any,
|
|
882
|
+
) -> Array[Shape]: ...
|
|
883
|
+
def add(
|
|
884
|
+
self,
|
|
885
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
886
|
+
*,
|
|
887
|
+
mode: str | None = None,
|
|
888
|
+
indices_are_sorted: bool = False,
|
|
889
|
+
unique_indices: bool = False,
|
|
890
|
+
wrap_negative_indices: bool = True,
|
|
891
|
+
**kwargs: Any,
|
|
892
|
+
) -> Array[Shape]: ...
|
|
893
|
+
def subtract(
|
|
894
|
+
self,
|
|
895
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
896
|
+
*,
|
|
897
|
+
mode: str | None = None,
|
|
898
|
+
indices_are_sorted: bool = False,
|
|
899
|
+
unique_indices: bool = False,
|
|
900
|
+
wrap_negative_indices: bool = True,
|
|
901
|
+
**kwargs: Any,
|
|
902
|
+
) -> Array[Shape]: ...
|
|
903
|
+
def multiply(
|
|
904
|
+
self,
|
|
905
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
906
|
+
*,
|
|
907
|
+
mode: str | None = None,
|
|
908
|
+
indices_are_sorted: bool = False,
|
|
909
|
+
unique_indices: bool = False,
|
|
910
|
+
wrap_negative_indices: bool = True,
|
|
911
|
+
**kwargs: Any,
|
|
912
|
+
) -> Array[Shape]: ...
|
|
913
|
+
def divide(
|
|
914
|
+
self,
|
|
915
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
916
|
+
*,
|
|
917
|
+
mode: str | None = None,
|
|
918
|
+
indices_are_sorted: bool = False,
|
|
919
|
+
unique_indices: bool = False,
|
|
920
|
+
wrap_negative_indices: bool = True,
|
|
921
|
+
**kwargs: Any,
|
|
922
|
+
) -> Array[Shape]: ...
|
|
923
|
+
def power(
|
|
924
|
+
self,
|
|
925
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
926
|
+
*,
|
|
927
|
+
mode: str | None = None,
|
|
928
|
+
indices_are_sorted: bool = False,
|
|
929
|
+
unique_indices: bool = False,
|
|
930
|
+
wrap_negative_indices: bool = True,
|
|
931
|
+
**kwargs: Any,
|
|
932
|
+
) -> Array[Shape]: ...
|
|
933
|
+
def min(
|
|
934
|
+
self,
|
|
935
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
936
|
+
*,
|
|
937
|
+
mode: str | None = None,
|
|
938
|
+
indices_are_sorted: bool = False,
|
|
939
|
+
unique_indices: bool = False,
|
|
940
|
+
wrap_negative_indices: bool = True,
|
|
941
|
+
**kwargs: Any,
|
|
942
|
+
) -> Array[Shape]: ...
|
|
943
|
+
def max(
|
|
944
|
+
self,
|
|
945
|
+
values: ArrayLike[Any] | Sequence[Any],
|
|
946
|
+
*,
|
|
947
|
+
mode: str | None = None,
|
|
948
|
+
indices_are_sorted: bool = False,
|
|
949
|
+
unique_indices: bool = False,
|
|
950
|
+
wrap_negative_indices: bool = True,
|
|
951
|
+
**kwargs: Any,
|
|
952
|
+
) -> Array[Shape]: ...
|
|
953
|
+
def apply(
|
|
954
|
+
self,
|
|
955
|
+
func: Callable[..., Any],
|
|
956
|
+
*,
|
|
957
|
+
mode: str | None = None,
|
|
958
|
+
indices_are_sorted: bool = False,
|
|
959
|
+
unique_indices: bool = False,
|
|
960
|
+
wrap_negative_indices: bool = True,
|
|
961
|
+
**kwargs: Any,
|
|
962
|
+
) -> Array[Shape]: ...
|
|
963
|
+
def get(
|
|
964
|
+
self,
|
|
965
|
+
*,
|
|
966
|
+
mode: str | None = None,
|
|
967
|
+
fill_value: Any = None,
|
|
968
|
+
indices_are_sorted: bool = False,
|
|
969
|
+
unique_indices: bool = False,
|
|
970
|
+
wrap_negative_indices: bool = True,
|
|
971
|
+
strategy: str | None = None,
|
|
972
|
+
**kwargs: Any,
|
|
973
|
+
) -> Array[SliceShape]: ...
|
|
974
|
+
|
|
975
|
+
class _IndexUpdateHelper[Shape: _Shape]:
|
|
976
|
+
@overload
|
|
977
|
+
def __getitem__[I: Index](
|
|
978
|
+
self, index: I
|
|
979
|
+
) -> _IndexUpdateRef[Shape, index_shape(Shape, I)]: ...
|
|
980
|
+
@overload
|
|
981
|
+
def __getitem__(
|
|
982
|
+
self,
|
|
983
|
+
index: _BasicIndex | _ArrayIndex | tuple[_BasicIndex | _ArrayIndex, ...],
|
|
984
|
+
) -> _IndexUpdateRef[Shape, IntTuple]: ...
|
|
@@ -124,26 +124,30 @@ def parameter_broadcast_shape(
|
|
|
124
124
|
return result_shape
|
|
125
125
|
|
|
126
126
|
@type_shape_dsl_function
|
|
127
|
-
def multinomial_shape(
|
|
128
|
-
|
|
127
|
+
def multinomial_shape(n_shape: IntTuple, p_shape: IntTuple) -> IntTuple:
|
|
128
|
+
batch_shape = p_shape[:-1]
|
|
129
|
+
return multinomial_sample_shape(n_shape, p_shape, batch_shape)
|
|
130
|
+
|
|
131
|
+
@type_shape_dsl_function
|
|
132
|
+
def multinomial_sample_shape(
|
|
133
|
+
n_shape: IntTuple, p_shape: IntTuple, sample_shape: IntTuple
|
|
129
134
|
) -> IntTuple:
|
|
130
|
-
if len(p_shape) == 0
|
|
135
|
+
if len(p_shape) == 0:
|
|
131
136
|
return dsl.Invalid("multinomial probabilities must have an event dimension")
|
|
132
|
-
probability_shapes = dsl.IntTuples((p_shape,
|
|
137
|
+
probability_shapes = dsl.IntTuples((p_shape[:-1], sample_shape))
|
|
133
138
|
probability_shape = gufunc_broadcast("(),()->()", probability_shapes)
|
|
134
|
-
if len(probability_shape) != len(
|
|
135
|
-
probability_shape[index] !=
|
|
136
|
-
for index in range(len(
|
|
139
|
+
if len(probability_shape) != len(sample_shape) or any(
|
|
140
|
+
probability_shape[index] != sample_shape[index]
|
|
141
|
+
for index in range(len(sample_shape))
|
|
137
142
|
):
|
|
138
143
|
return dsl.Invalid("probabilities cannot broadcast to the requested shape")
|
|
139
|
-
count_shapes = dsl.IntTuples((n_shape,
|
|
144
|
+
count_shapes = dsl.IntTuples((n_shape, sample_shape))
|
|
140
145
|
count_shape = gufunc_broadcast("(),()->()", count_shapes)
|
|
141
|
-
if len(count_shape) != len(
|
|
142
|
-
count_shape[index] !=
|
|
143
|
-
for index in range(len(result_shape) - 1)
|
|
146
|
+
if len(count_shape) != len(sample_shape) or any(
|
|
147
|
+
count_shape[index] != sample_shape[index] for index in range(len(sample_shape))
|
|
144
148
|
):
|
|
145
149
|
return dsl.Invalid("counts cannot broadcast to the requested batch shape")
|
|
146
|
-
return
|
|
150
|
+
return dsl.concat(sample_shape, p_shape[-1:])
|
|
147
151
|
|
|
148
152
|
@type_shape_dsl_function
|
|
149
153
|
def multivariate_normal_shape(
|
|
@@ -840,6 +844,50 @@ def vecmat_shape(left: IntTuple, right: IntTuple) -> IntTuple:
|
|
|
840
844
|
spec = "(n),(n,m)->(m)"
|
|
841
845
|
return gufunc_broadcast(spec, operands)
|
|
842
846
|
|
|
847
|
+
@type_shape_dsl_function
|
|
848
|
+
def tensordot_axes_shape(
|
|
849
|
+
left: IntTuple,
|
|
850
|
+
right: IntTuple,
|
|
851
|
+
left_axes: IntTuple,
|
|
852
|
+
right_axes: IntTuple,
|
|
853
|
+
) -> IntTuple:
|
|
854
|
+
if len(left_axes) != len(right_axes):
|
|
855
|
+
return dsl.Invalid("tensordot axis sequences must have equal length")
|
|
856
|
+
if any(axis < 0 - len(left) or axis >= len(left) for axis in left_axes):
|
|
857
|
+
return dsl.Invalid("axis out of bounds")
|
|
858
|
+
if any(axis < 0 - len(right) or axis >= len(right) for axis in right_axes):
|
|
859
|
+
return dsl.Invalid("axis out of bounds")
|
|
860
|
+
left_norm = dsl.IntTuple(
|
|
861
|
+
axis + len(left) if axis < 0 else axis for axis in left_axes
|
|
862
|
+
)
|
|
863
|
+
right_norm = dsl.IntTuple(
|
|
864
|
+
axis + len(right) if axis < 0 else axis for axis in right_axes
|
|
865
|
+
)
|
|
866
|
+
left_indices = dsl.IntTuple(i for i in range(len(left)))
|
|
867
|
+
right_indices = dsl.IntTuple(i for i in range(len(right)))
|
|
868
|
+
left_rem = dsl.IntTuple(
|
|
869
|
+
dimension
|
|
870
|
+
for dimension, index in zip(left, left_indices)
|
|
871
|
+
if not any(index == axis for axis in left_norm)
|
|
872
|
+
)
|
|
873
|
+
right_rem = dsl.IntTuple(
|
|
874
|
+
dimension
|
|
875
|
+
for dimension, index in zip(right, right_indices)
|
|
876
|
+
if not any(index == axis for axis in right_norm)
|
|
877
|
+
)
|
|
878
|
+
if len(left_rem) + len(left_norm) != len(left):
|
|
879
|
+
return dsl.Invalid("duplicate axis")
|
|
880
|
+
if len(right_rem) + len(right_norm) != len(right):
|
|
881
|
+
return dsl.Invalid("duplicate axis")
|
|
882
|
+
mismatches = dsl.IntTuple(
|
|
883
|
+
1
|
|
884
|
+
for left_axis, right_axis in zip(left_norm, right_norm)
|
|
885
|
+
if left[left_axis] != right[right_axis]
|
|
886
|
+
)
|
|
887
|
+
if len(mismatches) != 0:
|
|
888
|
+
return dsl.Invalid("tensordot contracted dimensions must match")
|
|
889
|
+
return dsl.concat(left_rem, right_rem)
|
|
890
|
+
|
|
843
891
|
@type_shape_dsl_function
|
|
844
892
|
def tensordot_shape(
|
|
845
893
|
left: IntTuple,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from jax._array import Array as Array
|
|
8
|
+
|
|
9
|
+
type StaticScalar = np.bool_ | np.number | bool | int | float | complex
|
|
10
|
+
type ArrayLike = Array | np.ndarray | StaticScalar
|
|
@@ -45,6 +45,7 @@ from jax._src.lax.lax import (
|
|
|
45
45
|
DotAlgorithm as DotAlgorithm,
|
|
46
46
|
DotAlgorithmPreset as DotAlgorithmPreset,
|
|
47
47
|
DotDimensionNumbers as DotDimensionNumbers,
|
|
48
|
+
polynomial as polynomial,
|
|
48
49
|
Precision as Precision,
|
|
49
50
|
PrecisionLike as PrecisionLike,
|
|
50
51
|
RaggedDotDimensionNumbers as RaggedDotDimensionNumbers,
|
|
@@ -10,6 +10,7 @@ from typing import (
|
|
|
10
10
|
Literal,
|
|
11
11
|
NamedTuple,
|
|
12
12
|
overload,
|
|
13
|
+
Protocol,
|
|
13
14
|
Sequence,
|
|
14
15
|
Unpack,
|
|
15
16
|
)
|
|
@@ -80,6 +81,7 @@ from jax._shapes import (
|
|
|
80
81
|
swapaxes_shape,
|
|
81
82
|
take_along_axis_shape,
|
|
82
83
|
take_shape,
|
|
84
|
+
tensordot_axes_shape,
|
|
83
85
|
tensordot_shape,
|
|
84
86
|
tile_shape,
|
|
85
87
|
top_k_shape,
|
|
@@ -209,6 +211,7 @@ def zeros[N: IntVar](
|
|
|
209
211
|
dtype: DTypeLike | None = ...,
|
|
210
212
|
*,
|
|
211
213
|
device: _Device | _Sharding | None = ...,
|
|
214
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
212
215
|
) -> _Array[[N]]: ...
|
|
213
216
|
@overload
|
|
214
217
|
def zeros[Shape: _Shape](
|
|
@@ -216,6 +219,7 @@ def zeros[Shape: _Shape](
|
|
|
216
219
|
dtype: DTypeLike | None = ...,
|
|
217
220
|
*,
|
|
218
221
|
device: _Device | _Sharding | None = ...,
|
|
222
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
219
223
|
) -> _Array[Shape]: ...
|
|
220
224
|
@overload
|
|
221
225
|
def zeros(
|
|
@@ -223,6 +227,7 @@ def zeros(
|
|
|
223
227
|
dtype: DTypeLike | None = ...,
|
|
224
228
|
*,
|
|
225
229
|
device: _Device | _Sharding | None = ...,
|
|
230
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
226
231
|
) -> _Array[IntTuple]: ...
|
|
227
232
|
@overload
|
|
228
233
|
def ones[N: IntVar](
|
|
@@ -230,6 +235,7 @@ def ones[N: IntVar](
|
|
|
230
235
|
dtype: DTypeLike | None = ...,
|
|
231
236
|
*,
|
|
232
237
|
device: _Device | _Sharding | None = ...,
|
|
238
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
233
239
|
) -> _Array[[N]]: ...
|
|
234
240
|
@overload
|
|
235
241
|
def ones[Shape: _Shape](
|
|
@@ -237,6 +243,7 @@ def ones[Shape: _Shape](
|
|
|
237
243
|
dtype: DTypeLike | None = ...,
|
|
238
244
|
*,
|
|
239
245
|
device: _Device | _Sharding | None = ...,
|
|
246
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
240
247
|
) -> _Array[Shape]: ...
|
|
241
248
|
@overload
|
|
242
249
|
def ones(
|
|
@@ -244,6 +251,7 @@ def ones(
|
|
|
244
251
|
dtype: DTypeLike | None = ...,
|
|
245
252
|
*,
|
|
246
253
|
device: _Device | _Sharding | None = ...,
|
|
254
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
247
255
|
) -> _Array[IntTuple]: ...
|
|
248
256
|
@overload
|
|
249
257
|
def empty[N: IntVar](
|
|
@@ -276,6 +284,7 @@ def full[N: IntVar](
|
|
|
276
284
|
dtype: DTypeLike | None = ...,
|
|
277
285
|
*,
|
|
278
286
|
device: _Device | _Sharding | None = ...,
|
|
287
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
279
288
|
) -> _Array[[N]]: ...
|
|
280
289
|
@overload
|
|
281
290
|
def full[Shape: _Shape](
|
|
@@ -284,6 +293,7 @@ def full[Shape: _Shape](
|
|
|
284
293
|
dtype: DTypeLike | None = ...,
|
|
285
294
|
*,
|
|
286
295
|
device: _Device | _Sharding | None = ...,
|
|
296
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
287
297
|
) -> _Array[Shape]: ...
|
|
288
298
|
@overload
|
|
289
299
|
def full(
|
|
@@ -292,6 +302,7 @@ def full(
|
|
|
292
302
|
dtype: DTypeLike | None = ...,
|
|
293
303
|
*,
|
|
294
304
|
device: _Device | _Sharding | None = ...,
|
|
305
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
295
306
|
) -> _Array[IntTuple]: ...
|
|
296
307
|
|
|
297
308
|
# `_like` constructors
|
|
@@ -447,6 +458,7 @@ def arange[N: IntVar](
|
|
|
447
458
|
*,
|
|
448
459
|
dtype: DTypeLike | None = ...,
|
|
449
460
|
device: _Device | _Sharding | None = ...,
|
|
461
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
450
462
|
) -> _Array[[arange_stop(Int[N])]]: ...
|
|
451
463
|
@overload
|
|
452
464
|
def arange(
|
|
@@ -454,6 +466,7 @@ def arange(
|
|
|
454
466
|
*,
|
|
455
467
|
dtype: DTypeLike | None = ...,
|
|
456
468
|
device: _Device | _Sharding | None = ...,
|
|
469
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
457
470
|
) -> _Array[[int]]: ...
|
|
458
471
|
@overload
|
|
459
472
|
def arange[Start: Flag[int], Stop: Flag[int]](
|
|
@@ -461,6 +474,9 @@ def arange[Start: Flag[int], Stop: Flag[int]](
|
|
|
461
474
|
stop: Stop,
|
|
462
475
|
step: Literal[1] = ...,
|
|
463
476
|
dtype: DTypeLike | None = ...,
|
|
477
|
+
*,
|
|
478
|
+
device: _Device | _Sharding | None = ...,
|
|
479
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
464
480
|
) -> _Array[[arange_size(Start, Stop, 1)]]: ...
|
|
465
481
|
@overload
|
|
466
482
|
def arange[Start: Flag[int], Stop: Flag[int], Step: Flag[int]](
|
|
@@ -468,6 +484,9 @@ def arange[Start: Flag[int], Stop: Flag[int], Step: Flag[int]](
|
|
|
468
484
|
stop: Stop,
|
|
469
485
|
step: Step,
|
|
470
486
|
dtype: DTypeLike | None = ...,
|
|
487
|
+
*,
|
|
488
|
+
device: _Device | _Sharding | None = ...,
|
|
489
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
471
490
|
) -> _Array[[arange_size(Start, Stop, Step)]]: ...
|
|
472
491
|
@overload
|
|
473
492
|
def arange(
|
|
@@ -475,6 +494,9 @@ def arange(
|
|
|
475
494
|
stop: int | float,
|
|
476
495
|
step: int | float = ...,
|
|
477
496
|
dtype: DTypeLike | None = ...,
|
|
497
|
+
*,
|
|
498
|
+
device: _Device | _Sharding | None = ...,
|
|
499
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
478
500
|
) -> _Array[[int]]: ...
|
|
479
501
|
@overload
|
|
480
502
|
def linspace[
|
|
@@ -1051,6 +1073,22 @@ def outer(
|
|
|
1051
1073
|
b: _ArrayLike[Any] | Sequence[Any],
|
|
1052
1074
|
out: None = None,
|
|
1053
1075
|
) -> _Array[IntTuple]: ...
|
|
1076
|
+
@overload
|
|
1077
|
+
def tensordot[
|
|
1078
|
+
Left: _Shape,
|
|
1079
|
+
Right: _Shape,
|
|
1080
|
+
LeftAxes: IntTuple,
|
|
1081
|
+
RightAxes: IntTuple,
|
|
1082
|
+
](
|
|
1083
|
+
a: _ArrayLike[Left],
|
|
1084
|
+
b: _ArrayLike[Right],
|
|
1085
|
+
axes: tuple[LeftAxes, RightAxes],
|
|
1086
|
+
*,
|
|
1087
|
+
precision: Any = None,
|
|
1088
|
+
preferred_element_type: Any = None,
|
|
1089
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
1090
|
+
) -> _Array[tensordot_axes_shape(Left, Right, LeftAxes, RightAxes)]: ...
|
|
1091
|
+
@overload
|
|
1054
1092
|
def tensordot[
|
|
1055
1093
|
Left: _Shape = [],
|
|
1056
1094
|
Right: _Shape = [],
|
|
@@ -1200,6 +1238,8 @@ def reshape(
|
|
|
1200
1238
|
def ravel[Shape: _Shape = []](
|
|
1201
1239
|
a: _ArrayLike[Shape],
|
|
1202
1240
|
order: str = "C",
|
|
1241
|
+
*,
|
|
1242
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
1203
1243
|
) -> _Array[ravel_shape(Shape)]: ...
|
|
1204
1244
|
@overload
|
|
1205
1245
|
def squeeze[Shape: _Shape = [], Axis: Flag[_Axis] = None](
|
|
@@ -1225,11 +1265,15 @@ def expand_dims(
|
|
|
1225
1265
|
def broadcast_to[TargetShape: Flag[_NewShape], Shape: _Shape = []](
|
|
1226
1266
|
array: _ArrayLike[Shape],
|
|
1227
1267
|
shape: TargetShape,
|
|
1268
|
+
*,
|
|
1269
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
1228
1270
|
) -> _Array[broadcast_to_shape(Shape, TargetShape)]: ...
|
|
1229
1271
|
@overload
|
|
1230
1272
|
def broadcast_to(
|
|
1231
1273
|
array: _ArrayLike[Any],
|
|
1232
1274
|
shape: Sequence[int] | int,
|
|
1275
|
+
*,
|
|
1276
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = ...,
|
|
1233
1277
|
) -> _Array[IntTuple]: ...
|
|
1234
1278
|
@overload
|
|
1235
1279
|
def broadcast_arrays[Shape: _Shape = []](
|
|
@@ -1473,6 +1517,7 @@ def repeat[
|
|
|
1473
1517
|
axis: Axis = None,
|
|
1474
1518
|
*,
|
|
1475
1519
|
total_repeat_length: None = None,
|
|
1520
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
1476
1521
|
) -> _Array[repeat_shape(Shape, Repeats, Axis)]: ...
|
|
1477
1522
|
|
|
1478
1523
|
# TODO(stroxler): Separate dynamic repeat counts from invalid concrete counts and axes.
|
|
@@ -1483,6 +1528,7 @@ def repeat(
|
|
|
1483
1528
|
axis: int | None = None,
|
|
1484
1529
|
*,
|
|
1485
1530
|
total_repeat_length: int | None = None,
|
|
1531
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
1486
1532
|
) -> _Array[IntTuple]: ...
|
|
1487
1533
|
@overload
|
|
1488
1534
|
def resize(a: _ArrayLike[Any], new_shape: tuple[()]) -> _Array[[]]: ...
|
|
@@ -1580,19 +1626,37 @@ def atleast_1d[Shape: _Shape = []](
|
|
|
1580
1626
|
ary: _ArrayLike[Shape], /
|
|
1581
1627
|
) -> _Array[atleast_1d_shape(Shape)]: ...
|
|
1582
1628
|
@overload
|
|
1583
|
-
def atleast_1d
|
|
1629
|
+
def atleast_1d[Shapes: IntTuples](
|
|
1630
|
+
*arys: Unpack[MapIntTuples[lambda S: _Array[S], Shapes]],
|
|
1631
|
+
) -> MapIntTuples[lambda S: _Array[atleast_1d_shape(S)], Shapes]: ...
|
|
1632
|
+
@overload
|
|
1633
|
+
def atleast_1d[Shapes: IntTuples](
|
|
1634
|
+
*arys: Unpack[MapIntTuples[lambda S: _ArrayLike[S], Shapes]],
|
|
1635
|
+
) -> MapIntTuples[lambda S: _Array[S], Shapes]: ...
|
|
1584
1636
|
@overload
|
|
1585
1637
|
def atleast_2d[Shape: _Shape = []](
|
|
1586
1638
|
ary: _ArrayLike[Shape], /
|
|
1587
1639
|
) -> _Array[atleast_2d_shape(Shape)]: ...
|
|
1588
1640
|
@overload
|
|
1589
|
-
def atleast_2d
|
|
1641
|
+
def atleast_2d[Shapes: IntTuples](
|
|
1642
|
+
*arys: Unpack[MapIntTuples[lambda S: _Array[S], Shapes]],
|
|
1643
|
+
) -> MapIntTuples[lambda S: _Array[atleast_2d_shape(S)], Shapes]: ...
|
|
1644
|
+
@overload
|
|
1645
|
+
def atleast_2d[Shapes: IntTuples](
|
|
1646
|
+
*arys: Unpack[MapIntTuples[lambda S: _ArrayLike[S], Shapes]],
|
|
1647
|
+
) -> MapIntTuples[lambda S: _Array[S], Shapes]: ...
|
|
1590
1648
|
@overload
|
|
1591
1649
|
def atleast_3d[Shape: _Shape = []](
|
|
1592
1650
|
ary: _ArrayLike[Shape], /
|
|
1593
1651
|
) -> _Array[atleast_3d_shape(Shape)]: ...
|
|
1594
1652
|
@overload
|
|
1595
|
-
def atleast_3d
|
|
1653
|
+
def atleast_3d[Shapes: IntTuples](
|
|
1654
|
+
*arys: Unpack[MapIntTuples[lambda S: _Array[S], Shapes]],
|
|
1655
|
+
) -> MapIntTuples[lambda S: _Array[atleast_3d_shape(S)], Shapes]: ...
|
|
1656
|
+
@overload
|
|
1657
|
+
def atleast_3d[Shapes: IntTuples](
|
|
1658
|
+
*arys: Unpack[MapIntTuples[lambda S: _ArrayLike[S], Shapes]],
|
|
1659
|
+
) -> MapIntTuples[lambda S: _Array[S], Shapes]: ...
|
|
1596
1660
|
|
|
1597
1661
|
# JAX accepts any integer sequence for an axis, but only a tuple is a Flag
|
|
1598
1662
|
# domain, so any other sequence yields a gradual shape. Rejecting it would flag
|
|
@@ -3443,6 +3507,7 @@ def histogram[Bins: Flag[int] = 10](
|
|
|
3443
3507
|
range: Sequence[Any] | None = None,
|
|
3444
3508
|
weights: _ArrayLike[Any] | None = None,
|
|
3445
3509
|
density: bool | None = None,
|
|
3510
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
3446
3511
|
) -> tuple[
|
|
3447
3512
|
_Array[histogram_counts_shape(Bins)], _Array[histogram_edges_shape(Bins)]
|
|
3448
3513
|
]: ...
|
|
@@ -3453,6 +3518,7 @@ def histogram(
|
|
|
3453
3518
|
range: Sequence[Any] | None = None,
|
|
3454
3519
|
weights: _ArrayLike[Any] | None = None,
|
|
3455
3520
|
density: bool | None = None,
|
|
3521
|
+
out_sharding: _NamedSharding | _PartitionSpec | None = None,
|
|
3456
3522
|
) -> tuple[_Array[IntTuple], _Array[IntTuple]]: ...
|
|
3457
3523
|
@overload
|
|
3458
3524
|
def histogram2d[Bins: Flag[int] = 10](
|
|
@@ -3617,44 +3683,53 @@ def roots(p: _ArrayLike[Any], *, strip_zeros: bool = True) -> _Array[IntTuple]:
|
|
|
3617
3683
|
|
|
3618
3684
|
# Scalar constructors
|
|
3619
3685
|
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3686
|
+
class _ScalarType(Protocol):
|
|
3687
|
+
@property
|
|
3688
|
+
def dtype(self) -> np.dtype: ...
|
|
3689
|
+
@property
|
|
3690
|
+
def __numpy_dtype__(self) -> np.dtype: ...
|
|
3691
|
+
def __call__(self, x: Any, /) -> _Array: ...
|
|
3692
|
+
def __hash__(self, /) -> int: ...
|
|
3693
|
+
def __eq__(self, other: Any, /) -> bool: ...
|
|
3694
|
+
|
|
3695
|
+
bool: _ScalarType
|
|
3696
|
+
bool_: _ScalarType
|
|
3697
|
+
int_: _ScalarType
|
|
3698
|
+
int8: _ScalarType
|
|
3699
|
+
int16: _ScalarType
|
|
3700
|
+
int32: _ScalarType
|
|
3701
|
+
int64: _ScalarType
|
|
3702
|
+
uint: _ScalarType
|
|
3703
|
+
uint8: _ScalarType
|
|
3704
|
+
uint16: _ScalarType
|
|
3705
|
+
uint32: _ScalarType
|
|
3706
|
+
uint64: _ScalarType
|
|
3707
|
+
int1: _ScalarType
|
|
3708
|
+
int2: _ScalarType
|
|
3709
|
+
int4: _ScalarType
|
|
3710
|
+
uint1: _ScalarType
|
|
3711
|
+
uint2: _ScalarType
|
|
3712
|
+
uint4: _ScalarType
|
|
3713
|
+
float_: _ScalarType
|
|
3714
|
+
float16: _ScalarType
|
|
3715
|
+
float32: _ScalarType
|
|
3716
|
+
float64: _ScalarType
|
|
3717
|
+
bfloat16: _ScalarType
|
|
3718
|
+
single: _ScalarType
|
|
3719
|
+
double: _ScalarType
|
|
3720
|
+
csingle: _ScalarType
|
|
3721
|
+
cdouble: _ScalarType
|
|
3722
|
+
complex_: _ScalarType
|
|
3723
|
+
complex64: _ScalarType
|
|
3724
|
+
complex128: _ScalarType
|
|
3725
|
+
float4_e2m1fn: _ScalarType
|
|
3726
|
+
float6_e2m3fn: _ScalarType
|
|
3727
|
+
float6_e3m2fn: _ScalarType
|
|
3728
|
+
float8_e3m4: _ScalarType
|
|
3729
|
+
float8_e4m3: _ScalarType
|
|
3730
|
+
float8_e4m3b11fnuz: _ScalarType
|
|
3731
|
+
float8_e4m3fn: _ScalarType
|
|
3732
|
+
float8_e4m3fnuz: _ScalarType
|
|
3733
|
+
float8_e5m2: _ScalarType
|
|
3734
|
+
float8_e5m2fnuz: _ScalarType
|
|
3735
|
+
float8_e8m0fnu: _ScalarType
|
|
@@ -13,6 +13,7 @@ from jax._shapes import (
|
|
|
13
13
|
double_sided_maxwell_shape,
|
|
14
14
|
event_sample_shape,
|
|
15
15
|
event_shape,
|
|
16
|
+
multinomial_sample_shape,
|
|
16
17
|
multinomial_shape,
|
|
17
18
|
multivariate_normal_shape,
|
|
18
19
|
orthogonal_shape,
|
|
@@ -913,7 +914,7 @@ def multinomial[NShape: _Shape = [], PShape: _Shape = []](
|
|
|
913
914
|
shape: None = None,
|
|
914
915
|
dtype: DTypeLike | None = None,
|
|
915
916
|
unroll: int | bool = 1,
|
|
916
|
-
) -> _Array[multinomial_shape(NShape, PShape
|
|
917
|
+
) -> _Array[multinomial_shape(NShape, PShape)]: ...
|
|
917
918
|
@overload
|
|
918
919
|
def multinomial[NShape: _Shape = [], PShape: _Shape = [], Shape: _Shape = []](
|
|
919
920
|
key: _Array[IntTuple],
|
|
@@ -923,7 +924,7 @@ def multinomial[NShape: _Shape = [], PShape: _Shape = [], Shape: _Shape = []](
|
|
|
923
924
|
shape: Shape,
|
|
924
925
|
dtype: DTypeLike | None = None,
|
|
925
926
|
unroll: int | bool = 1,
|
|
926
|
-
) -> _Array[
|
|
927
|
+
) -> _Array[multinomial_sample_shape(NShape, PShape, Shape)]: ...
|
|
927
928
|
@overload
|
|
928
929
|
def multinomial(
|
|
929
930
|
key: _Array[IntTuple],
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
from jax._array import Array
|
|
7
|
+
from jax._src.core import ManualAxisType as ManualAxisType
|
|
8
|
+
from jax._src.mesh import (
|
|
9
|
+
AbstractDevice as AbstractDevice,
|
|
10
|
+
AbstractMesh as AbstractMesh,
|
|
11
|
+
AxisType as AxisType,
|
|
12
|
+
get_abstract_mesh as get_abstract_mesh,
|
|
13
|
+
Mesh as Mesh,
|
|
14
|
+
use_abstract_mesh as use_abstract_mesh,
|
|
15
|
+
)
|
|
16
|
+
from jax._src.partition_spec import (
|
|
17
|
+
PartitionSpec as PartitionSpec,
|
|
18
|
+
UnreducedKind as UnreducedKind,
|
|
19
|
+
)
|
|
20
|
+
from jax._src.pjit import (
|
|
21
|
+
auto_axes as auto_axes,
|
|
22
|
+
explicit_axes as explicit_axes,
|
|
23
|
+
)
|
|
24
|
+
from jax._src.sharding import Sharding as Sharding
|
|
25
|
+
from jax._src.sharding_impls import (
|
|
26
|
+
get_mesh as get_mesh,
|
|
27
|
+
make_single_device_sharding as make_single_device_sharding,
|
|
28
|
+
NamedSharding as NamedSharding,
|
|
29
|
+
set_mesh as set_mesh,
|
|
30
|
+
SingleDeviceSharding as SingleDeviceSharding,
|
|
31
|
+
)
|
|
32
|
+
from shape_extensions import IntTuple
|
|
33
|
+
|
|
34
|
+
def reshard[Shape: IntTuple](
|
|
35
|
+
xs: Array[Shape], out_shardings: NamedSharding | PartitionSpec
|
|
36
|
+
) -> Array[Shape]: ...
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This source code is licensed under the MIT license found in the
|
|
4
|
+
# LICENSE file in the root directory of this source tree.
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
from jax._array import Array
|
|
10
|
+
from jax._src.typing import DTypeLike as DTypeLike
|
|
11
|
+
|
|
12
|
+
type ArrayLike = (
|
|
13
|
+
Array[Any] | np.ndarray[Any] | np.bool_ | np.number | bool | int | float | complex
|
|
14
|
+
)
|
|
@@ -8,7 +8,7 @@ description = "JAX type stubs with array-shape tracking, maintained by Pyrefly"
|
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
|
-
version = "1.
|
|
11
|
+
version = "1.5.0.dev1"
|
|
12
12
|
keywords = ["typechecker", "typechecking", "stubs", "jax"]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Development Status :: 4 - Beta",
|
|
@@ -18,7 +18,8 @@ classifiers = [
|
|
|
18
18
|
"Typing :: Stubs Only",
|
|
19
19
|
]
|
|
20
20
|
dependencies = [
|
|
21
|
-
"pyrefly-shape-extensions==1.
|
|
21
|
+
"pyrefly-shape-extensions==1.5.0.dev1",
|
|
22
|
+
"pyrefly-numpy-stubs==1.5.0.dev1",
|
|
22
23
|
"jax",
|
|
23
24
|
]
|
|
24
25
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|