Skip to content

Filter an array based on another boolean array (JIT compiled) #10105

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

You must be logged in to vote

No, unfortunately jax.jit requires statically-shaped arrays, so there is no way to do what you're asking within a JIT-compiled function. The standard workaround is to re-express your computation in terms of statically shaped arrays, and I find in practice this can often be done with some thought. Another possiblity is to split your computation such that the dynamic arrays are generated outside of a JIT context, and the computation on those arrays are then done within JIT.

If you have a specific application in mind that you're having trouble re-expressing this way, feel free to open a discussion with more detail.

Replies: 3 comments 5 replies

Comment options

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

Answer selected by valentinmace
Comment options

You must be logged in to vote
4 replies
@valentinmace
Comment options

@jakevdp
Comment options

@YouJiacheng
Comment options

@YouJiacheng
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants