diff options
Diffstat (limited to 'vespajlib')
5 files changed, 16 insertions, 10 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index 5d5a5f74063..74b338fb503 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -3,6 +3,7 @@ package com.yahoo.tensor; import com.google.common.collect.ImmutableMap; +import com.yahoo.tensor.impl.StringTensorAddress; import java.util.ArrayList; import java.util.Arrays; @@ -553,7 +554,7 @@ public class MixedTensor implements Tensor { mappedIndex++; } } - return TensorAddress.of(labels); + return StringTensorAddress.unsafeOf(labels); } @Override @@ -563,7 +564,7 @@ public class MixedTensor implements Tensor { private String contentToString(MixedTensor tensor, long maxCells) { if (mappedDimensions.size() > 1) throw new IllegalStateException("Should be ensured by caller"); - if (mappedDimensions.size() == 0) { + if (mappedDimensions.isEmpty()) { StringBuilder b = new StringBuilder(); int cellsWritten = denseSubspaceToString(tensor, 0, maxCells, b); if (cellsWritten == maxCells && cellsWritten < tensor.size()) diff --git a/vespajlib/src/main/java/com/yahoo/tensor/PartialAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/PartialAddress.java index f1b3245ec80..3e41e6d94eb 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/PartialAddress.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/PartialAddress.java @@ -1,6 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor; +import com.yahoo.tensor.impl.StringTensorAddress; + import java.util.Arrays; /** @@ -83,7 +85,7 @@ public class PartialAddress { throw new IllegalArgumentException(type + " dimension names does not match " + this); stringLabels[i] = label; } - return TensorAddress.of(stringLabels); + return StringTensorAddress.unsafeOf(stringLabels); } } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java index 0e4fab95c87..8d8fe2b356f 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java @@ -10,6 +10,7 @@ import com.yahoo.tensor.TypeResolver; import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.impl.StringTensorAddress; import java.util.Arrays; import java.util.HashMap; @@ -368,7 +369,7 @@ public class Concat<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET default -> throw new IllegalArgumentException("cannot handle: " + how); } } - return TensorAddress.of(labels); + return StringTensorAddress.unsafeOf(labels); } Tensor merge(CellVectorMapMap a, CellVectorMapMap b) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java index 4c92e1e57a2..1ded16636d3 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java @@ -12,6 +12,7 @@ import com.yahoo.tensor.TypeResolver; import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.impl.StringTensorAddress; import java.util.ArrayList; import java.util.HashMap; @@ -144,7 +145,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP } private static Tensor indexedSubspaceJoin(IndexedTensor subspace, IndexedTensor superspace, TensorType joinedType, boolean reversedArgumentOrder, DoubleBinaryOperator combinator) { - if (subspace.size() == 0 || superspace.size() == 0) // special case empty here to avoid doing it when finding sizes + if (subspace.isEmpty() || superspace.isEmpty()) // special case empty here to avoid doing it when finding sizes return Tensor.Builder.of(joinedType, new DimensionSizes.Builder(joinedType.dimensions().size()).build()).build(); DimensionSizes joinedSizes = joinedSize(joinedType, subspace, superspace); @@ -227,7 +228,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP String[] subspaceLabels = new String[subspaceIndexes.length]; for (int i = 0; i < subspaceIndexes.length; i++) subspaceLabels[i] = superAddress.label(subspaceIndexes[i]); - return TensorAddress.of(subspaceLabels); + return StringTensorAddress.unsafeOf(subspaceLabels); } /** Slow join which works for any two tensors */ @@ -377,7 +378,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP mapContent(a, joinedLabels, aToIndexes); boolean compatible = mapContent(b, joinedLabels, bToIndexes); if ( ! compatible) return null; - return TensorAddress.of(joinedLabels); + return StringTensorAddress.unsafeOf(joinedLabels); } /** @@ -418,7 +419,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP for (int i = 0; i < labels.length; ++i) { labels[i] = address.label(indexMap[i]); } - return TensorAddress.of(labels); + return StringTensorAddress.unsafeOf(labels); } } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java index a2a3874eced..ecd302db361 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java @@ -8,6 +8,7 @@ import com.yahoo.tensor.TypeResolver; import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; +import com.yahoo.tensor.impl.StringTensorAddress; import java.util.HashMap; import java.util.Iterator; @@ -35,7 +36,7 @@ public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET Objects.requireNonNull(argument, "The argument tensor cannot be null"); Objects.requireNonNull(fromDimensions, "The 'from' dimensions cannot be null"); Objects.requireNonNull(toDimensions, "The 'to' dimensions cannot be null"); - if (fromDimensions.size() < 1) + if (fromDimensions.isEmpty()) throw new IllegalArgumentException("from dimensions is empty, must rename at least one dimension"); if (fromDimensions.size() != toDimensions.size()) throw new IllegalArgumentException("Rename from and to dimensions must be equal, was " + @@ -122,7 +123,7 @@ public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET String[] reorderedLabels = new String[toIndexes.length]; for (int i = 0; i < toIndexes.length; i++) reorderedLabels[toIndexes[i]] = address.label(i); - return TensorAddress.of(reorderedLabels); + return StringTensorAddress.unsafeOf(reorderedLabels); } private String toVectorString(List<String> elements) { |