Skip to content

Commit

Permalink
Fix float dimensions bug on some nested submatrices
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Sep 12, 2023
1 parent 8492d98 commit 6fb716e
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 5 deletions.
Binary file added doc/images/html-4d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/html-adjacency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/html-cities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/latex-edgecases.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions matrepr/adapters/numpy_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, mat):
super().__init__()
self.mat = mat
self.is_vec = len(mat.shape) < 2
if self.is_vec:
self.row_labels = False

def get_shape(self) -> tuple:
# present at most 2D, higher dimensions will be handled as nested arrays
Expand Down
4 changes: 2 additions & 2 deletions matrepr/html_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def pprint(self, obj, current_indent=0, is_index=False):
from copy import copy
fmt = copy(self)
fmt.lines = []
fmt.max_rows = max(self.max_rows / 2, 2)
fmt.max_cols = max(self.max_cols / 2, 2)
fmt.max_rows = max(self.max_rows // 2, 2)
fmt.max_cols = max(self.max_cols // 2, 2)
fmt.num_after_dots = 0
fmt.title = None
fmt.indices = False
Expand Down
4 changes: 2 additions & 2 deletions matrepr/latex_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def pprint(self, obj, is_index=False):
from . import _get_adapter
adapter = _get_adapter(obj, None, unsupported_raise=False)
if adapter:
fmt = LatexFormatter(max_rows=max(self.max_rows / 2, 2),
max_cols=max(self.max_cols / 2, 2),
fmt = LatexFormatter(max_rows=max(self.max_rows // 2, 2),
max_cols=max(self.max_cols // 2, 2),
num_after_dots=0, title_latex=None,
fill_value=self.fill_value,
latex_matrix_env=self.latex_matrix_env,
Expand Down
2 changes: 1 addition & 1 deletion matrepr/string_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def to_tabulate(mat: Any, **kwargs) -> str:
adapter = _get_adapter(mat, options)

if options.width_str:
txt_max_cols = max(1, int(options.width_str / 3)) # minimum 3 chars per column (if empty)
txt_max_cols = max(1, options.width_str // 3) # minimum 3 chars per column (if empty)
cols = min(options.max_cols, txt_max_cols)
trunc = to_trunc(adapter, options.max_rows, cols, options.num_after_dots)

Expand Down
1 change: 1 addition & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setUp(self):
[[1, 2], [3, 4]],
[[100, 200], [300, 400]],
]),
np.random.randint(low=0, high=10_000, size=(3, 5, 10)), # 3D
np.random.randint(low=0, high=10_000, size=(2, 2, 2, 2)) # 4D
]

Expand Down

0 comments on commit 6fb716e

Please sign in to comment.