Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. Modified code for codecov #4

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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