Skip to content

Commit

Permalink
fixes #37 general datatype for scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
lanpa committed Sep 28, 2017
1 parent 2e40cf2 commit 13167bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tensorboardX/x2num.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def makenp(x, modality=None):
if modality == 'IMG' and x.dtype == np.uint8:
return x.astype(np.float32)/255.0
return x
if isinstance(x, float) or isinstance(x, int):
if np.isscalar(x):
return np.array([x])
if 'torch' in str(type(x)):
return pytorch_np(x, modality)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from tensorboardX import x2num
import numpy as np
def test_scalar():
res = x2num.makenp(1.1)
assert isinstance(res, np.ndarray) and res.shape == (1,)
res = x2num.makenp(1000000000000000000000)
assert isinstance(res, np.ndarray) and res.shape == (1,)
res = x2num.makenp(np.float16(1.00000087))
assert isinstance(res, np.ndarray) and res.shape == (1,)
res = x2num.makenp(np.float128(1.00008+9))
assert isinstance(res, np.ndarray) and res.shape == (1,)
res = x2num.makenp(np.int64(100000000000))
assert isinstance(res, np.ndarray) and res.shape == (1,)


def test_make_grid():
pass

0 comments on commit 13167bd

Please sign in to comment.