<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Le 24/11/2021 à 19:34, Stéphane
Mottelet a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:0a19c887-fb09-1103-aabb-a059dc42c6fb@utc.fr">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Hi,<br>
</p>
<div class="moz-cite-prefix">Le 24/11/2021 à 18:07, Samuel Gougeon
a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:50880f14-0fad-5eb4-b8c3-c79a38c99fe9@free.fr">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<div class="moz-cite-prefix">Le 24/11/2021 à 09:51, Stéphane
Mottelet a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:d2524bec-c4bd-7a40-d74b-baf5eab7edb8@utc.fr">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<p>Hi,<br>
</p>
<div class="moz-cite-prefix">Le 24/11/2021 à 01:42, Federico
Miyara a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:1250650f-0161-3eff-37ee-1ea69b625508@fceia.unr.edu.ar">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<br>
<font face="Courier New">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.</font></blockquote>
<font face="Courier New">No. Internally, input arguments are
passed as references to the true object. There is no copy <font
color="#0000ff"><i>unless an input argument <b>is
modified</b></i></font> in the function (in that case
a copy with local scope only). </font><br>
</blockquote>
<p><br>
</p>
<p>Are you sure about that? Not when they are only reached in
read mode?</p>
<p>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.</p>
</blockquote>
<p>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 :</p>
<p><a class="moz-txt-link-freetext"
href="https://github.com/opencollab/scilab/blob/master/scilab/modules/ast/src/cpp/types/function.cpp#L333"
moz-do-not-send="true">https://github.com/opencollab/scilab/blob/master/scilab/modules/ast/src/cpp/types/function.cpp#L333</a></p>
</blockquote>
<p><br>
</p>
<p>3 years ago, we were talking about macros in Scilab 6.0.(1)<br>
This huge improvement of Scilab 6 with respect to Scilab 5 can be
actually tested (below).<br>
As far as i remember, it was never advertized when Scilab 6.0.0
alpha or final version were released. Has it?<br>
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.<br>
<br>
So, yes, "hopefully", passed inputs are<b><i> no longer</i></b>
copied when only addressed, since Scilab 6.<br>
Thanks for having clarified it.<br>
</p>
<p><br>
<b>With Scilab 5.5.2:</b></p>
<p>-->a = rand(1000, 1000, 5);<br>
<br>
-->function test(aa),<font color="#01a90e"> b = 1,</font>
endfunction<br>
-->tic(); for i = 1:100, test(a); end; toc()<br>
<font color="#01a90e"><font color="#000000"> ans =</font><br>
0.002 </font><br>
<br>
-->function test(aa),<font color="#ff0080"> aa,</font>
endfunction // aa just addressed, without change<br>
-->tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#ff0080"> 3.211 </font> <br>
</p>
<p><b>With Scilab 6.0.0:</b></p>
<p>--> a = rand(1000, 1000, 5);<br>
<br>
--> function test(aa),<font color="#1ca018"> b = 1;</font>,
endfunction<br>
--> tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#1ba50c"> 0.0003982</font><br>
<br>
--> function test(aa), <font color="#ea0000">aa,</font>
endfunction<br>
--> tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#1ba50c"> 0.0003522 !!!!</font><br>
<br>
--> function test(aa),<font color="#ea0000"> b = aa(2,2,2)</font>,
endfunction<br>
--> tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#1ba50c"> 0.0006584</font><br>
<br>
--> function test(aa), <font color="#ea0000">aa = 3,</font>
endfunction<br>
--> tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#1ba50c"> 0.0003663</font><br>
<br>
--> function test(aa),<font color="#ea0000"> aa(2,2,2) = 1</font>,
endfunction<br>
--> tic(); for i = 1:100, test(a); end; toc()<br>
ans =<br>
<font color="#ea0000"> 1.7976679 as expected</font><br>
</p>
<br>
</body>
</html>