A structure to implement Distance Api for type DistCFnPtr<T>,
i.e distance provided by a C function pointer.
It must be noted that this can be used in Julia via the macro @cfunction
to define interactiveley a distance function , compile it on the fly and sent it
to Rust via the init_hnsw_{f32, i32, u16, u32, u8} function
defined in libext
Cosine distance : implemented for f32, f64, i64, i32 , u16
This is essentially the Cosine distance but we suppose
all vectors (graph construction and request vectors have been l2 normalized to unity
BEFORE INSERTING in HNSW!.
No control is made, so it is the user responsability to send normalized vectors
everywhere in inserting and searching.
This structure is to let user define their own distance with closures.
Hamming distance. Implemented for u8, u16, u32, i32 and i16
The distance returned is normalized by length of slices, so it is between 0. and 1.
A structure to compute Hellinger distance between probalilities.
Vector must be >= 0 and normalized to 1.
Jaccard distance. Implemented for u8, u16 , u32.
A structure to compute Jeffreys divergence between probalilities.
If p and q are 2 probability distributions
the “distance” is computed as:
sum (p[i] - q[i]) * ln(p[i]/q[i])
Jensen-Shannon distance.
It is defined as the square root of the Jensen–Shannon divergence and is a metric.
Vector must be >= 0 and normalized to 1!
The distance computation does not check that.
L1 distance : implemented for i32, f64, i64, u32 , u16 , u8 and with Simd avx2 for f32
L2 distance : implemented for i32, f64, i64, u32 , u16 , u8 and with Simd avx2 for f32
Levenshtein distance. Implemented for u16
This structure uses a Rust function pointer to define the distance.
For commodity it can build upon a fonction returning a f64.
Beware that if F is f64, the distance converted to f32 can overflow!
Special forbidden computation distance. It is associated to a unit NoData structure
This is a special structure used when we want to only reload the graph from a previous computation
possibly from an foreign language (and we do not have access to the original type of data from the foreign language).