Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cosine distance #231

Merged
merged 4 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/service/src/prelude/global/f16_cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl G for F16Cos {
type L2 = F16L2;

fn distance(lhs: &[F16], rhs: &[F16]) -> F32 {
super::f16::cosine(lhs, rhs) * (-1.0)
F32(1.0) - super::f16::cosine(lhs, rhs)
}

fn elkan_k_means_normalize(vector: &mut [F16]) {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl G for F16Cos {
x2 += _x * _x;
y2 += _y * _y;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand All @@ -73,7 +73,7 @@ impl G for F16Cos {
x2 += _x * _x;
y2 += _y * _y;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -103,7 +103,7 @@ impl G for F16Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -134,7 +134,7 @@ impl G for F16Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -166,7 +166,7 @@ impl G for F16Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/service/src/prelude/global/f32_cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl G for F32Cos {
type L2 = F32L2;

fn distance(lhs: &[F32], rhs: &[F32]) -> F32 {
cosine(lhs, rhs) * (-1.0)
F32(1.0) - cosine(lhs, rhs)
}

fn elkan_k_means_normalize(vector: &mut [F32]) {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl G for F32Cos {
x2 += _x * _x;
y2 += _y * _y;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand All @@ -73,7 +73,7 @@ impl G for F32Cos {
x2 += _x * _x;
y2 += _y * _y;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -103,7 +103,7 @@ impl G for F32Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -134,7 +134,7 @@ impl G for F32Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}

#[multiversion::multiversion(targets(
Expand Down Expand Up @@ -166,7 +166,7 @@ impl G for F32Cos {
x2 += _x2;
y2 += _y2;
}
xy / (x2 * y2).sqrt() * (-1.0)
F32(1.0) - xy / (x2 * y2).sqrt()
}
}

Expand Down
Loading