Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparse(I, J, V) doesn't support unsorted inputs #1407

Closed
CarloLucibello opened this issue Feb 24, 2022 · 1 comment · Fixed by #1411
Closed

sparse(I, J, V) doesn't support unsorted inputs #1407

CarloLucibello opened this issue Feb 24, 2022 · 1 comment · Fixed by #1411
Labels
bug Something isn't working

Comments

@CarloLucibello
Copy link
Contributor

julia> using CUDA, SparseArrays

julia> I = [1, 1, 2, 3, 3, 4, 5, 4, 6, 4, 5, 6, 6, 6]

julia> J = [4, 6, 4, 5, 6, 6, 6, 1, 1, 2, 3, 3, 4, 5]

julia> A = sparse(I, J, ones(length(I)), 6, 6)
6×6 SparseMatrixCSC{Float64, Int64} with 14 stored entries:
             1.0      1.0
             1.0        
                 1.0  1.0
 1.0  1.0              1.0
         1.0          1.0
 1.0      1.0  1.0  1.0    

julia> Agpu= sparse(I |> cu, J |> cu, ones(length(I)) |> cu, 6, 6)
6×6 CUDA.CUSPARSE.CuSparseMatrixCSC{Float32, Int32} with 14 stored entries:
             1.0      1.0
             1.0        
                 1.0  1.0
 1.0                  1.0
                       
 1.0  1.0  1.0  1.0  1.0    

julia> Array(Agpu) == A
false
@CarloLucibello
Copy link
Contributor Author

CarloLucibello commented Feb 24, 2022

Sorting by row index seems to fix this specific example:

julia> p = sortperm(I);

julia> I2, J2 = I[p], J[p];

julia> sparse(I2 |> cu, J2 |> cu, ones(length(I2)) |> cu, 6, 6)
6×6 CuSparseMatrixCSC{Float32, Int32} with 14 stored entries:
             1.0      1.0
             1.0        
                 1.0  1.0
 1.0  1.0              1.0
         1.0          1.0
 1.0      1.0  1.0  1.0    

@maleadt maleadt changed the title sparse(I, J, V) doesn't always return correct result sparse(I, J, V) doesn't support unsorted inputs Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant