[Scilab-users] Getting the variable name used for a function input argument
Samuel Gougeon
sgougeon at free.fr
Sat Nov 27 13:30:18 CET 2021
Le 24/11/2021 à 19:34, Stéphane Mottelet a écrit :
>
> Hi,
>
> Le 24/11/2021 à 18:07, Samuel Gougeon a écrit :
>> Le 24/11/2021 à 09:51, Stéphane Mottelet a écrit :
>>>
>>> Hi,
>>>
>>> Le 24/11/2021 à 01:42, Federico Miyara a écrit :
>>>>
>>>> I'm not completely sure, but I think this is not possible since
>>>> what is passed to the function isn't a variable but the value
>>>> contained in the variable.
>>> No. Internally, input arguments are passed as references to the true
>>> object. There is no copy /unless an input argument *is modified*/ in
>>> the function (in that case a copy with local scope only).
>>
>>
>> Are you sure about that? Not when they are only reached in read mode?
>>
>> I might have misunderstood, but i remember a discussion with Clément
>> during the last ScilabTech. Clément was categorically stating that
>> all input arguments are copied, only and always copied.
>>
> It depends on the type of Callable. If you are talking about Scilab
> macros, inputs are (hopefully) never copied. However, if you are
> talking about old-style Scilab 5 C-gateways, yes, there is a wrapper
> that triggers a copy :
>
> https://github.com/opencollab/scilab/blob/master/scilab/modules/ast/src/cpp/types/function.cpp#L333
>
3 years ago, we were talking about macros in Scilab 6.0.(1)
This huge improvement of Scilab 6 with respect to Scilab 5 can be
actually tested (below).
As far as i remember, it was never advertized when Scilab 6.0.0 alpha
or final version were released. Has it?
Yet, it drastically improves performances, as in many situations huge
arrays are passed while only a tiny part is extracted and used in the
function.
So, yes, "hopefully", passed inputs are*/no longer/* copied when only
addressed, since Scilab 6.
Thanks for having clarified it.
*With Scilab 5.5.2:*
-->a = rand(1000, 1000, 5);
-->function test(aa),b = 1, endfunction
-->tic(); for i = 1:100, test(a); end; toc()
ans =
0.002
-->function test(aa),aa, endfunction // aa just addressed, without change
-->tic(); for i = 1:100, test(a); end; toc()
ans =
3.211
*With Scilab 6.0.0:*
--> a = rand(1000, 1000, 5);
--> function test(aa),b = 1;, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
ans =
0.0003982
--> function test(aa), aa, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
ans =
0.0003522 !!!!
--> function test(aa),b = aa(2,2,2), endfunction
--> tic(); for i = 1:100, test(a); end; toc()
ans =
0.0006584
--> function test(aa), aa = 3, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
ans =
0.0003663
--> function test(aa),aa(2,2,2) = 1, endfunction
--> tic(); for i = 1:100, test(a); end; toc()
ans =
1.7976679 as expected
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20211127/298b5a5e/attachment.htm>
More information about the users
mailing list