vkostyukov / la4j

Linear Algebra for Java
http://la4j.org
Apache License 2.0
371 stars 109 forks source link

InsertRow for matrix with 0 rows failing #285

Closed gerbsen closed 6 years ago

gerbsen commented 7 years ago

hey there, I'm currently trying to use the sparse matrix functionality provided by la4j. my problem now is that I typically start with empty matrices. I do know the number of columns but the number of rows is variable. As I've read over the documentation insertRow(index, double[]) should be what I need, but this doesn't work for matrices with 0 rows.

final CRSMatrix crsMatrix = new CRSMatrix(0, 3);
crsMatrix.insertRow(0, SparseVector.fromArray(new double[]{0,1,2}));

This gives me Exception in thread "main" java.lang.IndexOutOfBoundsException: Illegal row number, must be 0..-1. How can I fix this?

Cheers, Daniel