Matrix slices and vector pieces

Sometimes it is convenient to operate on a single row, column, or element of a matrix, or a single element of a vector. (Of course, in data-parallel programming we wish to avoid this practice as much as possible, and operate on the entire vector or matrix, but sometimes it is necessary). You can refer to single elements ("piece") by subscripting:

intVector A(N); intMatrix B(N,N); ... A[3] = 5; B[1][3] = A[4];

You can also refer to a particular row or column of a matrix (a "slice") with a special subscripting form:

intVector A(N); intMatrix B(N,N); ... A = B[2][_]; // assign row 2 of matrix B to vector A B[_][3] = A; // assign vector A to column 3 of matrix B Notice the underscore (_) that is used as a placeholder, to indicate "all of the indices in this dimension." Slices can be used anywhere a vector can be used. The first use above is a row slice; the second is a column slice. Row slices need not use a placeholder, that is, B[3] means the same thing as B[3][_] (it is better style to include the [_], however).