diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-04-30 14:08:03 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-04-30 14:08:06 +0000 |
commit | 400a428fd3ae71684988e93953eb6c89462d057e (patch) | |
tree | acf2e09b984428532dc64a6affe76d4403a951a7 /vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java | |
parent | 8e2478b8965bbd29709957e2c4fc37e8333a59e5 (diff) |
add api for detecting cell existence
* new API "has(TensorAddress)" detects if a Tensor has a cell with the given address.
* use new API in join and merge. This will give different results for
cells that are present but contain NaN versus cells that aren't present at all.
* use new API in slice. This gives a different default (0, not NaN) when trying to
access cells that aren't present.
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java index 607c9a0ab44..da24aef50bc 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Slice.java @@ -63,8 +63,14 @@ public class Slice<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETY TensorType resultType = resultType(tensor.type()); PartialAddress subspaceAddress = subspaceToAddress(tensor.type(), context); - if (resultType.rank() == 0) // shortcut common case - return Tensor.from(tensor.get(subspaceAddress.asAddress(tensor.type()))); + if (resultType.rank() == 0) { // shortcut common case + var key = subspaceAddress.asAddress(tensor.type()); + if (tensor.has(key)) { + return Tensor.from(tensor.get(key)); + } else { + return Tensor.from(0.0); + } + } Tensor.Builder b = Tensor.Builder.of(resultType); for (Iterator<Tensor.Cell> i = tensor.cellIterator(); i.hasNext(); ) { |