From 86435140ef6f7e2c6c18fac883f19507e093f95d Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Tue, 4 Jun 2019 15:37:21 +0200 Subject: Validate more --- vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java') diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index a03131f3ec9..3c15d7540b2 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -112,7 +112,7 @@ public abstract class IndexedTensor implements Tensor { public double get(TensorAddress address) { // optimize for fast lookup within bounds: try { - return get((int)toValueIndex(address, dimensionSizes)); + return get((int)toValueIndex(address, dimensionSizes, type)); } catch (IndexOutOfBoundsException e) { return Double.NaN; @@ -151,14 +151,13 @@ public abstract class IndexedTensor implements Tensor { return valueIndex; } - static long toValueIndex(TensorAddress address, DimensionSizes sizes) { + static long toValueIndex(TensorAddress address, DimensionSizes sizes, TensorType type) { if (address.isEmpty()) return 0; long valueIndex = 0; for (int i = 0; i < address.size(); i++) { - if (address.numericLabel(i) >= sizes.size(i)) { - throw new IndexOutOfBoundsException(); - } + if (address.numericLabel(i) >= sizes.size(i)) + throw new IllegalArgumentException(address + " is not within bounds of " + type); valueIndex += productOfDimensionsAfter(i, sizes) * address.numericLabel(i); } return valueIndex; -- cgit v1.2.3