diff options
author | Arne Juul <arnej@vespa.ai> | 2023-12-01 12:20:29 +0000 |
---|---|---|
committer | Arne Juul <arnej@vespa.ai> | 2023-12-01 12:20:29 +0000 |
commit | 617726bb3ebcce78a8fc98fe5a7fa2fd7372650e (patch) | |
tree | 825e448a199dad5a80cc5ae75d42e1f7c23600a1 /vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java | |
parent | 3d35a610b0da4127593d5e98f4c52f397c311d61 (diff) |
handle "blocks" syntax for mixed tensors with multiple indexed dimensions
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java | 18 |
1 files changed, 14 insertions, 4 deletions
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 0ac9ea18029..28f14c8d7ca 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java @@ -400,13 +400,23 @@ public class JsonFormat { }; } + private static void decodeMaybeNestedValuesInBlock(Inspector arrayField, double[] target, MutableInteger index) { + if (arrayField.entries() == 0) { + throw new IllegalArgumentException("The block value array does not contain any values"); + } + arrayField.traverse((ArrayTraverser) (__, value) -> { + if (value.type() == Type.ARRAY) { + decodeMaybeNestedValuesInBlock(value, target, index); + } else { + target[index.next()] = decodeNumeric(value); + } + }); + } + private static double[] decodeValuesInBlock(Inspector valuesField, MixedTensor.BoundBuilder mixedBuilder) { double[] values = new double[(int)mixedBuilder.denseSubspaceSize()]; if (valuesField.type() == Type.ARRAY) { - if (valuesField.entries() == 0) { - throw new IllegalArgumentException("The block value array does not contain any values"); - } - valuesField.traverse((ArrayTraverser) (index, value) -> values[index] = decodeNumeric(value)); + decodeMaybeNestedValuesInBlock(valuesField, values, new MutableInteger(0)); } else if (valuesField.type() == Type.STRING) { double[] decoded = decodeHexString(valuesField.asString(), mixedBuilder.type().valueType()); if (decoded.length == 0) { |