From c10677061733478b8e4028fafc68f05972877643 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 12 Jan 2017 21:48:54 +0100 Subject: Revert "Bratseth/tensor type info in documents" --- .../src/main/java/com/yahoo/tensor/TensorType.java | 19 ------------------- .../tensor/serialization/SparseBinaryFormat.java | 14 +++++++++++++- .../yahoo/tensor/serialization/TypedBinaryFormat.java | 2 +- 3 files changed, 14 insertions(+), 21 deletions(-) (limited to 'vespajlib/src/main/java/com/yahoo/tensor') diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java index b0132693fa3..fbc469c1829 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java @@ -74,25 +74,6 @@ public class TensorType { return Optional.empty(); } - /** - * 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. - */ - public boolean isAssignableTo(TensorType other) { - if (other.dimensions().size() != this.dimensions().size()) return false; - for (int i = 0; i < other.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; - } - } - return true; - } - @Override public String toString() { return "tensor(" + dimensions.stream().map(Dimension::toString).collect(Collectors.joining(",")) + ")"; 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 8ab23c8d77c..30b36e83457 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java @@ -54,12 +54,24 @@ class SparseBinaryFormat implements BinaryFormat { @Override public Tensor decode(TensorType type, GrowableByteBuffer buffer) { - consumeAndValidateDimensions(type, buffer); + if (type == null) // TODO (January 2017): Remove this when types are available + type = decodeDimensionsToType(buffer); + else + consumeAndValidateDimensions(type, buffer); Tensor.Builder builder = Tensor.Builder.of(type); decodeCells(buffer, builder, type); return builder.build(); } + private TensorType decodeDimensionsToType(GrowableByteBuffer buffer) { + TensorType.Builder builder = new TensorType.Builder(); + int numDimensions = buffer.getInt1_4Bytes(); + for (int i = 0; i < numDimensions; ++i) { + builder.mapped(buffer.getUtf8String()); + } + return builder.build(); + } + private void consumeAndValidateDimensions(TensorType type, GrowableByteBuffer buffer) { int dimensionCount = buffer.getInt1_4Bytes(); if (type.dimensions().size() != dimensionCount) diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java index 19c1810d928..65216aa2fcd 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java @@ -24,7 +24,7 @@ public class TypedBinaryFormat { public static byte[] encode(Tensor tensor) { GrowableByteBuffer buffer = new GrowableByteBuffer(); - if (tensor instanceof IndexedTensor) { + if (tensor instanceof IndexedTensor && 1==2) { // TODO: Activate when we have type information everywhere buffer.putInt1_4Bytes(DENSE_BINARY_FORMAT_TYPE); new DenseBinaryFormat().encode(buffer, tensor); } -- cgit v1.2.3