2020
2121import io .milvus .common .utils .Float16Utils ;
2222import io .milvus .param .R ;
23-
2423import org .tensorflow .Tensor ;
2524import org .tensorflow .ndarray .Shape ;
2625import org .tensorflow .ndarray .buffer .ByteDataBuffer ;
@@ -69,7 +68,7 @@ public static List<List<Float>> generateFloatVectors(int dimension, int count) {
6968 public static List <List <Float >> generateFixFloatVectors (int dimension , int count ) {
7069 List <List <Float >> vectors = new ArrayList <>();
7170 for (int n = 0 ; n < count ; ++n ) {
72- List <Float > vector = generateFloatVector (dimension , (float )n );
71+ List <Float > vector = generateFloatVector (dimension , (float ) n );
7372 vectors .add (vector );
7473 }
7574 return vectors ;
@@ -87,7 +86,7 @@ public static void compareFloatVectors(List<Float> vec1, List<Float> vec2) {
8786 }
8887 }
8988
90- /////////////////////////////////////////////////////////////////////////////////////////////////////
89+ /// //////////////////////////////////////////////////////////////////////////////////////////////////
9190 public static ByteBuffer generateBinaryVector (int dimension ) {
9291 Random ran = new Random ();
9392 int byteCount = dimension / 8 ;
@@ -117,7 +116,7 @@ public static void printBinaryVector(ByteBuffer vector) {
117116 System .out .println ();
118117 }
119118
120- /////////////////////////////////////////////////////////////////////////////////////////////////////
119+ /// //////////////////////////////////////////////////////////////////////////////////////////////////
121120 public static TBfloat16 genTensorflowBF16Vector (int dimension ) {
122121 Random ran = new Random ();
123122 float [] array = new float [dimension ];
@@ -131,7 +130,7 @@ public static TBfloat16 genTensorflowBF16Vector(int dimension) {
131130 public static List <TBfloat16 > genTensorflowBF16Vectors (int dimension , int count ) {
132131 List <TBfloat16 > vectors = new ArrayList <>();
133132 for (int n = 0 ; n < count ; ++n ) {
134- TBfloat16 vector = genTensorflowBF16Vector (dimension );
133+ TBfloat16 vector = genTensorflowBF16Vector (dimension );
135134 vectors .add (vector );
136135 }
137136
@@ -140,7 +139,7 @@ public static List<TBfloat16> genTensorflowBF16Vectors(int dimension, int count)
140139
141140 public static ByteBuffer encodeTensorBF16Vector (TBfloat16 vector ) {
142141 ByteDataBuffer tensorBuf = vector .asRawTensor ().data ();
143- ByteBuffer buf = ByteBuffer .allocate ((int )tensorBuf .size ());
142+ ByteBuffer buf = ByteBuffer .allocate ((int ) tensorBuf .size ());
144143 for (long i = 0 ; i < tensorBuf .size (); i ++) {
145144 buf .put (tensorBuf .getByte (i ));
146145 }
@@ -157,10 +156,10 @@ public static List<ByteBuffer> encodeTensorBF16Vectors(List<TBfloat16> vectors)
157156 }
158157
159158 public static TBfloat16 decodeBF16VectorToTensor (ByteBuffer buf ) {
160- if (buf .limit ()% 2 != 0 ) {
159+ if (buf .limit () % 2 != 0 ) {
161160 return null ;
162161 }
163- int dim = buf .limit ()/ 2 ;
162+ int dim = buf .limit () / 2 ;
164163 ByteDataBuffer bf = DataBuffers .of (buf .array ());
165164 return Tensor .of (TBfloat16 .class , Shape .of (dim ), bf );
166165 }
@@ -197,7 +196,7 @@ public static List<TFloat16> genTensorflowFP16Vectors(int dimension, int count)
197196
198197 public static ByteBuffer encodeTensorFP16Vector (TFloat16 vector ) {
199198 ByteDataBuffer tensorBuf = vector .asRawTensor ().data ();
200- ByteBuffer buf = ByteBuffer .allocate ((int )tensorBuf .size ());
199+ ByteBuffer buf = ByteBuffer .allocate ((int ) tensorBuf .size ());
201200 for (long i = 0 ; i < tensorBuf .size (); i ++) {
202201 buf .put (tensorBuf .getByte (i ));
203202 }
@@ -214,10 +213,10 @@ public static List<ByteBuffer> encodeTensorFP16Vectors(List<TFloat16> vectors) {
214213 }
215214
216215 public static TFloat16 decodeFP16VectorToTensor (ByteBuffer buf ) {
217- if (buf .limit ()% 2 != 0 ) {
216+ if (buf .limit () % 2 != 0 ) {
218217 return null ;
219218 }
220- int dim = buf .limit ()/ 2 ;
219+ int dim = buf .limit () / 2 ;
221220 ByteDataBuffer bf = DataBuffers .of (buf .array ());
222221 return Tensor .of (TFloat16 .class , Shape .of (dim ), bf );
223222 }
@@ -231,7 +230,7 @@ public static List<Float> decodeFP16VectorToFloat(ByteBuffer buf) {
231230 return vector ;
232231 }
233232
234- /////////////////////////////////////////////////////////////////////////////////////////////////////
233+ /// //////////////////////////////////////////////////////////////////////////////////////////////////
235234 public static ByteBuffer encodeFloat16Vector (List <Float > originVector , boolean bfloat16 ) {
236235 if (bfloat16 ) {
237236 return Float16Utils .f32VectorToBf16Buffer (originVector );
@@ -274,7 +273,7 @@ public static List<ByteBuffer> generateFloat16Vectors(int dimension, int count,
274273 return vectors ;
275274 }
276275
277- /////////////////////////////////////////////////////////////////////////////////////////////////////
276+ /// //////////////////////////////////////////////////////////////////////////////////////////////////
278277 public static ByteBuffer generateInt8Vector (int dimension ) {
279278 Random ran = new Random ();
280279 int byteCount = dimension ;
@@ -295,13 +294,13 @@ public static List<ByteBuffer> generateInt8Vectors(int dimension, int count) {
295294 return vectors ;
296295 }
297296
298- /////////////////////////////////////////////////////////////////////////////////////////////////////
297+ /// //////////////////////////////////////////////////////////////////////////////////////////////////
299298 public static SortedMap <Long , Float > generateSparseVector () {
300299 Random ran = new Random ();
301300 SortedMap <Long , Float > sparse = new TreeMap <>();
302301 int dim = ran .nextInt (10 ) + 10 ;
303302 while (sparse .size () < dim ) {
304- sparse .put ((long )ran .nextInt (1000000 ), ran .nextFloat ());
303+ sparse .put ((long ) ran .nextInt (1000000 ), ran .nextFloat ());
305304 }
306305 return sparse ;
307306 }
0 commit comments