diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-21 11:20:59 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-21 11:38:53 +0100 |
commit | 351e0f62fe4f9b1b1015c0c1289a3f519fa9f868 (patch) | |
tree | 28c7e3c8c3b00ddc52cb5a80ecaccffc9dab1c24 /vespajlib/src/main/java/com/yahoo/tensor/Tensor.java | |
parent | f481110c07a4759b98452deb35fe719ce6c49be4 (diff) |
- Extract dimension names in a set to avoid recomputing it in dimensionNames() mathod.
- Also extract some information about what kind of dimensions a tensor has construcion time.
This avoids streamin through all diemsion later on, and keeps this local in the TensorType.
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/Tensor.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/Tensor.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java index cc8e1602adb..cff17fdfd7c 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java @@ -113,7 +113,7 @@ public interface Tensor { * @throws IllegalStateException if this does not have zero dimensions and one value */ default double asDouble() { - if (type().dimensions().size() > 0) + if (!type().dimensions().isEmpty()) throw new IllegalStateException("Require a dimensionless tensor but has " + type()); if (size() == 0) return Double.NaN; return valueIterator().next(); @@ -553,8 +553,8 @@ public interface Tensor { /** Creates a suitable builder for the given type */ static Builder of(TensorType type) { - boolean containsIndexed = type.dimensions().stream().anyMatch(TensorType.Dimension::isIndexed); - boolean containsMapped = type.dimensions().stream().anyMatch( d -> ! d.isIndexed()); + boolean containsIndexed = type.hasIndexedDimensions(); + boolean containsMapped = type.hasMappedDimensions(); if (containsIndexed && containsMapped) return MixedTensor.Builder.of(type); if (containsMapped) @@ -565,8 +565,8 @@ public interface Tensor { /** Creates a suitable builder for the given type */ static Builder of(TensorType type, DimensionSizes dimensionSizes) { - boolean containsIndexed = type.dimensions().stream().anyMatch(TensorType.Dimension::isIndexed); - boolean containsMapped = type.dimensions().stream().anyMatch( d -> ! d.isIndexed()); + boolean containsIndexed = type.hasIndexedDimensions(); + boolean containsMapped = type.hasMappedDimensions(); if (containsIndexed && containsMapped) return MixedTensor.Builder.of(type); if (containsMapped) |