You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by so...@apache.org on 2021/01/28 15:35:53 UTC

[lucene-solr] branch master updated: Exclude degenerate edge case (maxConn=1) from TestKnnGraph.testSearch

This is an automated email from the ASF dual-hosted git repository.

sokolov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new d84925a  Exclude degenerate edge case (maxConn=1) from TestKnnGraph.testSearch
d84925a is described below

commit d84925a201aa5e6432af51894ae5cae2db89dc6f
Author: Michael Sokolov <so...@amazon.com>
AuthorDate: Thu Jan 28 10:16:05 2021 -0500

    Exclude degenerate edge case (maxConn=1) from TestKnnGraph.testSearch
---
 .../test/org/apache/lucene/index/TestKnnGraph.java | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java b/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
index cbcb1f1..736cc19 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestKnnGraph.java
@@ -59,7 +59,7 @@ public class TestKnnGraph extends LuceneTestCase {
     randSeed = random().nextLong();
     if (random().nextBoolean()) {
       maxConn = HnswGraphBuilder.DEFAULT_MAX_CONN;
-      HnswGraphBuilder.DEFAULT_MAX_CONN = random().nextInt(256) + 1;
+      HnswGraphBuilder.DEFAULT_MAX_CONN = random().nextInt(256) + 2;
     }
     int strategy = random().nextInt(SearchStrategy.values().length - 1) + 1;
     searchStrategy = SearchStrategy.values()[strategy];
@@ -215,7 +215,7 @@ public class TestKnnGraph extends LuceneTestCase {
     searchStrategy = SearchStrategy.EUCLIDEAN_HNSW;
     try (Directory dir = newDirectory();
         IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig())) {
-      // Add a document for every cartesian point  in an NxN square so we can
+      // Add a document for every cartesian point in an NxN square so we can
       // easily know which are the nearest neighbors to every point. Insert by iterating
       // using a prime number that is not a divisor of N*N so that we will hit each point once,
       // and chosen so that points will be inserted in a deterministic
@@ -225,7 +225,8 @@ public class TestKnnGraph extends LuceneTestCase {
       int index = 0;
       for (int i = 0; i < values.length; i++) {
         // System.out.printf("%d: (%d, %d)\n", i, index % n, index / n);
-        values[i] = new float[] {index % n, index / n};
+        int x = index % n, y = index / n;
+        values[i] = new float[] {x, y};
         index = (index + stepSize) % (n * n);
         add(iw, i, values[i]);
         if (i == 13) {
@@ -249,10 +250,10 @@ public class TestKnnGraph extends LuceneTestCase {
         //  9 24 14  4 19
         // 12  2 17  7 22
 
-        // For this small graph the "search" is exhaustive, so this mostly tests the APIs, the
-        // orientation of the
-        // various priority queues, the scoring function, but not so much the approximate KNN search
-        // algo
+        /* For this small graph the "search" is exhaustive, so this mostly tests the APIs, the
+         * orientation of the various priority queues, the scoring function, but not so much the
+         * approximate KNN search algorithm
+         */
         assertGraphSearch(new int[] {0, 15, 3, 18, 5}, new float[] {0f, 0.1f}, dr);
         // Tiebreaking by docid must be done after VectorValues.search.
         // assertGraphSearch(new int[]{11, 1, 8, 14, 21}, new float[]{2, 2}, dr);
@@ -266,8 +267,7 @@ public class TestKnnGraph extends LuceneTestCase {
     TopDocs results = doKnnSearch(reader, vector, 5);
     for (ScoreDoc doc : results.scoreDocs) {
       // map docId to insertion id
-      int id = Integer.parseInt(reader.document(doc.doc).get("id"));
-      doc.doc = id;
+      doc.doc = Integer.parseInt(reader.document(doc.doc).get("id"));
     }
     assertResults(expected, results);
   }
@@ -313,7 +313,7 @@ public class TestKnnGraph extends LuceneTestCase {
           continue;
         }
         KnnGraphValues graphValues = vectorReader.getGraphValues(KNN_GRAPH_FIELD);
-        assertTrue((vectorValues == null) == (graphValues == null));
+        assertEquals((vectorValues == null), (graphValues == null));
         if (vectorValues == null) {
           continue;
         }
@@ -388,11 +388,10 @@ public class TestKnnGraph extends LuceneTestCase {
   }
 
   private void assertMaxConn(int[][] graph, int maxConn) {
-    for (int i = 0; i < graph.length; i++) {
-      if (graph[i] != null) {
-        assert (graph[i].length <= maxConn);
-        for (int j = 0; j < graph[i].length; j++) {
-          int k = graph[i][j];
+    for (int[] ints : graph) {
+      if (ints != null) {
+        assert (ints.length <= maxConn);
+        for (int k : ints) {
           assertNotNull(graph[k]);
         }
       }