nshutils 0.20.0__py3-none-any.whl → 0.21.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ from dataclasses import dataclass
9
9
  from functools import wraps
10
10
  from logging import getLogger
11
11
  from pathlib import Path
12
- from typing import TYPE_CHECKING, Generic, TypeAlias, cast, overload
12
+ from typing import TYPE_CHECKING, Generic, Literal, cast, overload
13
13
 
14
14
  import numpy as np
15
15
  from typing_extensions import Never, ParamSpec, TypeAliasType, TypeVar, override
@@ -22,15 +22,17 @@ if not TYPE_CHECKING:
22
22
  import torch # type: ignore
23
23
 
24
24
  Tensor = torch.Tensor
25
+ _torch_installed = True
25
26
  except ImportError:
26
27
  torch = None
28
+ _torch_installed = False
27
29
 
28
30
  Tensor = Never
29
31
  else:
30
32
  import torch # type: ignore
31
33
 
32
34
  Tensor = torch.Tensor
33
-
35
+ _torch_installed: Literal[True] = True
34
36
 
35
37
  log = getLogger(__name__)
36
38
 
@@ -41,7 +43,7 @@ ValueOrLambda = TypeAliasType("ValueOrLambda", Value | Callable[..., Value])
41
43
 
42
44
 
43
45
  def _torch_is_scripting() -> bool:
44
- if torch is None:
46
+ if _torch_installed:
45
47
  return False
46
48
 
47
49
  return torch.jit.is_scripting()
@@ -56,7 +58,7 @@ def _to_numpy(activation: Value) -> np.ndarray:
56
58
  return np.array(activation)
57
59
  elif isinstance(activation, np.ndarray):
58
60
  return activation
59
- elif isinstance(activation, Tensor):
61
+ elif _torch_installed and isinstance(activation, Tensor):
60
62
  activation_ = activation.detach()
61
63
  if activation_.is_floating_point():
62
64
  # NOTE: We need to convert to float32 because [b]float16 is not supported by numpy
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nshutils
3
- Version: 0.20.0
3
+ Version: 0.21.0
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
7
- Requires-Python: >=3.10,<4.0
7
+ Requires-Python: >=3.9,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
9
10
  Classifier: Programming Language :: Python :: 3.10
10
11
  Classifier: Programming Language :: Python :: 3.11
11
12
  Classifier: Programming Language :: Python :: 3.12
@@ -22,8 +23,8 @@ Requires-Dist: pysnooper ; extra == "extra"
22
23
  Requires-Dist: pysnooper ; extra == "snoop"
23
24
  Requires-Dist: rich[jupyter] ; extra == "extra"
24
25
  Requires-Dist: rich[jupyter] ; extra == "pprint"
25
- Requires-Dist: treescope ; extra == "extra"
26
- Requires-Dist: treescope ; extra == "pprint"
26
+ Requires-Dist: treescope ; (python_version >= "3.10") and (extra == "extra")
27
+ Requires-Dist: treescope ; (python_version >= "3.10") and (extra == "pprint")
27
28
  Requires-Dist: typing-extensions
28
29
  Requires-Dist: uuid7
29
30
  Project-URL: Homepage, https://github.com/nimashoghi/nshutils
@@ -2,7 +2,7 @@ nshutils/__init__.py,sha256=AFx1d5k34MyJ2kCHQL5vrZB8GDp2nYUaIUEjszSa25I,477
2
2
  nshutils/__init__.pyi,sha256=ICbY2_XBAlXIVOGyK4PQpatmlUFHHc5-bqM4sfFZoAY,613
3
3
  nshutils/actsave/__init__.py,sha256=hAVsog9d1g3_rQN1TRslrl6sK1PhCGbjy8PPUAmJI58,203
4
4
  nshutils/actsave/_loader.py,sha256=mof3HezUNvLliz7macstX6ewXW05L0Mtv3zJyrbmImg,4640
5
- nshutils/actsave/_saver.py,sha256=pvhtkGALxZqjfVVKthTZYcwgx2PGOBmeLCCNwePSm6A,10312
5
+ nshutils/actsave/_saver.py,sha256=LulgC_B7oYtsGjW_I_pnSLrf1k9lmMvHqRxcmfqqrjU,10441
6
6
  nshutils/collections.py,sha256=QWGyANmo4Efq4XRNHDSTE9tRLStwEZHGwE0ATHR-Vqo,5233
7
7
  nshutils/display.py,sha256=Ge63yllx7gi-MKL3mKQeQ5doql_nj56-o5aoTVmusDg,1473
8
8
  nshutils/logging.py,sha256=78pv3-I_gmbKSf5_mYYBr6_H4GNBGErghAdhH9wfYIc,2205
@@ -17,6 +17,6 @@ nshutils/lovely/utils.py,sha256=2ksT5YGVViFuWc8jSkwVCsABripJmyVJdEDDH7aab70,1045
17
17
  nshutils/snoop.py,sha256=7d7_Q5sJmINL1J29wcnxEvpV95zvZYNoVn5frCq-rww,7393
18
18
  nshutils/typecheck.py,sha256=Gi7xtfilN_UwZ1FTFqBVKDhcQzBEDonVxIv3bUj-uXY,5582
19
19
  nshutils/util.py,sha256=tx-XiRbOrpafV3OkJDE5IVFtzn3kN7uSZ8FkMor0H5c,2845
20
- nshutils-0.20.0.dist-info/METADATA,sha256=ha4yqytCPH6u0S3PNQqGBuwCQg9fxuoegr2FN-4ThRo,4316
21
- nshutils-0.20.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
22
- nshutils-0.20.0.dist-info/RECORD,,
20
+ nshutils-0.21.0.dist-info/METADATA,sha256=Qa4bVvnzN2Ip9fbmuaToECZbRSKhgj-zmaNqTKmXXJ4,4431
21
+ nshutils-0.21.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
22
+ nshutils-0.21.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any