Skip to content
Discussion options

You must be logged in to vote

Hi - the issue is your use of Python's and and or. This attempts to cast the operands on either side to boolean, which leads to this error. If you want traceable boolean logic, you need to use &, |, and ~ instead of and, or, and not (for what it's worth, this is simlar to what's required for element-wise operations on numpy arrays)

The fix would look like this:

return jax.lax.cond((_at(grid,i,j) == 1) & ((live_neighbors < 2) | (live_neighbors > 3)),
                    ...

Note the additional parentheses, which are required because of the relative operator precedence of logical and inequality ops.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by abhinavprao
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
2 participants