Package org.apache.lucene.util
Class VectorUtil
java.lang.Object
org.apache.lucene.util.VectorUtil
Utilities for computations with numeric arrays
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidadd(float[] u, float[] v) Adds the second argument to the firststatic floatcosine(float[] v1, float[] v2) Returns the cosine similarity between the two vectors.static floatdotProduct(float[] a, float[] b) Returns the vector dot product of the two vectors.static float[]l2normalize(float[] v) Modifies the argument to be unit length, dividing by its l2-norm.static float[]l2normalize(float[] v, boolean throwOnZero) Modifies the argument to be unit length, dividing by its l2-norm.static floatsquareDistance(float[] v1, float[] v2) Returns the sum of squared differences of the two vectors.
- 
Method Details- 
dotProductpublic static float dotProduct(float[] a, float[] b) Returns the vector dot product of the two vectors.- Throws:
- IllegalArgumentException- if the vectors' dimensions differ.
 
- 
cosinepublic static float cosine(float[] v1, float[] v2) Returns the cosine similarity between the two vectors.- Throws:
- IllegalArgumentException- if the vectors' dimensions differ.
 
- 
squareDistancepublic static float squareDistance(float[] v1, float[] v2) Returns the sum of squared differences of the two vectors.- Throws:
- IllegalArgumentException- if the vectors' dimensions differ.
 
- 
l2normalizepublic static float[] l2normalize(float[] v) Modifies the argument to be unit length, dividing by its l2-norm. IllegalArgumentException is thrown for zero vectors.- Returns:
- the input array after normalization
 
- 
l2normalizepublic static float[] l2normalize(float[] v, boolean throwOnZero) Modifies the argument to be unit length, dividing by its l2-norm.- Parameters:
- v- the vector to normalize
- throwOnZero- whether to throw an exception when- vhas all zeros
- Returns:
- the input array after normalization
- Throws:
- IllegalArgumentException- when the vector is all zero and throwOnZero is true
 
- 
addpublic static void add(float[] u, float[] v) Adds the second argument to the first- Parameters:
- u- the destination
- v- the vector to add to the destination
 
 
-