mirror of https://github.com/apache/lucene.git
Use panama vector for l2normalize (#12518)
Use panama vector for l2normalize
This commit is contained in:
parent
16e4874bb9
commit
d1c3531161
|
@ -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
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue