Elementwise operations

Once you have a few vectors or matrices defined, you can manipulate them, in parallel, much like their scalar equivalents. For example:

intVector A(N), B(N), C(N); ... A = B + C; What this means is that corresponding elements (which are scalars) of the vectors B and C are added, and then assigned to the corresponding element of vector A. It is similar to the C code int A[N], B[N], C[N]; ... for (i = 0; i < N; i++) A[i] = B[i] + C[i];

There are many elementwise operators:

Not all operators apply to all types of vectors or matrices (see details for vectors and matrices).

One additional elementwise operation is to apply a function to every element of a vector or matrix. The function, and any functions it calls, must be pure, that is, it must be free of side effects like writing global variables or doing I/O. For example:

extern double sqrt(const double); doubleMatrix A(N,M), B(N,M); ... A = apply(sqrt, B); Each element of B is passed to sqrt(), and the result stored in the corresponding element of A.