From 7a8431337f96544db8883578b65db830828959cd Mon Sep 17 00:00:00 2001 From: Bruno Roustant Date: Sat, 11 May 2024 18:23:38 +0200 Subject: [PATCH 1/4] Add ArrayUtil.copyOf methods. --- .../org/apache/lucene/util/ArrayUtil.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java index 336b5b3e6bb..88e7aefa53f 100644 --- a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java @@ -623,6 +623,13 @@ protected int comparePivot(int j) { }.select(from, to, k); } + /** + * Copies an array into a new array. + */ + public static byte[] copyOf(byte[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -636,6 +643,13 @@ public static byte[] copyOfSubArray(byte[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static char[] copyOf(char[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -649,6 +663,13 @@ public static char[] copyOfSubArray(char[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static short[] copyOf(short[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -662,6 +683,13 @@ public static short[] copyOfSubArray(short[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static int[] copyOf(int[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -675,6 +703,13 @@ public static int[] copyOfSubArray(int[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static long[] copyOf(long[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -688,6 +723,13 @@ public static long[] copyOfSubArray(long[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static float[] copyOf(float[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -701,6 +743,13 @@ public static float[] copyOfSubArray(float[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static double[] copyOf(double[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * @@ -714,6 +763,13 @@ public static double[] copyOfSubArray(double[] array, int from, int to) { return copy; } + /** + * Copies an array into a new array. + */ + public static T[] copyOf(T[] array) { + return copyOfSubArray(array, 0, array.length); + } + /** * Copies the specified range of the given array into a new sub array. * From 72f8074fe403e3ee7c8daa4d2ed39063a92a74d9 Mon Sep 17 00:00:00 2001 From: Bruno Roustant Date: Sat, 11 May 2024 18:34:45 +0200 Subject: [PATCH 2/4] Call ArrayUtil.copyOf instead of copySubArray. --- .../lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java | 2 +- .../src/java/org/apache/lucene/search/BlendedTermQuery.java | 2 +- .../src/java/org/apache/lucene/search/KnnByteVectorQuery.java | 2 +- .../java/org/apache/lucene/search/KnnFloatVectorQuery.java | 2 +- .../core/src/test/org/apache/lucene/search/TestBoolean2.java | 2 +- .../src/test/org/apache/lucene/search/TestPhraseQuery.java | 2 +- .../lucene/search/TestSimpleExplanationsWithFillerDocs.java | 2 +- .../src/test/org/apache/lucene/util/BaseSortTestCase.java | 2 +- .../org/apache/lucene/util/hnsw/MockByteVectorValues.java | 4 ++-- .../test/org/apache/lucene/util/hnsw/MockVectorValues.java | 4 ++-- .../quantization/TestScalarQuantizedVectorSimilarity.java | 4 ++-- .../test/org/apache/lucene/spatial/TestDistanceStrategy.java | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java b/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java index 9914d2cb537..8a105c9ae2a 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java @@ -44,7 +44,7 @@ public static float quantizeQuery( switch (similarityFunction) { case EUCLIDEAN, DOT_PRODUCT, MAXIMUM_INNER_PRODUCT -> query; case COSINE -> { - float[] queryCopy = ArrayUtil.copyOfSubArray(query, 0, query.length); + float[] queryCopy = ArrayUtil.copyOf(query); VectorUtil.l2normalize(queryCopy); yield queryCopy; } diff --git a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java index 05d86819486..998e3a7a098 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java @@ -268,7 +268,7 @@ public String toString(String field) { @Override public final Query rewrite(IndexSearcher indexSearcher) throws IOException { - final TermStates[] contexts = ArrayUtil.copyOfSubArray(this.contexts, 0, this.contexts.length); + final TermStates[] contexts = ArrayUtil.copyOf(this.contexts); for (int i = 0; i < contexts.length; ++i) { if (contexts[i] == null || contexts[i].wasBuiltFor(indexSearcher.getTopReaderContext()) == false) { diff --git a/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java b/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java index e3d733e516f..2b622a5e1fe 100644 --- a/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java @@ -128,6 +128,6 @@ public int hashCode() { * @return the target query vector of the search. Each vector element is a byte. */ public byte[] getTargetCopy() { - return ArrayUtil.copyOfSubArray(target, 0, target.length); + return ArrayUtil.copyOf(target); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java b/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java index 91cf4474e1c..87f65b9ba8d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java @@ -131,6 +131,6 @@ public int hashCode() { * @return the target query vector of the search. Each vector element is a float. */ public float[] getTargetCopy() { - return ArrayUtil.copyOfSubArray(target, 0, target.length); + return ArrayUtil.copyOf(target); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java index ccb8c954c28..d604b3f6231 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java @@ -229,7 +229,7 @@ public void queriesTest(Query query, int[] expDocNrs) throws Exception { // adjust the expected doc numbers according to our filler docs if (0 < NUM_FILLER_DOCS) { - expDocNrs = ArrayUtil.copyOfSubArray(expDocNrs, 0, expDocNrs.length); + expDocNrs = ArrayUtil.copyOf(expDocNrs); for (int i = 0; i < expDocNrs.length; i++) { expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java index 05cb9df5397..fd143818de5 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java @@ -755,7 +755,7 @@ public void testBackwardPositions() throws Exception { public void testTopPhrases() throws IOException { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); - String[] docs = ArrayUtil.copyOfSubArray(DOCS, 0, DOCS.length); + String[] docs = ArrayUtil.copyOf(DOCS); Collections.shuffle(Arrays.asList(docs), random()); for (String value : DOCS) { Document doc = new Document(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java index 93dd4402c4c..cf7162f6390 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java @@ -103,7 +103,7 @@ private static Document makeFillerDoc() { @Override public void qtest(Query q, int[] expDocNrs) throws Exception { - expDocNrs = ArrayUtil.copyOfSubArray(expDocNrs, 0, expDocNrs.length); + expDocNrs = ArrayUtil.copyOf(expDocNrs); for (int i = 0; i < expDocNrs.length; i++) { expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]); } diff --git a/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java b/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java index e887448578f..9617e249fa5 100644 --- a/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java +++ b/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java @@ -49,7 +49,7 @@ public BaseSortTestCase(boolean stable) { public void assertSorted(Entry[] original, Entry[] sorted) { assertEquals(original.length, sorted.length); - Entry[] actuallySorted = ArrayUtil.copyOfSubArray(original, 0, original.length); + Entry[] actuallySorted = ArrayUtil.copyOf(original); Arrays.sort(actuallySorted); for (int i = 0; i < original.length; ++i) { assertEquals(actuallySorted[i].value, sorted[i].value); diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java index fdc2566c022..c723eb044c8 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java @@ -50,9 +50,9 @@ static MockByteVectorValues fromValues(byte[][] values) { @Override public MockByteVectorValues copy() { return new MockByteVectorValues( - ArrayUtil.copyOfSubArray(values, 0, values.length), + ArrayUtil.copyOf(values), dimension, - ArrayUtil.copyOfSubArray(denseValues, 0, denseValues.length), + ArrayUtil.copyOf(denseValues), numVectors); } diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java index c10f80e20a8..2229587ff5f 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java @@ -50,9 +50,9 @@ static MockVectorValues fromValues(float[][] values) { @Override public MockVectorValues copy() { return new MockVectorValues( - ArrayUtil.copyOfSubArray(values, 0, values.length), + ArrayUtil.copyOf(values), dimension, - ArrayUtil.copyOfSubArray(denseValues, 0, denseValues.length), + ArrayUtil.copyOf(denseValues), numVectors); } diff --git a/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java b/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java index 468046090a5..d9e3cf53d64 100644 --- a/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java +++ b/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java @@ -209,7 +209,7 @@ private static float[] quantizeVectorsNormalized( int i = 0; float[] offsets = new float[floats.length]; for (float[] f : floats) { - float[] v = ArrayUtil.copyOfSubArray(f, 0, f.length); + float[] v = ArrayUtil.copyOf(f); VectorUtil.l2normalize(v); quantized[i] = new byte[v.length]; offsets[i] = scalarQuantizer.quantize(v, quantized[i], similarityFunction); @@ -226,7 +226,7 @@ public float[] vectorValue() throws IOException { if (curDoc == -1 || curDoc >= floats.length) { throw new IOException("Current doc not set or too many iterations"); } - float[] v = ArrayUtil.copyOfSubArray(floats[curDoc], 0, floats[curDoc].length); + float[] v = ArrayUtil.copyOf(floats[curDoc]); VectorUtil.l2normalize(v); return v; } diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java index e3cf440d2b1..e8611463513 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java @@ -108,7 +108,7 @@ public void testRecipScore() throws IOException { void checkDistValueSource(Point pt, float... distances) throws IOException { float multiplier = random().nextFloat() * 100f; - float[] dists2 = ArrayUtil.copyOfSubArray(distances, 0, distances.length); + float[] dists2 = ArrayUtil.copyOf(distances); for (int i = 0; i < dists2.length; i++) { dists2[i] *= multiplier; } From 48c808a20a0dbcecd78cbb7512abbdc5397af458 Mon Sep 17 00:00:00 2001 From: Bruno Roustant Date: Sat, 11 May 2024 18:49:45 +0200 Subject: [PATCH 3/4] Rename ArrayUtil.copyArray. --- .../codecs/hnsw/ScalarQuantizedVectorScorer.java | 2 +- .../apache/lucene/search/BlendedTermQuery.java | 2 +- .../apache/lucene/search/KnnByteVectorQuery.java | 2 +- .../lucene/search/KnnFloatVectorQuery.java | 2 +- .../java/org/apache/lucene/util/ArrayUtil.java | 16 ++++++++-------- .../org/apache/lucene/search/TestBoolean2.java | 2 +- .../apache/lucene/search/TestPhraseQuery.java | 2 +- .../TestSimpleExplanationsWithFillerDocs.java | 2 +- .../org/apache/lucene/util/BaseSortTestCase.java | 2 +- .../lucene/util/hnsw/MockByteVectorValues.java | 4 ++-- .../lucene/util/hnsw/MockVectorValues.java | 4 ++-- .../TestScalarQuantizedVectorSimilarity.java | 4 ++-- .../lucene/spatial/TestDistanceStrategy.java | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java b/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java index 8a105c9ae2a..3590acab2ef 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/hnsw/ScalarQuantizedVectorScorer.java @@ -44,7 +44,7 @@ public static float quantizeQuery( switch (similarityFunction) { case EUCLIDEAN, DOT_PRODUCT, MAXIMUM_INNER_PRODUCT -> query; case COSINE -> { - float[] queryCopy = ArrayUtil.copyOf(query); + float[] queryCopy = ArrayUtil.copyArray(query); VectorUtil.l2normalize(queryCopy); yield queryCopy; } diff --git a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java index 998e3a7a098..8b7d3e80fcd 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java @@ -268,7 +268,7 @@ public String toString(String field) { @Override public final Query rewrite(IndexSearcher indexSearcher) throws IOException { - final TermStates[] contexts = ArrayUtil.copyOf(this.contexts); + final TermStates[] contexts = ArrayUtil.copyArray(this.contexts); for (int i = 0; i < contexts.length; ++i) { if (contexts[i] == null || contexts[i].wasBuiltFor(indexSearcher.getTopReaderContext()) == false) { diff --git a/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java b/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java index 2b622a5e1fe..5b60e680e10 100644 --- a/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/KnnByteVectorQuery.java @@ -128,6 +128,6 @@ public int hashCode() { * @return the target query vector of the search. Each vector element is a byte. */ public byte[] getTargetCopy() { - return ArrayUtil.copyOf(target); + return ArrayUtil.copyArray(target); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java b/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java index 87f65b9ba8d..b06e81eb5d8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/KnnFloatVectorQuery.java @@ -131,6 +131,6 @@ public int hashCode() { * @return the target query vector of the search. Each vector element is a float. */ public float[] getTargetCopy() { - return ArrayUtil.copyOf(target); + return ArrayUtil.copyArray(target); } } diff --git a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java index 88e7aefa53f..9164f328f58 100644 --- a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java @@ -626,7 +626,7 @@ protected int comparePivot(int j) { /** * Copies an array into a new array. */ - public static byte[] copyOf(byte[] array) { + public static byte[] copyArray(byte[] array) { return copyOfSubArray(array, 0, array.length); } @@ -646,7 +646,7 @@ public static byte[] copyOfSubArray(byte[] array, int from, int to) { /** * Copies an array into a new array. */ - public static char[] copyOf(char[] array) { + public static char[] copyArray(char[] array) { return copyOfSubArray(array, 0, array.length); } @@ -666,7 +666,7 @@ public static char[] copyOfSubArray(char[] array, int from, int to) { /** * Copies an array into a new array. */ - public static short[] copyOf(short[] array) { + public static short[] copyArray(short[] array) { return copyOfSubArray(array, 0, array.length); } @@ -686,7 +686,7 @@ public static short[] copyOfSubArray(short[] array, int from, int to) { /** * Copies an array into a new array. */ - public static int[] copyOf(int[] array) { + public static int[] copyArray(int[] array) { return copyOfSubArray(array, 0, array.length); } @@ -706,7 +706,7 @@ public static int[] copyOfSubArray(int[] array, int from, int to) { /** * Copies an array into a new array. */ - public static long[] copyOf(long[] array) { + public static long[] copyArray(long[] array) { return copyOfSubArray(array, 0, array.length); } @@ -726,7 +726,7 @@ public static long[] copyOfSubArray(long[] array, int from, int to) { /** * Copies an array into a new array. */ - public static float[] copyOf(float[] array) { + public static float[] copyArray(float[] array) { return copyOfSubArray(array, 0, array.length); } @@ -746,7 +746,7 @@ public static float[] copyOfSubArray(float[] array, int from, int to) { /** * Copies an array into a new array. */ - public static double[] copyOf(double[] array) { + public static double[] copyArray(double[] array) { return copyOfSubArray(array, 0, array.length); } @@ -766,7 +766,7 @@ public static double[] copyOfSubArray(double[] array, int from, int to) { /** * Copies an array into a new array. */ - public static T[] copyOf(T[] array) { + public static T[] copyArray(T[] array) { return copyOfSubArray(array, 0, array.length); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java index d604b3f6231..b0634e56da4 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2.java @@ -229,7 +229,7 @@ public void queriesTest(Query query, int[] expDocNrs) throws Exception { // adjust the expected doc numbers according to our filler docs if (0 < NUM_FILLER_DOCS) { - expDocNrs = ArrayUtil.copyOf(expDocNrs); + expDocNrs = ArrayUtil.copyArray(expDocNrs); for (int i = 0; i < expDocNrs.length; i++) { expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java index fd143818de5..f91f1a5e6f4 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java @@ -755,7 +755,7 @@ public void testBackwardPositions() throws Exception { public void testTopPhrases() throws IOException { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); - String[] docs = ArrayUtil.copyOf(DOCS); + String[] docs = ArrayUtil.copyArray(DOCS); Collections.shuffle(Arrays.asList(docs), random()); for (String value : DOCS) { Document doc = new Document(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java index cf7162f6390..f799cb896a5 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanationsWithFillerDocs.java @@ -103,7 +103,7 @@ private static Document makeFillerDoc() { @Override public void qtest(Query q, int[] expDocNrs) throws Exception { - expDocNrs = ArrayUtil.copyOf(expDocNrs); + expDocNrs = ArrayUtil.copyArray(expDocNrs); for (int i = 0; i < expDocNrs.length; i++) { expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]); } diff --git a/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java b/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java index 9617e249fa5..ba4ed6fa82b 100644 --- a/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java +++ b/lucene/core/src/test/org/apache/lucene/util/BaseSortTestCase.java @@ -49,7 +49,7 @@ public BaseSortTestCase(boolean stable) { public void assertSorted(Entry[] original, Entry[] sorted) { assertEquals(original.length, sorted.length); - Entry[] actuallySorted = ArrayUtil.copyOf(original); + Entry[] actuallySorted = ArrayUtil.copyArray(original); Arrays.sort(actuallySorted); for (int i = 0; i < original.length; ++i) { assertEquals(actuallySorted[i].value, sorted[i].value); diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java index c723eb044c8..26d8129ebbd 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java @@ -50,9 +50,9 @@ static MockByteVectorValues fromValues(byte[][] values) { @Override public MockByteVectorValues copy() { return new MockByteVectorValues( - ArrayUtil.copyOf(values), + ArrayUtil.copyArray(values), dimension, - ArrayUtil.copyOf(denseValues), + ArrayUtil.copyArray(denseValues), numVectors); } diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java index 2229587ff5f..8815ef98739 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java @@ -50,9 +50,9 @@ static MockVectorValues fromValues(float[][] values) { @Override public MockVectorValues copy() { return new MockVectorValues( - ArrayUtil.copyOf(values), + ArrayUtil.copyArray(values), dimension, - ArrayUtil.copyOf(denseValues), + ArrayUtil.copyArray(denseValues), numVectors); } diff --git a/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java b/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java index d9e3cf53d64..38238815e7c 100644 --- a/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java +++ b/lucene/core/src/test/org/apache/lucene/util/quantization/TestScalarQuantizedVectorSimilarity.java @@ -209,7 +209,7 @@ private static float[] quantizeVectorsNormalized( int i = 0; float[] offsets = new float[floats.length]; for (float[] f : floats) { - float[] v = ArrayUtil.copyOf(f); + float[] v = ArrayUtil.copyArray(f); VectorUtil.l2normalize(v); quantized[i] = new byte[v.length]; offsets[i] = scalarQuantizer.quantize(v, quantized[i], similarityFunction); @@ -226,7 +226,7 @@ public float[] vectorValue() throws IOException { if (curDoc == -1 || curDoc >= floats.length) { throw new IOException("Current doc not set or too many iterations"); } - float[] v = ArrayUtil.copyOf(floats[curDoc]); + float[] v = ArrayUtil.copyArray(floats[curDoc]); VectorUtil.l2normalize(v); return v; } diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java index e8611463513..31212621e4a 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/TestDistanceStrategy.java @@ -108,7 +108,7 @@ public void testRecipScore() throws IOException { void checkDistValueSource(Point pt, float... distances) throws IOException { float multiplier = random().nextFloat() * 100f; - float[] dists2 = ArrayUtil.copyOf(distances); + float[] dists2 = ArrayUtil.copyArray(distances); for (int i = 0; i < dists2.length; i++) { dists2[i] *= multiplier; } From 5ee3b2fb14b65cc71126f5e29d8d7199b4179d89 Mon Sep 17 00:00:00 2001 From: Bruno Roustant Date: Sat, 11 May 2024 18:52:14 +0200 Subject: [PATCH 4/4] Tidy --- .../org/apache/lucene/util/ArrayUtil.java | 32 +++++-------------- .../util/hnsw/MockByteVectorValues.java | 5 +-- .../lucene/util/hnsw/MockVectorValues.java | 5 +-- 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java index 9164f328f58..722df2ff687 100644 --- a/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java @@ -623,9 +623,7 @@ protected int comparePivot(int j) { }.select(from, to, k); } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static byte[] copyArray(byte[] array) { return copyOfSubArray(array, 0, array.length); } @@ -643,9 +641,7 @@ public static byte[] copyOfSubArray(byte[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static char[] copyArray(char[] array) { return copyOfSubArray(array, 0, array.length); } @@ -663,9 +659,7 @@ public static char[] copyOfSubArray(char[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static short[] copyArray(short[] array) { return copyOfSubArray(array, 0, array.length); } @@ -683,9 +677,7 @@ public static short[] copyOfSubArray(short[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static int[] copyArray(int[] array) { return copyOfSubArray(array, 0, array.length); } @@ -703,9 +695,7 @@ public static int[] copyOfSubArray(int[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static long[] copyArray(long[] array) { return copyOfSubArray(array, 0, array.length); } @@ -723,9 +713,7 @@ public static long[] copyOfSubArray(long[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static float[] copyArray(float[] array) { return copyOfSubArray(array, 0, array.length); } @@ -743,9 +731,7 @@ public static float[] copyOfSubArray(float[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static double[] copyArray(double[] array) { return copyOfSubArray(array, 0, array.length); } @@ -763,9 +749,7 @@ public static double[] copyOfSubArray(double[] array, int from, int to) { return copy; } - /** - * Copies an array into a new array. - */ + /** Copies an array into a new array. */ public static T[] copyArray(T[] array) { return copyOfSubArray(array, 0, array.length); } diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java index 26d8129ebbd..a3b17b9a621 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockByteVectorValues.java @@ -50,10 +50,7 @@ static MockByteVectorValues fromValues(byte[][] values) { @Override public MockByteVectorValues copy() { return new MockByteVectorValues( - ArrayUtil.copyArray(values), - dimension, - ArrayUtil.copyArray(denseValues), - numVectors); + ArrayUtil.copyArray(values), dimension, ArrayUtil.copyArray(denseValues), numVectors); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java index 8815ef98739..f183f6c99a6 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/MockVectorValues.java @@ -50,10 +50,7 @@ static MockVectorValues fromValues(float[][] values) { @Override public MockVectorValues copy() { return new MockVectorValues( - ArrayUtil.copyArray(values), - dimension, - ArrayUtil.copyArray(denseValues), - numVectors); + ArrayUtil.copyArray(values), dimension, ArrayUtil.copyArray(denseValues), numVectors); } @Override