Skip to content

Commit e9a8fa4

Browse files
committed
Add utility function to check whether 'torch' is available
1 parent f4eeed8 commit e9a8fa4

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/graphnet/utilities/imports.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from functools import wraps
44

5-
from graphnet.utilities.logging import get_logger
5+
from graphnet.utilities.logging import get_logger, warn_once
66

77

88
logger = get_logger()
@@ -15,6 +15,23 @@ def has_icecube_package() -> bool:
1515

1616
return True
1717
except ImportError:
18+
warn_once(
19+
logger,
20+
"`icecube` not available. Some functionality may be missing.",
21+
)
22+
return False
23+
24+
25+
def has_torch_package() -> bool:
26+
"""Check whether the `torch` package is available."""
27+
try:
28+
import torch
29+
30+
return True
31+
except ImportError:
32+
warn_once(
33+
logger, "`torch` not available. Some functionality may be missing."
34+
)
1835
return False
1936

2037

0 commit comments

Comments
 (0)