Add test coverage for gnm_common#25
Conversation
Adds gnm_common_test.py covering the backend-agnostic math shared by every GNM backend: array helpers (take, eye, reshape_with_batch_dims, zeros_with_batch_dims), axis_angle_to_rotation_matrix (identity, per-axis invariance, known rotations, orthonormality/determinant, batch shapes), joint_transforms_world forward kinematics, linear_blend_skinning (rest pose, translation, batching), the bind-pose helpers, and compute_pose_correctives. 25 tests, following the existing absltest style.
655792d to
6996da4
Compare
| class ArrayHelpersTest(parameterized.TestCase): | ||
| """Tests for the backend-agnostic array helpers.""" | ||
|
|
||
| def test_take_selects_along_axis(self) -> None: |
There was a problem hiding this comment.
Please remove the return type annotation from all the test_* functions. This is to stay consistent with our internal codebase.
| from gnm.shape import gnm_common | ||
|
|
||
|
|
||
| class ArrayHelpersTest(parameterized.TestCase): |
There was a problem hiding this comment.
For all the tests, please use the parameterized to generate a given test for all the backends supported by xnp (NumPy, jax, TF, pytorch).
For the functions which take xnp as an input argument, you can iterate over the backends directly (take, eye), for the other functions you can iterate over input arrays built by the individual backends from which the current xnp is extracted at runtime within the functions under test (reshape_with_batch_dims, zeros_with_batch_dims).
This will help the tests catch any potential bugs specific to a given backend.
| np.testing.assert_array_equal(zeros, np.zeros((4, 4, 4))) | ||
|
|
||
|
|
||
| class AxisAngleToRotationMatrixTest(parameterized.TestCase): |
There was a problem hiding this comment.
As in the comment about ArrayHelperTest, please use the parameterized to iterate as well over the supported backends. Fo the actual asserts, for simplicity one could always convert the values to np.ndarray.
| self.assertEqual(matrices.shape, (2, 4, 3, 3)) | ||
|
|
||
|
|
||
| class JointTransformsWorldTest(parameterized.TestCase): |
There was a problem hiding this comment.
As in the comment about ArrayHelperTest, please use the parameterized to iterate as well over the supported backends. Fo the actual asserts, for simplicity one could always convert the values to np.ndarray.
| ) | ||
|
|
||
|
|
||
| class LinearBlendSkinningTest(parameterized.TestCase): |
There was a problem hiding this comment.
As in the comment about ArrayHelperTest, please use the parameterized to iterate as well over the supported backends. Fo the actual asserts, for simplicity one could always convert the values to np.ndarray.
| self.assertEqual(posed.shape, (4, 3, 3)) | ||
|
|
||
|
|
||
| class BindPoseTest(parameterized.TestCase): |
There was a problem hiding this comment.
As in the comment about ArrayHelperTest, please use the parameterized to iterate as well over the supported backends. Fo the actual asserts, for simplicity one could always convert the values to np.ndarray.
| ) | ||
|
|
||
|
|
||
| class PoseCorrectivesTest(parameterized.TestCase): |
There was a problem hiding this comment.
As in the comment about ArrayHelperTest, please use the parameterized to iterate as well over the supported backends. Fo the actual asserts, for simplicity one could always convert the values to np.ndarray.
|
@manumishra12 Thanks for the PR! Besides the comments above, please see also the output of the linter CI. |
Adds
gnm_common_test.py.gnm_common.pyholds the backend-agnostic mathshared by all four GNM backends but had no dedicated test (it was only
exercised indirectly through the per-backend tests).
The new suite (25 tests) covers:
take,eye,reshape_with_batch_dims,zeros_with_batch_dims.principal axis leaves that axis invariant, the 90 degrees-about-z reference
matrix, orthonormality and unit determinant on random inputs, and batch-shape
preservation.
a global translation shifts the chain, and a root rotation propagates to the
child joint.
translates the vertices, and batch shapes are preserved.
Noneparameters return the template, and identity/expression bases are applied
correctly.
Noneinputs and zero rotations produce zerocorrectives, and batch shapes are preserved.
Follows the existing
abslteststyle used across the package. All tests passlocally with the NumPy backend.