Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues around auto visualization row/column preference specification #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions treescope/_internal/api/array_autovisualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ def _autovisualize_array(
# Assign axes, using preferred axes if possible.
row_axes = []
column_axes = []
for info in array_axis_info:
if isinstance(info, NamedPositionalAxisInfo | NamedPositionlessAxisInfo):
if info.axis_name in self.prefers_column:
column_axes.append(info.axis_name)
elif info.axis_name in self.prefers_row:
row_axes.append(info.axis_name)
for column_key in self.prefers_column:
for info in array_axis_info:
if isinstance(info, NamedPositionalAxisInfo | NamedPositionlessAxisInfo | PositionalAxisInfo):
if info.logical_key() == column_key:
column_axes.append(info)

for row_key in self.prefers_row:
for info in array_axis_info:
if isinstance(info, NamedPositionalAxisInfo | NamedPositionlessAxisInfo | PositionalAxisInfo):
if info.logical_key() == row_key:
row_axes.append(info)
Comment on lines +100 to +110
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this to a double loop? I think the original loop structure will be faster and avoid unnecessary checks for axes that are not named.

Also, are you trying to add support for preferring integer axis positions? I don't think this works correctly since NamedPositionalAxisInfo has both a name and a position and the logical_key just returns one of them.


# Infer a good truncated shape for this array.
edge_items_per_axis = arrayviz_impl.infer_balanced_truncation(
Expand Down
4 changes: 1 addition & 3 deletions treescope/_internal/arrayviz_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ def infer_rows_and_columns(
# so that position axes are in reverse position order, and the explicitly
# mentioned named axes are before the unassigned ones.
def ax_sort_key(ax: AxisInfo):
if isinstance(ax, PositionalAxisInfo | NamedPositionalAxisInfo):
return (0, -ax.axis_logical_index)
elif ax in unassigned:
if ax in unassigned:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

return (2,)
else:
return (1,)
Expand Down