Skip to content

use jnp.nanmin and jnp.nanmax to compute new stepsize factor #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions diffrax/step_size_controller/adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,7 @@ def _scale(_y0, _y1_candidate, _y_error):
factor2 = 1 if _zero_coeff(coeff2) else prev_inv_scaled_error ** coeff2
factor3 = 1 if _zero_coeff(coeff3) else prev_prev_inv_scaled_error ** coeff3
factormin = jnp.where(keep_step, 1, self.factormin)
factor = jnp.clip(
self.safety * factor1 * factor2 * factor3,
a_min=factormin,
a_max=self.factormax,
)
factor = jnp.nanmin(jnp.array([self.factormax, jnp.nanmax(jnp.array([self.safety * factor1 * factor2 * factor3, factormin]))]))
# Once again, see above. In case we have gradients on {i,p,d}coeff.
# (Probably quite common for them to have zero tangents if passed across
# a grad API boundary as part of a larger model.)
Expand Down