-
Notifications
You must be signed in to change notification settings - Fork 841
Fix compatibility with numpy 2.5 #5404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0df2fd7
a0dce8c
3bcf762
fd6fa86
7cecd60
0aebde9
2f46b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1280,8 +1280,8 @@ class TestPBCFlag(object): | |
| ), | ||
| "principal_axes": np.array( | ||
| [ | ||
| [0.78787867, 0.26771575, -0.55459488], | ||
| [-0.40611024, -0.45112859, -0.7947059], | ||
| [-0.78787867, -0.26771575, 0.55459488], | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe these are fine since the eigenvector sign is arbitrary?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the sign is algorithm-dependent and therefore can differ between
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like some tests are still failing because of sign issues. Maybe to make them more robust we could check for all the eigenvector tests that they are numerically equivalent up to a sign change?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'm thinking we should do an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done - just to sanity check me, can I get a re-review please?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it again. abs is not the same as sign-check. Will comment on review. |
||
| [0.40611024, 0.45112859, 0.7947059], | ||
| [-0.46294889, 0.85135849, -0.24671249], | ||
| ] | ||
| ), | ||
|
|
@@ -1315,8 +1315,8 @@ class TestPBCFlag(object): | |
| ), | ||
| "principal_axes": np.array( | ||
| [ | ||
| [0.85911708, -0.19258726, -0.4741603], | ||
| [0.07520116, 0.96394227, -0.25526473], | ||
| [-0.85911708, 0.19258726, 0.4741603], | ||
| [-0.07520116, -0.96394227, 0.25526473], | ||
| [0.50622389, 0.18364489, 0.84262206], | ||
| ] | ||
| ), | ||
|
|
@@ -1355,6 +1355,14 @@ def test_wrap(self, ag, wrap, ref, method_name): | |
| if method_name == "bsphere": | ||
| assert_almost_equal(result[0], ref[method_name][0], self.prec) | ||
| assert_almost_equal(result[1], ref[method_name][1], self.prec) | ||
| elif method_name == "principal_axes": | ||
| # See PR #5404 | ||
| # The direction (sign) of the principal axes is dependent on the | ||
| # specific algorithm used, but the direction itself is not physically | ||
| # relevant, so we get the signs to flip any anti-parallel vectors before | ||
| # comparing the two results arrays | ||
| signs = np.sign(np.einsum("ij,ij->i", result, ref[method_name])) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fancy, I convinced myself that it does the right thing for the output of principal_axes(). |
||
| assert_almost_equal(result * signs[:, np.newaxis], ref[method_name], self.prec) | ||
| else: | ||
| assert_almost_equal(result, ref[method_name], self.prec) | ||
|
|
||
|
|
@@ -1620,16 +1628,21 @@ def test_coordinates(self, ag): | |
| ) | ||
|
|
||
| def test_principal_axes(self, ag): | ||
| assert_almost_equal( | ||
| ag.principal_axes(), | ||
| np.array( | ||
| [ | ||
| [1.53389276e-03, 4.41386224e-02, 9.99024239e-01], | ||
| [1.20986911e-02, 9.98951474e-01, -4.41539838e-02], | ||
| [-9.99925632e-01, 1.21546132e-02, 9.98264877e-04], | ||
| ] | ||
| ), | ||
| ref = np.array( | ||
| [ | ||
| [-1.53389276e-03, -4.41386224e-02, -9.99024239e-01], | ||
| [-1.20986911e-02, -9.98951474e-01, 4.41539838e-02], | ||
| [-9.99925632e-01, 1.21546132e-02, 9.98264877e-04], | ||
| ] | ||
| ) | ||
| result = ag.principal_axes() | ||
| # See PR #5404 | ||
| # The direction (sign) of the principal axes is dependent on the | ||
| # specific algorithm used, but the direction itself is not physically | ||
| # relevant, so we get the signs to flip any anti-parallel vectors before | ||
| # comparing the two results arrays | ||
| signs = np.sign(np.einsum("ij,ij->i", result, ref)) | ||
| assert_almost_equal(result * signs[:, np.newaxis], ref) | ||
|
|
||
| def test_principal_axes_duplicates(self, ag): | ||
| ag2 = ag + ag[0] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should fix it?
Someone with better maths knowledge should double check this - my understanding is that the moment of intertia tensor is always a real symmetric matrix, so it should satisfy the requirements of np.linalg.eigh.
My understanding is that eigh doesn't have the stability issues of eig, so I tried swapping it out and it seems to be working fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed,
eighis preferred for symmetric/Hermitian matrices.