Skip to content

Cannot insert new column as last column. #309

@aintHuman

Description

@aintHuman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions