summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <jonbratseth@yahoo.com>2017-01-12 22:17:49 +0100
committerGitHub <noreply@github.com>2017-01-12 22:17:49 +0100
commit585a5b38c5811da950336c26326636773ca289e3 (patch)
treebacb7cb5b8d3e881a2df260589b9b0e046b12e89 /vespajlib
parentb72c29c29a2c8dd8ecac8aeffdaff688b21ee41c (diff)
Revert "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, 23 insertions, 17 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
index fbc469c1829..b0132693fa3 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
@@ -74,6 +74,25 @@ 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 30b36e83457..8ab23c8d77c 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/SparseBinaryFormat.java
@@ -54,24 +54,12 @@ class SparseBinaryFormat implements BinaryFormat {
@Override
public Tensor decode(TensorType type, GrowableByteBuffer buffer) {
- if (type == null) // TODO (January 2017): Remove this when types are available
- type = decodeDimensionsToType(buffer);
- else
- consumeAndValidateDimensions(type, buffer);
+ 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 65216aa2fcd..19c1810d928 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 && 1==2) { // TODO: Activate when we have type information everywhere
+ if (tensor instanceof IndexedTensor) {
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 e0edc6f4e64..d303a69a68d 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 <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @author Simon Thoresen
*/
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 d2b2044f3ed..15e82e6b15c 100644
--- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/DenseBinaryFormatTestCase.java
@@ -28,7 +28,6 @@ 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