Skip to content

First attempt at sparse implementation#7

Open
redhog wants to merge 1 commit intosamson-wang:masterfrom
emerald-geomodelling:sparse
Open

First attempt at sparse implementation#7
redhog wants to merge 1 commit intosamson-wang:masterfrom
emerald-geomodelling:sparse

Conversation

@redhog
Copy link

@redhog redhog commented Nov 16, 2022

Hi!

When working with large numbers of bboxes (at least outside of the neural network domain), it is useful to use sparse matrixes (as most bboxes won't overlap).

I have mashed together a some very simple support for that here, mostly as a discussion starter. Would you be ok with including something along these lines?

If so, I'd be happy to discuss how to make a better PR (for now, I basically included two copies of the code, one sparse and one dense, which is not optimal, but at least does not slow down either implementation).

Usage example:

>>> ov = cython_bbox.bbox_overlaps(shapes.bounds.values, shapes.bounds.values, True)
>>> print(type(ov), ov.size, (ov > 0).sum(), ov.shape[0]*ov.shape[1])
<class 'scipy.sparse._arrays.dok_array'> 27906 27906 6574096

>>> ov = cython_bbox.bbox_overlaps(shapes.bounds.values, shapes.bounds.values)
>>> print(type(ov), ov.size, (ov > 0).sum(), ov.shape[0]*ov.shape[1])
<class 'numpy.ndarray'> 6574096 27906 6574096

Best regards,
Egil

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.

1 participant