Skip to content

Why does jit + if statement work here? #14224

Answered by jakevdp
HHalva asked this question in Q&A
Discussion options

You must be logged in to vote

jit is compatible with if statements whose truth or falsehood is decidable at trace time. x is None fits this criterion, because it concerns the identity of the Python variable.

Other statements that can be used within if statements are static attributes of the an array, such as shape, size, or dtype.

What will not work within JIT is attempting to branch based on dynamic quantites, such as values within arrays.

There's some discussion of these topics in How To Think In JAX.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@HHalva
Comment options

Answer selected by HHalva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants