Skip to content

Commit

Permalink
Tweak DRangedTree self test
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmessage committed Sep 27, 2023
1 parent 99a7b93 commit 8cda030
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions methods/utils/dranged_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ def make_tree_without_d(d: int, rects):
right = _make_tree_internal(rights, right_bounds, state.descend(d))
return SplitDTree(left, right, d, split_at)

# ========================================
# Self test code, not needed for operation
# ========================================
def _self_test():
ALLOWED_VARIATION = np.array([
200,
Expand Down Expand Up @@ -537,7 +540,7 @@ def build_dranged_tree_for_k(k_rows) -> DRangedTree:

# Special case for the zero-width zero columns (CPC deforestation; if an original block has no deforestation, then
# it can only match to exactly zero deforestation)
special_zero_columns = [4, 6, 8]
special_zero_columns = [-5, -3, -1]
for d in special_zero_columns:
fix_fraction = math.pow(expected_fraction / filled_fraction, 1/len(special_zero_columns)) * np.sum(source[:, d] == 0) / len(source)
fix_rows = np.random.choice(len(test_values), math.floor(len(test_values) * fix_fraction), replace=False)
Expand Down Expand Up @@ -573,8 +576,8 @@ def do_drange_tree_matching():
for i in range(length):
found += 1 if tree.contains(test_values[i]) else 0
return found
speed_of("NP matching", do_np_matching)

#speed_of("NP matching", do_np_matching)
speed_of("Tree matching", do_drange_tree_matching)

if __name__ == "__main__":
Expand Down

0 comments on commit 8cda030

Please sign in to comment.