diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-08 17:22:57 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-08 17:22:57 +0200 |
commit | 75bbf9ef27e9bc41a7bd3a648e637f44b44308ac (patch) | |
tree | 4977aaa996059d7040c5bff65eb1ab3402f75e25 /config-model | |
parent | 1f33495b8170f41f8d4a6a53d17e4471a464a8a0 (diff) |
Parse nested arrays
Diffstat (limited to 'config-model')
-rw-r--r-- | config-model/src/main/javacc/IntermediateParser.jj | 27 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java | 10 |
2 files changed, 21 insertions, 16 deletions
diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index 57fa9e4142c..314de9878ee 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -39,6 +39,7 @@ import com.yahoo.searchlib.rankingexpression.Reference; import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; import com.yahoo.searchlib.rankingexpression.evaluation.Value; import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.MixedTensor; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.TensorAddress; @@ -2499,10 +2500,10 @@ void mappedTensorBlock(Tensor.Builder builder) : void indexedTensorBlockValues(TensorAddress sparseAddress, Tensor.Builder builder) : { - List<Double> values; + List<Double> values = new ArrayList<Double>(); } { - values = arrayTensorValues() + arrayTensorValues(values) { MixedTensor.BoundBuilder boundBuilder = (MixedTensor.BoundBuilder)builder; double[] arrayValues = new double[values.size()]; @@ -2515,26 +2516,26 @@ void indexedTensorBlockValues(TensorAddress sparseAddress, Tensor.Builder builde void indexedTensorValues(Tensor.Builder builder) : { - List<Double> values; + List<Double> values = new ArrayList<Double>(); } { - values = arrayTensorValues() + arrayTensorValues(values) { + IndexedTensor.BoundBuilder boundBuilder = (IndexedTensor.BoundBuilder)builder; + double[] arrayValues = new double[values.size()]; for (int i = 0; i < values.size(); i++ ) { - TensorAddress.Builder addressBuilder = new TensorAddress.Builder(builder.type()); - addressBuilder.add(String.valueOf(i)); - builder.cell(addressBuilder.build(), values.get(i)); + arrayValues[i] = values.get(i); } + boundBuilder.fill(arrayValues); } } -List<Double> arrayTensorValues() : -{ - List<Double> values = new ArrayList<Double>(); -} +/** Tensor array values. Using sub-bracketing for multiple dimensions is optional and therefore ignored here. */ +void arrayTensorValues(List<Double> values) : {} { - "[" ( indexedTensorValue(values) )* ( <COMMA> (<NL>)* indexedTensorValue(values) )* "]" - { return values; } + "[" ( ( indexedTensorValue(values) | arrayTensorValues(values)) )* + ( <COMMA> (<NL>)* ( indexedTensorValue(values) | arrayTensorValues(values)) )* + "]" } void indexedTensorValue(List<Double> values) : diff --git a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java index 91234e9eeb1..01ddd82c4bd 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java @@ -24,7 +24,9 @@ public class SchemaInfoTestCase { " query(myDouble2) tensor()" + " query(myMap) tensor(key{}): { label1:1.0,\n \"label2\": 2.0, 'label3': 3.0 }" + " query(myVector) tensor(x[3]):\n\n[1 ,2.0,3]" + - " query(myMixed) tensor(key{},x[2]): { key1:[-1.0, 1.1], key2: [1,2]}" + + " query(myMatrix) tensor(x[2],y[3]):[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]" + + " query(myMixed1) tensor(key{},x[2]): { key1:[-1.0, 1.1], key2: [1,2]}" + + " query(myMixed2) tensor(k1{},k2{},x[2]): { {k1:l1,k2:l2}:[-1.0, 1.1], {k1:l1,k2:l2}: [1,2]}" + " }" + " }"; List<String> schemas = List.of("type1", "type2"); @@ -52,14 +54,16 @@ public class SchemaInfoTestCase { tester.assertRankProfile(schema, 5, "rankfeatures", false, true); var inputs = tester.assertRankProfile(schema, 6, "inputs", false, false); - assertEquals(7, inputs.input().size()); + assertEquals(9, inputs.input().size()); assertInput("query(foo)", "tensor<float>(x[10])", inputs.input(0)); assertInput("query(bar)", "tensor(key{},x[1000])", inputs.input(1)); assertInput("query(myDouble1)", "tensor()", inputs.input(2)); assertInput("query(myDouble2)", "tensor()", inputs.input(3)); assertInput("query(myMap)", "tensor(key{})", inputs.input(4)); assertInput("query(myVector)", "tensor(x[3])", inputs.input(5)); - assertInput("query(myMixed)", "tensor(key{},x[2])", inputs.input(6)); + assertInput("query(myMatrix)", "tensor(x[2],y[3])", inputs.input(6)); + assertInput("query(myMixed1)", "tensor(key{},x[2])", inputs.input(7)); + assertInput("query(myMixed2)", "tensor(k1{},k2{},x[2])", inputs.input(8)); assertEquals(2, schema.summaryclass().size()); assertEquals("default", schema.summaryclass(0).name()); |