xwhile#
- t3toolbox.backend.common.xwhile(cond, body, init_state, use_jit=False)#
def xwhile( cond, # state -> 0-d bool (eager) / traced bool (jit): loop while True body, # state -> state (a pytree of the SAME structure and leaf shapes) init_state, # the loop-carried state (pytree) use_jit: bool = False, # True + jax state -> jax.lax.while_loop; else a Python while loop ):
Data-dependent
whilewith the numpy / eager-jax / jit dispatch – thexscanprecedent for awhile. Withuse_jitand a jax state it compiles viajax.lax.while_loop; otherwise (numpy, eager jax, or jax not installed) it runswhile bool(cond(state)): state = body(state), so it works on every backend and silently falls back to eager when jit is unavailable. Writecond/bodybackend-agnostically (condreturns a 0-d boolean;bodyusesxnp.where, not Python branches) so the SAME pair drives both paths.- Parameters:
use_jit (bool)