diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-18 13:46:08 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-18 13:46:08 +0200 |
commit | f6d3249d38f07a4526b2343ada38564d762d50d7 (patch) | |
tree | 3d6f9d5d420a84d7b76b7241b624552c968501a7 /vespajlib/src/main/java | |
parent | df72032ccaa6f2a132bba6a7c47b9885479b09de (diff) |
Read dense tensor form in documents
Diffstat (limited to 'vespajlib/src/main/java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java | 2 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index aca2bfc1b0f..bc351b45b28 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -382,8 +382,10 @@ public abstract class IndexedTensor implements Tensor { DimensionSizes sizes() { return sizes; } + /** Sets a value by its right-adjacent traversal position */ public abstract void cellByDirectIndex(long index, double value); + /** Sets a value by its right-adjacent traversal position */ public abstract void cellByDirectIndex(long index, float value); } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java index 01da45c67aa..c73ff03a0eb 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java @@ -58,6 +58,7 @@ public class JsonFormat { } /** Deserializes the given tensor from JSON format */ + // NOTE: This must be kept in sync with com.yahoo.document.json.readers.TensorReader in the document module public static Tensor decode(TensorType type, byte[] jsonTensorValue) { Tensor.Builder builder = Tensor.Builder.of(type); Inspector root = new JsonDecoder().decode(new Slime(), jsonTensorValue).get(); @@ -66,6 +67,8 @@ public class JsonFormat { decodeCells(root.field("cells"), builder); else if (root.field("values").valid()) decodeValues(root.field("values"), builder); + else if (builder.type().dimensions().stream().anyMatch(d -> d.isIndexed())) // sparse can be empty + throw new IllegalArgumentException("Expected a tensor value to contain either 'cells' or 'values'"); return builder.build(); } @@ -102,4 +105,5 @@ public class JsonFormat { indexedBuilder.cellByDirectIndex(index.next(), value.asDouble()); }); } + } |