diskann_vector/value.rs
1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6/// The DiskANN library uses `f32` values to represent similarity scores, but distance
7/// functions can return either similarity-scores (those that are potentially transformed
8/// so that minimization yields higher similarity) and mathematical values (those that
9/// are computed from the mathematical definition of the operation.
10///
11/// Since those are currently mixed in the library with the more common use being a
12/// similarity-score, make the `MathematicalValue` the type to represent no transformation
13/// was performed.
14#[derive(Debug, Clone, Copy, PartialOrd, PartialEq)]
15pub struct MathematicalValue<T>(T)
16where
17 T: Copy;
18
19impl<T: Copy> MathematicalValue<T> {
20 pub fn new(value: T) -> Self {
21 Self(value)
22 }
23
24 #[inline(always)]
25 pub fn into_inner(self) -> T {
26 self.0
27 }
28}
29
30/// The DiskANN library uses `f32` values to represent similarity scores, but distance
31/// functions can return either similarity-scores (those that are potentially transformed
32/// so that minimization yields higher similarity) and mathematical values (those that
33/// are computed from the mathematical definition of the operation.
34///
35/// Since those are currently mixed in the library with the more common use being a
36/// similarity-score, make the `MathematicalValue` the type to represent no transformation
37/// was performed.
38#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
39pub struct SimilarityScore<T>(T)
40where
41 T: Copy;
42
43impl<T: Copy> SimilarityScore<T> {
44 pub fn new(value: T) -> Self {
45 Self(value)
46 }
47
48 #[inline(always)]
49 pub fn into_inner(self) -> T {
50 self.0
51 }
52}