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::filesystem::path &dir) 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_Numeric type for the distances, usually floating-point.

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::filesystem::path & dir) const
inlinevirtual

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

An implementation of this method should create an ALGORITHM file inside dir 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/directories of any format inside dir. We recommend that the name of each file/directory immediately starts with an upper case letter and is in all-capitals. This allows applications to add more custom files without the risk of conflicts, e.g., by naming them without an upper-case letter.

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
dirPath to a directory in which to save the index. This directory should already exist.

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