Skip to content

Commit 581378b

Browse files
committed
addressing PR comments
1 parent 8063726 commit 581378b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104ScalarQuantizedVectorsWriter.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ private void writeVectors(
203203
float[] v = fieldData.getVectors().get(i);
204204
OptimizedScalarQuantizer.QuantizationResult corrections =
205205
scalarQuantizer.scalarQuantize(v, scratch, encoding.getBits(), clusterCenter);
206-
if (encoding == ScalarEncoding.PACKED_NIBBLE) {
207-
OffHeapScalarQuantizedVectorValues.packNibbles(scratch, vector);
208-
} else if (encoding == ScalarEncoding.SINGLE_BIT_QUERY_NIBBLE) {
209-
OptimizedScalarQuantizer.packAsBinary(scratch, vector);
206+
switch (encoding) {
207+
case PACKED_NIBBLE -> OffHeapScalarQuantizedVectorValues.packNibbles(scratch, vector);
208+
case SINGLE_BIT_QUERY_NIBBLE -> OptimizedScalarQuantizer.packAsBinary(scratch, vector);
209+
case UNSIGNED_BYTE, SEVEN_BIT -> {}
210210
}
211211
vectorData.writeBytes(vector, vector.length);
212212
vectorData.writeInt(Float.floatToIntBits(corrections.lowerInterval()));
@@ -263,10 +263,10 @@ private void writeSortedVectors(
263263
float[] v = fieldData.getVectors().get(ordinal);
264264
OptimizedScalarQuantizer.QuantizationResult corrections =
265265
scalarQuantizer.scalarQuantize(v, scratch, encoding.getBits(), clusterCenter);
266-
if (encoding == ScalarEncoding.PACKED_NIBBLE) {
267-
OffHeapScalarQuantizedVectorValues.packNibbles(scratch, vector);
268-
} else if (encoding == ScalarEncoding.SINGLE_BIT_QUERY_NIBBLE) {
269-
OptimizedScalarQuantizer.packAsBinary(scratch, vector);
266+
switch (encoding) {
267+
case PACKED_NIBBLE -> OffHeapScalarQuantizedVectorValues.packNibbles(scratch, vector);
268+
case SINGLE_BIT_QUERY_NIBBLE -> OptimizedScalarQuantizer.packAsBinary(scratch, vector);
269+
case UNSIGNED_BYTE, SEVEN_BIT -> {}
270270
}
271271
vectorData.writeBytes(vector, vector.length);
272272
vectorData.writeInt(Float.floatToIntBits(corrections.lowerInterval()));
@@ -870,10 +870,10 @@ private void quantize(int ord) throws IOException {
870870
corrections =
871871
quantizer.scalarQuantize(
872872
values.vectorValue(ord), quantized, encoding.getBits(), centroid);
873-
if (encoding == ScalarEncoding.PACKED_NIBBLE) {
874-
OffHeapScalarQuantizedVectorValues.packNibbles(quantized, packed);
875-
} else if (encoding == ScalarEncoding.SINGLE_BIT_QUERY_NIBBLE) {
876-
OptimizedScalarQuantizer.packAsBinary(quantized, packed);
873+
switch (encoding) {
874+
case PACKED_NIBBLE -> OffHeapScalarQuantizedVectorValues.packNibbles(quantized, packed);
875+
case SINGLE_BIT_QUERY_NIBBLE -> OptimizedScalarQuantizer.packAsBinary(quantized, packed);
876+
case UNSIGNED_BYTE, SEVEN_BIT -> {}
877877
}
878878
}
879879

0 commit comments

Comments
 (0)