Skip to content

Commit

Permalink
Make blockdiag return a 0×0 SparseMatrixCSC{Union{},Int} (#28053)
Browse files Browse the repository at this point in the history
Fixes #14850.
  • Loading branch information
martinholters authored and KristofferC committed Jul 12, 2018
1 parent 5f19151 commit f16f8b0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
52 changes: 52 additions & 0 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,5 +571,57 @@ precompile(Tuple{typeof(REPL.setup_interface), REPL.LineEditREPL, Bool, Array{Ba
precompile(Tuple{typeof(REPL.setup_interface), REPL.LineEditREPL, Bool, Base.Dict{Any, Any}})
precompile(Tuple{typeof(Random.__init__)})
precompile(Tuple{typeof(eval), Module, Expr})

precompile(Tuple{getfield(Base, Symbol("##parse#344")), Int64, typeof(Base.parse), Type{Base.GMP.BigInt}, String})
precompile(Tuple{getfield(Random, Symbol("##RandomDevice#3#4")), Bool, Type{Random.RandomDevice}})
precompile(Tuple{typeof(Base.hvcat), Tuple{Int64, Int64}, Float64, Float64, Float64, Float64})
precompile(Tuple{getfield(Base, Symbol("##print_to_string#336")), Nothing, typeof(Base.print_to_string), Sockets.IPv4})
precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, String, String, String, String, String, String, String})
precompile(Tuple{getfield(Base, Symbol("##822#824")){Bool, Bool, Bool, Bool}, Module})
precompile(Tuple{getfield(Base, Symbol("##string#314")), Int64, Int64, typeof(Base.string), UInt64})
precompile(Tuple{getfield(Distributed, Symbol("##139#140"))})
precompile(Tuple{typeof(Base.wait), Base.Condition})
precompile(Tuple{typeof(Base.__atreplinit), REPL.LineEditREPL})
precompile(Tuple{getfield(Pkg, Symbol("##1#2")), REPL.LineEditREPL})
precompile(Tuple{getfield(REPL, Symbol("##setup_interface#49")), Bool, Array{Base.Dict{Any, Any}, 1}, typeof(REPL.setup_interface), REPL.LineEditREPL})
precompile(Tuple{Type{NamedTuple{(:prompt_prefix, :prompt_suffix, :repl, :complete, :on_enter), T} where T<:Tuple}, Tuple{String, typeof(Base.input_color), REPL.LineEditREPL, REPL.REPLCompletionProvider, typeof(REPL.return_callback)}})
precompile(Tuple{Type{NamedTuple{(:prompt_prefix, :prompt_suffix, :repl, :complete, :on_done), T} where T<:Tuple}, Tuple{String, typeof(Base.input_color), REPL.LineEditREPL, REPL.REPLCompletionProvider, getfield(REPL, Symbol("#do_respond#42")){Bool, typeof(REPL.helpmode), REPL.LineEditREPL, REPL.LineEdit.Prompt}}})
precompile(Tuple{getfield(Core, Symbol("#kw#Type")), NamedTuple{(:prompt_prefix, :prompt_suffix, :repl, :complete, :on_done), Tuple{String, typeof(Base.input_color), REPL.LineEditREPL, REPL.REPLCompletionProvider, getfield(REPL, Symbol("#do_respond#42")){Bool, typeof(REPL.helpmode), REPL.LineEditREPL, REPL.LineEdit.Prompt}}}, Type{REPL.LineEdit.Prompt}, String})
precompile(Tuple{Type{NamedTuple{(:prompt_prefix, :prompt_suffix, :repl, :complete, :on_done), T} where T<:Tuple}, Tuple{String, typeof(Base.input_color), REPL.LineEditREPL, REPL.ShellCompletionProvider, getfield(REPL, Symbol("#do_respond#42")){Bool, getfield(REPL, Symbol("##50#59")){REPL.LineEditREPL}, REPL.LineEditREPL, REPL.LineEdit.Prompt}}})
precompile(Tuple{getfield(Core, Symbol("#kw#Type")), NamedTuple{(:prompt_prefix, :prompt_suffix, :repl, :complete, :on_done), Tuple{String, typeof(Base.input_color), REPL.LineEditREPL, REPL.ShellCompletionProvider, getfield(REPL, Symbol("#do_respond#42")){Bool, getfield(REPL, Symbol("##50#59")){REPL.LineEditREPL}, REPL.LineEditREPL, REPL.LineEdit.Prompt}}}, Type{REPL.LineEdit.Prompt}, String})
precompile(Tuple{Type{Base.Dict{Symbol, Any}}, Base.Pair{Symbol, REPL.LineEdit.Prompt}, Base.Pair{Symbol, REPL.LineEdit.Prompt}, Base.Pair{Symbol, REPL.LineEdit.Prompt}})
precompile(Tuple{getfield(Base.Filesystem, Symbol("##mkpath#8")), UInt16, typeof(Base.Filesystem.mkpath), String})
precompile(Tuple{getfield(Base, Symbol("##open#301")), Bool, Bool, Bool, Nothing, Nothing, typeof(Base.open), String})
precompile(Tuple{Type{Base.Dict{Any, Any}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##44#75"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##45#76"))}, Base.Pair{Char, getfield(REPL.LineEdit, Symbol("##46#77")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{Char, Char}, Base.Pair{Char, getfield(REPL.LineEdit, Symbol("##47#78"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##48#79"))}, Base.Pair{Char, getfield(REPL.LineEdit, Symbol("##49#80"))}, Base.Pair{Int64, REPL.LineEdit.KeyAlias}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##50#81"))}, Base.Pair{String, String}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##51#82"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##52#83"))}, Base.Pair{String, String}, Base.Pair{String, String}, Base.Pair{String, String}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##53#84")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##54#85"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##55#86"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##56#87")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##57#88")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##58#89")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##59#90")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##60#91")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##61#92")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##62#93")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##63#94")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, String}, Base.Pair{String, String}, Base.Pair{String, String}, Base.Pair{String, String}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##64#95")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##65#96")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##66#97"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##67#98")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##68#99")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##69#100"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##70#101"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##71#102"))}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##72#103"))}})
precompile(Tuple{Type{Base.Dict{Any, Any}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##73#104")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##74#105")){REPL.LineEdit.HistoryPrompt{REPL.REPLHistoryProvider}}}})
precompile(Tuple{Type{Base.Dict{Any, Any}}, Base.Pair{Char, getfield(REPL, Symbol("##53#62")){REPL.LineEdit.Prompt}}, Base.Pair{Char, getfield(REPL, Symbol("##55#64")){REPL.LineEdit.Prompt}}, Base.Pair{String, getfield(REPL, Symbol("##57#66"))}, Base.Pair{String, getfield(REPL, Symbol("##58#67"))}})
precompile(Tuple{Type{Base.Dict{Any, Any}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##248#252")){REPL.LineEdit.PrefixHistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##249#253")){REPL.LineEdit.PrefixHistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##250#254")){REPL.LineEdit.PrefixHistoryPrompt{REPL.REPLHistoryProvider}}}, Base.Pair{String, getfield(REPL.LineEdit, Symbol("##251#255")){REPL.LineEdit.PrefixHistoryPrompt{REPL.REPLHistoryProvider}}}})
precompile(Tuple{Type{Base.Dict{Any, Any}}, Base.Pair{Char, getfield(REPL, Symbol("##43#46")){REPL.LineEdit.Prompt}}, Base.Pair{String, getfield(REPL, Symbol("##45#48")){REPL.LineEdit.Prompt}}})
precompile(Tuple{Type{NamedTuple{(:prompt_prefix, :prompt_suffix, :complete, :sticky), T} where T<:Tuple}, Tuple{String, String, Pkg.REPLMode.PkgCompletionProvider, Bool}})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("#kw##add_nested_key!")), NamedTuple{(:override,), Tuple{Bool}}, typeof(REPL.LineEdit.add_nested_key!), Base.Dict{Char, Any}, Char, getfield(Pkg.REPLMode, Symbol("##35#37")){REPL.LineEdit.Prompt}})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##add_nested_key!#22")), Bool, typeof(REPL.LineEdit.add_nested_key!), Base.Dict{Char, Any}, Char, getfield(Pkg.REPLMode, Symbol("##35#37")){REPL.LineEdit.Prompt}})
precompile(Tuple{typeof(REPL.run_repl), REPL.LineEditREPL, getfield(Base, Symbol("##823#825"))})
precompile(Tuple{typeof(Base.:(==)), Base.Multimedia.TextDisplay, REPL.REPLDisplay{REPL.LineEditREPL}})
precompile(Tuple{typeof(Base.:(==)), REPL.REPLDisplay{REPL.LineEditREPL}, REPL.REPLDisplay{REPL.LineEditREPL}})
precompile(Tuple{getfield(REPL, Symbol("##28#29")){REPL.REPLBackend}})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##refresh_multi_line#17")), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, typeof(REPL.LineEdit.refresh_multi_line), REPL.Terminals.TTYTerminal, REPL.LineEdit.PromptState})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##refresh_multi_line#16")), Int64, Bool, typeof(REPL.LineEdit.refresh_multi_line), REPL.Terminals.TerminalBuffer, REPL.Terminals.TTYTerminal, Base.GenericIOBuffer{Array{UInt8, 1}}, REPL.LineEdit.InputAreaState, REPL.LineEdit.PromptState})
precompile(Tuple{typeof(Base.write), Base.GenericIOBuffer{Array{UInt8, 1}}, String})
precompile(Tuple{typeof(Base.displaysize), Base.TTY})
precompile(Tuple{typeof(Base.:(!=)), Int64, Int64})
precompile(Tuple{getfield(Base, Symbol("#readcb_specialized#476")), Base.TTY, Int64, UInt64})
precompile(Tuple{typeof(Base.push!), Array{Char, 1}, Char})
precompile(Tuple{typeof(Base.get), Base.Dict{Char, Any}, Char, Nothing})
precompile(Tuple{typeof(REPL.LineEdit.match_input), getfield(REPL.LineEdit, Symbol("##112#164")), REPL.LineEdit.MIState, REPL.Terminals.TTYTerminal, Array{Char, 1}, Base.Dict{Char, Any}})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##27#28")){getfield(REPL.LineEdit, Symbol("##112#164")), String}, REPL.LineEdit.MIState, REPL.LineEditREPL})
precompile(Tuple{typeof(Core.Compiler.getindex), Tuple{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, typeof(Base.invokelatest), getfield(REPL.LineEdit, Symbol("##112#164"))}, Int64})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##112#164")), REPL.LineEdit.MIState, REPL.LineEditREPL, String})
precompile(Tuple{getfield(REPL.LineEdit, Symbol("##edit_abort#107")), String, typeof(REPL.LineEdit.edit_abort), REPL.LineEdit.MIState, Bool})
precompile(Tuple{typeof(REPL.LineEdit.mode), REPL.LineEdit.PromptState})
precompile(Tuple{getfield(REPL, Symbol("#do_respond#42")){Bool, getfield(REPL, Symbol("##52#61")){REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt}, REPL.LineEdit.MIState, Base.GenericIOBuffer{Array{UInt8, 1}}, Bool})
precompile(Tuple{getfield(Logging, Symbol("##7#8"))})
precompile(Tuple{getfield(LibGit2, Symbol("##176#177"))})
precompile(Tuple{getfield(REPL, Symbol("##51#60")), REPL.REPLCompletionProvider})

end
end
3 changes: 2 additions & 1 deletion stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ function blockdiag(X::SparseMatrixCSC...)
n = sum(nX)

Tv = promote_type(map(x->eltype(x.nzval), X)...)
Ti = promote_type(map(x->eltype(x.rowval), X)...)
Ti = isempty(X) ? Int : promote_type(map(x->eltype(x.rowval), X)...)

colptr = Vector{Ti}(undef, n+1)
nnzX = Int[ nnz(x) for x in X ]
Expand All @@ -3158,6 +3158,7 @@ function blockdiag(X::SparseMatrixCSC...)
nX_sofar += nX[i]
mX_sofar += mX[i]
end
colptr[n+1] = nnz_sofar + 1

SparseMatrixCSC(m, n, colptr, rowval, nzval)
end
Expand Down
2 changes: 2 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ end

@testset "blockdiag concatenation" begin
@test blockdiag(se33, se33) == sparse(1:6,1:6,fill(1.,6))
@test blockdiag() == spzeros(0, 0)
@test nnz(blockdiag()) == 0
end

@testset "concatenation promotion" begin
Expand Down

0 comments on commit f16f8b0

Please sign in to comment.