From 619d924440939076e399f2504fa6850976d2a303 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 18 May 2022 11:38:27 +0200 Subject: Unify constant syntax across models and rank profiles --- .../main/java/com/yahoo/tensor/TensorAddress.java | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'vespajlib/src') diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java index d9ab67d6c5f..bce8aa7c82b 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java @@ -171,8 +171,8 @@ public abstract class TensorAddress implements Comparable { /** Builder of a tensor address */ public static class Builder { - private final TensorType type; - private final String[] labels; + final TensorType type; + final String[] labels; public Builder(TensorType type) { this(type, new String[type.dimensions().size()]); @@ -218,14 +218,39 @@ public abstract class TensorAddress implements Comparable { /** Returns the type of the tensor this address is being built for. */ public TensorType type() { return type; } - public TensorAddress build() { + void validate() { for (int i = 0; i < labels.length; i++) if (labels[i] == null) throw new IllegalArgumentException("Missing a label for dimension " + type.dimensions().get(i).name() + " for " + type); + } + + public TensorAddress build() { + validate(); return TensorAddress.of(labels); } } + /** Builder of an address to a subset of the dimensions of a tensor type */ + public static class PartialBuilder extends Builder { + + public PartialBuilder(TensorType type) { + super(type); + } + + private PartialBuilder(TensorType type, String[] labels) { + super(type, labels); + } + + /** Creates a copy of this which can be modified separately */ + public Builder copy() { + return new PartialBuilder(type, Arrays.copyOf(labels, labels.length)); + } + + @Override + void validate() { } + + } + } -- cgit v1.2.3