Skip to content

Commit

Permalink
Merge pull request #270 from astronomy-commons/sean/fix-outer-alignme…
Browse files Browse the repository at this point in the history
…nt-bug

Fix infinite loop in outer alignment edge case
  • Loading branch information
smcguire-cmu authored May 13, 2024
2 parents 943e426 + 827be29 commit 9d7dfdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hipscat/pixel_tree/pixel_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,12 @@ def _add_pixels_until(
"""
while add_from < add_to:
# maximum power of 4 that is a factor of add_from
max_p4_from = add_from & -add_from
if max_p4_from & 0xAAAAAAAAAAAAAAA:
max_p4_from = max_p4_from >> 1
# If add_from is 0, can add any power of 4, so use largest healpix order of 4**29
max_p4_from = 1 << 58
if add_from != 0:
max_p4_from = add_from & -add_from
if max_p4_from & 0xAAAAAAAAAAAAAAA:
max_p4_from = max_p4_from >> 1

# maximum power of 4 less than or equal to (add_to - add_from)
max_p4_to_log2 = np.int64(np.log2(add_to - add_from))
Expand Down
11 changes: 11 additions & 0 deletions tests/hipscat/pixel_tree/test_pixel_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,14 @@ def test_catalog_align_outer(pixel_tree_2, pixel_tree_3, aligned_trees_2_3_outer
alignment = left_cat_with_moc.align(right_cat_with_moc, alignment_type="outer")
assert_trees_equal(alignment.pixel_tree, both_moc_correct_tree)
assert_mapping_matches_tree(alignment)


def test_outer_align_start_0():
left_tree = PixelTree.from_healpix([HealpixPixel(0, 0)])
right_tree = PixelTree.from_healpix([HealpixPixel(1, 1)])
alignment = align_trees(left_tree, right_tree, alignment_type="outer")
expected_tree = PixelTree.from_healpix(
[HealpixPixel(1, 0), HealpixPixel(1, 1), HealpixPixel(1, 2), HealpixPixel(1, 3)]
)
assert_trees_equal(alignment.pixel_tree, expected_tree)
assert_mapping_matches_tree(alignment)

0 comments on commit 9d7dfdd

Please sign in to comment.