diff options
Diffstat (limited to 'vespajlib/src/main/java')
3 files changed, 19 insertions, 12 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index ad82dd6c3ac..dc17c657db9 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -178,9 +178,7 @@ public abstract class IndexedTensor implements Tensor { @Override public abstract IndexedTensor withType(TensorType type); - public DimensionSizes dimensionSizes() { - return dimensionSizes; - } + public DimensionSizes dimensionSizes() { return dimensionSizes; } @Override public Map<TensorAddress, Double> cells() { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index 1ec4993bf57..f608aead347 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -152,7 +152,6 @@ public class MixedTensor implements Tensor { return index.denseSubspaceSize(); } - /** * Base class for building mixed tensors. */ 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 bcff4392c9a..5c47572c779 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java @@ -51,31 +51,41 @@ public class TypedBinaryFormat { } private static BinaryFormat getFormatEncoder(GrowableByteBuffer buffer, Tensor tensor) { - if (tensor instanceof MixedTensor && tensor.type().valueType() == TensorType.Value.DOUBLE) { + boolean hasMappedDimensions = tensor.type().dimensions().stream().anyMatch(d -> d.isMapped()); + boolean hasIndexedDimensions = tensor.type().dimensions().stream().anyMatch(d -> d.isIndexed()); + boolean isMixed = hasMappedDimensions && hasIndexedDimensions; + + // TODO: Encoding as indexed if the implementation is mixed is not yet supported so use mixed format instead + if (tensor instanceof MixedTensor && ! isMixed && hasIndexedDimensions) + isMixed = true; + + if (isMixed && tensor.type().valueType() == TensorType.Value.DOUBLE) { encodeFormatType(buffer, MIXED_BINARY_FORMAT_TYPE); return new MixedBinaryFormat(); } - if (tensor instanceof MixedTensor) { + else if (isMixed) { encodeFormatType(buffer, MIXED_BINARY_FORMAT_WITH_CELLTYPE); encodeValueType(buffer, tensor.type().valueType()); return new MixedBinaryFormat(tensor.type().valueType()); } - if (tensor instanceof IndexedTensor && tensor.type().valueType() == TensorType.Value.DOUBLE) { + else if (hasIndexedDimensions && tensor.type().valueType() == TensorType.Value.DOUBLE) { encodeFormatType(buffer, DENSE_BINARY_FORMAT_TYPE); return new DenseBinaryFormat(); } - if (tensor instanceof IndexedTensor) { + else if (hasIndexedDimensions) { encodeFormatType(buffer, DENSE_BINARY_FORMAT_WITH_CELLTYPE); encodeValueType(buffer, tensor.type().valueType()); return new DenseBinaryFormat(tensor.type().valueType()); } - if (tensor.type().valueType() == TensorType.Value.DOUBLE) { + else if (tensor.type().valueType() == TensorType.Value.DOUBLE) { encodeFormatType(buffer, SPARSE_BINARY_FORMAT_TYPE); return new SparseBinaryFormat(); } - encodeFormatType(buffer, SPARSE_BINARY_FORMAT_WITH_CELLTYPE); - encodeValueType(buffer, tensor.type().valueType()); - return new SparseBinaryFormat(tensor.type().valueType()); + else { + encodeFormatType(buffer, SPARSE_BINARY_FORMAT_WITH_CELLTYPE); + encodeValueType(buffer, tensor.type().valueType()); + return new SparseBinaryFormat(tensor.type().valueType()); + } } private static BinaryFormat getFormatDecoder(GrowableByteBuffer buffer) { |