Skip to content

Should we check if row indices is sorted in every column when importing sparse matrix? #236

Description

@songjhaha

In docs of SparseArrays.jl

If you have data in CSC format from a different application or library, and wish to import it in Julia, make sure that you use 1-based indexing. The row indices in every column need to be sorted, and if they are not, the matrix will display incorrectly. If your SparseMatrixCSC object contains unsorted row indices, one quick way to sort them is by doing a double transpose. Since the transpose operation is lazy, make a copy to materialize each transpose.

And i get some .mat data from https://github.com/qpsolvers/maros_meszaros_qpbenchmark/blob/main/data/QFORPLAN.mat which contains sparse matrix with unsorted row indices. Then the getindex method would crash because Julia remove inbounds check.

We could check the Ir and Jc to make sure row indices is sorted, If it's unsorted, use double transpose to collect the correct result?

It's a feature request and I would make an PR if we agree it should be done in MAT.jl instead of SparseArrays.jl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions