<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    Most of you should have noticed that the expression 1:$ has the
    index type:<br>
    <br>
    --> type(1:$)<br>
     ans  =<br>
    <br>
       129.<br>
    <br>
    which means that when you write something like<br>
    <br>
    --> a=rand(10,1); a(1:$)<br>
    <br>
    then 1:$ is passed as an index to the interpreter, and not as a
    vector. The two constructs<br>
    <br>
    a(1:$)<br>
    a(1:10)<br>
    <br>
    should be treated the same way by the interpreter, but this is not
    the case as the 1:10 has not the index type<br>
    <br>
    <br>
    --> type(1:10)<br>
     ans  =<br>
    <br>
       1.<br>
    <br>
    This means that Scilab handles 1:10 as any other vector of
    scrambled/duplicate indices without seeing that all the components
    are contiguous in memory. In fact, this behavior is a major
    bottleneck, as illustrated in the following (Scilab 5.5.2 timings on
    a 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    Xeon E5-2660 v2 (2.20 GHz)
    <title></title>
    )<br>
    <br>
    --> n=200000;a=rand(n,1);<br>
    <br>
    --> timer();for i=1:1000;sum(a(10:100000));end;disp(timer())<br>
    <br>
        1.51426  <br>
    <br>
    --> timer();for
    i=1:1000;sum(a($-n+10:$-n+100000));end;disp(timer())<br>
    <br>
        0.588478  <br>
    <br>
    almost three times faster... But the problem is that we have been
    all get used to mistake indices  for vectors. That's why Julia, for
    example, uses brackets to make the difference : <br>
    <br>
    1:10 <br>
    <br>
    is an index set and <br>
    <br>
    [1:10] <br>
    <br>
    is the vector [1,2,3,...,10]. I know that introducing this in Scilab
    is almost impossible as it would break a lot of things, but maybe a
    solution could be found at the interpreter level, as the trick of
    replacing <br>
    <br>
    a(10:100000)<br>
    <br>
    by<br>
    <br>
    a($-n+10:$-n+100000)<br>
    <br>
    is really boosting the indexing mechanism.<br>
    <br>
    S.<br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Département de Génie Informatique
EA 4297 Transformations Intégrées de la Matière Renouvelable
Université de Technologie de Compiègne -  CS 60319
60203 Compiègne cedex</pre>
  </body>
</html>