JuliaIO / JuliaIO/MAT.jl

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

Open
#236 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
293
Forks
79
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing MAT.jl’s sparse-matrix import path and reproduce the failure with QFORPLAN.mat, focusing on the Ir and Jc row-index data and the getindex behavior. Compare the proposed validation or normalization with the SparseArrays documentation; done means the unsorted-row case has an agreed implementation location and no longer crashes during import or access.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
46/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.