Skip to content

Commit

Permalink
Faster import (lazy numpy)
Browse files Browse the repository at this point in the history
  • Loading branch information
anivegesana authored Aug 8, 2023
1 parent 17b96b1 commit 153eb03
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions simple_parsing/helpers/hparams/priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
overload,
)

numpy_installed = False
try:
import numpy as np
import importlib.util

numpy_installed = True
except ImportError:
pass
class _np_lazy:
def __getattr__(self, attr):
global np
import numpy as np
return getattr(np, attr)

np = _np_lazy()
numpy_installed = importlib.util.find_spec("numpy") is not None


T = TypeVar("T")
Expand Down

0 comments on commit 153eb03

Please sign in to comment.