JuliaIO / MAT.jl

Julia module for reading MATLAB files
MIT License
278 stars 76 forks source link

Fix Issue #169 SparseMatrixCSC illegal buffers #170

Closed mkitti closed 2 years ago

mkitti commented 2 years ago

Fix #169

Truncate row values to the length of the non-zero elements to comply with strict SparseMatrixCSC buffers: https://github.com/JuliaLang/julia/blob/b3e4341d43da32f4ab6087230d98d00b89c8c004/stdlib/SparseArrays/src/sparsematrix.jl#L86-L90

johnnychen94 commented 2 years ago

Looks good; can you add a test case for this?

mkitti commented 2 years ago

We already have a test case for this. It's been failing.

ERROR: LoadError: ArgumentError: Illegal buffers for SparseMatrixCSC construction 20 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] [1] Float64[]
Stacktrace:
  [1] SparseMatrixCSC
    @ /opt/hostedtoolcache/julia/1.7.0/x64/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:29 [inlined]
  [2] SparseMatrixCSC(m::Int64, n::Int64, colptr::Vector{Int64}, rowval::Vector{Int64}, nzval::Vector{Float64})
    @ SparseArrays /opt/hostedtoolcache/julia/1.7.0/x64/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:44
  [3] read_sparse(f::IOStream, swap_bytes::Bool, dimensions::Vector{Int32}, flags::Vector{UInt32})
    @ MAT.MAT_v5 ~/work/MAT.jl/MAT.jl/src/MAT_v5.jl:248
  [4] read_matrix(f::IOStream, swap_bytes::Bool)
    @ MAT.MAT_v5 ~/work/MAT.jl/MAT.jl/src/MAT_v5.jl:340
  [5] read(matfile::MAT.MAT_v5.Matlabv5File, varname::String)
    @ MAT.MAT_v5 ~/work/MAT.jl/MAT.jl/src/MAT_v5.jl:413
  [6] check(filename::String, result::Dict{String, SparseMatrixCSC{Tv, Int64} where Tv})
    @ Main ~/work/MAT.jl/MAT.jl/test/read.jl:7
  [7] top-level scope
    @ ~/work/MAT.jl/MAT.jl/test/read.jl:137
  [8] include(fname::String)
    @ Base.MainInclude ./client.jl:451
  [9] top-level scope
    @ ~/work/MAT.jl/MAT.jl/test/runtests.jl:3
 [10] include(fname::String)
    @ Base.MainInclude ./client.jl:451
 [11] top-level scope
    @ none:6
mkitti commented 2 years ago

https://github.com/JuliaIO/MAT.jl/runs/4511309944?check_suite_focus=true