Julia 对向量的参数向量进行调度时发生MethodError
我写了一个函数,它在Julia 对向量的参数向量进行调度时发生MethodError,julia,Julia,我写了一个函数,它在Integers的向量上分派。但是,当我尝试使用它时,会出现MethodError: julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x)); julia> x = [[1], [2, 3], [4, 5, 6]] 3-element Array{Array{Int64,1},1}: [1] [2, 3] [4, 5, 6] julia> foo(x) ERROR:
Integer
s的向量上分派。但是,当我尝试使用它时,会出现MethodError:
julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x));
julia> x = [[1], [2, 3], [4, 5, 6]]
3-element Array{Array{Int64,1},1}:
[1]
[2, 3]
[4, 5, 6]
julia> foo(x)
ERROR: MethodError: no method matching foo(::Array{Array{Int64,1},1})
Closest candidates are:
foo(::Array{Array{#s17,1} where #s17<:Integer,1}) at REPL[1]:1
julia>foo(x::Vector{Vector{x=[[1],[2,3],[4,5,6]]
三元数组{Array{Int64,1},1}:
[1]
[2, 3]
[4, 5, 6]
朱莉娅>福(x)
错误:MethodError:没有与foo匹配的方法(::数组{Array{Int64,1},1})
最接近的候选人是:
foo(::Array{Array{s17,1},其中{s17这里的符号有点微妙。您为x
参数Vector{Vector{bar(y)声明的参数类型
错误:MethodError:没有方法匹配栏(::数组{Array{{s17,1}其中#s17)
julia> Vector{Vector{<:Integer}}
Array{Array{#s17,1} where #s17<:Integer,1}
julia> Vector{Vector{T} where T<:Integer}
Array{Array{#s17,1} where #s17<:Integer,1}
julia> typeof([Int8(1), Int16(2)])
Array{Int16,1}
julia> typeof([Int8[1], Int16[2, 3]])
Array{Array{Int16,1},1}
julia> foo(x::Vector{Vector{<:Integer}}) = last(last(x));
julia> y = Vector{<:Integer}[Int8[1], Int16[2, 3], Int32[4, 5, 6]]
3-element Array{Array{#s17,1} where #s17<:Integer,1}:
Int8[1]
Int16[2, 3]
Int32[4, 5, 6]
julia> foo(y)
6
julia> bar(x::Vector{Vector{T}}) where T<:Integer = last(last(x));
julia> x = [[1], [2, 3], [4, 5, 6]]
3-element Array{Array{Int64,1},1}:
[1]
[2, 3]
[4, 5, 6]
julia> bar(x)
6
julia> bar(y)
ERROR: MethodError: no method matching bar(::Array{Array{#s17,1} where #s17<:Integer,1})
Closest candidates are:
bar(::Array{Array{T,1},1}) where T<:Integer at REPL[35]:1