summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <jonbratseth@yahoo.com>2017-01-12 21:48:54 +0100
committerGitHub <noreply@github.com>2017-01-12 21:48:54 +0100
commitc10677061733478b8e4028fafc68f05972877643 (patch)
treefd8ea0f55ec4a17feff93139238a435ddf7715ac /vespajlib
parent08fbcebedf2c2bd78c13727fb91cc25b9b196c2f (diff)
Revert "Bratseth/tensor type info in documents"
Diffstat (limited to 'vespajlib')
-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
-rw-r--r--vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java4
-rw-r--r--vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java1
5 files changed, 17 insertions, 23 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);
}
diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java
index d303a69a68d..e0edc6f4e64 100644
--- a/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java
+++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java
@@ -16,7 +16,7 @@ import java.util.HashMap;
* methods.
*
* @author baldersheim
- * @author Simon Thoresen
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class Identifiable extends Selectable implements Cloneable {
@@ -177,7 +177,7 @@ public class Identifiable extends Selectable implements Cloneable {
*
* @param id The class identifier to register with.
* @param spec The class to register.
- * @return the identifier argument.
+ * @return The identifier argument.
*/
protected static int registerClass(int id, Class<? extends Identifiable> spec) {
if (registry == null) {
diff --git a/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java
index 15e82e6b15c..d2b2044f3ed 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java
@@ -28,6 +28,7 @@ public class DenseBinaryFormatTestCase {
}
@Test
+ @Ignore // TODO: Activate when encoding in this format is activated
public void requireThatSerializationFormatDoNotChange() {
byte[] encodedTensor = new byte[]{2, // binary format type
2, // dimension count