SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

`sort!(::SparseMatrixCSC; dims)` produces incorrect results

Open LilithHafner opened this issue 2 years ago • 0 comments

This is a problem on both 1.8.3 and nightly:

julia> using SparseArrays

julia> s = spzeros(30, 5); for i in eachindex(s); if rand() < .4; s[i] = 1; s[i] = rand([-1, -0.0, 0.0, 1]); end; end;

julia> sort!(s, dims=1)
30×5 SparseMatrixCSC{Float64, Int64} with 91 stored entries:
⣷⠿⡇
⢶⠏⡇
⣎⢲⠁
⢀⠳⡄
⡈⣤⡅
⡇⣾⠀
⡯⣿⠂
⠋⠛⠃

julia> Matrix(s)
30×5 Matrix{Float64}:
  0.0   0.0   0.0   0.0   0.0
 -1.0   0.0  -1.0  -1.0  -1.0
 -1.0  -1.0  -1.0  -0.0  -1.0
 -1.0  -1.0   0.0   0.0  -1.0
  0.0   0.0  -1.0  -0.0  -1.0
  0.0  -1.0  -1.0   0.0  -1.0
  0.0  -0.0  -0.0   0.0  -0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   0.0   0.0
  0.0   0.0   0.0   1.0   0.0
  0.0   0.0   0.0   1.0   0.0
  0.0   0.0   0.0   1.0   0.0
  0.0   0.0   0.0   1.0   0.0
  0.0   0.0   0.0   1.0   0.0
  1.0   0.0   1.0   1.0   0.0
  1.0   0.0   1.0   1.0   0.0
  1.0   0.0   1.0   1.0   1.0

LilithHafner avatar Nov 28 '22 02:11 LilithHafner