forked from deepmodeling/deepmd-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix general_fitting, add xp type dict
- Loading branch information
Han Wang
committed
Oct 23, 2024
1 parent
a261d67
commit b213475
Showing
3 changed files
with
59 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import unittest | ||
|
||
import array_api_compat | ||
import ml_dtypes | ||
import numpy as np | ||
|
||
from deepmd.dpmodel.common import ( | ||
get_xp_precision, | ||
) | ||
from deepmd.env import ( | ||
GLOBAL_NP_FLOAT_PRECISION, | ||
) | ||
|
||
|
||
class TestGetXPPrecision(unittest.TestCase): | ||
def test(self): | ||
aa = np.zeros(3) | ||
xp = array_api_compat.array_namespace(aa) | ||
self.assertTrue(get_xp_precision(xp, "float16"), xp.float16) | ||
self.assertTrue(get_xp_precision(xp, "float32"), xp.float32) | ||
self.assertTrue(get_xp_precision(xp, "float64"), xp.float64) | ||
self.assertTrue(get_xp_precision(xp, "single"), xp.float32) | ||
self.assertTrue(get_xp_precision(xp, "double"), xp.float64) | ||
self.assertTrue(get_xp_precision(xp, "global"), GLOBAL_NP_FLOAT_PRECISION) | ||
self.assertTrue(get_xp_precision(xp, "default"), GLOBAL_NP_FLOAT_PRECISION) | ||
self.assertTrue(get_xp_precision(xp, "bfloat16"), ml_dtypes.bfloat16) |