Skip to content

vmap and logical tests #5898

Answered by jakevdp
hovren asked this question in Q&A
Mar 2, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

This issue is discussed here: How to Think in JAX: Tracing and static variables.

In particular, when you apply a vmap transformation on code, the mapped variables are traced, and it is not possible to do control flow that depends on the values being mapped. So this statement:

    if not is_ok(x, -1., 1.):
        raise ValueError("Bad value")

is incompatible with vmap when x is a mapped value. You cannot raise an error conditional on mapped values.

The best course of action depends on what you're doing with the result. Can you say more about the application that this simple snippet is meant to represent?

Replies: 1 comment 4 replies

Comment options

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

@jakevdp
Comment options

@hovren
Comment options

@jakevdp
Comment options

Answer selected by hovren
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