Skip to content

Avoid sqrt of negative discriminants in MJX ray quadratics - #3513

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/mjx-ray-negative-discriminant
Open

Avoid sqrt of negative discriminants in MJX ray quadratics#3513
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/mjx-ray-negative-discriminant

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Prevent _ray_quad from taking sqrt of a negative discriminant before no-intersection masking is applied.

The current code computes jp.sqrt(det) first and only afterward replaces results with infinity when det < mjMINVAL. For negative discriminants, the square root therefore produces NaNs unnecessarily.

Clamp only the square-root input to zero:

jp.sqrt(jp.maximum(det, 0))

The existing det < mjMINVAL condition still controls the returned no-intersection result, so positive-discriminant behavior and the existing threshold are unchanged.

Adds a focused regression test for a quadratic with a negative discriminant, asserting both roots are inf rather than NaN.

The original diagnosis was reported in closed, unmerged PR #2895 by @zhangbaozhe. This is a narrower reimplementation on current main.

Validation

Final branch is based on current main, with one implementation line and one focused regression test.

The MJX runtime test was not executed locally because the required MuJoCo/JAX Python environment is not installed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant