vkostyukov / la4j

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

Cannot insert new column as last column. #309

Open aintHuman opened 4 years ago

aintHuman commented 4 years ago

Dealing with sparse matrix, I want to insert a column, as a new last column, so if the initial matrix was m x n, then the new matrix should be m x (n+1)

If my sparse matrix occupies the variable mat, then I am trying this as follows:

mat = (SparseMatrix)mat.insertColumn(mat.columns(), Vector.fromArray(new_column_array_data));

However, this throws an error java.lang.IndexOutOfBoundsException: Illegal row number,

Now if I perform the same operation, but 1 column back, inserting between the current 2nd last and current last column,

mat = (SparseMatrix)mat.insertColumn(mat.columns()-1, Vector.fromArray(new_column_array_data));

Then the new data is indeed inserted, however, it is not in the correct position per my requirements, I need the new column inserted as the final column.

So is this a bug or a feature?

In order to get around the above, at the moment, I am having to insert (duplicate) the current last column, at the 2nd last column, then insert my desired column, and then finally remove the last column. Requiring 3 operations.