Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from luyuncheng/add_bit_hamming_int32
Browse files Browse the repository at this point in the history
1. Modified code for codecov
  • Loading branch information
luyuncheng authored Jan 6, 2021
2 parents d8735aa + 2b79ef6 commit c2abcb2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,16 @@ public static final class Pair {
public Pair(int[] docs, float[][] vectors) {
this.docs = docs;
this.vectors = vectors;
this.vectorsStr = new String[0];
this.vectorsInt = new int[0][0];
}
public Pair(int[] docs, int[][] vectorsInt) {
this.docs = docs;
this.vectorsInt = vectorsInt;
this.vectors = new float[0][0];
this.vectorsStr = new String[0];
}
public Pair(int[] docs, String[] vectorsStr) {
this.docs = docs;
this.vectorsStr = vectorsStr;
this.vectors = new float[0][0];
this.vectorsInt = new int[0][0];
}
public int[] docs;
public float[][] vectors;
public int[][] vectorsInt;
public String[] vectorsStr;
}

public static KNNCodecUtil.Pair getFloats(BinaryDocValues values) throws IOException {
Expand Down Expand Up @@ -91,27 +82,4 @@ public static KNNCodecUtil.Pair getInts(BinaryDocValues values) throws IOExcepti
}
return new KNNCodecUtil.Pair(docIdList.stream().mapToInt(Integer::intValue).toArray(), vectorList.toArray(new int[][]{}));
}
public static KNNCodecUtil.Pair getStrings(BinaryDocValues values) throws IOException {
ArrayList<String> vectorList = new ArrayList<>();
ArrayList<Integer> docIdList = new ArrayList<>();
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
BytesRef bytesref = values.binaryValue();
try (ByteArrayInputStream byteStream = new ByteArrayInputStream(bytesref.bytes, bytesref.offset, bytesref.length);
ObjectInputStream objectStream = new ObjectInputStream(byteStream)) {
float[] vector = (float[]) objectStream.readObject();
//[1,0,1,0,1] --> "1 0 1 0 1"
char[] charArray = new char[vector.length*2];
for (int bit = 0; bit < vector.length; ++bit) {
int oneBit = ((int)(vector[bit]))%2;
charArray[bit*2] = (char) ('0' + oneBit);
charArray[bit*2+1] = ' ';
}
vectorList.add(String.valueOf(charArray));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
docIdList.add(doc);
}
return new KNNCodecUtil.Pair(docIdList.stream().mapToInt(Integer::intValue).toArray(), vectorList.toArray(new String[]{}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void testAddAndQueryHnswIndexBitHammingWithString() throws Exception {
AccessController.doPrivileged(
new PrivilegedAction<Void>() {
public Void run() {
KNNIndex.saveIndexB(docs, vectors, indexPath, algoParams, "bit_hamming", true);
KNNIndex.saveIndex(docs, vectors, indexPath, algoParams, "bit_hamming");
return null;
}
}
Expand Down

0 comments on commit c2abcb2

Please sign in to comment.