jpountz commented on code in PR #13772:
URL: https://github.com/apache/lucene/pull/13772#discussion_r1756843565


##########
lucene/core/src/java/org/apache/lucene/util/TermAndVector.java:
##########
@@ -24,37 +24,24 @@
  *
  * @lucene.experimental
  */
-public class TermAndVector {
-
-  private final BytesRef term;
-  private final float[] vector;
-
-  public TermAndVector(BytesRef term, float[] vector) {
-    this.term = term;
-    this.vector = vector;
-  }
-
-  public BytesRef getTerm() {
-    return this.term;
-  }
-
-  public float[] getVector() {
-    return this.vector;
-  }
+public record TermAndVector(BytesRef term, float[] vector) {
 
   public int size() {
     return vector.length;
   }
 
-  public void normalizeVector() {
+  /** Return a {@link TermAndVector} whose vector is normalized according to 
the L2 norm. */
+  public TermAndVector normalizeVector() {
     float vectorLength = 0;
     for (int i = 0; i < vector.length; i++) {
       vectorLength += vector[i] * vector[i];
     }
     vectorLength = (float) Math.sqrt(vectorLength);
+    float[] newVector = new float[vector.length];
     for (int i = 0; i < vector.length; i++) {
-      vector[i] /= vectorLength;
+      newVector[i] = vector[i] / vectorLength;
     }

Review Comment:
   Good call



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to