Add test from https://github.com/google/jax/pull/5165, with a couple of small improvements..
Add test from https://github.com/google/jax/pull/5165, with a couple of small improvements..

google/jax,google/jax,google/jax,google/jax