Skip to content

Instantly share code, notes, and snippets.

View fayalalebrun's full-sized avatar

Francisco Ayala Le Brun fayalalebrun

View GitHub Profile
@fayalalebrun
fayalalebrun / quantize_posit.py
Created March 2, 2024 07:13
Simulate posit quantization using JAX
import unittest
import jax
import jax.numpy as jnp
from functools import partial
def decompose(x: jnp.float32) -> tuple[jnp.int32, jnp.int32, jnp.int32]:
"""decomposes a float32 into negative, exponent, and significand"""
negative = x < 0
n = jnp.abs(x).view(jnp.int32)
exponent = (n >> 23) - 127