Skip to content

Commit 7907da9

Browse files
committed
rename the vector format to vector codec
1 parent 9ab541e commit 7907da9

7 files changed

+41
-41
lines changed

src/distance/angular.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub struct NodeHeaderAngular {
2525

2626
impl Distance for Angular {
2727
type Header = NodeHeaderAngular;
28-
type VectorFormat = f32;
28+
type VectorCodec = f32;
2929

3030
fn name() -> &'static str {
3131
"angular"
3232
}
3333

34-
fn new_header(vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header {
34+
fn new_header(vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header {
3535
NodeHeaderAngular { norm: Self::norm_no_header(vector) }
3636
}
3737

@@ -56,7 +56,7 @@ impl Distance for Angular {
5656
d
5757
}
5858

59-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32 {
59+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32 {
6060
dot_product(v, v).sqrt()
6161
}
6262

@@ -67,7 +67,7 @@ impl Distance for Angular {
6767
fn create_split<'a, R: Rng>(
6868
children: &'a ImmutableSubsetLeafs<Self>,
6969
rng: &mut R,
70-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>> {
70+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>> {
7171
let [node_p, node_q] = two_means(rng, children, true)?;
7272
let vector: Vec<f32> =
7373
node_p.vector.iter().zip(node_q.vector.iter()).map(|(p, q)| p - q).collect();
@@ -79,8 +79,8 @@ impl Distance for Angular {
7979
}
8080

8181
fn margin_no_header(
82-
p: &UnalignedVector<Self::VectorFormat>,
83-
q: &UnalignedVector<Self::VectorFormat>,
82+
p: &UnalignedVector<Self::VectorCodec>,
83+
q: &UnalignedVector<Self::VectorCodec>,
8484
) -> f32 {
8585
dot_product(p, q)
8686
}

src/distance/binary_quantized_euclidean.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ pub struct NodeHeaderBinaryQuantizedEuclidean {
2626

2727
impl Distance for BinaryQuantizedEuclidean {
2828
type Header = NodeHeaderBinaryQuantizedEuclidean;
29-
type VectorFormat = unaligned_vector::BinaryQuantized;
29+
type VectorCodec = unaligned_vector::BinaryQuantized;
3030

3131
fn name() -> &'static str {
3232
"binary quantized euclidean"
3333
}
3434

35-
fn new_header(_vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header {
35+
fn new_header(_vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header {
3636
NodeHeaderBinaryQuantizedEuclidean { bias: 0.0 }
3737
}
3838

3939
fn built_distance(p: &Leaf<Self>, q: &Leaf<Self>) -> f32 {
4040
dot_product(&p.vector, &q.vector)
4141
}
4242

43-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32 {
43+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32 {
4444
dot_product(v, v).sqrt()
4545
}
4646

@@ -49,7 +49,7 @@ impl Distance for BinaryQuantizedEuclidean {
4949
fn create_split<'a, R: Rng>(
5050
children: &'a ImmutableSubsetLeafs<Self>,
5151
rng: &mut R,
52-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>> {
52+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>> {
5353
let [node_p, node_q] = two_means(rng, children, false)?;
5454
let vector: Vec<f32> =
5555
node_p.vector.iter().zip(node_q.vector.iter()).map(|(p, q)| p - q).collect();
@@ -67,8 +67,8 @@ impl Distance for BinaryQuantizedEuclidean {
6767
}
6868

6969
fn margin_no_header(
70-
p: &UnalignedVector<Self::VectorFormat>,
71-
q: &UnalignedVector<Self::VectorFormat>,
70+
p: &UnalignedVector<Self::VectorCodec>,
71+
q: &UnalignedVector<Self::VectorCodec>,
7272
) -> f32 {
7373
dot_product(p, q)
7474
}

src/distance/dot_product.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ pub struct NodeHeaderDotProduct {
3030

3131
impl Distance for DotProduct {
3232
type Header = NodeHeaderDotProduct;
33-
type VectorFormat = f32;
33+
type VectorCodec = f32;
3434

3535
fn name() -> &'static str {
3636
"dot-product"
3737
}
3838

39-
fn new_header(_vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header {
39+
fn new_header(_vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header {
4040
// We compute the norm when we preprocess the vector, before generating the tree nodes.
4141
NodeHeaderDotProduct { extra_dim: 0.0, norm: 0.0 }
4242
}
@@ -66,7 +66,7 @@ impl Distance for DotProduct {
6666
(dot + leaf.header.extra_dim * leaf.header.extra_dim).sqrt()
6767
}
6868

69-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32 {
69+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32 {
7070
dot_product(v, v).sqrt()
7171
}
7272

@@ -90,7 +90,7 @@ impl Distance for DotProduct {
9090
fn create_split<'a, R: Rng>(
9191
children: &'a ImmutableSubsetLeafs<Self>,
9292
rng: &mut R,
93-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>> {
93+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>> {
9494
let [node_p, node_q] = two_means(rng, children, true)?;
9595
let vector: Vec<f32> =
9696
node_p.vector.iter().zip(node_q.vector.iter()).map(|(p, q)| p - q).collect();
@@ -109,8 +109,8 @@ impl Distance for DotProduct {
109109
}
110110

111111
fn margin_no_header(
112-
p: &UnalignedVector<Self::VectorFormat>,
113-
q: &UnalignedVector<Self::VectorFormat>,
112+
p: &UnalignedVector<Self::VectorCodec>,
113+
q: &UnalignedVector<Self::VectorCodec>,
114114
) -> f32 {
115115
dot_product(p, q)
116116
}

src/distance/euclidean.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ pub struct NodeHeaderEuclidean {
2727

2828
impl Distance for Euclidean {
2929
type Header = NodeHeaderEuclidean;
30-
type VectorFormat = f32;
30+
type VectorCodec = f32;
3131

3232
fn name() -> &'static str {
3333
"euclidean"
3434
}
3535

36-
fn new_header(_vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header {
36+
fn new_header(_vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header {
3737
NodeHeaderEuclidean { bias: 0.0 }
3838
}
3939

4040
fn built_distance(p: &Leaf<Self>, q: &Leaf<Self>) -> f32 {
4141
euclidean_distance(&p.vector, &q.vector)
4242
}
4343

44-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32 {
44+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32 {
4545
dot_product(v, v).sqrt()
4646
}
4747

@@ -50,7 +50,7 @@ impl Distance for Euclidean {
5050
fn create_split<'a, R: Rng>(
5151
children: &'a ImmutableSubsetLeafs<Self>,
5252
rng: &mut R,
53-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>> {
53+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>> {
5454
let [node_p, node_q] = two_means(rng, children, false)?;
5555
let vector: Vec<_> =
5656
node_p.vector.iter().zip(node_q.vector.iter()).map(|(p, q)| p - q).collect();
@@ -76,8 +76,8 @@ impl Distance for Euclidean {
7676
}
7777

7878
fn margin_no_header(
79-
p: &UnalignedVector<Self::VectorFormat>,
80-
q: &UnalignedVector<Self::VectorFormat>,
79+
p: &UnalignedVector<Self::VectorCodec>,
80+
q: &UnalignedVector<Self::VectorCodec>,
8181
) -> f32 {
8282
dot_product(p, q)
8383
}

src/distance/manhattan.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ pub struct NodeHeaderManhattan {
2626

2727
impl Distance for Manhattan {
2828
type Header = NodeHeaderManhattan;
29-
type VectorFormat = f32;
29+
type VectorCodec = f32;
3030

3131
fn name() -> &'static str {
3232
"manhattan"
3333
}
3434

35-
fn new_header(_vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header {
35+
fn new_header(_vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header {
3636
NodeHeaderManhattan { bias: 0.0 }
3737
}
3838

@@ -44,7 +44,7 @@ impl Distance for Manhattan {
4444
d.max(0.0)
4545
}
4646

47-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32 {
47+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32 {
4848
dot_product(v, v).sqrt()
4949
}
5050

@@ -53,7 +53,7 @@ impl Distance for Manhattan {
5353
fn create_split<'a, R: Rng>(
5454
children: &'a ImmutableSubsetLeafs<Self>,
5555
rng: &mut R,
56-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>> {
56+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>> {
5757
let [node_p, node_q] = two_means(rng, children, false)?;
5858
let vector: Vec<_> =
5959
node_p.vector.iter().zip(node_q.vector.iter()).map(|(p, q)| p - q).collect();
@@ -79,8 +79,8 @@ impl Distance for Manhattan {
7979
}
8080

8181
fn margin_no_header(
82-
p: &UnalignedVector<Self::VectorFormat>,
83-
q: &UnalignedVector<Self::VectorFormat>,
82+
p: &UnalignedVector<Self::VectorCodec>,
83+
q: &UnalignedVector<Self::VectorCodec>,
8484
) -> f32 {
8585
dot_product(p, q)
8686
}

src/distance/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ mod manhattan;
3030
pub trait Distance: Send + Sync + Sized + Clone + fmt::Debug + 'static {
3131
/// A header structure with informations related to the
3232
type Header: Pod + Zeroable + fmt::Debug;
33-
type VectorFormat: UnalignedVectorCodec;
33+
type VectorCodec: UnalignedVectorCodec;
3434

3535
fn name() -> &'static str;
3636

37-
fn new_header(vector: &UnalignedVector<Self::VectorFormat>) -> Self::Header;
37+
fn new_header(vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header;
3838

3939
/// Returns a non-normalized distance.
4040
fn built_distance(p: &Leaf<Self>, q: &Leaf<Self>) -> f32;
@@ -59,7 +59,7 @@ pub trait Distance: Send + Sync + Sized + Clone + fmt::Debug + 'static {
5959
Self::norm_no_header(&leaf.vector)
6060
}
6161

62-
fn norm_no_header(v: &UnalignedVector<Self::VectorFormat>) -> f32;
62+
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32;
6363

6464
fn normalize(node: &mut Leaf<Self>) {
6565
let norm = Self::norm(node);
@@ -84,19 +84,19 @@ pub trait Distance: Send + Sync + Sized + Clone + fmt::Debug + 'static {
8484
fn create_split<'a, R: Rng>(
8585
children: &'a ImmutableSubsetLeafs<Self>,
8686
rng: &mut R,
87-
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorFormat>>>;
87+
) -> heed::Result<Cow<'a, UnalignedVector<Self::VectorCodec>>>;
8888

8989
fn margin(p: &Leaf<Self>, q: &Leaf<Self>) -> f32 {
9090
Self::margin_no_header(&p.vector, &q.vector)
9191
}
9292

9393
fn margin_no_header(
94-
p: &UnalignedVector<Self::VectorFormat>,
95-
q: &UnalignedVector<Self::VectorFormat>,
94+
p: &UnalignedVector<Self::VectorCodec>,
95+
q: &UnalignedVector<Self::VectorCodec>,
9696
) -> f32;
9797

9898
fn side<R: Rng>(
99-
normal_plane: &UnalignedVector<Self::VectorFormat>,
99+
normal_plane: &UnalignedVector<Self::VectorCodec>,
100100
node: &Leaf<Self>,
101101
rng: &mut R,
102102
) -> Side {

src/node.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct Leaf<'a, D: Distance> {
3838
/// The header of this leaf.
3939
pub header: D::Header,
4040
/// The vector of this leaf.
41-
pub vector: Cow<'a, UnalignedVector<D::VectorFormat>>,
41+
pub vector: Cow<'a, UnalignedVector<D::VectorCodec>>,
4242
}
4343

4444
impl<D: Distance> fmt::Debug for Leaf<'_, D> {
@@ -115,7 +115,7 @@ impl fmt::Debug for ItemIds<'_> {
115115
pub struct SplitPlaneNormal<'a, D: Distance> {
116116
pub left: NodeId,
117117
pub right: NodeId,
118-
pub normal: Cow<'a, UnalignedVector<D::VectorFormat>>,
118+
pub normal: Cow<'a, UnalignedVector<D::VectorCodec>>,
119119
}
120120

121121
impl<D: Distance> fmt::Debug for SplitPlaneNormal<'_, D> {
@@ -171,15 +171,15 @@ impl<'a, D: Distance> BytesDecode<'a> for NodeCodec<D> {
171171
[LEAF_TAG, bytes @ ..] => {
172172
let (header_bytes, remaining) = bytes.split_at(size_of::<D::Header>());
173173
let header = pod_read_unaligned(header_bytes);
174-
let vector = UnalignedVector::<D::VectorFormat>::from_bytes(remaining)?;
174+
let vector = UnalignedVector::<D::VectorCodec>::from_bytes(remaining)?;
175175

176176
Ok(Node::Leaf(Leaf { header, vector }))
177177
}
178178
[SPLIT_PLANE_NORMAL_TAG, bytes @ ..] => {
179179
let (left, bytes) = NodeId::from_bytes(bytes);
180180
let (right, bytes) = NodeId::from_bytes(bytes);
181181
Ok(Node::SplitPlaneNormal(SplitPlaneNormal {
182-
normal: UnalignedVector::<D::VectorFormat>::from_bytes(bytes)?,
182+
normal: UnalignedVector::<D::VectorCodec>::from_bytes(bytes)?,
183183
left,
184184
right,
185185
}))

0 commit comments

Comments
 (0)