aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
index 59a5e2a49b1..5c2c4d77fad 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java
@@ -32,9 +32,7 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
return TensorAddressAny.of(labels);
}
- /**
- * Returns the number of labels in this
- */
+ /** Returns the number of labels in this */
public abstract int size();
/**
@@ -69,10 +67,10 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
@Override
public String toString() {
StringBuilder sb = new StringBuilder("cell address (");
- int sz = size();
- if (sz > 0) {
+ int size = size();
+ if (size > 0) {
sb.append(label(0));
- for (int i = 1; i < sz; i++) {
+ for (int i = 1; i < size; i++) {
sb.append(',').append(label(i));
}
}
@@ -113,9 +111,9 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
return TensorAddressAny.ofUnsafe(labels);
}
- /** Creates a complete address by taking the sparse dimmensions from this and the indexed from the densePart */
- public TensorAddress fullAddressOf(List<TensorType.Dimension> dimensions, int [] densePart) {
- int [] labels = new int[dimensions.size()];
+ /** Creates a complete address by taking the mapped dimmensions from this and the indexed from the indexedPart */
+ public TensorAddress fullAddressOf(List<TensorType.Dimension> dimensions, int[] densePart) {
+ int[] labels = new int[dimensions.size()];
int mappedIndex = 0;
int indexedIndex = 0;
for (int i = 0; i < labels.length; i++) {
@@ -131,11 +129,17 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
return TensorAddressAny.ofUnsafe(labels);
}
- /** Extracts the sparse(non-indexed) dimensions of the address */
- public TensorAddress sparsePartialAddress(TensorType sparseType, List<TensorType.Dimension> dimensions) {
+ /**
+ * Returns an address containing the mapped dimensions of this.
+ *
+ * @param mappedType the type of the mapped subset of the type this is an address of;
+ * which is also the type of the returned address
+ * @param dimensions all the dimensions of the type this is an address of
+ */
+ public TensorAddress mappedPartialAddress(TensorType mappedType, List<TensorType.Dimension> dimensions) {
if (dimensions.size() != size())
throw new IllegalArgumentException("Tensor type of " + this + " is not the same size as " + this);
- TensorAddress.Builder builder = new TensorAddress.Builder(sparseType);
+ TensorAddress.Builder builder = new TensorAddress.Builder(mappedType);
for (int i = 0; i < dimensions.size(); ++i) {
TensorType.Dimension dimension = dimensions.get(i);
if ( ! dimension.isIndexed())
@@ -150,9 +154,9 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
final TensorType type;
final int[] labels;
- private static int [] createEmptyLabels(int size) {
- int [] labels = new int[size];
- Arrays.fill(labels, Tensor.INVALID_INDEX);
+ private static int[] createEmptyLabels(int size) {
+ int[] labels = new int[size];
+ Arrays.fill(labels, Tensor.invalidIndex);
return labels;
}
@@ -174,7 +178,7 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
var mappedSubtype = type.mappedSubtype();
if (mappedSubtype.rank() != 1)
throw new IllegalArgumentException("Cannot add a label without explicit dimension to a tensor of type " +
- type + ": Must have exactly one sparse dimension");
+ type + ": Must have exactly one mapped dimension");
add(mappedSubtype.dimensions().get(0).name(), label);
return this;
}
@@ -212,7 +216,7 @@ public abstract class TensorAddress implements Comparable<TensorAddress> {
void validate() {
for (int i = 0; i < labels.length; i++)
- if (labels[i] == Tensor.INVALID_INDEX)
+ if (labels[i] == Tensor.invalidIndex)
throw new IllegalArgumentException("Missing a label for dimension '" +
type.dimensions().get(i).name() + "' for " + type);
}