Menu

#3 Wrongly thrown Exception in SparseRCDoubleMatrix2D.assign

open
nobody
None
5
2014-08-16
2013-04-11
wetzeld
No

Hey all,

There seems to be a bug in the following method, when the second argument is set to "DoubleFunctions.plus":

cern.colt.matrix.tdouble.impl.SparseRCDoubleMatrix2D.assign(DoubleMatrix2D y, DoubleDoubleFunction function)

An exception - IllegalArgumentException("The number of elements in C exceeds nzmax") - is thrown for this test case:

import cern.colt.matrix.tdouble.impl.SparseRCDoubleMatrix2D;
import cern.jet.math.tdouble.DoubleFunctions;

public class ColtSparseRcMatrixTestSmall {

public static void main(String[] args) {
//1 x 242555 sparse matrix, nnz = 4);
SparseRCDoubleMatrix2D m1 = new SparseRCDoubleMatrix2D(1, 242555);
m1.set(0,3070,0.47702029383273525);
m1.set(0,10740,0.060347205280804415);
m1.set(0,10874,0.135743642660277);
m1.set(0,11022,0.10648301470158532);

// 1 x 242555 sparse matrix, nnz = 6);
SparseRCDoubleMatrix2D m2 = new SparseRCDoubleMatrix2D(1, 242555);
m2.set(0,148,0.015728741774625375);
m2.set(0,841,0.07209754504309197);
m2.set(0,1052,0.11791309431543652);
m2.set(0,4172,0.09091164300549671);
m2.set(0,4403,0.00956834481703099);
m2.set(0,4613,0.014734665684616965);

m1.assign(m2, DoubleFunctions.plus);

System.out.println(m1.toStringShort());
}
}

Potential solution:
It appears to me that the three lines of code starting in line 496 of SparseRCDoubleMatrix2D.java:

if (kc >= nzmax) {
throw new IllegalArgumentException("The number of elements in C exceeds nzmax");
}

should rather be moved directly above line 469.

Could you please verify this?
Thanks a lot and greetings,
Dom

Discussion


Log in to post a comment.