aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/TensorType.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/TensorType.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
index bafec70be59..95cc70804e2 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java
@@ -80,11 +80,20 @@ public class TensorType {
/** Sorted list of the dimensions of this */
private final ImmutableList<Dimension> dimensions;
+ private final TensorType mappedSubtype;
+
private TensorType(Value valueType, Collection<Dimension> dimensions) {
this.valueType = valueType;
List<Dimension> dimensionList = new ArrayList<>(dimensions);
Collections.sort(dimensionList);
this.dimensions = ImmutableList.copyOf(dimensionList);
+
+ if (dimensionList.stream().allMatch(d -> d.isIndexed()))
+ mappedSubtype = empty;
+ else if (dimensionList.stream().noneMatch(d -> d.isIndexed()))
+ mappedSubtype = this;
+ else
+ mappedSubtype = new TensorType(valueType, dimensions.stream().filter(d -> ! d.isIndexed()).collect(Collectors.toList()));
}
static public Value combinedValueType(TensorType ... types) {
@@ -116,6 +125,9 @@ public class TensorType {
/** Returns the numeric type of the cell values of this */
public Value valueType() { return valueType; }
+ /** The type representing the mapped subset of dimensions of this. */
+ public TensorType mappedSubtype() { return mappedSubtype; }
+
/** Returns the number of dimensions of this: dimensions().size() */
public int rank() { return dimensions.size(); }