/rust/registry/src/index.crates.io-1949cf8c6b5b557f/diskann-vector-0.53.0/src/value.rs
Line | Count | Source |
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)] |
15 | | pub struct MathematicalValue<T>(T) |
16 | | where |
17 | | T: Copy; |
18 | | |
19 | | impl<T: Copy> MathematicalValue<T> { |
20 | 0 | pub fn new(value: T) -> Self { |
21 | 0 | Self(value) |
22 | 0 | } |
23 | | |
24 | | #[inline(always)] |
25 | 0 | pub fn into_inner(self) -> T { |
26 | 0 | self.0 |
27 | 0 | } |
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)] |
39 | | pub struct SimilarityScore<T>(T) |
40 | | where |
41 | | T: Copy; |
42 | | |
43 | | impl<T: Copy> SimilarityScore<T> { |
44 | 0 | pub fn new(value: T) -> Self { |
45 | 0 | Self(value) |
46 | 0 | } |
47 | | |
48 | | #[inline(always)] |
49 | 0 | pub fn into_inner(self) -> T { |
50 | 0 | self.0 |
51 | 0 | } |
52 | | } |