-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unnecessary float() for offering torch.float16 option (#220)
* remove unnecessary float() for offering torch.float16 option * united test for default data type is added * fix test_default_dtype.py
- Loading branch information
Showing
5 changed files
with
35 additions
and
4 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,24 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pytest | ||
import torch | ||
from matgl import set_default_dtype | ||
|
||
|
||
def test_set_default_dtype(): | ||
set_default_dtype("float", 32) | ||
assert torch.get_default_dtype() == torch.float32 | ||
assert np.dtype("float32") == np.float32 | ||
|
||
|
||
def test_set_default_dtype_invalid_size(): | ||
with pytest.raises(ValueError, match="Invalid dtype size"): | ||
set_default_dtype("float", 128) | ||
set_default_dtype("float", 32) | ||
|
||
|
||
def test_set_default_dtype_exception(): | ||
with pytest.raises(Exception, match="torch.float16 is not supported for M3GNet"): | ||
set_default_dtype("float", 16) | ||
set_default_dtype("float", 32) |