Skip to content

Commit

Permalink
[MINOR] Remove exception in cast as IntArray
Browse files Browse the repository at this point in the history
This commit removes the exception in cast as IntArray from DoubleArray.
We encounter an issue in this conversion for large numbers of double
values, that does not cast perfectly to the same double values when
casting the integer values back to doubles.

The script that reproduce the bug is:

```
k = ifdef($k, 5)
paq = ifdef($paq, 1)
X = round(rand(rows = 50, cols = 10, min=1, max=10))
y = X %*% rand(rows = ncol(X), cols = 1)
w = lm(X = X, y = y)
yhat = X %*% w
ress = slicefinder(X = X, e = abs(y - yhat), k = k, maxL = 0, minSup =
1, alpha = 1, selFeat = TRUE, verbose = TRUE)
print(toString(ress))
```

A subsequent commits add a test case that ensure this bug does not
happen again.
  • Loading branch information
Baunsgaard committed Jan 30, 2024
1 parent 69231e1 commit 75cf454
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,33 +293,24 @@ protected Array<Float> changeTypeFloat() {
@Override
protected Array<Integer> changeTypeInteger() {
int[] ret = new int[size()];
for(int i = 0; i < size(); i++) {
if(_data[i] != (int) _data[i])
throw new DMLRuntimeException("Unable to change to Integer from Double array because of value:" + _data[i]);
for(int i = 0; i < size(); i++)
ret[i] = (int) _data[i];
}
return new IntegerArray(ret);
}

@Override
protected Array<Long> changeTypeLong() {
long[] ret = new long[size()];
for(int i = 0; i < size(); i++) {
if(_data[i] != (long) _data[i])
throw new DMLRuntimeException("Unable to change to Long from Double array because of value:" + _data[i]);
for(int i = 0; i < size(); i++)
ret[i] = (long) _data[i];
}
return new LongArray(ret);
}

@Override
protected Array<Object> changeTypeHash64() {
long[] ret = new long[size()];
for(int i = 0; i < size(); i++) {
if(_data[i] != (long) _data[i])
throw new DMLRuntimeException("Unable to change to Long from Double array because of value:" + _data[i]);
for(int i = 0; i < size(); i++)
ret[i] = (long) _data[i];
}
return new HashLongArray(ret);
}

Expand Down

0 comments on commit 75cf454

Please sign in to comment.