summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-01-18 10:38:08 +0100
committerJon Bratseth <bratseth@yahoo-inc.com>2017-01-18 10:38:08 +0100
commit5bd40b8cdb0c025e439483bd7f246b68fee0e478 (patch)
treeca8ea288b55dd801aed7b95bc6e061ca6b8eee8f /vespajlib/src/main/java/com/yahoo/tensor
parentbad625e3565d83a72436224ed5ccbc2649ab89db (diff)
Simplify and test type check
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java18
1 files changed, 2 insertions, 16 deletions
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 6b0443c9bfe..6419cb04497 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
@@ -57,7 +57,8 @@ class SparseBinaryFormat implements BinaryFormat {
TensorType type;
if (optionalType.isPresent()) {
type = optionalType.get();
- consumeAndValidateDimensions(optionalType.get(), buffer);
+ TensorType serializedType = decodeType(buffer);
+ serializedType.isAssignableTo(type);
}
else {
type = decodeType(buffer);
@@ -67,21 +68,6 @@ class SparseBinaryFormat implements BinaryFormat {
return builder.build();
}
- private void consumeAndValidateDimensions(TensorType type, GrowableByteBuffer buffer) {
- int dimensionCount = buffer.getInt1_4Bytes();
- if (type.dimensions().size() != dimensionCount)
- throw new IllegalArgumentException("Type/instance mismatch: Instance has " + dimensionCount +
- " dimensions but type is " + type);
-
- for (int i = 0; i < dimensionCount; ++i) {
- TensorType.Dimension expectedDimension = type.dimensions().get(i);
- String encodedName = buffer.getUtf8String();
- if ( ! expectedDimension.name().equals(encodedName))
- throw new IllegalArgumentException("Type/instance mismatch: Instance has '" + encodedName +
- "' as dimension " + i + " but type is " + type);
- }
- }
-
private TensorType decodeType(GrowableByteBuffer buffer) {
int numDimensions = buffer.getInt1_4Bytes();
TensorType.Builder builder = new TensorType.Builder();