SparseArrays.jl
SparseArrays.jl copied to clipboard
setindex! for SparseMatrixCSC errors in corner cases
It seems that the TODO mentioned in
https://github.com/JuliaLang/julia/blob/master/stdlib/SparseArrays/src/sparsematrix.jl#L2701
causes an error reported in https://stackoverflow.com/questions/55326817/mapping-a-function-to-an-array-of-sparse-matrices-in-julia.
This issue is similar to https://github.com/JuliaLang/julia/issues/29034 but seems to be a separate case (not 100% sure, as I do not know this part of sources very well).
A MWE is something like:
julia> mapslices(x -> "a", sprand(3, 3, 0.5), dims=2)
ERROR: MethodError: no method matching zero(::Type{String})
Are you sure this is about https://github.com/JuliaLang/julia/blob/master/stdlib/SparseArrays/src/sparsematrix.jl#L2701? Isnøt the issue just that SparseMatrixCSC doesn't really work for element types without a zero defined.
I think I am sure (i.e. the bug is that we try to create a sparse matrix while we should create a dense matrix and there would be no problem).
Here is another example that should in theory produce the same result, but one fails because zero is not defined for the processed type (as you note):
julia> mapslices(findmax, sprand(3,3,0.5), dims=2)
ERROR: MethodError: no method matching zero(::Type{Tuple{Float64,Int64}})
julia> findmax(sprand(3,3,0.5), dims=2)
(
[1, 1] = 0.467715
[2, 1] = 0.0989516
[3, 1] = 0.593281, CartesianIndex{2}[CartesianIndex(1, 2); CartesianIndex(2, 2); CartesianIndex(3, 3)])
But as I have said above - I did not dig too deeply into the source code.