Skip to content

Commit

Permalink
Simplify the logic of adjusting signs for estimated eigenvectors comp…
Browse files Browse the repository at this point in the history
…arisons

Summary: Leverage PyTorch indices comparions to adjust the signs of `estimated_eigenvectors` more Pythonic.

Reviewed By: gajjanag

Differential Revision: D65866712

fbshipit-source-id: 2ec3e50faaf75b4a98027a7dac867c1528f44d72
  • Loading branch information
tsunghsienlee authored and facebook-github-bot committed Nov 14, 2024
1 parent 18fe48c commit ae4a81e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tests/matrix_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,10 @@ def test_matrix_eigenvectors(self) -> None:
eigenvector_computation_config=qr_config,
)
# Ensure that the signs of the eigenvectors are consistent.
for col in range(A.shape[1]):
if (
expected_eigenvectors[0, col]
/ estimated_eigenvectors[0, col]
< 0
):
estimated_eigenvectors[:, col] *= -1
estimated_eigenvectors[
:,
expected_eigenvectors[0, :] / estimated_eigenvectors[0, :] < 0,
] *= -1
torch.testing.assert_close(
expected_eigenvectors,
estimated_eigenvectors,
Expand Down

0 comments on commit ae4a81e

Please sign in to comment.