-
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.
Merge pull request #2 from epistoteles/feature-1d-and-dynamic-sizing
Support 1D tensors and dynamic sizing to terminal width
- Loading branch information
Showing
7 changed files
with
146 additions
and
20 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,54 @@ | ||
import pytest | ||
import torch | ||
import numpy as np | ||
from tensorhue.viz import viz | ||
from tensorhue._torch import _tensorhue_to_numpy_torch | ||
|
||
|
||
@pytest.mark.parametrize("tensor", [np.ones(10), _tensorhue_to_numpy_torch(torch.ones(10))]) | ||
def test_1d_tensor(tensor, capsys): | ||
viz(tensor) | ||
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 = {tensor.shape}" | ||
|
||
|
||
@pytest.mark.parametrize("tensor", [np.ones((10, 10)), _tensorhue_to_numpy_torch(torch.ones(10, 10))]) | ||
def test_2d_tensor(tensor, capsys): | ||
viz(tensor) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 6 | ||
assert out.count("▀") == 100 / 2 | ||
assert out.split("\n")[-1] == f"shape = {tensor.shape}" | ||
|
||
|
||
@pytest.mark.parametrize("tensor", [np.ones(200), _tensorhue_to_numpy_torch(torch.ones(200))]) | ||
def test_1d_tensor_too_wide(tensor, capsys): | ||
viz(tensor) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert out.count(" ··· ") == 1 | ||
assert out.count("▀") == 95 | ||
assert out.split("\n")[-1] == f"shape = {tensor.shape}" | ||
|
||
|
||
@pytest.mark.parametrize("tensor", [np.ones((10, 200)), _tensorhue_to_numpy_torch(torch.ones(10, 200))]) | ||
def test_2d_tensor_too_wide(tensor, capsys): | ||
viz(tensor) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert out.count(" ··· ") == 5 | ||
assert out.count("▀") == 950 / 2 | ||
assert out.split("\n")[-1] == f"shape = {tensor.shape}" | ||
|
||
|
||
@pytest.mark.parametrize("tensor", [np.ones(10), _tensorhue_to_numpy_torch(torch.ones(10))]) | ||
def test_no_legend(tensor, capsys): | ||
viz(tensor, legend=False) | ||
captured = capsys.readouterr() | ||
out = captured.out.rstrip("\n") | ||
assert len(out.split("\n")) == 1 | ||
assert out.count("▀") == 10 |