summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-01-18 11:06:59 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2017-01-18 11:06:59 +0100
commit32e3cbf82a532f9e1c7763270fc485bbf0d79d0e (patch)
tree0ad053f317cd2f3ea04977061958180b82cca101 /vespajlib
parentac728c6a77543ea618bee127221f950670e84eb8 (diff)
reverse isAssignableTo
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorType.java22
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java2
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java2
3 files changed, 13 insertions, 13 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
index b0132693fa3..f934c4fcaf9 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
@@ -75,19 +75,19 @@ public class TensorType {
}
/**
- * Returns whether a tensor of the given type can be assigned to this type,
- * i.e of this type is a generalization of the given type.
+ * Returns whether this type can be assigned to the given type,
+ * i.e if the given type is a generalization of this type.
*/
- public boolean isAssignableTo(TensorType other) {
- if (other.dimensions().size() != this.dimensions().size()) return false;
- for (int i = 0; i < other.dimensions().size(); i++) {
+ public boolean isAssignableTo(TensorType generalization) {
+ if (generalization.dimensions().size() != this.dimensions().size()) return false;
+ for (int i = 0; i < generalization.dimensions().size(); i++) {
Dimension thisDimension = this.dimensions().get(i);
- Dimension otherDimension = other.dimensions().get(i);
- if (thisDimension.isIndexed() != otherDimension.isIndexed()) return false;
- if ( ! thisDimension.name().equals(otherDimension.name())) return false;
- if (thisDimension.size().isPresent()) {
- if ( ! otherDimension.size().isPresent()) return false;
- if (otherDimension.size().get() > thisDimension.size().get() ) return false;
+ Dimension generalizationDimension = generalization.dimensions().get(i);
+ if (thisDimension.isIndexed() != generalizationDimension.isIndexed()) return false;
+ if ( ! thisDimension.name().equals(generalizationDimension.name())) return false;
+ if (generalizationDimension.size().isPresent()) {
+ if ( ! thisDimension.size().isPresent()) return false;
+ if (thisDimension.size().get() > generalizationDimension.size().get() ) return false;
}
}
return true;
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java
index 1c6d8170885..5a34f59fe89 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java
@@ -52,7 +52,7 @@ public class DenseBinaryFormat implements BinaryFormat {
if (optionalType.isPresent()) {
type = optionalType.get();
TensorType serializedType = decodeType(buffer);
- if ( ! type.isAssignableTo(serializedType))
+ if ( ! serializedType.isAssignableTo(type))
throw new IllegalArgumentException("Type/instance mismatch: A tensor of type " + serializedType +
" cannot be assigned to type " + type);
sizes = sizesFromType(serializedType);
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
index 4442b5521c3..7609f6748f4 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
@@ -58,7 +58,7 @@ class SparseBinaryFormat implements BinaryFormat {
if (optionalType.isPresent()) {
type = optionalType.get();
TensorType serializedType = decodeType(buffer);
- if ( ! type.isAssignableTo(serializedType))
+ if ( ! serializedType.isAssignableTo(type))
throw new IllegalArgumentException("Type/instance mismatch: A tensor of type " + serializedType +
" cannot be assigned to type " + type);
}