Browse Source

Merge pull request #121 from dddddai/master

Determine the size of the array
Xiaohai Xu 4 years ago
parent
commit
8e5f830a98

+ 5 - 5
examples/src/main/java/MilvusClientExample.java

@@ -34,10 +34,10 @@ import java.util.stream.DoubleStream;
 public class MilvusClientExample {
 public class MilvusClientExample {
 
 
   // Helper function that generates random vectors
   // Helper function that generates random vectors
-  static List<List<Float>> generateVectors(long vectorCount, long dimension) {
+  static List<List<Float>> generateVectors(int vectorCount, int dimension) {
     SplittableRandom splitcollectionRandom = new SplittableRandom();
     SplittableRandom splitcollectionRandom = new SplittableRandom();
-    List<List<Float>> vectors = new ArrayList<>();
-    for (long i = 0; i < vectorCount; ++i) {
+    List<List<Float>> vectors = new ArrayList<>(vectorCount);
+    for (int i = 0; i < vectorCount; ++i) {
       splitcollectionRandom = splitcollectionRandom.split();
       splitcollectionRandom = splitcollectionRandom.split();
       DoubleStream doubleStream = splitcollectionRandom.doubles(dimension);
       DoubleStream doubleStream = splitcollectionRandom.doubles(dimension);
       List<Float> vector =
       List<Float> vector =
@@ -80,8 +80,8 @@ public class MilvusClientExample {
 
 
     // Create a collection with the following collection mapping
     // Create a collection with the following collection mapping
     final String collectionName = "example"; // collection name
     final String collectionName = "example"; // collection name
-    final long dimension = 128; // dimension of each vector
-    final long indexFileSize = 1024; // maximum size (in MB) of each index file
+    final int dimension = 128; // dimension of each vector
+    final int indexFileSize = 1024; // maximum size (in MB) of each index file
     final MetricType metricType = MetricType.IP; // we choose IP (Inner Product) as our metric type
     final MetricType metricType = MetricType.IP; // we choose IP (Inner Product) as our metric type
     CollectionMapping collectionMapping =
     CollectionMapping collectionMapping =
         new CollectionMapping.Builder(collectionName, dimension)
         new CollectionMapping.Builder(collectionName, dimension)

+ 11 - 11
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -40,14 +40,14 @@ class MilvusClientTest {
   private RandomStringGenerator generator;
   private RandomStringGenerator generator;
 
 
   private String randomCollectionName;
   private String randomCollectionName;
-  private long size;
-  private long dimension;
+  private int size;
+  private int dimension;
 
 
   // Helper function that generates random float vectors
   // Helper function that generates random float vectors
-  static List<List<Float>> generateFloatVectors(long vectorCount, long dimension) {
+  static List<List<Float>> generateFloatVectors(int vectorCount, int dimension) {
     SplittableRandom splittableRandom = new SplittableRandom();
     SplittableRandom splittableRandom = new SplittableRandom();
-    List<List<Float>> vectors = new ArrayList<>();
-    for (long i = 0; i < vectorCount; ++i) {
+    List<List<Float>> vectors = new ArrayList<>(vectorCount);
+    for (int i = 0; i < vectorCount; ++i) {
       splittableRandom = splittableRandom.split();
       splittableRandom = splittableRandom.split();
       DoubleStream doubleStream = splittableRandom.doubles(dimension);
       DoubleStream doubleStream = splittableRandom.doubles(dimension);
       List<Float> vector =
       List<Float> vector =
@@ -58,12 +58,12 @@ class MilvusClientTest {
   }
   }
 
 
   // Helper function that generates random binary vectors
   // Helper function that generates random binary vectors
-  static List<ByteBuffer> generateBinaryVectors(long vectorCount, long dimension) {
+  static List<ByteBuffer> generateBinaryVectors(int vectorCount, int dimension) {
     Random random = new Random();
     Random random = new Random();
-    List<ByteBuffer> vectors = new ArrayList<>();
-    final long dimensionInByte = dimension / 8;
-    for (long i = 0; i < vectorCount; ++i) {
-      ByteBuffer byteBuffer = ByteBuffer.allocate((int) dimensionInByte);
+    List<ByteBuffer> vectors = new ArrayList<>(vectorCount);
+    final int dimensionInByte = dimension / 8;
+    for (int i = 0; i < vectorCount; ++i) {
+      ByteBuffer byteBuffer = ByteBuffer.allocate(dimensionInByte);
       random.nextBytes(byteBuffer.array());
       random.nextBytes(byteBuffer.array());
       vectors.add(byteBuffer);
       vectors.add(byteBuffer);
     }
     }
@@ -326,7 +326,7 @@ class MilvusClientTest {
 
 
   @org.junit.jupiter.api.Test
   @org.junit.jupiter.api.Test
   void insertBinary() {
   void insertBinary() {
-    final long binaryDimension = 10000;
+    final int binaryDimension = 10000;
 
 
     String binaryCollectionName = generator.generate(10);
     String binaryCollectionName = generator.generate(10);
     CollectionMapping collectionMapping =
     CollectionMapping collectionMapping =