diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2017-01-12 21:49:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-12 21:49:40 +0100 |
commit | b72c29c29a2c8dd8ecac8aeffdaff688b21ee41c (patch) | |
tree | fd8ea0f55ec4a17feff93139238a435ddf7715ac /vespajlib/src/main/java/com/yahoo/tensor/serialization | |
parent | 08fbcebedf2c2bd78c13727fb91cc25b9b196c2f (diff) | |
parent | c10677061733478b8e4028fafc68f05972877643 (diff) |
Merge pull request #1502 from yahoo/revert-1495-bratseth/tensor-type-info-in-documents
Revert "Bratseth/tensor type info in documents"
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/serialization')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java | 14 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java | 2 |
2 files changed, 14 insertions, 2 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 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); } |