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/IndexedTensor.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/IndexedTensor.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index dfc26cf0282..67eace78c45 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -118,6 +118,17 @@ public abstract class IndexedTensor implements Tensor { } } + @Override + public boolean has(TensorAddress address) { + try { + long index = toValueIndex(address, dimensionSizes, type); + if (index < 0) return false; + return (index < size()); + } catch (IllegalArgumentException e) { + return false; + } + } + /** * Returns the value at the given <i>standard value order</i> index as a double. * |