mirror of https://github.com/apache/lucene.git
Fix test failure with zero-length vector (#12493)
This adds assertions around the random test vector dimension count and continues to generate random vectors until it has a `squareSum > 0`
This commit is contained in:
parent
a65cf8960a
commit
dd4e66dad6
|
@ -1222,15 +1222,23 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
|
|||
}
|
||||
|
||||
private float[] randomVector(int dim) {
|
||||
assert dim > 0;
|
||||
float[] v = new float[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
v[i] = random().nextFloat();
|
||||
double squareSum = 0.0;
|
||||
// keep generating until we don't get a zero-length vector
|
||||
while (squareSum == 0.0) {
|
||||
squareSum = 0.0;
|
||||
for (int i = 0; i < dim; i++) {
|
||||
v[i] = random().nextFloat();
|
||||
squareSum += v[i] * v[i];
|
||||
}
|
||||
}
|
||||
VectorUtil.l2normalize(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
private byte[] randomVector8(int dim) {
|
||||
assert dim > 0;
|
||||
float[] v = randomVector(dim);
|
||||
byte[] b = new byte[dim];
|
||||
for (int i = 0; i < dim; i++) {
|
||||
|
|
Loading…
Reference in New Issue