Fixing the type declarations for inner and outer (Array{Int,1} instead of 
Array{Int}), and isolating the type unstable R array filling in a extra 
function, cut the time down from 1.5 to 1 second. There are still a huge 
difference though.

A ugly attempt is at https://github.com/julialang/julia/commit/fe359a4 

mandag 2. mars 2015 13.25.48 UTC+1 skrev Simon Kornblith følgende:
>
> Keyword arguments can add additional overhead when calling a function and 
> prevent its return type from being inferred properly, but the code that 
> runs is specialized for the types of the keyword arguments, so I don't 
> think keyword arguments alone explain this. But it looks like there is some 
> type instability inside repeat because it creates arrays where the number 
> of dimensions can't be inferred.
>
> Simon
>
> On Monday, March 2, 2015 at 5:35:15 AM UTC-5, Ivar Nesje wrote:
>>
>> The speed difference is because Julia doesn't specialize for specific 
>> types for keyword arguments, and type unstable code creates really slow 
>> loops in Julia.
>>
>> Thanks for reporting, I'll work on a fix.
>>
>> mandag 2. mars 2015 09.09.04 UTC+1 skrev antony schutz følgende:
>>>
>>> Hi Steven,
>>>
>>> Thanks for your answer but my question is a bit different.
>>> I'm not asking about creating a mesh grid and how or why doing it. 
>>> My question is more "naive": 
>>> Why the first method is faster than the 2 with only (well written) 1 
>>> line command.
>>>
>>> and a more general question is: why "repeat" is slower than "repmat"   , 
>>> for example: 
>>>
>>> *tic(); repmat([1:10],1000,1000); toc()*
>>>
>>> elapsed time: 0.035878247 seconds
>>>
>>>
>>> *tic(); **repeat([1:10],outer=[1000,1000]);** toc()*
>>>
>>> elapsed time: 1.176858309 seconds
>>>
>>> Thanks
>>>
>>>
>>> Le vendredi 27 février 2015 15:11:10 UTC+1, antony schutz a écrit :
>>>>
>>>> Hello, 
>>>>
>>>> I have a question about the best way to implement a grid similar to a 
>>>> mesh grid: 
>>>> My first intuition was to do the following: 
>>>>
>>>> nx = 256
>>>> nb = 195
>>>>
>>>> kx = [-nx/2:-1+nx/2]
>>>>
>>>> tic()
>>>> k1   = repmat(kx,1,nx)
>>>> k1v = vec(k1)'#/nx
>>>> k1m = repmat(k1v,nb,1)
>>>> toc()
>>>> # 0.0256 sec 
>>>>
>>>> Then I tried in one operation the following: 
>>>> tic()
>>>> ka = repeat(kx,outer=[nx,nb])'# reshape( 
>>>> repeat(repeat(kx,inner=[nb]),outer=[nx]) ,nb,nx*nx )
>>>> toc()
>>>> # 0.477
>>>>
>>>> Does somebody knows why the repeat is ~20 times slower than the 
>>>> repeat/vec/repmat 
>>>> Is it the best way to do this ?
>>>>
>>>> Thanks in advance
>>>>
>>>> Bests.
>>>>
>>>> Antony
>>>>
>>>>

Reply via email to