[Scilab-users] repmat() slow compared to .* and .*. <= Re: More rapid calculation
Samuel Gougeon
sgougeon at free.fr
Fri Feb 16 07:48:54 CET 2018
Le 15/02/2018 à 11:45, Stéphane Mottelet a écrit :
> Le 15/02/2018 à 00:02, fujimoto2005 a écrit :
>> .../...
>
> Hello,
>
> In your code, most of the cpu time is spent between lines 40-54
> (random generation of big matrices), then between lines 54-60, where
> one of the bottlenecks is the use of repmat (and you use it twice) and
> the "cumsum".In previous posts of Heinz Nabielek related to code
> optimization, you may have noticed that using matrix multiplication by
> a vector of ones gives the same result BUT uses the BLAS ! For
> example, compare these timings, with size(timePoints_V)=[1 25000] and
> sample=5000) :
>
> tic;repmat(timePoints_V,2*sample,1);disp(toc())
>
> 12.372273
>
> tic;ones(2*sample,1)*timePoints_V;disp(toc())
>
> 1.823105
>
> On my machine (MacPro, OSX, Scilab 6.0.0), this last piece of code
> uses 100% cpu (four cores).
Thank you Stéphane for having pointed out the repmat() slowness.
Additional tests show that the Kronecker product is even slightly faster
than .*
A new version of repmat() is proposed on review:
https://codereview.scilab.org/19782
It is rewritten mainly using .*., which simplifies a lot the code.
This version is more than 7x faster than the current one, and uses both
CPU of my PC.
It is roughly the ratio 12.37/1.82 ~ 6.8 that you give here-above.
Best regards
Samuel
More information about the users
mailing list