You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ju...@apache.org on 2022/04/08 16:50:54 UTC
[lucene] branch branch_9_1 updated: Fix rare failures in TestVectorUtil cosine tests
This is an automated email from the ASF dual-hosted git repository.
julietibs pushed a commit to branch branch_9_1
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9_1 by this push:
new 9ae2181be57 Fix rare failures in TestVectorUtil cosine tests
9ae2181be57 is described below
commit 9ae2181be57ebdfc023b05ed5cba8ebc0b1dfd29
Author: Julie Tibshirani <ju...@apache.org>
AuthorDate: Fri Apr 8 09:26:15 2022 -0700
Fix rare failures in TestVectorUtil cosine tests
If one of the vectors is zero, the cosine is not defined. This change makes sure
the test vectors are non-zero.
---
lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
index 54ed53efdb1..491322c2801 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVectorUtil.java
@@ -80,6 +80,8 @@ public class TestVectorUtil extends LuceneTestCase {
public void testSelfCosine() {
// the dot product of a vector with itself is always equal to 1
float[] v = randomVector();
+ // ensure the vector is non-zero so that cosine is defined
+ v[0] = random().nextFloat() + 0.01f;
assertEquals(1.0f, VectorUtil.cosine(v, v), DELTA);
}
@@ -87,7 +89,8 @@ public class TestVectorUtil extends LuceneTestCase {
// the cosine of two perpendicular vectors is 0
float[] v = new float[2];
v[0] = random().nextInt(100);
- v[1] = random().nextInt(100);
+ // ensure the vector is non-zero so that cosine is defined
+ v[1] = 1 + random().nextInt(99);
float[] u = new float[2];
u[0] = v[1];
u[1] = -v[0];