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

Broadcasting type constructor over sparse array results in Any sparse array

Open vvjn opened this issue 5 years ago • 3 comments

julia> versioninfo()
Julia Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

julia> using SparseArrays

julia> Float64.(sprand(4,5,0.4) .> 0.5)
4×5 SparseMatrixCSC{Any,Int64} with 4 stored entries:
  [1, 1]  =  1.0
  [4, 3]  =  1.0
  [2, 5]  =  1.0
  [4, 5]  =  1.0

I was expecting SparseMatrixCSC{Float64,Int64} obviously. Same thing happens in the Linux version too.

vvjn avatar Apr 13 '20 13:04 vvjn

I think it has to do with the fusing of dot operations, since separating the two works:

julia> x = sprand(4,5,0.4) .> 0.5;

julia> Float64.(x)
4×5 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
  [1, 2]  =  1.0
  [2, 3]  =  1.0
  [2, 4]  =  1.0
  [3, 5]  =  1.0

Liozou avatar Apr 13 '20 14:04 Liozou

Basically duplicate of JuliaLang/julia#19595, I guess.

martinholters avatar May 18 '20 07:05 martinholters

Yes, but this is a simpler case and could/should be handled directly and separately. It's likely that we're stashing the function into a tuple somewhere and just need a ::Type{T} specialization. Sparse broadcast is quite the ball of knots, but I think this should be an easier lift than the big JuliaLang/julia#19595 rewrite.

mbauman avatar May 18 '20 15:05 mbauman