Not sure why it doesn't work when the array comes first:

julia> dispatchtest(2,[1,2])
"success"

julia> dispatchtest(2,[1,2],2)
"success"

julia> dispatchtest(2,[1,2],2,[1,2])
"success"

julia> dispatchtest([1,2],2,[1,2],2,[1,2])
ERROR: MethodError: `dispatchtest` has no method matching dispatchtest(::
Array{Int64,1}, ::Int64, ::Array{Int64,1}, ::Int64, ::Array{Int64,1})
Closest candidates are:
  dispatchtest{T}(::Union{Array{T,1},T}...)
  dispatchtest{T}(::Union{Array{T,1},T}...)






On Tuesday, October 20, 2015 at 1:33:37 PM UTC+2, Andras Niedermayer wrote:
>
> This doesn't work:
> dispatchtest{T}(x::Vararg{Union{T,Array{T,1}}}) = "success"
> dispatchtest([1,2],3)
>
>
> results in
>
> LoadError: MethodError: `dispatchtest` has no method matching 
> dispatchtest(::Array{Int64,1}, ::Int64)
> Closest candidates are:
>   dispatchtest{T}(!Matched::Union{Array{T,1},T}...)
> while loading In[8], in expression starting on line 1
>
>
>
> On Tuesday, October 20, 2015 at 1:19:24 PM UTC+2, Kristoffer Carlsson 
> wrote:
>>
>> Try: Base.vcat{T}(x::Vararg{Union{T,Array{T,1}}}) = mixed_vcat(x...)
>>
>> On Tuesday, October 20, 2015 at 11:44:15 AM UTC+2, Andras Niedermayer 
>> wrote:
>>>
>>> I've written an implementation of vcat for the special case of mixed 
>>> scalar-vector parameters (e.g. vcat(1,[2,3],4)) using generated functions. 
>>> I get a speed increase of a factor 70 and memory usage reduction by a 
>>> factor 10. It also makes this special case of vcat type stable (e.g. the 
>>> inferred type is Array{Int64,1} rather than Any for vcat(1,[2,3],4)). See
>>> https://gist.github.com/afniedermayer/947faadd362778d088d7
>>>
>>> I'd like to make a pull request (or at least provide a package that 
>>> overloads vcat to start with), but I haven't figured out how to dispatch on 
>>> mixed scalar-vector parameters.
>>> Base.vcat{T}(x::Union{T,Array{T,1}}...) = mixed_vcat(x...)
>>>
>>>
>>> doesn't work, see
>>> https://groups.google.com/forum/#!topic/julia-users/NCfxu7_9VR0
>>>
>>> Is there a way to dispatch on mixed scalar-vector parameters (besides 
>>> dispatching in the generated function)?
>>>
>>

Reply via email to