Skip to content

Commit

Permalink
Satisfy stricter input requirement for jnp.linalg.norm
Browse files Browse the repository at this point in the history
The previous version of the code caused an error under the new more restrictive API of `jnp.linalg.norm` (see jax-ml/jax#12670).

PiperOrigin-RevId: 484080138
  • Loading branch information
Jake VanderPlas authored and JAX-CFD authors committed Oct 26, 2022
1 parent 3680144 commit 95a2cca
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jax_cfd/base/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _log_normal_pdf(x, mode, variance=.25):


def _max_speed(v):
return jnp.linalg.norm([u.data for u in v], axis=0).max()
return jnp.linalg.norm(jnp.array([u.data for u in v]), axis=0).max()


def filtered_velocity_field(
Expand Down
2 changes: 1 addition & 1 deletion jax_cfd/base/initial_conditions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_filtered_velocity_field(
self, seed, grid, maximum_velocity, peak_wavenumber):
v = ic.filtered_velocity_field(
jax.random.PRNGKey(seed), grid, maximum_velocity, peak_wavenumber)
actual_maximum_velocity = jnp.linalg.norm([u.data for u in v], axis=0).max()
actual_maximum_velocity = jnp.linalg.norm(jnp.array([u.data for u in v]), axis=0).max()
max_divergence = fd.divergence(v).data.max()

# Assert that initial velocity is divergence free
Expand Down
2 changes: 1 addition & 1 deletion jax_cfd/collocated/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _log_normal_pdf(x, mode, variance=.25):


def _max_speed(v):
return jnp.linalg.norm([u.data for u in v], axis=0).max()
return jnp.linalg.norm(jnp.array([u.data for u in v]), axis=0).max()


def filtered_velocity_field(
Expand Down
2 changes: 1 addition & 1 deletion jax_cfd/collocated/initial_conditions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_filtered_velocity_field(
self, seed, grid, maximum_velocity, peak_wavenumber):
v = initial_conditions.filtered_velocity_field(
jax.random.PRNGKey(seed), grid, maximum_velocity, peak_wavenumber)
actual_maximum_velocity = jnp.linalg.norm([u.data for u in v], axis=0).max()
actual_maximum_velocity = jnp.linalg.norm(jnp.array([u.data for u in v]), axis=0).max()
max_divergence = fd.centered_divergence(v).data.max()

# Assert that initial velocity is divergence free
Expand Down

0 comments on commit 95a2cca

Please sign in to comment.