knncolle
Collection of KNN methods in C++
Loading...
Searching...
No Matches
knncolle::Prebuilt< Index_, Data_, Distance_ > Class Template Referenceabstract

Interface for prebuilt nearest-neighbor search indices. More...

#include <Prebuilt.hpp>

Public Member Functions

virtual Index_ num_observations () const =0
 
virtual std::size_t num_dimensions () const =0
 
virtual std::unique_ptr< Searcher< Index_, Data_, Distance_ > > initialize () const =0
 
virtual void save (const std::string &prefix) const
 
auto initialize_known () const
 

Detailed Description

template<typename Index_, typename Data_, typename Distance_>
class knncolle::Prebuilt< Index_, Data_, Distance_ >

Interface for prebuilt nearest-neighbor search indices.

Instances of Prebuilt subclasses are typically constructed with Builder::build_raw(). Note that a Prebuilt instance may outlive the Builder object used to generate it, so the former should not hold any references to the latter.

Template Parameters
Index_Integer type for the observation indices.
Data_Numeric type for the query data.
Distance_Floating point type for the distances.

Member Function Documentation

◆ initialize()

template<typename Index_ , typename Data_ , typename Distance_ >
virtual std::unique_ptr< Searcher< Index_, Data_, Distance_ > > knncolle::Prebuilt< Index_, Data_, Distance_ >::initialize ( ) const
pure virtual

Create a Searcher for searching the index.

Returns
Pointer to a Searcher instance.

◆ initialize_known()

template<typename Index_ , typename Data_ , typename Distance_ >
auto knncolle::Prebuilt< Index_, Data_, Distance_ >::initialize_known ( ) const
inline
Returns
Unqiue pointer to a Searcher subclass.

Subclasses may override this method to return a pointer to a specific Searcher subclass. This is used for devirtualization in other knncolle functions. If no override is provided, initialize() is called instead.

◆ num_dimensions()

template<typename Index_ , typename Data_ , typename Distance_ >
virtual std::size_t knncolle::Prebuilt< Index_, Data_, Distance_ >::num_dimensions ( ) const
pure virtual
Returns
Number of dimensions.

◆ num_observations()

template<typename Index_ , typename Data_ , typename Distance_ >
virtual Index_ knncolle::Prebuilt< Index_, Data_, Distance_ >::num_observations ( ) const
pure virtual
Returns
Number of observations in the dataset to be searched.

◆ save()

template<typename Index_ , typename Data_ , typename Distance_ >
virtual void knncolle::Prebuilt< Index_, Data_, Distance_ >::save ( const std::string & prefix) const
inlinevirtual

Save the prebuilt index to disk, to be reloaded with load_prebuilt_raw() and friends.

It is expected that load_prebuilt_raw() should create an object that is "equivalent" to the object that was saved with save(). That is, any neighbor search results should be the same across the original and reloaded object. It is also expected that the relevant template parameters used in load_prebuilt_raw() should be the same as those in the original Prebuilt object.

An implementation of this method should create a <prefix>ALGORITHM file that contains the search algorithm's name. This should be an ASCII file with no newlines, where the algorithm name should follow the <library>::<algorithm> format, e.g., knncolle::Vptree. This will be used by load_prebuilt_raw() to determine the exact loader function to call. Other than the ALGORITHM file, each implementation may create any number of additional files of any format, as long as they start with prefix.

An implementation of this method is not required to use portable file formats. load_prebuilt_raw() is only expected to work on the same system (i.e., architecture, compiler, compilation settings) that was used for the save() call. Any additional portability is at the discretion of the implementation, e.g., it is common to assume IEEE floating-point and two's-complement integers.

An implementation of this method is not required to create files that are readable by different versions of the implementation. Thus, the files created by this method are generally unsuitable for archival storage. However, implementations are recommended to at least provide enough information to throw an exception if an incompatible version of load_prebuilt_raw() is used.

If a subclass does not implement this method, an error is thrown by default.

Parameters
prefixPrefix of the file path(s) in which to save the index. All files created by this method should start with this prefix. Any directories required to write a file starting with prefix should already have been created.

The documentation for this class was generated from the following file: