Your code (without @code_warntype
) does not run:
Is that intentional?
julia> function replace_listcomp(r :: Vector{Vector{Int}}, p :: Vector{Pair{Int, Int}})
result = [replace(rr, p...) for rr in r]
return result
end
replace_listcomp (generic function with 1 method)
julia> replace_listcomp([Int[]], Pair{Int, Int}[])
ERROR: MethodError: no method matching promote_valuetype()
Closest candidates are:
promote_valuetype(::Pair{K, V}) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:580
promote_valuetype(::Pair{K, V}, ::Pair...) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:581
Stacktrace:
[1] replace(::Vector{Int64}; count::Nothing)
@ Base ./set.jl:570
[2] replace(::Vector{Int64})
@ Base ./set.jl:570
[3] #3
@ ./array.jl:0 [inlined]
[4] iterate
@ ./generator.jl:47 [inlined]
[5] collect(itr::Base.Generator{Vector{Vector{Int64}}, var"#3#4"{Vector{Pair{Int64, Int64}}}})
@ Base ./array.jl:724
[6] replace_listcomp(r::Vector{Vector{Int64}}, p::Vector{Pair{Int64, Int64}})
@ Main ./REPL[7]:2
[7] top-level scope
@ REPL[8]:1
julia> function replace_broadcast(r :: Vector{Vector{Int}}, p :: Vector{Pair{Int, Int}})
result = replace.(r, p...)
return result
end
replace_broadcast (generic function with 1 method)
julia>
julia> replace_broadcast([Int[]], Pair{Int, Int}[])
ERROR: MethodError: no method matching promote_valuetype()
Closest candidates are:
promote_valuetype(::Pair{K, V}) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:580
promote_valuetype(::Pair{K, V}, ::Pair...) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:581
Stacktrace:
[1] replace(::Vector{Int64}; count::Nothing)
@ Base ./set.jl:570
[2] replace(::Vector{Int64})
@ Base ./set.jl:570
[3] _broadcast_getindex_evalf
@ ./broadcast.jl:670 [inlined]
[4] _broadcast_getindex
@ ./broadcast.jl:643 [inlined]
[5] getindex
@ ./broadcast.jl:597 [inlined]
[6] copy
@ ./broadcast.jl:899 [inlined]
[7] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(replace), Tuple{Vector{Vector{Int64}}}})
@ Base.Broadcast ./broadcast.jl:860
[8] replace_broadcast(r::Vector{Vector{Int64}}, p::Vector{Pair{Int64, Int64}})
@ Main ./REPL[9]:2
[9] top-level scope
@ REPL[10]:1
julia> function replace_listcomp(r :: Vector{Vector{Int}}, p :: Vector{Pair{Int, Int}})
result = [replace(rr, p...) for rr in r]
return result
end
replace_listcomp (generic function with 1 method)
julia> replace_listcomp([Int[]], Pair{Int, Int}[])
ERROR: MethodError: no method matching promote_valuetype()
Closest candidates are:
promote_valuetype(::Pair{K, V}) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:580
promote_valuetype(::Pair{K, V}, ::Pair...) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:581
Stacktrace:
[1] replace(::Vector{Int64}; count::Nothing)
@ Base ./set.jl:570
[2] replace(::Vector{Int64})
@ Base ./set.jl:570
[3] #3
@ ./array.jl:0 [inlined]
[4] iterate
@ ./generator.jl:47 [inlined]
[5] collect(itr::Base.Generator{Vector{Vector{Int64}}, var"#3#4"{Vector{Pair{Int64, Int64}}}})
@ Base ./array.jl:724
[6] replace_listcomp(r::Vector{Vector{Int64}}, p::Vector{Pair{Int64, Int64}})
@ Main ./REPL[7]:2
[7] top-level scope
@ REPL[8]:1
julia> function replace_broadcast(r :: Vector{Vector{Int}}, p :: Vector{Pair{Int, Int}})
result = replace.(r, p...)
return result
end
replace_broadcast (generic function with 1 method)
julia>
julia> replace_broadcast([Int[]], Pair{Int, Int}[])
ERROR: MethodError: no method matching promote_valuetype()
Closest candidates are:
promote_valuetype(::Pair{K, V}) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:580
promote_valuetype(::Pair{K, V}, ::Pair...) where {K, V} at ~/Programme/julia-1.7.0/share/julia/base/set.jl:581
Stacktrace:
[1] replace(::Vector{Int64}; count::Nothing)
@ Base ./set.jl:570
[2] replace(::Vector{Int64})
@ Base ./set.jl:570
[3] _broadcast_getindex_evalf
@ ./broadcast.jl:670 [inlined]
[4] _broadcast_getindex
@ ./broadcast.jl:643 [inlined]
[5] getindex
@ ./broadcast.jl:597 [inlined]
[6] copy
@ ./broadcast.jl:899 [inlined]
[7] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(replace), Tuple{Vector{Vector{Int64}}}})
@ Base.Broadcast ./broadcast.jl:860
[8] replace_broadcast(r::Vector{Vector{Int64}}, p::Vector{Pair{Int64, Int64}})
@ Main ./REPL[9]:2
[9] top-level scope
@ REPL[10]:1
This seems to run but produces the same red line with @code_warntype
.
EDIT:
julia> replace_broadcast([Int[1]], Pair{Int, Int}[1 => 1])
1-element Vector{Vector{Int64}}:
[1]
julia> replace_listcomp([Int[1]], Pair{Int, Int}[1 => 1])
1-element Vector{Vector{Int64}}:
[1]