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

Broadcasting over sparse matrix generating wrong type

Open KlausC opened this issue 4 years ago • 1 comments

julia> VERSION
v"1.7.0-DEV.1108"

julia> rem.(sparse([1 2; 3 4]), 2)
2×2 SparseMatrixCSC{Int64, Int64} with 2 stored entries:
 1  ⋅
 1  ⋅

julia> big.(rem.(sparse([1 2; 3 4]), 2))
2×2 SparseMatrixCSC{BigInt, Int64} with 2 stored entries:
 1  ⋅
 1  ⋅

julia> BigInt.(rem.(sparse([1 2; 3 4]), 2))
2×2 SparseMatrixCSC{Any, Int64} with 2 stored entries:
Error showing value of type SparseMatrixCSC{Any, Int64}:
ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:

...

julia> BigInt.(rem.(sparse([1 2; 3 4]), 2));

julia> typeof(ans)
SparseMatrixCSC{Any, Int64}

julia> BigFloat.(rem.(sparse([1 2; 3 4]), 2));

julia> typeof(ans)
SparseMatrixCSC{Any, Int64}

KlausC avatar May 21 '21 16:05 KlausC

Expected behaviour is, that the type of BigInt.(rem.(...)) should be SparseMatrixCSC{BigInt, Int64}. That is what b = rem.(...); BigInt.(b) has.

Looks to me like a regression between 1.0.5 and 1.5 (same bug found in 1.5 and 1.6)

KlausC avatar May 22 '21 09:05 KlausC