Namespace for the knncolle_kmeans library.
template<class KmeansFloat_ >
| std::function< void(const std::filesystem::path &)> & knncolle_kmknn::custom_save_for_kmknn_kmeansfloat |
( |
| ) |
|
Define a global function to preserve KmeansFloat_ type information when saving a prebuilt KMKNN index in knncolle::Prebuilt::save(). Users should define their own function here to handle an KmeansFloat_ type that is unknown to knncolle::get_numeric_type(). The action of setting/unsetting the global function is not thread-safe and should be done in a serial section.
The sole argument of the global function is the same dir provided to knncolle::Prebuilt::save(). If set, the global function is generally expected to write information about KmeansFloat_ to files inside dir. It is recommended that the names of such files should not start with an upper-case letter to avoid conflicts with files generated by save().
- Template Parameters
-
| KmeansFloat_ | Floating-point type of the cluster centroids. |
- Returns
- Reference to a global function for saving information about
KmeansFloat_. By default, the global function is not set. If set, the global function will be called by the knncolle::Prebuilt::save() method for the KMKNN knncolle::Prebuilt subclass.
template<typename Index_ , typename Data_ , typename Distance_ , class DistanceMetricData_ = knncolle::DistanceMetric<Data_, Distance_>, typename KmeansFloat_ = Distance_, class DistanceMetricCenter_ = knncolle::DistanceMetric<KmeansFloat_, Distance_>>
| auto knncolle_kmknn::load_kmknn_prebuilt |
( |
const std::filesystem::path & | dir | ) |
|
Helper function to define a knncolle::LoadPrebuiltFunction for KMKNN in knncolle::load_prebuilt_raw().
To load an KMKNN index from disk, users are expected to define and register an KMKNN-specific knncolle::LoadPrebuiltFunction. In this function, users should call load_kmknn_prebuilt_types() to figure out the saved index's KmknnFloat_. Then, they should call load_kmknn_prebuilt() with the appropriate types to return a pointer to a knncolle::Prebuilt object. This user-defined function should be registered in load_prebuilt_registry() with the key in knncolle_kmknn::kmknn_prebuilt_save_name.
For unknown types, users can set custom_save_for_kmknn_kmeansfloat(). Each custom function saves additional information about its type to disk during a knncolle::Prebuilt::save() call. That information can then be parsed in the user-defined knncolle::LoadPrebuiltFunction to recover an KMKNN index with the appropriate template types.
- Template Parameters
-
| Index_ | Integer type for the observation indices. |
| Data_ | Numeric type for the input and query data. |
| Distance_ | Floating-point type for the distances. |
| DistanceMetricData_ | Class implementing the calculation of distances between observations. This should satisfy the knncolle::DistanceMetric interface. |
| KmeansFloat_ | Floating-point type of the cluster centroids. |
| DistanceMetricCenter_ | Class implementing the calculation of distances between an observation and a cluster centroid. This should satisfy the knncolle::DistanceMetric interface. |
- Parameters
-
| dir | Path to a directory in which a prebuilt KMKNN index was saved. An KMKNN index would typically be saved by calling the knncolle::Prebuilt::save() method of the KMKNN subclass instance. |
- Returns
- Pointer to a
knncolle::Prebuilt KMKNN index.