[Scilab-Dev] Scilab index type should be generalized

Stéphane Mottelet stephane.mottelet at utc.fr
Wed Mar 23 10:05:13 CET 2016


Hello,

Most of you should have noticed that the expression 1:$ has the index type:

--> type(1:$)
  ans  =

    129.

which means that when you write something like

--> a=rand(10,1); a(1:$)

then 1:$ is passed as an index to the interpreter, and not as a vector. 
The two constructs

a(1:$)
a(1:10)

should be treated the same way by the interpreter, but this is not the 
case as the 1:10 has not the index type


--> type(1:10)
  ans  =

    1.

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 Xeon E5-2660 v2 
(2.20 GHz) )

--> n=200000;a=rand(n,1);

--> timer();for i=1:1000;sum(a(10:100000));end;disp(timer())

     1.51426

--> timer();for i=1:1000;sum(a($-n+10:$-n+100000));end;disp(timer())

     0.588478

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 :

1:10

is an index set and

[1:10]

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

a(10:100000)

by

a($-n+10:$-n+100000)

is really boosting the indexing mechanism.

S.

-- 
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/dev/attachments/20160323/a53b7c73/attachment.htm>


More information about the dev mailing list