diff --git a/drafts/local-reduce-edits.txt b/drafts/local-reduce-edits.txt index e9ebe2e..6eb6ce4 100644 --- a/drafts/local-reduce-edits.txt +++ b/drafts/local-reduce-edits.txt @@ -2,7 +2,7 @@ To: J3 J3/26-103 From: Brandon Cook & Dan Bonachea Subject: US20: Edits for Local Prefix Operation Intrinsics Date: 2025-December-19 -References: 25-145r1, 25-186r2, 25-195r1, WG5/N-2249, 25-196r1, 25-007r1 +References: 25-145r1, 25-186r2, 25-195r1, 25-196r1, 25-007r1, WG5/N-2249 1. Background ============= @@ -71,9 +71,8 @@ SUM_PREFIX_INCLUSIVE(ARRAY, DIM [, MASK]) [469:21+] In 16.9 Specifications of the standard intrinsic procedures, after the specification of REDUCE, add: -16.9.173a \ -REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL [, ORDERED]) or -REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM [, ORDERED]) +16.9.173a REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL [, ORDERED]) or \ + REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM [, ORDERED]) <> General exclusive prefix reduction of array. @@ -93,12 +92,12 @@ OPERATION shall be a pure function with exactly two arguments; each argument commutative. If ORDERED is absent or false, then OPERATION should implement a mathematically associative operation. +INITIAL shall be scalar with the same declared type and type parameters as + ARRAY. + DIM shall be an integer scalar with a value in the range 1 <= DIM <= n, where n is the rank of ARRAY. -INITIAL shall be scalar with the same declared type and type - parameters as ARRAY. - ORDERED (optional) shall be a logical scalar. <> If OPERATION is not computationally associative, @@ -110,43 +109,43 @@ ORDERED (optional) shall be a logical scalar. <> -The result is of the same declared type, type parameters, rank, -and shape as ARRAY. +The result is of the same declared type, type parameters, rank, and shape as +ARRAY. <> -Case (i): The result of REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL) is - the exclusive prefix reduction, with initial value INITIAL, of the - sequence defined by elements of ARRAY in array element order, with the - result sequence provided in array element order. The exclusive prefix - reduction of a sequence s_1, s_2, ..., s_n, with OPERATION and initial - value INITIAL, is the sequence r_1, r_2, ..., r_n. r_1 is INITIAL, - and for i>1, r_i is the generalized noncommutative reduction with - OPERATION of the sequence INITIAL, s_1, s_2, ..., s_{i-1}. The result - of a generalized noncommutative reduction of a sequence of items with - OPERATION is the result of an iterative process. While the sequence - has more than one item, each iteration involves the selection of two - adjacent items x and y, with x immediately preceding y, and the - subsequent replacement of the two selected items in the sequence with - the value OPERATION(x, y), preserving order. If the ORDERED argument - is present with the value true, then x is the first item in the - sequence. Otherwise, the choice of x is processor-dependent. When the - sequence has a single item, that is the result. +Case (i): The result of REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL + [, ORDERED]) is the exclusive prefix reduction, with initial value + INITIAL, of the sequence defined by elements of ARRAY in array element + order, with the result sequence provided in array element order. The + exclusive prefix reduction of a sequence s_1, s_2, ..., s_n, with + OPERATION and initial value INITIAL, is the sequence r_1, r_2, ..., + r_n. r_1 is INITIAL, and for i>1, each r_i is the result of an + iterative process over the sequence INITIAL, s_1, s_2, ..., s_{i-1}. + While the sequence has more than one item, each iteration involves the + selection of two adjacent items x and y, with x immediately preceding + y, and the subsequent replacement of the two selected items in the + sequence with the value of OPERATION(x, y), preserving order. If the + ORDERED argument is present with the value true, then x is the first + item in the sequence. Otherwise, the choice of x is + processor-dependent. When the sequence has a single item, that is the + result. Case (ii): If ARRAY has rank one, then the result of - REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM [, ORDERED]) - has a value equal to REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, - INITIAL [, ORDERED]). Otherwise, the result of - REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM [, ORDERED]) - is defined by the semantics of Case (i) applied independently along + REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM = DIM + [, ORDERED = ORDERED ]) has a value equal to + REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL [, ORDERED = + ORDERED]). Otherwise, the result of REDUCE_PREFIX_EXCLUSIVE(ARRAY, + OPERATION, INITIAL, DIM = DIM [, ORDERED = ORDERED]) is defined by + the semantics of Case (i) applied independently along each sequence of ARRAY elements in dimension DIM. The value of result elements (i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n) of - REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM [, ORDERED = - ORDERED]) is equal to REDUCE_PREFIX_EXCLUSIVE( - ARRAY(i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n), OPERATION = - OPERATION, INITIAL = INITIAL, DIM = 1 [, ORDERED = ORDERED] ). + REDUCE_PREFIX_EXCLUSIVE(ARRAY, OPERATION, INITIAL, DIM = DIM + [, ORDERED = ORDERED]) is equal to REDUCE_PREFIX_EXCLUSIVE( + ARRAY(i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n), OPERATION, INITIAL, + DIM = 1 [, ORDERED = ORDERED] ). -<> The generalized noncommutative reduction described above matches the +<> The iterative process described above for each r_i matches the iterative process specified for REDUCE. <> The following examples use the function MULT, which returns the @@ -160,9 +159,8 @@ Case (ii): If A is the array | 2 2 3 4 | then REDUCE_PREFIX_EXCLUSIVE(A, MULT, INITIAL=1, DIM=2) is | 1 2 4 12 | | 1 2 2 4 |. -16.9.173b \ -REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION [, ORDERED]) or -REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM [, ORDERED]) +16.9.173b REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION [, ORDERED]) or \ + REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM [, ORDERED]) <> General inclusive prefix reduction of array. @@ -201,37 +199,36 @@ ARRAY. <> -Case (i): The result of REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION) is the - inclusive prefix reduction of the sequence defined by elements of +Case (i): The result of REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION [, ORDERED]) is + the inclusive prefix reduction of the sequence defined by elements of ARRAY in array element order, with the result sequence provided in array element order. The inclusive prefix reduction of a sequence s_1, s_2, ..., s_n, with OPERATION, is the sequence r_1, r_2, ..., - r_n. r_i is the generalized noncommutative reduction with OPERATION - of the sequence s_1, s_2, ..., s_i. The result of a generalized - noncommutative reduction of a sequence of items with OPERATION is the - result of an iterative process. While the sequence has more than one - item, each iteration involves the selection of two adjacent items x - and y, with x immediately preceding y, and the subsequent replacement - of the two selected items in the sequence with the value OPERATION(x, - y), preserving order. If the ORDERED argument is present with the - value true, then x is the first item in the sequence. Otherwise, the - choice of x is processor dependent. When the sequence has a single - item, that is the result. + r_n. Each r_i is the result of an iterative process over the sequence + s_1, s_2, ..., s_i. While the sequence has more than one item, each + iteration involves the selection of two adjacent items x and y, with x + immediately preceding y, and the subsequent replacement of the two + selected items in the sequence with the value of OPERATION(x, y), + preserving order. If the ORDERED argument is present with the value + true, then x is the first item in the sequence. Otherwise, the choice + of x is processor-dependent. When the sequence has a single item, that + is the result. Case (ii): If ARRAY has rank one, then the result of - REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM [, ORDERED]) has a - value equal to REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION [, ORDERED]). - Otherwise, the result of REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, - DIM [, ORDERED]) is defined by the semantics of Case (i) applied + REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM = DIM [, ORDERED = + ORDERED]) has a value equal to REDUCE_PREFIX_INCLUSIVE(ARRAY, + OPERATION [, ORDERED = ORDERED]). Otherwise, the result of + REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM = DIM [, ORDERED = + ORDERED]) is defined by the semantics of Case (i) applied independently along each sequence of ARRAY elements in dimension DIM. The value of result elements (i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n) of - REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM [, ORDERED = ORDERED]) - is equal to REDUCE_PREFIX_INCLUSIVE( - ARRAY(i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n), OPERATION = - OPERATION, DIM = 1 [, ORDERED = ORDERED] ). + REDUCE_PREFIX_INCLUSIVE(ARRAY, OPERATION, DIM =DIM [, ORDERED = + ORDERED]) is equal to REDUCE_PREFIX_INCLUSIVE( + ARRAY(i_1,i_2,...,i_(DIM-1),:,i_(DIM+1),...,i_n), OPERATION, DIM = 1 + [, ORDERED = ORDERED] ). -<> The generalized noncommutative reduction described above matches the +<> The iterative process described above for each r_i matches the iterative process specified for REDUCE. <> The following examples use the function MULT, which @@ -249,9 +246,8 @@ Case (ii): If A is the array | 2 3 5 | [482:26+] In 16.9 Specifications of the standard intrinsic procedures, after the specification of SUM, add: -16.9.201a \ -SUM_PREFIX_EXCLUSIVE(ARRAY [, MASK]) or \ -SUM_PREFIX_EXCLUSIVE(ARRAY, DIM [, MASK]) +16.9.201a SUM_PREFIX_EXCLUSIVE(ARRAY [, MASK]) or \ + SUM_PREFIX_EXCLUSIVE(ARRAY, DIM [, MASK]) <> Exclusive prefix sum of array. @@ -292,8 +288,8 @@ Case (iii): If ARRAY has rank one, the result of SUM_PREFIX_EXCLUSIVE(ARRAY, (i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, ..., i_n) of SUM_PREFIX_EXCLUSIVE(ARRAY, DIM = DIM [, MASK = MASK]) is equal to SUM_PREFIX_EXCLUSIVE(ARRAY(i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, - ..., i_n), DIM = 1 [, MASK(i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, - ..., i_n)]) + ..., i_n), DIM = 1 [, MASK = MASK(i_1, i_2, ..., i_{DIM-1}, :, + i_{DIM+1}, ..., i_n)]) <> @@ -310,9 +306,8 @@ Case (iii): If A is | 1 2 3 | which is | 0 1 3 | | 0 4 9 |. -16.9.201b \ -SUM_PREFIX_INCLUSIVE(ARRAY [, MASK]) or \ -SUM_PREFIX_INCLUSIVE(ARRAY, DIM [, MASK]) +16.9.201b SUM_PREFIX_INCLUSIVE(ARRAY [, MASK]) or \ + SUM_PREFIX_INCLUSIVE(ARRAY, DIM [, MASK]) <> Inclusive prefix sum of array. @@ -353,8 +348,8 @@ Case (iii): If ARRAY has rank one, the result of SUM_PREFIX_INCLUSIVE(ARRAY, (i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, ..., i_n) of SUM_PREFIX_INCLUSIVE(ARRAY, DIM = DIM [, MASK = MASK]) is equal to SUM_PREFIX_INCLUSIVE(ARRAY(i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, - ..., i_n), DIM = 1 [, MASK(i_1, i_2, ..., i_{DIM-1}, :, i_{DIM+1}, - ..., i_n)]) + ..., i_n), DIM = 1 [, MASK = MASK(i_1, i_2, ..., i_{DIM-1}, :, + i_{DIM+1}, ..., i_n)]) <>