Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
panxinmiao committed Dec 19, 2024
1 parent 5e54fd0 commit 43fa6e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylinalg/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def mat_decompose(matrix, /, *, scaling_signs=None, dtype=None, out=None):

rotation = out[1] if out is not None else None

rotation_matrix = matrix[:-1, :-1].copy()
rotation_matrix = matrix[:-1, :-1].copy().astype(float)
mask = scaling != 0
rotation_matrix[:, mask] /= scaling[mask][None, :]
rotation_matrix[:, ~mask] = 0.0
Expand Down
15 changes: 15 additions & 0 deletions tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ def test_mat_decompose():
npt.assert_array_almost_equal(rotation, [0, 0, np.sqrt(2) / 2, np.sqrt(2) / 2])


def test_mat_decompose_scaling_0():
"""Test that the matrices are decomposed correctly when scaling is 0."""

scaling = [0, 0, 2]
rotation = [0, 0, np.sqrt(2) / 2, np.sqrt(2) / 2]
translation = [2, 2, 2]

matrix = la.mat_compose(translation, rotation, scaling)
translation_, rotation_, scaling_ = la.mat_decompose(matrix)

npt.assert_array_almost_equal(translation_, translation)
npt.assert_array_almost_equal(scaling_, scaling)
# rotation is not uniquely defined when scaling is 0, but it should not be NaN
assert not np.isnan(rotation_).any()

@pytest.mark.parametrize(
"signs",
[
Expand Down

0 comments on commit 43fa6e1

Please sign in to comment.