mirror of
https://github.com/wassname/jaxtyping.git
synced 2026-09-09 11:24:55 +08:00
Now provides PyTreeDef, and can detect PyTrees via issubclass(x, PyTree)
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
# Advanced features
|
||||
|
||||
## Abstract base classes
|
||||
## Creating your own dtypes
|
||||
|
||||
::: jaxtyping.AbstractDtype
|
||||
selection:
|
||||
members:
|
||||
false
|
||||
|
||||
::: jaxtyping.AbstractArray
|
||||
selection:
|
||||
members:
|
||||
false
|
||||
## Introspection
|
||||
|
||||
If you're writing your own type hint parser, then you may wish to detect if some Python object is a jaxtyping-provided type.
|
||||
|
||||
You can check for dtypes by doing `issubclass(x, AbstractDtype)`. For example, `issubclass(Float32, AbstractDtype)` will pass.
|
||||
|
||||
You can check for arrays by doing `issubclass(x, AbstractArray)`. Here, `AbstractArray` is the base class for all shape-and-dtype specified arrays, e.g. it's a base class for `Float32[Array, "foo"]`.
|
||||
|
||||
You can check for pytrees by doing `issubclass(x, PyTree)`. For example, `issubclass(PyTree[int], PyTree)` will pass.
|
||||
|
||||
+5
-1
@@ -5,4 +5,8 @@
|
||||
members:
|
||||
false
|
||||
|
||||
Note that `jaxtyping.PyTree` is only available if JAX has been installed.
|
||||
`jaxtyping.PyTreeDef` is an alias for `jax.tree_util.PyTreeDef`, which is the type of the return from `jax.tree_util.tree_structure(...)`.
|
||||
|
||||
:::jaxtyping.PyTreeDef
|
||||
|
||||
Note that `jaxtyping.{PyTree, PyTreeDef}` are only available if JAX has been installed.
|
||||
|
||||
Reference in New Issue
Block a user