Skip to main content

Execute runtime assertions, indexing checks, and more if `jax` code is not traced.

Project description

https://github.com/tillahoffmann/ifnt/actions/workflows/build.yml/badge.svg https://readthedocs.org/projects/ifnt/badge/?version=latest https://img.shields.io/pypi/v/jax-ifnt

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.5.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

jax_ifnt-0.1.5-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file jax_ifnt-0.1.5.tar.gz.

File metadata

  • Download URL: jax_ifnt-0.1.5.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for jax_ifnt-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f42e4faedbcae8222b3ecfd7c39406657f9c15e33f15ab52cd766e53d7d23b10
MD5 d5eb46d7be745fea684c2828802d5eed
BLAKE2b-256 8065be0cc161b1b1b5dbb74a60db96e22c14f5d582a99c5a5ca0aa5c25fab751

See more details on using hashes here.

File details

Details for the file jax_ifnt-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: jax_ifnt-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for jax_ifnt-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 45348196b612c88458e35379963c8661b5928b6bbbf46ef4ef621ad0f2dac4a8
MD5 fbf2bd9bca57c36d341034b14088eae3
BLAKE2b-256 c8fb685295cee12de90649136d379d7bb86066d222f2ab4d38047e14de80ea5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page