Skip to content

Commit

Permalink
Assert leaf_size > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
remydubois committed Jan 21, 2023
1 parent 2625375 commit f9c1429
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Version 0.3.2
------------
- Fixed issue https://github.com/remydubois/lsnms/issues/12, by masking scores as well as boxes.
- Added torch and torchvision as proper dev dependencies
- Fixed Pillow version to 9.3.0 in dev dependencies because 9.4.0 does not compile on my mbp (see https://github.com/python-pillow/Pillow/issues/6862)
- Fixed Pillow version (dev dep) to 9.3.0 in dev dependencies because 9.4.0 does not compile on my mbp (see https://github.com/python-pillow/Pillow/issues/6862)
- Removed deprecated arguments: `cutoff_distance` and `tree`. Removed associated tests.
- Added sanity check to ensure `leaf_size` is strictly positive.


Version 0.3.1
Expand Down
1 change: 1 addition & 0 deletions lsnms/rtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, data, leaf_size=16, axis=0, indices=None):
self.data = data
self.axis = axis
# Quick sanity checks
assert leaf_size > 0, "Leaf size must be strictly positive"
assert len(data) > 0, "Empty dataset"
assert self.data.shape[-1] % 2 == 0, "odd dimensionality"
assert data.ndim == 2, "Boxes to index should be (n_boxes, 4)"
Expand Down
15 changes: 14 additions & 1 deletion tests/test_boxtree.py → tests/test_rtree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest

from lsnms.rtree import RTree
from lsnms.rtree import RNode, RTree


def intersection(boxA, boxB):
Expand Down Expand Up @@ -35,3 +36,15 @@ def test_intersect_tree():
out_inter = np.array([inter for i, inter in enumerate(np_intersect) if i not in indices])
np.testing.assert_allclose(in_inter, intersections)
np.testing.assert_array_less(out_inter, min_area)


def test_build_odd_tree(instances):
boxes, _ = instances
with pytest.raises(AssertionError):
_ = RTree(boxes, leaf_size=0)


def test_build_rnode_default_args(instances):
boxes, _ = instances

_ = RNode(boxes)
18 changes: 4 additions & 14 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
from lsnms.util import box_englobing_boxes, intersection, offset_bboxes


def datagen(n=10_000):
topleft = np.random.uniform(0.0, high=1_000, size=(n, 2))
wh = np.random.uniform(15, 45, size=topleft.shape)

boxes = np.concatenate([topleft, topleft + wh], axis=1)
scores = np.random.uniform(0.1, 1.0, size=len(topleft))

return boxes, scores


@njit
def intersect_many(tree, boxes):
intersections = []
Expand All @@ -31,8 +21,8 @@ def assert_no_intersect(boxesA, boxesB):
assert intersection(boxA, boxB) == 0.0


def test_offset_bboxes():
boxes, _ = datagen()
def test_offset_bboxes(instances):
boxes, _ = instances
rng = np.random.default_rng(0)
class_ids = rng.integers(0, 2, size=len(boxes))

Expand All @@ -50,10 +40,10 @@ def test_offset_bboxes():


@pytest.mark.skip(reason="Visual test")
def test_visual_offset_bboxes():
def test_visual_offset_bboxes(instances):
import matplotlib.pyplot as plt

boxes, _ = datagen()
boxes, _ = instances
# boxes = boxes.reshape(-1, 2, 2).mean(1)
rng = np.random.default_rng(0)
class_ids = rng.integers(0, 3, size=len(boxes))
Expand Down

0 comments on commit f9c1429

Please sign in to comment.