167 Commits
Author SHA1 Message Date
Michael J Clark 1456302503 link to why use type annotations 2024-05-19 09:16:10 +08:00
Michael J Clark 1c0186a1c9 tf, np, torch examples 2024-05-19 09:12:49 +08:00
Patrick Kidger 0d83ee77e6 Updated ecosystem again 2024-04-20 11:25:42 +02:00
Patrick Kidger 51ac630ef0 Updated ecosystem 2024-04-20 11:18:48 +02:00
Sergei Lebedev f83170e01d Define the IPython magic lazily
IPython is quite a chunky package, and importing it unconditionally makes
jaxtyping itself relatively slow to import.
2024-04-17 09:45:56 +02:00
Piotr Kaminski 07e58de0bd Replace ndim with len(shape) 2024-03-11 20:35:29 +01:00
Andy Rock 696cc5b90f also require jaxlib 2024-03-08 18:17:50 +01:00
Patrick Kidger 102e499d61 Fixes #188. v0.2.28 2024-03-07 18:28:08 +01:00
Patrick Kidger f708d1742b Quick fix for docs not generating correctly since the last jaxtyping release v0.2.27 2024-03-06 20:34:48 +01:00
Alex Ford 5e2518c591 Fix _check_shape str formatting for variadics 2024-03-06 20:21:03 +01:00
Patrick Kidger 1b3173ac01 Bump version v0.2.26 2024-02-25 12:07:01 +00:00
Roman Knyazhitskiy 172b83b4fc Adding a test for generator support (#171)
* Add a test for generators

* Remove output annotations from decorators

Also guarded torch imports for better compatibility with
requirements.txt

* Add flag to the main meta class to skip the typecheck

* Return to the old solution

* Make async tests work

* Minor adjustments/fixing typos

* Correct Python path for new tests

* Remove some jax-dependent code

* Implement equality for MetaArrays

* Make all Dim variations frozen dataclasses

* Shorten AbstractArray methods

* Final touches

* Removing get_origin use

* Update tests with @jaxtyp
2024-02-25 12:07:01 +00:00
Patrick Kidger 17ea4b13eb No longer imports JAX at all! This is done dynamically when required. See #178 2024-02-25 12:07:01 +00:00
jianlijianli 9beb5f2d29 Add int4/uint4 support in jaxtyping. (#174)
* Add int4/uint4 support in jaxtyping.

* Fix a typo and update api docs.
2024-02-25 12:07:01 +00:00
Patrick Kidger 1d4d40294c Added support for beartype 0.17.0's __instancecheck_str__.
Recall that jaxtyping will currently generate rich error messages in precisely one scenario: about the arguments and return types when doing:
```python
@jaxtyped(typechecker=beartype)
def foo(...): ...
```

With this commit we add support for beartype 0.17.0's pseudo-standard `__instancecheck_str__`, which means the following:

1. For those using beartype decorators, the following will *also* generate an informative error message, and moreover it will state exactly why (shape mismatch, dtype mismatch etc):
    ```python
    @jaxtyped(typechecker=None)
    @beartype
    def foo(...): ...
    ```
    (In practice we probably won't recommend the above combination in the docs just to keep things simple.)

2. For those using the beartype import hook together with the jaxtyping import hook, we can probably also check `assert isinstance(x, Float[Array, "foo"])` statements with rich error messages. (#153) We'll need to test + document that though. (@jeezrick interested?)

3. For those using plain `assert isinstance(...)` statements without beartype (#167, tagging @reinerp), then they can *also* get rich error messages by doing
    ```python
    tt = Float[Array, "foo"]
    assert isinstance(x, tt), tt.__instancecheck_str__(x) + "\n" + print_bindings()
    ```
    which is still a bit long-winded right now but is a step in the right direction.

(CC @leycec for interest.)
2024-02-25 12:07:01 +00:00
Patrick Kidger 28ad5275d7 Moved print_bindings into storage.py 2024-02-25 12:07:01 +00:00
Patrick Kidger d7fd59a34c Added print_bindings. 2024-02-25 12:07:01 +00:00
Afroz Mohiuddin 8de8c0bb68 Correct pytree path in array.md
Correct pytree path in array.md
2024-02-12 15:27:03 +00:00
Patrick Kidger f18de2ce28 Added better docs on stringified type annotations 2024-01-08 05:45:32 -08:00
Patrick Kidger eb9a23df63 Update dataclass docs (#155)
* Update dataclass docs
2024-01-05 13:17:45 +00:00
Jérome Eertmans adf1a5e4e3 chore(docs): fix typos in docstrings
Hello!

This is a small PR to fix typos in docstrings.

Maybe, I would suggest adding an import for `dataclass` in the example (otherwise it will not run), and maybe indicate that it works with other dataclasses decorators, like the `dataclass` decorator from chex.
2024-01-05 04:36:08 -08:00
Patrick Kidger 272be74e01 Bump version v0.2.25 2023-12-15 10:34:45 -08:00
Patrick Kidger 7df267efa4 Upgrade to ruff-format 2023-12-10 15:27:42 -08:00
Patrick Kidger d43933f942 Updated to latest pyktdocs_tweaks 2023-12-09 14:55:30 -08:00
Patrick Kidger 1acc0d7153 Improved error messages a little bit, in particular to highlight individual problematic arguments. 2023-12-08 10:17:57 -08:00
Patrick Kidger 33cf4fcdac Simplified internals by removing jaxtyping_raise; jaxtyping_malformed. 2023-12-05 19:06:00 -08:00
Patrick Kidger e5cc75e4a3 Removed internal jaxtyped_fns registry that is no longer needed. 2023-12-05 19:06:00 -08:00
Patrick Kidger 125bc89ee9 Added environment config flags.
These flags are `JAXTYPING_DISABLE` and `JAXTYPING_REMOVE_TYPECHECKER_STACK`.

In addition, have now added warnings when using old-style double-decorator syntax, which also serves to guard against the easy mistake of
```python
@jaxtyped(typechecker)
def foo(...)
```
which actually decorates the `typechecker`, not `foo`.
2023-12-05 19:06:00 -08:00
Patrick Kidger 8e47c9081c version bump v0.2.24 2023-11-27 09:50:02 -08:00
Patrick Kidger 205978958f Fix install_import_hook(..., None) 2023-11-27 09:50:02 -08:00
Patrick Kidger 850f4e72cd Handle beartype doing isinstance(None, hint) 2023-11-27 09:50:02 -08:00
Patrick Kidger 0a76c9c70c Error message improvements 2023-11-27 09:50:02 -08:00
Patrick Kidger 5fbd6718ab Added support for 'self' in dataclass attribute annotations; switched from args and kwargs to just arguments. 2023-11-27 09:50:02 -08:00
Patrick Kidger 80a99568f7 Removed unused elements from unions, e.g. Float[ArrayLike, ...] will no longer include Float[np.bool, ...]. 2023-11-27 09:50:02 -08:00
Patrick Kidger baffbef5ca Doc fix 2023-11-27 09:50:02 -08:00
Patrick Kidger 127eae56b7 array shapes+dtypes no longer checked as part of pytree flattening. This avoids edge-case crash when using pytree-path dependent sizes 2023-11-27 09:50:02 -08:00
Patrick Kidger 58600d3fe0 Fixed new-style PRNG keys. 2023-11-27 09:50:02 -08:00
Patrick Kidger 7925e278f4 Symbolic expressions now support delayed binding to arguments. Fixes #93. 2023-11-27 09:50:02 -08:00
Patrick Kidger ba3b2027cc Standardised terminology: now using just "axis"/"axes", not "dimension" 2023-11-27 09:50:02 -08:00
Patrick Kidger 12d540794f Pretty error messages: fixes #6.
Phew, this ended up being a pretty complicated change!
The basic summary is that we now support the syntax
```
@jaxtyped(typechecker=typechecker)
def f(...): ...
```
and when using this, we now get pretty error messages about what went
wrong.

(
The old syntax, i.e.
```
@jaxtyped
@typechecker
def f(...): ...
```
is still supported, but doesn't give much information.
)

The internals of this do quite a lot of magic! In particular we
dynamically create quite a lot of functions and test the provided
arguments against their signatures. The overhead should still be
minimal under `jax.jit`, though.
(TODO: what's the overhead like in non-jit situations, e.g. PyTorch?
I've tried to minimise the overhead throughout just to be sure, but
perhaps PyTorch users should stick to the old syntax?)
2023-11-27 09:50:02 -08:00
Patrick Kidger 63e0fdff74 Typecheck errors now state the size of the stored axis and structure values. 2023-11-27 09:50:02 -08:00
Patrick Kidger d12291de7e Added support for treepath-dependent sizes. 2023-11-27 09:50:02 -08:00
Patrick Kidger 9e1ba8a77d Added support for declaring PyTree structures. 2023-11-27 09:50:02 -08:00
Patrick Kidger e4a93ee218 Added with jaxtyped("context"):, for now undocumented. 2023-11-07 11:34:40 -08:00
Patrick Kidger 260fb36876 Fixed mixing variadic+broadcast with variadic+nonbroadcast dimensions.
Previously, something like this would not raise an error, as
variadic+broadcast dimensions were stored in a separate namespace to
variadic+nonbroadcast dimensions:
```python
def f(x: Float[Array, "*foo"], y: Float[Array, "#*foo"]):
    pass

a, b = ...
assert a.shape == (3, 4)
assert b.shape == (5,)
f(a, b)
```
2023-11-07 11:34:40 -08:00
Patrick Kidger 9646eff7e1 Fixes for g3 2023-10-23 22:00:51 -07:00
Patrick Kidger 1a048b1f2f Fixed Float[ArrayLike, "#*foo"] leaving out bool/int/float/complex. 2023-10-21 12:01:21 -07:00
Patrick Kidger 338ca631c6 beartype error messages for dataclass attributes now use the correct name 2023-10-21 11:38:44 -07:00
Patrick Kidger 2ab8286c81 Error message for bad symbolic shapes is now useful. 2023-10-21 11:38:04 -07:00
Patrick Kidger 7f85a12a85 Added DTypeLike to match jax.typing 2023-10-17 09:43:31 -07:00