[docs]classParameters(ABC):""" Abstract base class for the parameters of a nearest neighbor search. Each search algorithm should implement a subclass that contains the relevant parameters for controlling index construction or search. """pass
[docs]classBuilder:""" Pointer to a search index builder, i.e., ``knncolle_py::WrappedBuilder``, for use in C++ to build new neighbor search indices. The associated memory is automatically freed upon garbage collection. """
[docs]def__init__(self,ptr:int):""" Args: ptr: Address of a ``knncolle_py::WrappedBuilder``. """self._ptr=ptr
def__del__(self):"""Frees the builder in C++."""lib.free_builder(self._ptr)@propertydefptr(self):"""Address of a ``knncolle_py::WrappedBuilder``, to be passed into C++ as a ``uintptr_t``; see ``knncolle_py.h`` for details."""returnself._ptr
[docs]classIndex(ABC):""" Abstract base class for a prebuilt nearest neighbor-search index. Each search algorithm should implement their own subclasses, but are free to use any data structure to represent their search indices. """pass
[docs]classGenericIndex(Index):""" Abstract base class for a prebuilt nearest neighbor-search index that holds an address to a ``knncolle_py::WrappedPrebuilt`` instance in C++. The associated memory is automatically freed upon garbage collection. """
[docs]def__init__(self,ptr:int):""" Args: ptr: Address of a ``knncolle_py::WrappedPrebuilt``. """self._ptr=ptr
@propertydefptr(self)->int:"""Address of a ``knncolle_py::WrappedPrebuilt``, to be passed into C++ as a ``uintptr_t``; see ``knncolle_py.h`` for details."""returnself._ptrdef__del__(self):"""Frees the index in C++."""lib.free_prebuilt(self._ptr)
[docs]defnum_observations(self)->int:""" Returns: Number of observations in this index. """returnlib.generic_num_obs(self._ptr)
[docs]defnum_dimensions(self)->int:""" Returns: Number of dimensions in this index. """returnlib.generic_num_dims(self._ptr)