aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-18 12:23:36 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-18 12:23:36 +0200
commit0ba967d09f13da04f5220c05a5d4687afebe6186 (patch)
treef741be48e32df19fde1c911f424e1e2fc72cb298
parent9aa29161dfe87e498caf292ce9201b78cb199a79 (diff)
More leniency
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/search/test/SchemaInfoTestCase.java14
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java18
2 files changed, 19 insertions, 13 deletions
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 34afca703e9..b8a14bc763b 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
@@ -25,7 +25,8 @@ public class SchemaInfoTestCase {
" query(myDouble1) double: 0.5" +
" 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(myVector1) tensor(x[3]):\n\n[1 ,2.0,3]" +
+ " query(myVector2) tensor(x[3]):{{x:0}:1,{x: 1}: 2 , { x:2}:3.0 }" +
" 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:l1}:[-1.0, 1.1], {k1:l1,k2:l2}: [1,2]}" +
@@ -58,7 +59,7 @@ public class SchemaInfoTestCase {
tester.assertRankProfile(schema, 5, "rankfeatures", false, true);
var schemaInfoProfile = tester.assertRankProfile(schema, 6, "inputs", false, false);
- assertEquals(9, schemaInfoProfile.input().size());
+ assertEquals(10, schemaInfoProfile.input().size());
var rankProfilesProfile = rankProfilesConfig.rankprofile().get(6);
assertEquals("inputs", rankProfilesProfile.name());
assertInput("query(foo)", "tensor<float>(x[10])", null, 0, schemaInfoProfile, rankProfilesProfile);
@@ -66,10 +67,11 @@ public class SchemaInfoTestCase {
assertInput("query(myDouble1)", "tensor()", "0.5", 2, schemaInfoProfile, rankProfilesProfile);
assertInput("query(myDouble2)", "tensor()", null, 3, schemaInfoProfile, rankProfilesProfile);
assertInput("query(myMap)", "tensor(key{})", "tensor(key{}):{{key:label1}:1.0, {key:label2}:2.0, {key:label3}:3.0}", 4, schemaInfoProfile, rankProfilesProfile);
- assertInput("query(myVector)", "tensor(x[3])", "tensor(x[3]):{{x:0}:1.0, {x:1}:2.0, {x:2}:3.0}", 5, schemaInfoProfile, rankProfilesProfile);
- assertInput("query(myMatrix)", "tensor(x[2],y[3])", "tensor(x[2],y[3]):{{x:0,y:0}:1.0, {x:0,y:1}:2.0, {x:0,y:2}:3.0, {x:1,y:0}:4.0, {x:1,y:1}:5.0, {x:1,y:2}:6.0}", 6, schemaInfoProfile, rankProfilesProfile);
- assertInput("query(myMixed1)", "tensor(key{},x[2])", "tensor(key{},x[2]):{{key:key1,x:0}:-1.0, {key:key1,x:1}:1.1, {key:key2,x:0}:1.0, {key:key2,x:1}:2.0}", 7, schemaInfoProfile, rankProfilesProfile);
- assertInput("query(myMixed2)", "tensor(k1{},k2{},x[2])", "tensor(k1{},k2{},x[2]):{{k1:l1,k2:l1,x:0}:-1.0, {k1:l1,k2:l1,x:1}:1.1, {k1:l1,k2:l2,x:0}:1.0, {k1:l1,k2:l2,x:1}:2.0}", 8, schemaInfoProfile, rankProfilesProfile);
+ assertInput("query(myVector1)", "tensor(x[3])", "tensor(x[3]):{{x:0}:1.0, {x:1}:2.0, {x:2}:3.0}", 5, schemaInfoProfile, rankProfilesProfile);
+ assertInput("query(myVector2)", "tensor(x[3])", "tensor(x[3]):{{x:0}:1.0, {x:1}:2.0, {x:2}:3.0}", 6, schemaInfoProfile, rankProfilesProfile);
+ assertInput("query(myMatrix)", "tensor(x[2],y[3])", "tensor(x[2],y[3]):{{x:0,y:0}:1.0, {x:0,y:1}:2.0, {x:0,y:2}:3.0, {x:1,y:0}:4.0, {x:1,y:1}:5.0, {x:1,y:2}:6.0}", 7, schemaInfoProfile, rankProfilesProfile);
+ assertInput("query(myMixed1)", "tensor(key{},x[2])", "tensor(key{},x[2]):{{key:key1,x:0}:-1.0, {key:key1,x:1}:1.1, {key:key2,x:0}:1.0, {key:key2,x:1}:2.0}", 8, schemaInfoProfile, rankProfilesProfile);
+ assertInput("query(myMixed2)", "tensor(k1{},k2{},x[2])", "tensor(k1{},k2{},x[2]):{{k1:l1,k2:l1,x:0}:-1.0, {k1:l1,k2:l1,x:1}:1.1, {k1:l1,k2:l2,x:0}:1.0, {k1:l1,k2:l2,x:1}:2.0}", 9, schemaInfoProfile, rankProfilesProfile);
assertEquals(2, schema.summaryclass().size());
assertEquals("default", schema.summaryclass(0).name());
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
index bce8aa7c82b..92bdfb2b3a4 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
@@ -61,8 +61,10 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
@Override
public int hashCode() {
int result = 1;
- for (int i = 0; i < size(); i++)
- result = 31 * result + label(i).hashCode();
+ for (int i = 0; i < size(); i++) {
+ if (label(i) != null)
+ result = 31 * result + label(i).hashCode();
+ }
return result;
}
@@ -73,7 +75,7 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
TensorAddress other = (TensorAddress)o;
if (other.size() != this.size()) return false;
for (int i = 0; i < this.size(); i++)
- if ( ! this.label(i).equals(other.label(i)))
+ if ( ! Objects.equals(this.label(i), other.label(i)))
return false;
return true;
}
@@ -184,14 +186,16 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
}
/**
- * Adds the label to the only dimension of this.
+ * Adds the label to the only mapped dimension of this.
*
* @throws IllegalArgumentException if this does not have exactly one dimension
*/
public Builder add(String label) {
- if (type.rank() != 1)
- throw new IllegalArgumentException("Cannot add a label without explicit dimension to a tensor of type " + type);
- add(type.dimensions().get(0).name(), label);
+ var mappedSubtype = type.mappedSubtype();
+ if (mappedSubtype.rank() != 1)
+ throw new IllegalArgumentException("Cannot add a label without explicit dimension to a tensor of type " +
+ type + ": Must have exactly one sparse dimension");
+ add(mappedSubtype.dimensions().get(0).name(), label);
return this;
}