Derivative checks accept NaN and infinite Jacobians as matching finite differences
Reproduction
minimize.check_jacobian can report that invalid derivatives match finite differences. A NaN entry poisons the relative-error comparison, and an infinite entry produces inf/inf. Since NaN > tolerance is false, neither is rejected.
import numpy as np
from mujoco import minimize
minimize.check_jacobian(
lambda x: x, np.array([[1.]]), np.array([[1.]]),
np.array([[np.nan]]), np.float64(1e-6), 0)
# Prints: User-provided Jacobian matches finite-differences.The same occurs with positive/negative infinity, and when the finite-difference Jacobian is nonfinite while the supplied Jacobian is finite. This propagates to least_squares(check_derivatives=True) and the custom-norm gradient check.
Expected behavior
Reject nonfinite entries in either Jacobian before comparing them. Preserve the existing finite-data tolerance, evaluation counts, success messages and mismatch handling. A failed check must not print a success message.
Reproduced using the current checkout's complete minimize.py module with the MuJoCo 3.14.0 macOS wheel, Python 3.12.11. No renderer, downloaded models or robot hardware are involved. Repository issues and PRs were searched for overlapping derivative-check fixes.
Source: google-deepmind/mujoco