jax
8127392a - Use get() rather than a try-catch block in memoized function lookup.

Commit
7 years ago
Use get() rather than a try-catch block in memoized function lookup. Currently backtraces often look like this: ``` --------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/p/jax/jax/util.py in memoized_fun(*args, **kwargs) 133 try: --> 134 return cache[key] 135 except KeyError: KeyError: ((lu, ShapedArray(int32[2,2])), ()) During handling of the above exception, another exception occurred: KeyError Traceback (most recent call last) ~/p/jax/jax/util.py in memoized_fun(*args, **kwargs) 133 try: --> 134 return cache[key] 135 except KeyError: KeyError: ((lu, xla_client.Shape(_dtype=dtype('int32'), _dimensions=(2, 2), _is_tuple=False, _minor_to_major=None)), ()) During handling of the above exception, another exception occurred: NotImplementedError Traceback (most recent call last) <ipython-input-26-d6c00d50e3c9> in <module> ``` The "during handling of the above exception..." message is mostly a distraction for the user that occurs because we perform the memoized function evaluation inside a `catch` block. By performing the function evaluation outside the catch block, we can get better backtraces without the distraction of the KeyError exception. ```
Author
Committer
Parents
Loading