-
Notifications
You must be signed in to change notification settings - Fork 20
minor fix + test (test_tree_of_boxes) #118
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -174,10 +174,8 @@ def _apply_refine_flags_without_sorting( | |
| tob.nboxes | ||
| + nchildren * np.arange(len(refine_parents))) | ||
|
|
||
| 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) | ||
|
|
||
| box_parents = _resized_array(tob.box_parent_ids, nboxes_new) | ||
| box_centers = _resized_array(tob.box_centers, nboxes_new) | ||
|
|
@@ -230,27 +228,30 @@ def _apply_coarsen_flags( | |
| raise ValueError("attempting to coarsen non-leaf") | ||
|
|
||
| coarsen_sources, = np.where(coarsen_flags) | ||
| if np.any(tob.box_parent_ids[coarsen_sources] < 0): | ||
| raise ValueError("cannot coarsen the root box") | ||
| if coarsen_sources.size == 0: | ||
| return tob | ||
|
|
||
| coarsen_parents = tob.box_parent_ids[coarsen_sources] | ||
| coarsen_peers = tob.box_child_ids[:, coarsen_parents].reshape(-1) | ||
| coarsen_peers = tob.box_child_ids[:, coarsen_parents] | ||
| coarsen_peer_is_leaf = box_is_leaf[coarsen_peers] | ||
| coarsen_exec_flags = np.all(coarsen_peer_is_leaf, axis=0) | ||
|
|
||
| # when a leaf box marked for coarsening has non-leaf peers | ||
| coarsen_flags_ignored = np.sum(coarsen_exec_flags != coarsen_flags) | ||
| if coarsen_flags_ignored: | ||
| msg = (f"{coarsen_flags_ignored} out of {np.sum(coarsen_flags)} coarsening " | ||
| "flags ignored to prevent removing non-leaf boxes") | ||
| coarsen_flags_ignored = ~coarsen_exec_flags | ||
| if np.any(coarsen_flags_ignored): | ||
| msg = (f"{np.sum(coarsen_flags_ignored)} out of " | ||
| f"{np.sum(coarsen_flags)} coarsening flags ignored " | ||
| "to prevent removing non-leaf boxes") | ||
| if error_on_ignored_flags: | ||
| raise RuntimeError(msg) | ||
| else: | ||
| import warnings | ||
| warnings.warn(msg, stacklevel=3) | ||
|
|
||
| # deleted boxes are marked as: | ||
| # level = inf | ||
| # level = sentinel (max int) | ||
| # parent = -1 | ||
| coarsen_parents = coarsen_parents[coarsen_exec_flags] | ||
| coarsen_peers = coarsen_peers[:, coarsen_exec_flags] | ||
|
|
@@ -259,7 +260,7 @@ def _apply_coarsen_flags( | |
| box_children = tob.box_child_ids.copy() | ||
| box_children[:, coarsen_parents] = 0 | ||
| box_levels = tob.box_levels.copy() | ||
| box_levels[coarsen_peers] = np.inf | ||
| box_levels[coarsen_peers] = np.iinfo(box_levels.dtype).max | ||
|
inducer marked this conversation as resolved.
|
||
|
|
||
| return TreeOfBoxes( | ||
| box_centers=tob.box_centers, | ||
|
|
@@ -285,12 +286,22 @@ def _sort_boxes_by_level(tob: TreeOfBoxes) -> TreeOfBoxes: | |
| if not np.any(np.diff(tob.box_levels) < 0): | ||
| return tob | ||
|
|
||
| # reorder boxes to into non-decreasing levels | ||
| # reorder boxes into non-decreasing levels | ||
| neworder = np.argsort(tob.box_levels) | ||
| old_to_new = np.empty_like(neworder) | ||
| old_to_new[neworder] = np.arange(len(neworder)) | ||
|
|
||
| box_centers = tob.box_centers[:, neworder] | ||
| box_levels = tob.box_levels[neworder] | ||
| box_parent_ids = tob.box_parent_ids[neworder] | ||
| box_child_ids = tob.box_child_ids[:, neworder] | ||
| box_levels = tob.box_levels[neworder] | ||
|
|
||
| # box_parent_ids and box_child_ids need to be updated to | ||
| # reflect the new box numbering | ||
| 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]] | ||
|
Comment on lines
+301
to
+304
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's clear to me why the above |
||
|
|
||
| return TreeOfBoxes( | ||
| box_centers=box_centers, | ||
|
|
@@ -314,7 +325,7 @@ def _sort_boxes_by_level(tob: TreeOfBoxes) -> TreeOfBoxes: | |
|
|
||
| def _sort_and_prune_deleted_boxes(tob: TreeOfBoxes) -> TreeOfBoxes: | ||
| tob = _sort_boxes_by_level(tob) | ||
| n_stale_boxes = np.sum(tob.box_levels == np.inf) | ||
| n_stale_boxes = np.sum(tob.box_levels == np.iinfo(tob.box_levels.dtype).max) | ||
| newn = tob.nboxes - n_stale_boxes | ||
|
|
||
| return TreeOfBoxes( | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.