Package io.github.jbellis.jvector.vector
Interface VectorUtilSupport
public interface VectorUtilSupport
Interface for implementations of VectorUtil support.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddInPlace(float[] v1, float[] v2) Adds v2 into v1, in place (v1 will be modified)floatassembleAndSum(float[] data, int baseIndex, byte[] baseOffsets) Calculates the sum of sparse points in a vector.floatcosine(byte[] a, byte[] b) Returns the cosine similarity between the two byte vectors.floatcosine(float[] v1, float[] v2) Returns the cosine similarity between the two vectors.voiddivInPlace(float[] vector, float divisor) Divide vector by divisor, in place (vector will be modified)intdotProduct(byte[] a, byte[] b) Returns the dot product computed over signed bytes.floatdotProduct(float[] a, float[] b) Calculates the dot product of the given float arrays.floatdotProduct(float[] a, int aoffset, float[] b, int boffset, int length) Calculates the dot product of float arrays of differing sizes, or a subset of the datainthammingDistance(long[] v1, long[] v2) intsquareDistance(byte[] a, byte[] b) Returns the sum of squared differences of the two byte vectors.floatsquareDistance(float[] a, float[] b) Returns the sum of squared differences of the two vectors.floatsquareDistance(float[] a, int aoffset, float[] b, int boffset, int length) Calculates the sum of squared differences of float arrays of differing sizes, or a subset of the datafloat[]sub(float[] lhs, float[] rhs) voidsubInPlace(float[] v1, float[] v2) Subtracts v2 from v1, in place (v1 will be modified)floatsum(float[] vector) return the sum of the components of the vectorfloat[]returns the sum of the given vectors.
-
Method Details
-
dotProduct
float dotProduct(float[] a, float[] b) Calculates the dot product of the given float arrays. -
dotProduct
float dotProduct(float[] a, int aoffset, float[] b, int boffset, int length) Calculates the dot product of float arrays of differing sizes, or a subset of the data -
cosine
float cosine(float[] v1, float[] v2) Returns the cosine similarity between the two vectors. -
squareDistance
float squareDistance(float[] a, float[] b) Returns the sum of squared differences of the two vectors. -
squareDistance
float squareDistance(float[] a, int aoffset, float[] b, int boffset, int length) Calculates the sum of squared differences of float arrays of differing sizes, or a subset of the data -
dotProduct
int dotProduct(byte[] a, byte[] b) Returns the dot product computed over signed bytes. -
cosine
float cosine(byte[] a, byte[] b) Returns the cosine similarity between the two byte vectors. -
squareDistance
int squareDistance(byte[] a, byte[] b) Returns the sum of squared differences of the two byte vectors. -
sum
returns the sum of the given vectors. -
sum
float sum(float[] vector) return the sum of the components of the vector -
divInPlace
void divInPlace(float[] vector, float divisor) Divide vector by divisor, in place (vector will be modified) -
addInPlace
void addInPlace(float[] v1, float[] v2) Adds v2 into v1, in place (v1 will be modified) -
subInPlace
void subInPlace(float[] v1, float[] v2) Subtracts v2 from v1, in place (v1 will be modified) -
sub
float[] sub(float[] lhs, float[] rhs) - Returns:
- lhs - rhs, element-wise
-
assembleAndSum
float assembleAndSum(float[] data, int baseIndex, byte[] baseOffsets) Calculates the sum of sparse points in a vector. This assumes the data vector is a 2d matrix which has been flattened into 1 dimension so rather than data[n][m] it's data[n * m]. With this layout this method can quickly assemble the data from this heap and sum it.- Parameters:
data- the vector of all datapointsbaseIndex- the start of the data in the offset table (scaled by the index of the lookup table)baseOffsets- bytes that represent offsets from the baseIndex- Returns:
- the sum of the points
-
hammingDistance
int hammingDistance(long[] v1, long[] v2)
-