-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 1d tensor support, legends, and dynamic terminal width adjustment…
… when printing
- Loading branch information
1 parent
ffe95b5
commit 0165add
Showing
4 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import torch | ||
import numpy as np | ||
from tensorhue.viz import viz | ||
from tensorhue._torch import _tensorhue_to_numpy_torch | ||
|
||
|
||
def test_1d_tensor_numpy(capsys): | ||
n = np.ones(10) | ||
viz(n) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 2 | ||
assert out.count("▀") == 10 | ||
assert out.split("\n")[-1] == f"shape = {n.shape}" | ||
|
||
|
||
def test_2d_tensor_numpy(capsys): | ||
n = np.ones((10, 10)) | ||
viz(n) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 6 | ||
assert out.count("▀") == 50 | ||
assert out.split("\n")[-1] == f"shape = {n.shape}" | ||
|
||
|
||
def test_1d_tensor_torch(capsys): | ||
t = torch.ones(10) | ||
n = _tensorhue_to_numpy_torch(t) | ||
viz(n) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 2 | ||
assert out.count("▀") == 10 | ||
assert out.split("\n")[-1] == f"shape = {n.shape}" | ||
|
||
|
||
def test_2d_tensor_torch(capsys): | ||
t = torch.ones(10, 10) | ||
n = _tensorhue_to_numpy_torch(t) | ||
viz(n) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 6 | ||
assert out.count("▀") == 50 | ||
assert out.split("\n")[-1] == f"shape = {n.shape}" | ||
|
||
|
||
def test_no_legend(capsys): | ||
n = np.ones(10) | ||
viz(n, legend=False) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 1 | ||
assert out.count("▀") == 10 |