Skip to content

minor fix + test (test_tree_of_boxes)#118

Merged
inducer merged 3 commits into
inducer:mainfrom
ShawnL00:minor-fix
Jul 7, 2026
Merged

minor fix + test (test_tree_of_boxes)#118
inducer merged 3 commits into
inducer:mainfrom
ShawnL00:minor-fix

Conversation

@ShawnL00

@ShawnL00 ShawnL00 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Fixes

  • (_apply_refine_flags_without_sorting): refining multiple boxes in one call gave the new children wrong parent IDs. refine_parents_per_child was built (nchildren, len(refine_parents)) and flattened row-major (np.tile). But box_children[:, refine_parents] numbers the new boxes in one contiguous block per parent. Now uses np.repeat(refine_parents, nchildren).

  • (_sort_boxes_by_level): reordered the box arrays by neworder but didn't update the IDs stored in box_parent_ids and box_child_ids, which still referred to the old numbering. Sorting needs two steps - rearrange the boxes into their new positions, and remap the stored IDs to the new numbering.

  • (_apply_coarsen_flags, _sort_and_prune_deleted_boxes):

    • box_levels is an integer array, so using np.inf raises OverflowError.
    • coarsen_peers had a stray .reshape(-1) that flattened the (2**dim, n_sources), so coarsen_exec_flags = np.all(coarsen_peer_is_leaf, axis=0) collapsed to a single scalar.
    • coarsen_exec_flags != coarsen_flags was wrong since they have different sizes.

Tests are included for the above fixes.

@alexfikl alexfikl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left a few nitpicks going through this. 😁

It would be very appreciated if you could add a bit more context to this (explanation of the bug and fix) either to the commit or to the PR description.

Comment thread boxtree/tree_of_boxes.py
Comment on lines -177 to +178
refine_parents_per_child = np.empty(
(nchildren, len(refine_parents)), dtype=np.intp)
refine_parents_per_child[:] = refine_parents.reshape(-1)
refine_parents_per_child = refine_parents_per_child.reshape(-1)
# Assign the parent box number for each new child box.
refine_parents_per_child = np.repeat(refine_parents, nchildren)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this correct? The before code looks more like an np.tile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see, this was a bug fix! Fair enough.

Comment thread boxtree/tree_of_boxes.py
Comment on lines +299 to +302
parent_has_id = box_parent_ids >= 0
box_parent_ids[parent_has_id] = old_to_new[box_parent_ids[parent_has_id]]
child_has_id = box_child_ids != 0
box_child_ids[child_has_id] = old_to_new[box_child_ids[child_has_id]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's clear to me why the above box_parent_ids = tob.box_parent_ids[neworder] isn't enough. Maybe add a little comment to this block to explain what it's trying to do?

Comment thread boxtree/tree_of_boxes.py
@ShawnL00

ShawnL00 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review, Alex! I should have included more context in the PR description. Please let me know if anything else needs to be clarified or changed.

@alexfikl

alexfikl commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for the review, Alex! I should have included more context in the PR description. Please let me know if anything else needs to be clarified or changed.

Looks good to me now! Thanks for all the helpful explanations.

@inducer inducer enabled auto-merge (rebase) July 6, 2026 21:49
@inducer

inducer commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Thanks!

@inducer inducer merged commit f278ab8 into inducer:main Jul 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants