[Scilab-users] Ways to speed up simple things in Scilab ?
Stéphane Mottelet
stephane.mottelet at utc.fr
Fri Apr 24 16:58:15 CEST 2015
Le 24/04/2015 15:35, Samuel Gougeon a écrit :
> Le 24/04/2015 14:50, Stéphane Mottelet a écrit :
>> Hello Antoine
>>
>> I think your idea is excellent in my context, I Will try it and keep
>> you informed of the actual improvement,
>>
>> S.
>>
>> Le 24 avr. 2015 à 13:31, Antoine Monmayrant
>> <antoine.monmayrant at laas.fr <mailto:antoine.monmayrant at laas.fr>> a
>> écrit :
>>
>>> Hi again,
>>>
>>> Another way you might improve your code: can you write it as a
>>> matrix-vector product?
>>> Like
>>>
>>> M1_v=A*v;
>>> Where A is a matrix of size (839,172) that corresponds to your weird
>>> combination of v(i) to build M1_v.
>>> It seems to me that you should be able to write it that way, which
>>> would save a lot of time as matrix product are fast in Scilab.
>
> The test:
> A = sign(sprand(839,172,2/172, "normal"));
> i = A>0; A(i) = 1;
> i = A<0; A(i) = -1;
> p = rand(172,1);
> tic()
> for i = 1:1000
> M1_v = A*p;
> end
> toc()
> gives
> -->toc()
> ans =
> 0.156
>
> But somewhere you will somehow have to actually preset
> A(1,17) = 1;
> A(2,104) = 1;
> A(3,149) = 1;
> A(4, [18 63 103]) = -1;
> A(5, [18 63 103]) = -1;
> A(6,17) = 1;
> ...
> A(838, 104) = 1;
> A(839, 149) = 1;
>
> A priori, this is a bit more human-readable, but also more
> time-consuming... I am afraid that doing this in this way you will
> loose the gain "got" with matrix multiplication.
>
> Samuel
No it is not a problem because the A matrix has to be created only once,
since its sparsity pattern won't change later on.
S.
>
>>>
>>> Antoine
>>>
>>>
>>> Le 04/23/2015 11:51 PM, Stéphane Mottelet a écrit :
>>>> Hello,
>>>>
>>>> I am currently working on a project where Scilab code is
>>>> automatically generated, and after many code optimization, the
>>>> remaining bottleneck is the time that Scilab spends to execute
>>>> simple code like this (full script (where the vector has 839 lines)
>>>> with timings is attached) :
>>>>
>>>> M1_v=[v(17)
>>>> v(104)
>>>> v(149)
>>>> -(v(18)+v(63)+v(103))
>>>> -(v(18)+v(63)+v(103))
>>>> v(17)
>>>> ...
>>>> v(104)
>>>> v(149)
>>>> ]
>>>> .../...
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20150424/4fb88d17/attachment.htm>
More information about the users
mailing list