You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e230a9f
Browse filesBrowse the repository at this point in the historyBrowse files
jax-pyrefly-stubs: support DuckTypedArray in *_like and fix logsumexp/truncated_normal stubs (#5633)
Summary:
This PR fixes three stub signature mismatches in `jax-pyrefly-stubs`:
1. `jnp.empty_like`, `zeros_like`, `ones_like`, and `full_like` now accept `jax._src.typing.DuckTypedArray` (such as `jax.ShapeDtypeStruct`) in addition to `ArrayLike`, matching `jax/numpy/__init__.pyi`:
```python
import jax
import jax.numpy as jnp
spec = jax.ShapeDtypeStruct((2, 3), jnp.float32)
x = jnp.zeros_like(spec) # previously rejected `ShapeDtypeStruct`
y = jnp.ones_like(spec, shape=(4, 5))
```
2. `jax.nn.initializers.truncated_normal` now uses the runtime parameter names and order `(stddev: float = ..., dtype: Any = ..., lower: float = ..., upper: float = ...)` instead of `(lower, upper, dtype)`:
```python
import jax.nn as jnn
init = jnn.initializers.truncated_normal(stddev=0.02) # previously failed with `Unexpected keyword argument stddev`
```
3. `jax.nn.logsumexp` gradual fallback overloads for `return_sign: Literal[False] = False` and `return_sign: Literal[True] = ...` now accept `a: _ArrayLike[Any]` and `axis: Sequence[int] | int | None = None` (matching `logmeanexp`). Previously, non-literal `axis` types or `jax.jit` wrappers fell through to the `return_sign: bool` overload and returned `Array | tuple[Array, Array]` even when `return_sign` was omitted:
```python
from collections.abc import Sequence
import jax
import jax.nn as jnn
import jax.numpy as jnp
def reduce_lse(x: jax.Array, axis: int | Sequence[int] = -1) -> jax.Array:
return jnn.logsumexp(x, axis=axis) # previously inferred `Array | tuple[Array, Array]`
x = jnp.ones((3, 4))
out = jax.jit(jnn.logsumexp, static_argnames=("axis",))(x, -1)
```
- [x] I am a human, and I fully understand the code I am submitting.
Pull Request resolved: #5633
Test Plan: Added tests and confirmed no test regressions
Reviewed By: stroxler
Differential Revision: D131505294
fbshipit-source-id: 2ca47516fb4b4c14b308a692b4f42d016f558355
0 commit comments