Le mardi 19 avril 2016 à 06:58 -0700, Matt Bauman a écrit :
> That's https://github.com/JuliaLang/julia/pull/11242.  Another common
> workaround is a generated function (but the wrapper function is
> better if you don't need other generated functionality):
> 
> @generated function f(x...)
>     N = length(x)
>     :(Array{Int, $N})
> end
Perfect, thanks. I must say I never really understood what that giant
PR was about, except that it sounded interesting.


Regards


> > Hi! 
> > 
> > I'm looking for the recommended way of getting type inference to 
> > determine the number of elements passed via varargs. 
> > 
> > I guess a code snippet is better than a thousand words: in the 
> > following function, the type of a isn't inferred correctly. 
> > 
> > function f(x...) 
> >     N = length(x) 
> >     a = Array{Int, N}() 
> >     # ... 
> > end 
> > 
> > Using a wrapper function fixes the type instability: 
> > 
> > g(x...) = g(x) 
> > function g{N}(x::NTuple{N}) 
> >     a = Array{Int, N}() 
> >     # 
> > ... 
> > end 
> > 
> > Is there a better solution than this workaround? 
> > 
> > 
> > Regards 

Reply via email to