diff options
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) { |