Execute runtime assertions, indexing checks, and more if `jax` code is not traced.
Project description
Execute runtime assertions, indexing checks, and more if jax
code is not traced.
>>> import ifnt >>> import jax >>> from jax import numpy as jnp >>> >>> def safe_log(x): ... ifnt.testing.assert_array_less(0, x) ... return jnp.log(x) >>> >>> safe_log(-1) Traceback (most recent call last): ... AssertionError: Arrays are not strictly ordered `x < y` <BLANKLINE> Mismatched elements: 1 / 1 (100%) Max absolute difference among violations: 1 Max relative difference among violations: 1. x: array(0) y: array(-1) >>> jax.jit(safe_log)(-1) Array(nan, dtype=float32, weak_type=True)
Installation
$ pip install jax-ifnt
Relationship to chex
DeepMind’s chex provides similar, often complementary, assertions. While chex requires runtime assertions to be “functionalized” with chex.chexify
, ifnt will skip assertions in traced code. This facilitates, for example, verifying that indices are not out of bounds.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jax_ifnt-0.1.4.tar.gz
(7.8 kB
view details)
Built Distribution
File details
Details for the file jax_ifnt-0.1.4.tar.gz
.
File metadata
- Download URL: jax_ifnt-0.1.4.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dc1633e53d7c3b6ec785e963a825c1bbaca18b5a9c17dea552cce1d9658a649 |
|
MD5 | d20c0d2a25eaaf44b3529e80aeba7b63 |
|
BLAKE2b-256 | cf34c855188a7216c19cceeea29dd36e0fc7dca0a2abe34700a8a3c7c4a213b1 |
File details
Details for the file jax_ifnt-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: jax_ifnt-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e83ea80fa60fb79d038d05754eec5da5aa3f837c2d1fb17f7e8ecd6ca907142 |
|
MD5 | f652bb8bb9948a8b3182f86c009483ff |
|
BLAKE2b-256 | 75f178a7eb56c914e6fcb3d4523bb155c2ff090ced4c59a21b39f2db6cdff1e9 |