nshutils 0.5.0__tar.gz → 0.5.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshutils
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "nshutils"
3
- version = "0.5.0"
3
+ version = "0.5.1"
4
4
  description = ""
5
5
  authors = ["Nima Shoghi <nimashoghi@gmail.com>"]
6
6
  readme = "README.md"
@@ -16,18 +16,26 @@ try:
16
16
  import warnings
17
17
  from contextlib import nullcontext
18
18
 
19
- import lovely_numpy as lo
20
- import lovely_tensors as lt
21
- import numpy
22
19
  import pysnooper
23
20
  import pysnooper.utils
24
- import torch
25
21
  from pkg_resources import DistributionNotFound, get_distribution
26
22
 
23
+ try:
24
+ import torch
25
+ except ImportError:
26
+ torch = None
27
+
28
+ try:
29
+ import numpy
30
+ except ImportError:
31
+ numpy = None
32
+
27
33
  FLOATING_POINTS = set()
28
34
  for i in ["float", "double", "half", "complex128", "complex32", "complex64"]:
29
- if hasattr(torch, i): # older version of PyTorch do not have complex dtypes
30
- FLOATING_POINTS.add(getattr(torch, i))
35
+ # older version of PyTorch do not have complex dtypes
36
+ if torch is not None and not hasattr(torch, i):
37
+ continue
38
+ FLOATING_POINTS.add(getattr(torch, i))
31
39
 
32
40
  try:
33
41
  __version__ = get_distribution(__name__).version
@@ -37,13 +45,19 @@ try:
37
45
 
38
46
  def default_format(x):
39
47
  try:
40
- formatted = str(lt.lovely(x))
41
- return formatted
48
+ import lovely_tensors as lt
49
+
50
+ return = str(lt.lovely(x))
42
51
  except BaseException:
43
52
  return str(x.shape)
44
53
 
45
54
  def default_numpy_format(x):
46
- return str(lo.lovely(x))
55
+ try:
56
+ import lovely_numpy as lo
57
+
58
+ return str(lo.lovely(x))
59
+ except BaseException:
60
+ return str(x.shape)
47
61
 
48
62
  class TorchSnooper(pysnooper.tracer.Tracer):
49
63
  def __init__(
@@ -155,9 +169,9 @@ try:
155
169
 
156
170
  def compute_repr(self, x):
157
171
  orig_repr_func = pysnooper.utils.get_repr_function(x, self.orig_custom_repr)
158
- if torch.is_tensor(x):
172
+ if torch is not None and torch.is_tensor(x):
159
173
  return self.tensor_format(x)
160
- if isinstance(x, numpy.ndarray):
174
+ if numpy is not None and isinstance(x, numpy.ndarray):
161
175
  return self.numpy_format(x)
162
176
  if self.is_return_types(x):
163
177
  return self.return_types_repr(x)
File without changes