aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2020-12-01 14:56:09 +0100
committerGitHub <noreply@github.com>2020-12-01 14:56:09 +0100
commit80ed20529925faa4e2bcece3f22ea7b8f2b49f7f (patch)
treef11ed8bd70edf47229187ae6add9885f2b746280 /searchlib
parentef1c43d5433e4cf5ae7dd581f1c72c46e5611118 (diff)
parent85ee071bd26037bff7e46b03023446ab0b7749da (diff)
Merge pull request #15561 from vespa-engine/arnej/remove-java-tensor-conformance-unit-test
tensor conformance will now run as a system integration test only
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/tensor/TensorConformanceTest.java142
1 files changed, 0 insertions, 142 deletions
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/tensor/TensorConformanceTest.java b/searchlib/src/test/java/com/yahoo/searchlib/tensor/TensorConformanceTest.java
deleted file mode 100644
index 61aec069c72..00000000000
--- a/searchlib/src/test/java/com/yahoo/searchlib/tensor/TensorConformanceTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchlib.tensor;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.yahoo.io.GrowableByteBuffer;
-import com.yahoo.searchlib.rankingexpression.RankingExpression;
-import com.yahoo.searchlib.rankingexpression.evaluation.BooleanValue;
-import com.yahoo.searchlib.rankingexpression.evaluation.DoubleCompatibleValue;
-import com.yahoo.searchlib.rankingexpression.evaluation.MapContext;
-import com.yahoo.searchlib.rankingexpression.evaluation.StringValue;
-import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue;
-import com.yahoo.searchlib.rankingexpression.evaluation.Value;
-import com.yahoo.searchlib.rankingexpression.parser.ParseException;
-import com.yahoo.tensor.Tensor;
-import com.yahoo.tensor.serialization.TypedBinaryFormat;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-
-import static org.junit.Assert.assertEquals;
-
-public class TensorConformanceTest {
-
- private static String testPath = "eval/src/apps/tensor_conformance/test_spec.json";
-
- @Test
- public void testConformance() throws IOException {
- File testSpec = new File(testPath);
- if (!testSpec.exists()) {
- testSpec = new File("../" + testPath);
- }
- int count = 0;
- List<Integer> failList = new ArrayList<>();
-
- try(BufferedReader br = new BufferedReader(new FileReader(testSpec))) {
- String test = br.readLine();
- while (test != null) {
- boolean success = testCase(test, count);
- if (!success) {
- failList.add(count);
- }
- test = br.readLine();
- count++;
- }
- }
- assertEquals(failList.size() + " conformance test fails: " + failList, 0, failList.size());
- }
-
- private boolean testCase(String test, int count) {
- try {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode node = mapper.readTree(test);
-
- if (node.has("num_tests")) {
- Assert.assertEquals(node.get("num_tests").asInt(), count);
- return true;
- }
- if (!node.has("expression")) {
- return true; // ignore
- }
-
- String expression = node.get("expression").asText();
- MapContext context = getInput(node.get("inputs"));
- Tensor expect = getTensor(node.get("result").get("expect").asText());
- Tensor result = evaluate(expression, context);
- boolean equals = Tensor.equals(result, expect);
- if (!equals) {
- System.out.println(count + " : Tensors not equal. Result: " + result.toString() + " Expected: " + expect.toString() + " -> expression \"" + expression + "\"");
- } else if (! result.type().valueType().equals(expect.type().valueType())) {
- System.out.println(count + " : Tensor cell value types not equal. Result: " + result.type() + " Expected: " + expect.type() + " -> expression \"" + expression + "\"");
- equals = false;
- }
- return equals;
-
- } catch (Exception e) {
- System.out.println(count + " : " + e.toString());
- }
- return false;
- }
-
- private Tensor evaluate(String expression, MapContext context) throws ParseException {
- Value value = new RankingExpression(expression).evaluate(context);
- if (!(value instanceof TensorValue)) {
- throw new IllegalArgumentException("Result is not a tensor");
- }
- return ((TensorValue)value).asTensor();
- }
-
- private MapContext getInput(JsonNode inputs) {
- MapContext context = new MapContext();
- for (Iterator<String> i = inputs.fieldNames(); i.hasNext(); ) {
- String name = i.next();
- String value = inputs.get(name).asText();
- Tensor tensor = getTensor(value);
- context.put(name, new TensorValue(tensor));
- }
- return context;
- }
-
- private Tensor getTensor(String binaryRepresentation) {
- byte[] bin = getBytes(binaryRepresentation);
- return TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(bin));
- }
-
- private byte[] getBytes(String binaryRepresentation) {
- return parseHexValue(binaryRepresentation.substring(2));
- }
-
- private byte[] parseHexValue(String s) {
- final int len = s.length();
- byte[] bytes = new byte[len/2];
- for (int i = 0; i < len; i += 2) {
- int c1 = hexValue(s.charAt(i)) << 4;
- int c2 = hexValue(s.charAt(i + 1));
- bytes[i/2] = (byte)(c1 + c2);
- }
- return bytes;
- }
-
- private int hexValue(Character c) {
- if (c >= 'a' && c <= 'f') {
- return c - 'a' + 10;
- } else if (c >= 'A' && c <= 'F') {
- return c - 'A' + 10;
- } else if (c >= '0' && c <= '9') {
- return c - '0';
- }
- throw new IllegalArgumentException("Hex contains illegal characters");
- }
-
-}
-