aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/functions
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-18 11:51:01 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2024-01-18 11:51:01 +0100
commitc9ae223ea9189fefcbd2e7005a9142c7bcb44348 (patch)
tree80abcf42fd85ab6a0e9d3440bd76907f22a404bd /vespajlib/src/main/java/com/yahoo/tensor/functions
parent3af27a9e69f4a9be0d5029394bc4ea4828081c6f (diff)
Skip copying of array when there is no reuse possible.
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/functions')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java3
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java9
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java5
3 files changed, 10 insertions, 7 deletions
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) {