Skip to content

Commit a02897f

Browse files
yutingyemeta-codesync[bot]
authored andcommitted
Silence numpy/torch warnings in camera and diff_geometry tests (#1595)
Summary: Pull Request resolved: #1595 Two pymomentum unit tests emitted warnings on CI (surfaced by the OSS Windows pytest run): 1. `test_camera.py::test_fisheye_matches_numpy_reference` -- `RuntimeWarning: invalid value encountered in divide`. The numpy reference computed `np.where(r > 1e-8, theta_d / r, 1.0)`, but `np.where` evaluates both branches eagerly, so `theta_d / r` divided by zero for the on-axis point (`r == 0`). The bad values were discarded by the `where`, but the warning still fired. Guard the divisor with an inner `np.where` so the division never sees zero. 2. `test_diff_geometry.py::test_diffInverseParamTransform` -- `UserWarning` from `torch.autograd.gradcheck` about a non-double-precision input. The test built `modelParams` as float32 (missing `dtype=torch.float64`), so the derived `jointParams` passed to `gradcheck` was single precision, making the finite-difference check unreliable. Every other gradcheck test in the file already uses float64; add the missing dtype to match. Both are test-only changes; no library behavior changes. ___ Differential Revision: D113866040 fbshipit-source-id: 41b065ac4b6d5407247eebbab866a31284cc5c95
1 parent 6f86f08 commit a02897f

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎pymomentum/test/test_camera.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def test_fisheye_matches_numpy_reference(self) -> None:
456456
theta_d = theta * (
457457
1.0 + k1 * theta2 + k2 * theta2**2 + k3 * theta2**3 + k4 * theta2**4
458458
)
459-
scale = np.where(r > 1e-8, theta_d / r, 1.0)
459+
scale = np.where(r > 1e-8, theta_d / np.where(r > 1e-8, r, 1.0), 1.0)
460460
u_ref = fx_val * scale * a + cx_val
461461
v_ref = fy_val * scale * b + cy_val
462462

‎pymomentum/test/test_diff_geometry.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def test_diffInverseParamTransform(self) -> None:
9595
nBatch = 2
9696
# Some nonzero vector as 0 always maps to 0 in momentum:
9797
modelParams = 0.3 * torch.ones(
98-
nBatch, character.parameter_transform.size, requires_grad=AUTOGRAD_ENABLED
98+
nBatch,
99+
character.parameter_transform.size,
100+
requires_grad=AUTOGRAD_ENABLED,
101+
dtype=torch.float64,
99102
)
100103
jointParams = pym_diff_geometry.apply_parameter_transform(
101104
character, modelParams

0 commit comments

Comments
 (0)