next up previous contents index
Next: sparse_mat Up: array Previous: array   Contents   Index

Array operators

Arithmetical operators +,-,*,/,% are defined elementwise between array expressions, as well as broadcastwise if one argument is a scalar. For example if x and y and z are arrays, and a is a scalar,

  z=x+a*y    =>  for (i=0; i<idx.size(); i++) z[i]=x[i]+a*y[i];

Indexing operators [] can either take a single integer argument, which refers to a single array or expression element, or it can take an integer array expression, which performs vector indexing. So

y=x[idx];    =>  for (i=0; i<idx.size(); i++) y[i] = x[idx[i]];
y[idx]=x;    =>  for (i=0; i<idx.size(); i++) y[idx[i] = x[i];

Comparison operators <, > etc, and logical operators &&, || are also defined in elementwise and broadcast versions.

operator<<(expression1,expression2) is a concatenation operator, appending the elements of expression2 to the end of the elements of expression1.

Compound assignment variants also exist:

x+=y;    =>   x=x+y;
x*=y;    =>   x=x*y;
x<<=y;   =>   x=x<<y;

Russell Standish 2016-09-02