mirror of https://github.com/apache/lucene.git
LUCENE-9592: Loosen equality checks in TestVectorUtil. (#2084)
TestVectorUtil occasionally fails because of floating point errors. This change slightly increases the epsilon in equality checks -- testing shows that this will greatly decrease the chance of failure.
This commit is contained in:
parent
c4d4767bca
commit
8c7b709c08
|
@ -25,7 +25,7 @@ public class TestVectorUtil extends LuceneTestCase {
|
||||||
public void testSelfDotProduct() {
|
public void testSelfDotProduct() {
|
||||||
// the dot product of a vector with itself is equal to the sum of the squares of its components
|
// the dot product of a vector with itself is equal to the sum of the squares of its components
|
||||||
float[] v = randomVector();
|
float[] v = randomVector();
|
||||||
assertEquals(l2(v), VectorUtil.dotProduct(v, v), 1e-5);
|
assertEquals(l2(v), VectorUtil.dotProduct(v, v), 1e-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOrthogonalDotProduct() {
|
public void testOrthogonalDotProduct() {
|
||||||
|
@ -36,13 +36,13 @@ public class TestVectorUtil extends LuceneTestCase {
|
||||||
float[] u = new float[2];
|
float[] u = new float[2];
|
||||||
u[0] = v[1];
|
u[0] = v[1];
|
||||||
u[1] = -v[0];
|
u[1] = -v[0];
|
||||||
assertEquals(0, VectorUtil.dotProduct(u, v), 1e-5);
|
assertEquals(0, VectorUtil.dotProduct(u, v), 1e-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSelfSquareDistance() {
|
public void testSelfSquareDistance() {
|
||||||
// the l2 distance of a vector with itself is zero
|
// the l2 distance of a vector with itself is zero
|
||||||
float[] v = randomVector();
|
float[] v = randomVector();
|
||||||
assertEquals(0, VectorUtil.squareDistance(v, v), 1e-5);
|
assertEquals(0, VectorUtil.squareDistance(v, v), 1e-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasicSquareDistance() {
|
public void testBasicSquareDistance() {
|
||||||
|
@ -53,7 +53,7 @@ public class TestVectorUtil extends LuceneTestCase {
|
||||||
// the square distance of a vector with its inverse is equal to four times the sum of squares of its components
|
// the square distance of a vector with its inverse is equal to four times the sum of squares of its components
|
||||||
float[] v = randomVector();
|
float[] v = randomVector();
|
||||||
float[] u = negative(v);
|
float[] u = negative(v);
|
||||||
assertEquals(4 * l2(v), VectorUtil.squareDistance(u, v), 1e-5);
|
assertEquals(4 * l2(v), VectorUtil.squareDistance(u, v), 1e-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float l2(float[] v) {
|
private float l2(float[] v) {
|
||||||
|
|
Loading…
Reference in New Issue