J3/13-217
To: J3
From: Van Snyder
Subject: Scatter/gather subscript
Date: 2013 December 19
Reference: 04-195; 2004 hate-dislike-like-love score 0-0-11-2
Title: Scatter/gather subscript
Submitted by: Van Snyder
Status: For consideration
Basic functionality: Allow a single array with a first extent equal to
the rank of an array to be used as a subscript.
Rationale: One cannot use the result of an array-valued computation as
the set of subscripts of an array.
Estimated impact: Minor
Markham M6 conformance: Remove simple deficiency and discrepancy.
Detailed specification: Allow a single array with a first extent equal
to the rank of an array to provide subscripts for the first array. The
rank of the result is one less than the rank of the subscript. If the
rank of the result is not zero, the extent of the result is the same as
the extents of the dimensions of the subscript after the first.
Draft edits: To estimate scope of project
Revise R612:
"R612 <> [ ( ) ]
[ ]
<> [ ( ) ]
[ ]
"
Define
"R623a <>
"C627a (R623a) A shall be an array.
"
Define the semantics of :
Introduce subclause "<<6.5.3.3.3 Scatter-gather subscript>>
"A scatter-gather subscript is an array. The first extent of the
subscript shall be the same as the rank $r$ of the subscripted array.
If the other extents of the subscript are $n_1, n_2, ..., n_k$ the rank
of the designator is $k$ and its shape is $[n_1, n_2, ..., n_k]$.
"If $k$ is zero, the elements of the subscript array are used as
subscripts, one element for each dimension of the subscripted array, and
the resulting designator is a scalar.
"If $k$ is not zero, the elements of the rank-one extent-$r$ sections
over the first dimension of the subscript array are used as subscripts,
one element for each dimension of the subscripted array. The resulting
designator is an array of rank $k$ and shape $[n_1, n_2, ..., n_k]$.
"An array that is subscripted by a shall not
be
o argument associated with a dummy array that is defined or redefined,
o the in a pointer assignment statement, or
o an internal file.
"NOTE 6.15a
Example:
REAL :: A3(:,:,:)
INTEGER, PARAMETER :: S3 = RESHAPE( [(I,I=3,8)], [3,2] )
! [ 3 6 ]
! S3 = [ 4 7 ]
! [ 5 8 ]
A3(S3) is a rank-1 extent [2] array that can appear in a variable
definition context. It specifies the same array as [ A3(3,4,5),
A3(6,7,8)], which cannot appear in a variable-definition context.
This is different from A3(S3(1,:), S3(2,:), S3(3,:)) =
A3([3,6],[4,7],[5,8]), which can appear in a variable-definition
context, but is an array with shape [2,2,2], not [2].
If T3 has the value [3,4,5], the primary A3(T3) is the same as the
scalar A3(3,4,5). A3(reshape(T3,[3,1])) is the same as the
rank-1 extent-1 array A3([3],[4],[5]).
Assuming the array A in the example in Case (ii) in 13.7.61, and a
rank-two array B(3,4) = reshape( [((10*i+j,i=1,3),j=1,4)],[3,4] ), the
statement
PRINT *, B(FINDLOC(A,7)), B(FINDLOC(A,3))
would print 34 and 21, which could also be printed using
INTEGER :: T1(2), T2(2)
T1 = FINDLOC(A,7)
T2 = FINDLOC(A,3)
PRINT *, B(T1(1),B(T2)), B(T2(1),B(T2(2))
{end note}
"