To: J3 J3/20-113r1
From: Van Snyder
Subject: Rank-agnostic array element and section denotation, specs etc
Date: 2020-February-26
Reference: 19-150
1. Requirements
===============
Allow a one-dimensional array of constant size N to specify subscripts,
boundaries of sections, or strides, in N consecutive dimensions of an
array of rank not less than N.
2. Specifications
=================
- A one-dimensional array of constant size N can specify subscripts of N
consecutive dimensions of an array of rank not less than N. This is
called a "multiple subscript specification."
- A one-dimensional array of constant size N can specify the beginning,
ending, or stride values for section subscripts in N consecutive
dimensions of an array of rank not less than N. This is called a
"multiple section subscript specification."
- In a multiple section subscript specification, if more than one of the
beginning values, ending values, or strides are arrays, they shall be
of the same constant size.
- In a multiple section subscript specification, if a beginning
values, ending values, or strides are arrays, and the others are
scalars, the scalars are broadcast to the same size as the arrays.
- Arrays in a multiple (section) subscript specification, shall be of
integer type.
- These arrays may be expressions.
- The use of arrays to specify a multiple (section) subscript
specification can coexist with ordinary subscripts, ordinary section
subscripts, and vector subscripts, in other dimensions.
3. Syntax
=========
If the subscripts of any sequence of dimensions of any array, or
sequences of boundaries or strides of sections of an array, including
zero-length sequences, are specified by a one-dimensional array, the
is preceded by a character that distinguishes this
kind of subscripting from vector subscripting as described in subclause
9.5.3.3.3. The character proposed here is "@".
Simplest example:
The simplest form is A(@V), where the rank of A is equal to the size of
V. This is equivalent to
A(V(1), V(2), ..., V(size(V)))
More complicated examples:
Assume V1 and V2 are one-dimensional arrays. Then
A(@V1, :, @V2)
specifies a one-dimensional array section. The rank of A shall be
size(V1) + 1 + size(V2). V1 or V2 could be a zero-size array.
The elements of the specified arrays are used consecutively as
subscripts. Then
A(@V1, :, @V2)
is equivalent to
A ( V1(1), V1(2) , ..., V1(size(V1)) , :, &
& V2(1), V2(2) , ..., V2(size(V2)) )
The rank of A shall be equal to the sum of the sizes of the arrays that
specify multiple (section) subscripts plus the number of section
subscripts and vector subscripts. In this case, the rank of the result
is one and the shape of the result is [ size(A,size(v1+1)) ].
A(@V1, :, :, @V2)
is equivalent to
A ( V1(1), V1(2) , ..., V1(size(V1)) , :, :, &
& V2(1), V2(2) , ..., V2(size(V2)) )
In this case the rank of the result is two and the shape of the result
is [ size(A,size(v1+1)), size(A,size(v1+2)) ].
Assume V1 and V2 are one-dimensional arrays. Then
A(@V1, :, @V2:)
specifies an array section whose rank is equal to size(V2) + 1. Its
shape is
[ size(A,size(V1+1), &
& ( ubound(A,size(V1+1+i))-v2(i-size(V1)-1), &
& i = size(V1+2), rank(A) ) ]
It is equivalent to
A ( V1(1), V1(2) , ..., V1(size(V1)) , :, &
& V2(1):, V2(2):, ..., V2(size(V2)): )
Assume V1, V2, and V3 are one-dimensional arrays, with either size(V2)
the same as size(V3), or one of V2 or V3 is a scalar. Then
A(@V1, :, @V2:V3)
specifies an array section whose rank is equal to size(V1) + 1, plus
size(V2) or size(V3), whichever is an array. It is equivalent to
A ( V1(1), V1(2) , ..., V1(size(V1)) , :, &
& V2(1):V3(1), V2(2):V3(2), ..., V2(size(V2)):V3(size(V2)) )
or, if V2 is a scalar
A ( V1(1), V1(2) , ..., V1(size(v1)) , :, &
& V2:V3(1), V2:V3(2), ..., V2:V3(size(V3)) )
The rank of the result is the number of s that are
not preceded by @ and are subscript triplets, plus the size of array(s)
used to specify subscript triplets; in this case, rank(A) - size(V1).
Assume V1, V2, and V3 are rank-one arrays, with V1 and V3 of constant
size. Then
A(@V1, V2, @V3)
is a vector-subscripted array, and V2 is a vector subscripted array
section as described in 9.5.3.3.3. The rank of A shall be size(V1) + 1
+ size(V3). The rank of the result is one. The size of the result is
size(V2).