diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-18 11:38:27 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-18 11:38:27 +0200 |
commit | 619d924440939076e399f2504fa6850976d2a303 (patch) | |
tree | 83d680e0c0c516585b6d4e8e086d825dcb381365 /vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java | |
parent | 16de8d32fd0394335ffa065b61f4943c4fd49542 (diff) |
Unify constant syntax across models and rank profiles
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java | 31 |
1 files changed, 28 insertions, 3 deletions
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<TensorAddress> { /** 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<TensorAddress> { /** 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() { } + + } + } |