Added print_bindings.

This commit is contained in:
Patrick Kidger
2024-02-25 12:07:01 +00:00
parent 8de8c0bb68
commit d7fd59a34c
4 changed files with 40 additions and 3 deletions
+16 -1
View File
@@ -1,9 +1,10 @@
import abc
import jax.numpy as jnp
import jax.random as jr
import pytest
from jaxtyping import Array, Float, jaxtyped
from jaxtyping import Array, Float, jaxtyped, print_bindings
from .helpers import ParamError, ReturnError
@@ -166,3 +167,17 @@ def test_local_stringified_annotation(typecheck):
# We don't check that errors are raised if it goes wrong, since we can't usually
# resolve local type annotations at runtime. Best we can hope for is not to raise
# a spurious error about not being able to find the type.
def test_print_bindings(typecheck, capfd):
@jaxtyped(typechecker=typecheck)
def f(x: Float[Array, "foo bar"]):
print_bindings()
capfd.readouterr()
f(jnp.zeros((3, 4)))
text, _ = capfd.readouterr()
assert text == (
"The current values for each jaxtyping axis annotation are as follows."
"\nfoo=3\nbar=4\n"
)