Open
Description
Usingsortslices
on a boolean sparse matrix is more than 100x slower than sortslices
on sparse matrices of other data types or directly summing and sorting the slices.
Replicated the issue on both Windows and MacOS builds of Julia 1.11.1 and do not see the same issue on 1.10.5
using SparseArrays
function sum_sort(matrix::SparseMatrixCSC)
csum = vec(sum(matrix, dims=1))
perm = sortperm(csum)
return matrix[:,perm]
end
test_mat_bool = rand(Bool,1000,1000) |> SparseMatrixCSC
result_bool = @time sortslices(test_mat_bool, dims=2, by=sum)
result_bool2 = @time sum_sort(test_mat_bool)
@assert result_bool == (result_bool2 |> dropzeros!)
test_mat_int = rand(Int,1000,1000) |> SparseMatrixCSC
result_int = @time sortslices(test_mat_int, dims=2, by=sum)
result_int2 = @time sum_sort(test_mat_int)
@assert result_int == (result_int2 |> dropzeros!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment