summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-01-16 23:16:32 +0100
committerGitHub <noreply@github.com>2017-01-16 23:16:32 +0100
commit9efbe90ee02b6b56f1a1208614c20d4b053a3135 (patch)
tree86dc5fcbd4e2244c7a82c2019a77635d33f7b87a /vespajlib/src/main/java/com/yahoo/tensor
parent7305314406270fe663b7ef301cd6ad04714dcf9b (diff)
Revert "Revert "Revert "Bratseth/tensor type info in documents"""
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorType.java19
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java14
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java2
3 files changed, 14 insertions, 21 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..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);
}