question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lax.cond does not exist, contrary to the README

See original GitHub issue

The README says

If you want compiled control flow, use structured control flow primitives like lax.cond and lax.while.

But lax.cond does not actually exist, and lax.while only exists in the form of lax._while_loop.

  1. Is lax.cond already implemented somewhere, just not part of the master branch? I don’t need gradient support for lax.cond (which is tracked by PR #83), just jit-compilable cond would be a huge gain for me (currenty looking into whether I might be able to contribute this if it doesn’t exist yet)

  2. lax.while will probably never exist because while is a reserved keyword; so this should probably be renamed to lax.while_loop and can probably already be made available by renaming lax._while_loop, or what’s the problem with the _while_loop implementation (fori_loop and foreach_loop are not prefixed with an underscore and use _while_loop, so it should be fully functional)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mattjjcommented, Feb 6, 2019

Early versions of lax.cond (circa early 2017) lowered into while loops (though I think we needed 2 in general, I can’t remember why). But were totally broken from a tracing-composability perspective, which is why we don’t have them now.

The main reason we haven’t exposed a lax.cond yet is essentially the same as why #331 and #207 are outstanding issues, namely that we want to handle closures and arbitrary composability correctly. @dougalm designed the core system to handle these issues, and actually it enables two ways of handling higher-order functions like lax.cond and lax.while, which we can call “the hard way” and “the easy way”. We recently decided that the practical benefits of the hard way over the easy way are pretty miniscule (though academically interesting), and so @dougalm started going “the easy way” in #334.

#334 doesn’t add lax.cond but it paves the way for doing it (along with a differentiable lax.map and lax.scan).

2reactions
hawkinspcommented, Feb 5, 2019

@jekbradbury np.where(b, x, y) is also possible (aka lax.select with different broadcasting semantics).

Read more comments on GitHub >

github_iconTop Results From Across the Web

jax.lax.cond - JAX documentation - Read the Docs
The type can be a scalar, array, or any pytree (nested Python tuple/list/dict) thereof. Returns. Value (B) of either true_fun(*operands) or false_fun(*operands) ...
Read more >
clojure.tools.namespace - cljdoc
parse: A parser for namespace declarations in Clojure source files. Given a stream of characters from a Clojure source file, it can find...
Read more >
Release Notes — Airflow Documentation
When you set it to "false", the header was not added, so Airflow could be embedded in an iframe. By default Airflow could...
Read more >
Common Gotchas in JAX - Colaboratory - Google Colab
JAX transformation and compilation are designed to work only on Python functions that are functionally pure: all the input data is passed through...
Read more >
OSS Readme Part 1 - Bentley - Product Documentation
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found