Skip to content

Commit

Permalink
Use valid data for sqfp16 test
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 committed Feb 9, 2024
1 parent 9e28957 commit 015b30b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/test/java/org/opensearch/knn/jni/JNIServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public void testQueryIndex_faiss_sqfp16_valid() {
Path tmpFile = createTempFile();
JNIService.createIndex(
testData.indexData.docs,
testData.indexData.vectors,
truncateToFp16Range(testData.indexData.vectors),
tmpFile.toAbsolutePath().toString(),
ImmutableMap.of(INDEX_DESCRIPTION_PARAMETER, sqfp16IndexDescription, KNNConstants.SPACE_TYPE, SpaceType.L2.getValue()),
FAISS_NAME
Expand All @@ -547,6 +547,23 @@ public void testQueryIndex_faiss_sqfp16_valid() {
}
}

// If the value is outside of the fp16 range, then convert it to the fp16 minimum or maximum value
private float[][] truncateToFp16Range(final float[][] data) {
float[][] result = new float[data.length][data[0].length];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
float value = data[i][j];
if (value < Float.MIN_VALUE || value > Float.MAX_VALUE) {
// If value is outside of the range, set it to the maximum or minimum value
result[i][j] = value < 0 ? -Float.MAX_VALUE : Float.MAX_VALUE;
} else {
result[i][j] = value;
}
}
}
return result;
}

@SneakyThrows
public void testTrain_whenConfigurationIsIVFSQFP16_thenSucceed() {
long trainPointer = transferVectors(10);
Expand Down

0 comments on commit 015b30b

Please sign in to comment.