Use panama vector for l2normalize (#12518)

Use panama vector for l2normalize
This commit is contained in:
Benjamin Trent 2023-08-29 08:33:49 -04:00 committed by GitHub
parent 16e4874bb9
commit d1c3531161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -182,6 +182,8 @@ Optimizations
* GITHUB#12415: Optimized counts on disjunctive queries. (Adrien Grand)
* GITHUB#12518: Use panama vector API to speed up l2norm calculations (Ben Trent)
Bug Fixes
---------------------

View File

@ -106,11 +106,8 @@ public final class VectorUtil {
* @throws IllegalArgumentException when the vector is all zero and throwOnZero is true
*/
public static float[] l2normalize(float[] v, boolean throwOnZero) {
double squareSum = 0.0f;
double squareSum = IMPL.dotProduct(v, v);
int dim = v.length;
for (float x : v) {
squareSum += x * x;
}
if (squareSum == 0) {
if (throwOnZero) {
throw new IllegalArgumentException("Cannot normalize a zero-length vector");