To: J3 J3/13-318
Subject: UK-08 Reduce intrinsic
From: Dan Nagle
Date: 2013 September 10
Reference: N1982, N1975
UK-08 approved at Delft is to add a REDUCE intrinsic
to act on arrays, in analogy with the CO_REDUCE
collective intrinsic.
Specification: Reduce an array of any type by applying
a user-specified operation. By analogy with SUM and similar,
the array shall not be polymorphic.
Syntax:
REDUCE (ARRAY, OPERATOR, DIM [, MASK])
REDUCE (ARRAY, OPERATOR [, MASK])
Edits:
{add to table 13.1}
[322] add to the table
"REDUCE (ARRAY, OPERATOR, DIM [, MASK]) T Reduce by user-supplied
(ARRAY, OPERATOR [, MASK]) operation
{add description}
[382:2+] 13.7.138+ REDUCE(ARRAY, OPERATOR, DIM [, MASK]) or
REDUCE (ARRAY, OPERATOR [, MASK])
<> Reduce array by operation
<> Transformational function
<>
ARRAY shall be an array of any type. It shall not be polymorphic.
OPERATOR shall be a pure elemental function with two arguments of the
same type and type parameters (if any) as SOURCE. Its result
shall have the same type and type parameters as SOURCE. The
arguments and result shall not be polymorphic. OPERATOR
shall implement a mathematically commutative operation. If
the operation implemented by OPERATOR is not associative,
the computed value of the reduction is processor dependent.
DIM shall be an integer scalar with a value in the range
1 <= DIM <= , where is the rank of ARRAY. The
corresponding actual argument shall not be an optional
dummy argument.
MASK (optional) shall be of type logical and shall be conformable
with ARRAY.
<> The result is of the same type and kind type
parameters as ARRAY. It is scalar if DIM does not appear;
otherwise, the result has rank and shape
[d_1, d_2, ... d_DIM-1, d_DIM+1, ... d_n] where
[d_1, d_2, ... d_n] is the shape of ARRAY.
<>
The computed value of a reduction operation over a set of values
is an iterative process. Each iteration involves the execution
of r = OPERATOR(x,y) for each x and y elements of ARRAY,
the removal of x and y from the set, and the addition of r to the set.
The process continues until the set has only one value which
is the value of the reduction.
Case (i): REDUCE( ARRAY, OPERATOR)
The set initially consists of all elements of ARRAY.
Case (ii): REDUCE( ARRAY, OPERATOR, MASK)
The set initially consists of all elements
of ARRAY corresponding
to the true elements of MASK.
Case (iii): If ARRAY has rank one, REDUCE(ARRAY, OPERATOR, DIM=DIM
[, MASK]) has a value equal to REDUCE(ARRAY, OPERATOR, DIM=DIM
[, MASK]). Otherwise, the value of element (s_1, s_2, ...,
s_DIM-1, s_DIM+1, ... s_n) of REDUCE(ARRAY, OPERATOR,
DIM=DIM [, MASK=MASK]) is equal to REDUCE(
ARRAY( s_1, s_2, ... s_DIM-1, : , s_DIM+1, ... s_n), OPERATOR
[, MASK=MASK])
A null value is defined as zero for numeric types,
as false for logical types, and as the null string for character types.
For intrinsic types, where the array has size zero or there are no true
values in MASK, the result is the null value. For derived types,
the null result is an instance of the derived type whose ultimate
components are null values. If MASK is not present,
all allocatable components shall be
allocated and all pointer components shall be associated. If MASK is
present, all allocatable components corresponding to true values
of MASK shall be allocated and all pointer components corresponding
to true values of MASK shall be associated.