@@ -29,32 +29,6 @@ protected DiskBBQBulkWriter(int bulkSize, IndexOutput out) {
29
29
30
30
abstract void writeVectors (DefaultIVFVectorsWriter .QuantizedVectorValues qvv ) throws IOException ;
31
31
32
- private static void writeCorrections (OptimizedScalarQuantizer .QuantizationResult [] corrections , IndexOutput out ) throws IOException {
33
- for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
34
- out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
35
- }
36
- for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
37
- out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
38
- }
39
- for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
40
- int targetComponentSum = correction .quantizedComponentSum ();
41
- assert targetComponentSum >= 0 && targetComponentSum <= 0xffff ;
42
- out .writeShort ((short ) targetComponentSum );
43
- }
44
- for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
45
- out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
46
- }
47
- }
48
-
49
- private static void writeCorrection (OptimizedScalarQuantizer .QuantizationResult correction , IndexOutput out ) throws IOException {
50
- out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
51
- out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
52
- out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
53
- int targetComponentSum = correction .quantizedComponentSum ();
54
- assert targetComponentSum >= 0 && targetComponentSum <= 0xffff ;
55
- out .writeShort ((short ) targetComponentSum );
56
- }
57
-
58
32
static class OneBitDiskBBQBulkWriter extends DiskBBQBulkWriter {
59
33
private final OptimizedScalarQuantizer .QuantizationResult [] corrections ;
60
34
@@ -73,22 +47,48 @@ void writeVectors(DefaultIVFVectorsWriter.QuantizedVectorValues qvv) throws IOEx
73
47
corrections [j ] = qvv .getCorrections ();
74
48
out .writeBytes (qv , qv .length );
75
49
}
76
- writeCorrections (corrections , out );
50
+ writeCorrections (corrections );
77
51
}
78
52
// write tail
79
53
for (; i < qvv .count (); ++i ) {
80
54
byte [] qv = qvv .next ();
81
55
OptimizedScalarQuantizer .QuantizationResult correction = qvv .getCorrections ();
82
56
out .writeBytes (qv , qv .length );
83
- writeCorrection (correction , out );
57
+ writeCorrection (correction );
58
+ }
59
+ }
60
+
61
+ private void writeCorrections (OptimizedScalarQuantizer .QuantizationResult [] corrections ) throws IOException {
62
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
63
+ out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
64
+ }
65
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
66
+ out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
67
+ }
68
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
69
+ int targetComponentSum = correction .quantizedComponentSum ();
70
+ assert targetComponentSum >= 0 && targetComponentSum <= 0xffff ;
71
+ out .writeShort ((short ) targetComponentSum );
72
+ }
73
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
74
+ out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
84
75
}
85
76
}
77
+
78
+ private void writeCorrection (OptimizedScalarQuantizer .QuantizationResult correction ) throws IOException {
79
+ out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
80
+ out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
81
+ out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
82
+ int targetComponentSum = correction .quantizedComponentSum ();
83
+ assert targetComponentSum >= 0 && targetComponentSum <= 0xffff ;
84
+ out .writeShort ((short ) targetComponentSum );
85
+ }
86
86
}
87
87
88
- static class FourBitDiskBBQBulkWriter extends DiskBBQBulkWriter {
88
+ static class SevenBitDiskBBQBulkWriter extends DiskBBQBulkWriter {
89
89
private final OptimizedScalarQuantizer .QuantizationResult [] corrections ;
90
90
91
- FourBitDiskBBQBulkWriter (int bulkSize , IndexOutput out ) {
91
+ SevenBitDiskBBQBulkWriter (int bulkSize , IndexOutput out ) {
92
92
super (bulkSize , out );
93
93
this .corrections = new OptimizedScalarQuantizer .QuantizationResult [bulkSize ];
94
94
}
@@ -103,15 +103,37 @@ void writeVectors(DefaultIVFVectorsWriter.QuantizedVectorValues qvv) throws IOEx
103
103
corrections [j ] = qvv .getCorrections ();
104
104
out .writeBytes (qv , qv .length );
105
105
}
106
- writeCorrections (corrections , out );
106
+ writeCorrections (corrections );
107
107
}
108
108
// write tail
109
109
for (; i < qvv .count (); ++i ) {
110
110
byte [] qv = qvv .next ();
111
111
OptimizedScalarQuantizer .QuantizationResult correction = qvv .getCorrections ();
112
112
out .writeBytes (qv , qv .length );
113
- writeCorrection (correction , out );
113
+ writeCorrection (correction );
114
114
}
115
115
}
116
+
117
+ private void writeCorrections (OptimizedScalarQuantizer .QuantizationResult [] corrections ) throws IOException {
118
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
119
+ out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
120
+ }
121
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
122
+ out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
123
+ }
124
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
125
+ out .writeInt (correction .quantizedComponentSum ());
126
+ }
127
+ for (OptimizedScalarQuantizer .QuantizationResult correction : corrections ) {
128
+ out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
129
+ }
130
+ }
131
+
132
+ private void writeCorrection (OptimizedScalarQuantizer .QuantizationResult correction ) throws IOException {
133
+ out .writeInt (Float .floatToIntBits (correction .lowerInterval ()));
134
+ out .writeInt (Float .floatToIntBits (correction .upperInterval ()));
135
+ out .writeInt (Float .floatToIntBits (correction .additionalCorrection ()));
136
+ out .writeInt (correction .quantizedComponentSum ());
137
+ }
116
138
}
117
139
}
0 commit comments