-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DEV: improve backend settings * TEST: make tests run on cupy if available
- Loading branch information
1 parent
fd07a67
commit 858c68c
Showing
20 changed files
with
1,038 additions
and
947 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
__all_with_xp = [ | ||
"hyperpe", | ||
"models.interped", | ||
"models.mass", | ||
"models.redshift", | ||
"models.spin", | ||
"utils", | ||
"vt", | ||
] | ||
__all_with_scs = ["models.mass", "utils"] | ||
__backend__ = "" | ||
SUPPORTED_BACKENDS = ["numpy", "cupy"] | ||
_scipy_module = dict(numpy="scipy", cupy="cupyx.scipy") | ||
|
||
|
||
def disable_cupy(): | ||
from warnings import warn | ||
|
||
warn( | ||
f"Function enable_cupy is deprecated, use set_backed('cupy') instead", | ||
DeprecationWarning, | ||
) | ||
set_backend(backend="numpy") | ||
|
||
|
||
def enable_cupy(): | ||
from warnings import warn | ||
|
||
warn( | ||
f"Function enable_cupy is deprecated, use set_backed('cupy') instead", | ||
DeprecationWarning, | ||
) | ||
set_backend(backend="cupy") | ||
|
||
|
||
def set_backend(backend="numpy"): | ||
global __backend__ | ||
if backend not in SUPPORTED_BACKENDS: | ||
raise ValueError( | ||
f"Backend {backend} not supported, should be in {', '.join(SUPPORTED_BACKENDS)}" | ||
) | ||
elif backend == __backend__: | ||
return | ||
|
||
from importlib import import_module | ||
|
||
try: | ||
xp = import_module(backend) | ||
scs = import_module(_scipy_module[backend]).special | ||
except ModuleNotFoundError: | ||
raise ModuleNotFoundError(f"{backend} not installed") | ||
for module in __all_with_xp: | ||
__backend__ = backend | ||
import_module(f".{module}", package="gwpopulation").xp = xp | ||
for module in __all_with_scs: | ||
import_module(f".{module}", package="gwpopulation").scs = scs |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.