carsonfarmer / fastpair

FastPair: Data-structure for the dynamic closest-pair problem.
MIT License
12 stars 4 forks source link

adding & subtracting multiple points after calling ``build()`` #68

Open jGaboardi opened 3 months ago

jGaboardi commented 3 months ago

Currently with FastPair.__add__() only a single point can be added at time after calling build():

def __add__(self, p):
    self.points.append(p)
    if self.initialized:
        self._find_neighbor(p)
    elif len(self) >= self.min_points:
        self.build()
    return self

With some modification, a collection of points could be added to the data structure:

def __add__(self, p):
    if isinstance(p, list):
        for _p in p:
            self._add_1_point(_p)
    else:
        self._add_1_point(p)
    return self

def _add_1_point(self, p):
    self.points.append(p)
    if self.initialized:
        self._find_neighbor(p)
    elif len(self) >= self.min_points:
        self.build()
    return self

Seems like the same could go for FastPair.__sub__()

Thoughts?

cc @gegen07

gegen07 commented 2 months ago

Nice catch!

If we pass other types like geoSeries or np.array? Assuming that we will only support list, it is up to the user to pass the argument correctly. I mean, if the user has a geoSeries, it has to convert geoSeries to list.

I think we should support at least np.array, to provide a "medium-level" API. What are your thoughts?

jGaboardi commented 2 months ago

I think we should support at least np.array, to provide a "medium-level" API. What are your thoughts?

I agree, and this would probably play nicely with numba & jit decorators for improved performance (in the future, of course).