jax-pyrefly-stubs 1.4.0.dev3__tar.gz → 1.4.0.dev4__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.5
2
2
  Name: jax-pyrefly-stubs
3
- Version: 1.4.0.dev3
3
+ Version: 1.4.0.dev4
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/
@@ -33,7 +33,8 @@ Classifier: Programming Language :: Python
33
33
  Classifier: Programming Language :: Python :: 3
34
34
  Classifier: Typing :: Stubs Only
35
35
  Requires-Python: >=3.12
36
- Requires-Dist: pyrefly-shape-extensions==1.4.0.dev3
36
+ Requires-Dist: jax
37
+ Requires-Dist: pyrefly-shape-extensions==1.4.0.dev4
37
38
  Description-Content-Type: text/markdown
38
39
 
39
40
  # Pyrefly JAX shape stubs
@@ -42,6 +43,9 @@ This package is a PEP 561 stub-only distribution. It installs the `jax-stubs`
42
43
  stub package so Pyrefly can discover shape-aware stubs for the runtime `jax`
43
44
  package without replacing or shadowing JAX itself. It is versioned in lockstep
44
45
  with Pyrefly and depends on the matching `pyrefly-shape-extensions` package.
46
+ Installing it also installs `jax`, which provides upstream modules used by these
47
+ partial stubs. The `jax` dependency is unpinned, so projects can choose their own
48
+ JAX version.
45
49
 
46
50
  Shape-typed fixture stubs for a subset of JAX. This is a starting point for
47
51
  working with the JAX core team rather than a complete model: it covers array
@@ -4,6 +4,9 @@ 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
6
  with Pyrefly and depends on the matching `pyrefly-shape-extensions` package.
7
+ Installing it also installs `jax`, which provides upstream modules used by these
8
+ partial stubs. The `jax` dependency is unpinned, so projects can choose their own
9
+ JAX version.
7
10
 
8
11
  Shape-typed fixture stubs for a subset of JAX. This is a starting point for
9
12
  working with the JAX core team rather than a complete model: it covers array
@@ -1620,6 +1620,29 @@ def lax_scan_shape(shape: IntTuple, axis: int) -> IntTuple:
1620
1620
  return dsl.Invalid("axis out of bounds")
1621
1621
  return shape
1622
1622
 
1623
+ @type_shape_dsl_function
1624
+ def lax_scan_slice_shape(shape: IntTuple) -> IntTuple:
1625
+ # `lax_scan_stacked_shape` reports a missing scan axis for the whole call.
1626
+ if len(shape) == 0:
1627
+ return dsl.IntTuple.gradual()
1628
+ return shape[1:]
1629
+
1630
+ @type_shape_dsl_function
1631
+ def lax_scan_stacked_shape(xs_shapes: IntTuples, out_shape: IntTuple) -> IntTuple:
1632
+ if len(xs_shapes) == 0:
1633
+ return dsl.concat(dsl.IntTuple((dsl.Int.gradual(),)), out_shape)
1634
+ ranks = dsl.IntTuple((1 if len(shape) == 0 else 0 for shape in xs_shapes))
1635
+ if any(r == 1 for r in ranks):
1636
+ return dsl.Invalid("scan requires every xs array to have a leading axis")
1637
+ first = xs_shapes[0]
1638
+ length = first[0]
1639
+ mismatches = dsl.IntTuple((1 if shape[0] != length else 0 for shape in xs_shapes))
1640
+ if any(m == 1 for m in mismatches):
1641
+ return dsl.Invalid(
1642
+ "scan requires every xs array to have the same leading axis size"
1643
+ )
1644
+ return dsl.concat(dsl.IntTuple((length,)), out_shape)
1645
+
1623
1646
  @type_shape_dsl_function
1624
1647
  def lax_associative_scan_shape(shape: IntTuple, axis: int) -> IntTuple:
1625
1648
  rank = len(shape)
@@ -23,6 +23,8 @@ from jax._shapes import (
23
23
  lax_fft_shape,
24
24
  lax_reduce_shape,
25
25
  lax_scan_shape,
26
+ lax_scan_slice_shape,
27
+ lax_scan_stacked_shape,
26
28
  lax_select_n_shape,
27
29
  lax_select_shape,
28
30
  lax_sort_key_val_shape,
@@ -1343,6 +1345,19 @@ def scan[Carry, N: IntVar, InShape: _Shape, OutShape: _Shape](
1343
1345
  _split_transpose: bool = False,
1344
1346
  ) -> tuple[Carry, _Array[[N, *OutShape]]]: ...
1345
1347
  @overload
1348
+ def scan[Carry, InShapes: IntTuples, OutShape: _Shape](
1349
+ f: Callable[
1350
+ [Carry, MapIntTuples[lambda S: _Array[lax_scan_slice_shape(S)], InShapes]],
1351
+ tuple[Carry, _Array[OutShape]],
1352
+ ],
1353
+ init: Carry,
1354
+ xs: MapIntTuples[lambda S: _Array[S], InShapes],
1355
+ length: int | None = None,
1356
+ reverse: bool = False,
1357
+ unroll: int | bool = 1,
1358
+ _split_transpose: bool = False,
1359
+ ) -> tuple[Carry, _Array[lax_scan_stacked_shape(InShapes, OutShape)]]: ...
1360
+ @overload
1346
1361
  def scan[Carry, X, Y](
1347
1362
  f: Callable[[Carry, X], tuple[Carry, Y]],
1348
1363
  init: Carry,
@@ -1027,7 +1027,12 @@ def kron[AShape: _Shape = [], BShape: _Shape = []](
1027
1027
  b: _ArrayLike[BShape],
1028
1028
  ) -> _Array[kron_shape(AShape, BShape)]: ...
1029
1029
  def matmul[LeftShape: _Shape, RightShape: _Shape](
1030
- a: _ShapedArrayLike[LeftShape], b: _ShapedArrayLike[RightShape]
1030
+ a: _ShapedArrayLike[LeftShape],
1031
+ b: _ShapedArrayLike[RightShape],
1032
+ *,
1033
+ precision: Any = None,
1034
+ preferred_element_type: Any = None,
1035
+ out_sharding: _NamedSharding | _PartitionSpec | None = None,
1031
1036
  ) -> _Array[matmul_shape(LeftShape, RightShape)]: ...
1032
1037
  def matvec[LeftShape: _Shape, RightShape: _Shape](
1033
1038
  x1: _ShapedArrayLike[LeftShape],
@@ -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.4.0.dev3"
11
+ version = "1.4.0.dev4"
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.4.0.dev3",
21
+ "pyrefly-shape-extensions==1.4.0.dev4",
22
+ "jax",
22
23
  ]
23
24
 
24
25
  [project.urls]