mirror of https://github.com/apache/lucene.git
Call ArrayUtil.copyArray instead of ArrayUtil.copySubArray for full array copy. (#13360)
This commit is contained in:
parent
fc12cc1847
commit
bcb62f56ad
|
@ -44,7 +44,7 @@ public class ScalarQuantizedVectorScorer implements FlatVectorsScorer {
|
|||
switch (similarityFunction) {
|
||||
case EUCLIDEAN, DOT_PRODUCT, MAXIMUM_INNER_PRODUCT -> query;
|
||||
case COSINE -> {
|
||||
float[] queryCopy = ArrayUtil.copyOfSubArray(query, 0, query.length);
|
||||
float[] queryCopy = ArrayUtil.copyArray(query);
|
||||
VectorUtil.l2normalize(queryCopy);
|
||||
yield queryCopy;
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public final class BlendedTermQuery extends Query {
|
|||
|
||||
@Override
|
||||
public final Query rewrite(IndexSearcher indexSearcher) throws IOException {
|
||||
final TermStates[] contexts = ArrayUtil.copyOfSubArray(this.contexts, 0, this.contexts.length);
|
||||
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) {
|
||||
|
|
|
@ -128,6 +128,6 @@ public class KnnByteVectorQuery extends AbstractKnnVectorQuery {
|
|||
* @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.copyArray(target);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,6 @@ public class KnnFloatVectorQuery extends AbstractKnnVectorQuery {
|
|||
* @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.copyArray(target);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -623,6 +623,11 @@ public final class ArrayUtil {
|
|||
}.select(from, to, k);
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static byte[] copyArray(byte[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -636,6 +641,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static char[] copyArray(char[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -649,6 +659,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static short[] copyArray(short[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -662,6 +677,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static int[] copyArray(int[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -675,6 +695,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static long[] copyArray(long[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -688,6 +713,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static float[] copyArray(float[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -701,6 +731,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static double[] copyArray(double[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
@ -714,6 +749,11 @@ public final class ArrayUtil {
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Copies an array into a new array. */
|
||||
public static <T> T[] copyArray(T[] array) {
|
||||
return copyOfSubArray(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified range of the given array into a new sub array.
|
||||
*
|
||||
|
|
|
@ -229,7 +229,7 @@ public class TestBoolean2 extends LuceneTestCase {
|
|||
|
||||
// adjust the expected doc numbers according to our filler docs
|
||||
if (0 < NUM_FILLER_DOCS) {
|
||||
expDocNrs = ArrayUtil.copyOfSubArray(expDocNrs, 0, expDocNrs.length);
|
||||
expDocNrs = ArrayUtil.copyArray(expDocNrs);
|
||||
for (int i = 0; i < expDocNrs.length; i++) {
|
||||
expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]);
|
||||
}
|
||||
|
|
|
@ -755,7 +755,7 @@ public class TestPhraseQuery extends LuceneTestCase {
|
|||
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.copyArray(DOCS);
|
||||
Collections.shuffle(Arrays.asList(docs), random());
|
||||
for (String value : DOCS) {
|
||||
Document doc = new Document();
|
||||
|
|
|
@ -103,7 +103,7 @@ public class TestSimpleExplanationsWithFillerDocs extends TestSimpleExplanations
|
|||
@Override
|
||||
public void qtest(Query q, int[] expDocNrs) throws Exception {
|
||||
|
||||
expDocNrs = ArrayUtil.copyOfSubArray(expDocNrs, 0, expDocNrs.length);
|
||||
expDocNrs = ArrayUtil.copyArray(expDocNrs);
|
||||
for (int i = 0; i < expDocNrs.length; i++) {
|
||||
expDocNrs[i] = PRE_FILLER_DOCS + ((NUM_FILLER_DOCS + 1) * expDocNrs[i]);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public abstract class BaseSortTestCase extends LuceneTestCase {
|
|||
|
||||
public void assertSorted(Entry[] original, Entry[] sorted) {
|
||||
assertEquals(original.length, sorted.length);
|
||||
Entry[] actuallySorted = ArrayUtil.copyOfSubArray(original, 0, original.length);
|
||||
Entry[] actuallySorted = ArrayUtil.copyArray(original);
|
||||
Arrays.sort(actuallySorted);
|
||||
for (int i = 0; i < original.length; ++i) {
|
||||
assertEquals(actuallySorted[i].value, sorted[i].value);
|
||||
|
|
|
@ -50,10 +50,7 @@ class MockByteVectorValues extends AbstractMockVectorValues<byte[]>
|
|||
@Override
|
||||
public MockByteVectorValues copy() {
|
||||
return new MockByteVectorValues(
|
||||
ArrayUtil.copyOfSubArray(values, 0, values.length),
|
||||
dimension,
|
||||
ArrayUtil.copyOfSubArray(denseValues, 0, denseValues.length),
|
||||
numVectors);
|
||||
ArrayUtil.copyArray(values), dimension, ArrayUtil.copyArray(denseValues), numVectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,10 +50,7 @@ class MockVectorValues extends AbstractMockVectorValues<float[]>
|
|||
@Override
|
||||
public MockVectorValues copy() {
|
||||
return new MockVectorValues(
|
||||
ArrayUtil.copyOfSubArray(values, 0, values.length),
|
||||
dimension,
|
||||
ArrayUtil.copyOfSubArray(denseValues, 0, denseValues.length),
|
||||
numVectors);
|
||||
ArrayUtil.copyArray(values), dimension, ArrayUtil.copyArray(denseValues), numVectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -229,7 +229,7 @@ public class TestScalarQuantizedVectorSimilarity extends LuceneTestCase {
|
|||
int i = 0;
|
||||
float[] offsets = new float[floats.length];
|
||||
for (float[] f : floats) {
|
||||
float[] v = ArrayUtil.copyOfSubArray(f, 0, f.length);
|
||||
float[] v = ArrayUtil.copyArray(f);
|
||||
VectorUtil.l2normalize(v);
|
||||
quantized[i] = new byte[v.length];
|
||||
offsets[i] = scalarQuantizer.quantize(v, quantized[i], similarityFunction);
|
||||
|
@ -246,7 +246,7 @@ public class TestScalarQuantizedVectorSimilarity extends LuceneTestCase {
|
|||
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.copyArray(floats[curDoc]);
|
||||
VectorUtil.l2normalize(v);
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class TestDistanceStrategy extends StrategyTestCase {
|
|||
|
||||
void checkDistValueSource(Point pt, float... distances) throws IOException {
|
||||
float multiplier = random().nextFloat() * 100f;
|
||||
float[] dists2 = ArrayUtil.copyOfSubArray(distances, 0, distances.length);
|
||||
float[] dists2 = ArrayUtil.copyArray(distances);
|
||||
for (int i = 0; i < dists2.length; i++) {
|
||||
dists2[i] *= multiplier;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue