Sections

One of the most interesting features of multiarrays is the
possiblity of forming a *section* of a multiarray. This is an
idea that will be familiar to Fortran programmers.
A section (of some parent multiarray) is a multiarray in its
own right whose elements are a subset of the elements of the
parent. In other words it is a *subarray*.

A *section expression* is a generalized subscripting operation,
in which the subscripts may select some *range* of the allowed indexes
of the parent multiarray. A range of indices is represented by a term
call a *triplet*. In HPJava a triplet
has one of three forms:

Here the symbols , and stand for integer expressions. Any of the three kinds of triplet can appear as a subscript in a multiarray section expression. The first form, a single colon, means ``all allowed index values'' for the parent array. The second form means ``all index values between and , inclusive'' (the set is empty if is less than ). In the third form is a step value. If is positive, the index range includes all values , , , ..., less than or equal to . If is negative, the index range includes all values , , , ..., greater than or equal to .

The subscripts of a multiarray section expression can be any mixture of
triplet subscripts and
*scalar* subscripts^{1.4}. A scalar subscript is in an ordinary
integer expression, just like the subscript in an array element
reference. Double brackets rear their head again, mainly to make
the distinction between sections and element references very clear.
Here are some examples--we assume `a` is a rank-2 multiarray:

The first section evaluates to a rank-1 multiarray, containing the first row of . The second evaluates to a rank-1 multiarray containing the second

A section is a normal expression in the HPJava language, and it
can appear anywhere in an HPJava program that any other kind of
multiarray-valued expression can appear. It is particularly common
to see multiarray sections appearing as argument to methods.
So, for example, this statement:

presumably assigns the matrix product of

The elements of an array section are variables; they are aliases
(alternative names) for the elements of the parent array...if
you modify an element of the section, then the corresponding
element of the parent array is also changed.
Note, however, that the array section expression is not
*itself* a variable: an array section expression cannot appear on
the left-hand-side of an assignment. So this:

is illegal (this is different to Fortran).