diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-06 13:50:08 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-05-06 13:50:08 +0200 |
commit | a2eb1feb808a0533b5d7ef2b691a873f91c4c26b (patch) | |
tree | 3603ed065573ad1a0ac289bda1ed708c7519929a /vespajlib/src/main/java/com/yahoo | |
parent | 05a6a813237990882d6466a280efea62a5035ed0 (diff) |
Parse input default values
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/Tensor.java | 5 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java index 06e7b010a7a..94b00e7e277 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java @@ -533,7 +533,7 @@ public interface Tensor { return IndexedTensor.Builder.of(type, dimensionSizes); } - /** Returns the type this is building */ + /** Returns the type of the tensor this is building */ TensorType type(); /** Return a cell builder */ @@ -578,6 +578,9 @@ public interface Tensor { return this; } + /** Returns the type of the tensor this cell is build for. */ + public TensorType type() { return tensorBuilder.type(); } + public CellBuilder label(String dimension, long label) { return label(dimension, String.valueOf(label)); } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java index 27e752f1180..d9ab67d6c5f 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java @@ -168,7 +168,7 @@ public abstract class TensorAddress implements Comparable<TensorAddress> { } - /** Supports building of a tensor address */ + /** Builder of a tensor address */ public static class Builder { private final TensorType type; @@ -184,6 +184,18 @@ public abstract class TensorAddress implements Comparable<TensorAddress> { } /** + * Adds the label to the only dimension of this. + * + * @throws IllegalArgumentException if this does not have exactly one dimension + */ + public Builder add(String label) { + if (type.rank() != 1) + throw new IllegalArgumentException("Cannot add a label without explicit dimension to a tensor of type " + type); + add(type.dimensions().get(0).name(), label); + return this; + } + + /** * Adds a label in a dimension to this. * * @return this for convenience @@ -203,6 +215,9 @@ public abstract class TensorAddress implements Comparable<TensorAddress> { return new Builder(type, Arrays.copyOf(labels, labels.length)); } + /** Returns the type of the tensor this address is being built for. */ + public TensorType type() { return type; } + public TensorAddress build() { for (int i = 0; i < labels.length; i++) if (labels[i] == null) |