summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2020-01-02 11:35:37 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2020-01-02 11:35:37 +0100
commitfe102598a18b21a859d5b802883ccb2f462962f9 (patch)
tree70a8d6d239797c18a8634665e2a65bfaabebabba /vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
parent6d7909e022817be11b5f088cbd1e537d9b71919d (diff)
Add merge
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java25
1 files changed, 5 insertions, 20 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
index 0c4efe78113..ad4f0fd0dfb 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
@@ -53,9 +53,11 @@ public class MixedTensor implements Tensor {
@Override
public double get(TensorAddress address) {
long cellIndex = index.indexOf(address);
+ if (cellIndex < 0)
+ return Double.NaN;
Cell cell = cells.get((int)cellIndex);
if ( ! address.equals(cell.getKey()))
- throw new IllegalStateException("Unable to find correct cell in " + this + " by direct index " + address);
+ return Double.NaN;
return cell.getValue();
}
@@ -71,10 +73,6 @@ public class MixedTensor implements Tensor {
return cells.iterator();
}
- private Iterable<Cell> cellIterable() {
- return this::cellIterator;
- }
-
/**
* Returns an iterator over the values of this tensor.
* The iteration order is the same as for cellIterator.
@@ -113,20 +111,6 @@ public class MixedTensor implements Tensor {
}
@Override
- public Tensor merge(DoubleBinaryOperator op, Map<TensorAddress, Double> addCells) {
- Tensor.Builder builder = Tensor.Builder.of(type());
- for (Cell cell : cellIterable()) {
- TensorAddress address = cell.getKey();
- double value = cell.getValue();
- builder.cell(address, addCells.containsKey(address) ? op.applyAsDouble(value, addCells.get(address)) : value);
- }
- for (Map.Entry<TensorAddress, Double> addCell : addCells.entrySet()) {
- builder.cell(addCell.getKey(), addCell.getValue());
- }
- return builder.build();
- }
-
- @Override
public Tensor remove(Set<TensorAddress> addresses) {
Tensor.Builder builder = Tensor.Builder.of(type());
@@ -380,10 +364,11 @@ public class MixedTensor implements Tensor {
this.denseType = createPartialType(type.valueType(), indexedDimensions);
}
+ /** Returns the index of the given address, or -1 if it is not present */
public long indexOf(TensorAddress address) {
TensorAddress sparsePart = sparsePartialAddress(address);
if ( ! sparseMap.containsKey(sparsePart))
- throw new IllegalArgumentException("Address subspace " + sparsePart + " not found in " + this);
+ return -1;
long base = sparseMap.get(sparsePart);
long offset = denseOffset(address);
return base + offset;