summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-14 09:42:46 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-14 09:42:46 +0100
commitfa0bc59e2313aa6b6249ad88f7c1892a3a29553d (patch)
treef426c5657280a25c4599deecc5cca3be9378cab7 /vespajlib
parentc17b1582face7c7f31fea7e151a5855908fe04f5 (diff)
Handle argument bindings
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java4
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java27
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java2
3 files changed, 29 insertions, 4 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java
index 9fe6b7d053f..078f2e39815 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/MapEvaluationContext.java
@@ -20,8 +20,8 @@ public class MapEvaluationContext implements EvaluationContext {
public void put(String name, Tensor tensor) { bindings.put(name, tensor); }
@Override
- public TensorType getType(String name) {
- Tensor tensor = bindings.get(name);
+ public TensorType getType(Name name) {
+ Tensor tensor = bindings.get(name.toString());
if (tensor == null) return null;
return tensor.type();
}
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java
index 760a225efdf..ecb3a801324 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/TypeContext.java
@@ -16,6 +16,31 @@ public interface TypeContext {
* @return returns the type of the tensor which will be returned by calling getTensor(name)
* or null if getTensor will return null.
*/
- TensorType getType(String name);
+ TensorType getType(Name name);
+
+ /** A name which is just a string. Names are value objects. */
+ class Name {
+
+ private final String name;
+
+ public Name(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() { return name; }
+
+ @Override
+ public int hashCode() { return name.hashCode(); }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) return true;
+ if ( ! (other instanceof Name)) return false;
+ return ((Name)other).name.equals(this.name);
+ }
+
+ }
+
}
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java
index 34beb465d4c..5f809a3d2b1 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java
@@ -45,7 +45,7 @@ public class VariableTensor extends PrimitiveTensorFunction {
@Override
public TensorType type(TypeContext context) {
- TensorType givenType = context.getType(name);
+ TensorType givenType = context.getType(new TypeContext.Name(name));
if (givenType == null) return null;
verifyType(givenType);
return givenType;