-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST: fix workflow tests across OS and add test status badge
- Loading branch information
Showing
6 changed files
with
96 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Author: Mingjian He <[email protected]> | ||
Testing function for importing numpy and torch libraries | ||
""" | ||
import torch | ||
import numpy as np | ||
|
||
|
||
def test_import_numpy_torch(dim=2): | ||
""" | ||
Due to a strange dependency on sys lib5.dll between numpy and torch in | ||
macOS(osx-arm64), one must import torch first then numpy to avoid the error: | ||
>>> zsh: segmentation fault python | ||
This is a very problematic issue because it fails silently without any | ||
error message unless the offending function call is asked directly in a | ||
python session because it is a system-level error that does not return an | ||
error code to parent stacks, leading to all superordinate processes hanging. | ||
This unit test checks that numpy and torch can be imported without error. | ||
Note that we do not want to import within the function as it is executed | ||
in runtime during test suite collection such as by pytest. | ||
""" | ||
|
||
np.random.seed(1) | ||
A = np.random.rand(dim, dim) | ||
A = A @ A.T + np.eye(dim) | ||
_ = np.linalg.inv(A) # this call depends on lib5.dll | ||
A = torch.as_tensor(data=A, dtype=torch.float32) # does not call lib5.dll | ||
_ = torch.linalg.qr(A, mode='complete') # this call also invokes lib5.dll | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
test_import_numpy_torch() | ||
print('numpy and torch import test finished without exception.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters