Skip to content

Commit 8009f8b

Browse files
authored
Restrict the T attribute to two-dimensional arrays (#245)
* Restrict the `T` attribute to two-dimensional arrays * Add API recommendation * Fix function name
1 parent b134073 commit 8009f8b

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

spec/API_specification/array_object.md

+7-29
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ an array object supporting the following reflected operators:
183183
The results of applying reflected operators must match their non-reflected equivalents.
184184

185185
```{note}
186-
187186
All operators for which `array <op> scalar` is implemented must have an equivalent reflected operator implementation.
188187
```
189188

@@ -259,11 +258,17 @@ _TODO: need to more carefully consider this in order to accommodate, e.g., graph
259258

260259
Transpose of the array.
261260

261+
The array instance must be two-dimensional. If the array instance is not two-dimensional, an error should be raised.
262+
263+
```{note}
264+
Limiting the transpose to two-dimensional arrays (matrices) deviates from the NumPy et al practice of reversing all axes for arrays having more than two-dimensions. This is intentional, as reversing all axes was found to be problematic (e.g., conflicting with the mathematical definition of a transpose which is limited to matrices; not operating on batches of matrices; et cetera). In order to reverse all axes, one is recommended to use the functional `permute` interface found in this specification.
265+
```
266+
262267
#### Returns
263268

264269
- **out**: _&lt;array&gt;_
265270

266-
- array whose dimensions (axes) are permuted in reverse order relative to original array. The returned array must have the same data type as the original array.
271+
- two-dimensional array whose first and last dimensions (axes) are permuted in reverse order relative to original array. The returned array must have the same data type as the original array.
267272

268273
* * *
269274

@@ -297,7 +302,6 @@ For floating-point operands, let `self` equal `x`.
297302
- an array containing the element-wise absolute value. The returned array must have the same data type as `self`.
298303

299304
```{note}
300-
301305
Element-wise results must equal the results returned by the equivalent element-wise function [`abs(x)`](elementwise_functions.md#absx-).
302306
```
303307

@@ -329,7 +333,6 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`.
329333
- In the remaining cases, when neither `infinity`, `+0`, `-0`, nor a `NaN` is involved, and the operands have the same mathematical sign or have different magnitudes, the sum must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported round mode. If the magnitude is too large to represent, the operation overflows and the result is an `infinity` of appropriate mathematical sign.
330334

331335
```{note}
332-
333336
Floating-point addition is a commutative operation, but not always associative.
334337
```
335338

@@ -350,7 +353,6 @@ Floating-point addition is a commutative operation, but not always associative.
350353
- an array containing the element-wise sums. The returned array must have a data type determined by {ref}`type-promotion`.
351354

352355
```{note}
353-
354356
Element-wise results must equal the results returned by the equivalent element-wise function [`add(x1, x2)`](elementwise_functions.md#addx1-x2-).
355357
```
356358

@@ -376,7 +378,6 @@ Evaluates `self_i & other_i` for each element of an array instance with the resp
376378
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
377379

378380
```{note}
379-
380381
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-).
381382
```
382383

@@ -524,7 +525,6 @@ Computes the truth value of `self_i == other_i` for each element of an array ins
524525
- an array containing the element-wise results. The returned array must have a data type of `bool`.
525526
526527
```{note}
527-
528528
Element-wise results must equal the results returned by the equivalent element-wise function [`equal(x1, x2)`](elementwise_functions.md#equalx1-x2-).
529529
```
530530

@@ -567,7 +567,6 @@ Evaluates `self_i // other_i` for each element of an array instance with the res
567567
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
568568

569569
```{note}
570-
571570
Element-wise results must equal the results returned by the equivalent element-wise function [`floor_divide(x1, x2)`](elementwise_functions.md#floor_dividex1-x2-).
572571
```
573572

@@ -593,7 +592,6 @@ Computes the truth value of `self_i >= other_i` for each element of an array ins
593592
- an array containing the element-wise results. The returned array must have a data type of `bool`.
594593

595594
```{note}
596-
597595
Element-wise results must equal the results returned by the equivalent element-wise function [`greater_equal(x1, x2)`](elementwise_functions.md#greater_equalx1-x2-).
598596
```
599597

@@ -640,7 +638,6 @@ Computes the truth value of `self_i > other_i` for each element of an array inst
640638
- an array containing the element-wise results. The returned array must have a data type of `bool`.
641639

642640
```{note}
643-
644641
Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greaterx1-x2-).
645642
```
646643

@@ -679,7 +676,6 @@ Evaluates `~self_i` for each element of an array instance.
679676
- an array containing the element-wise results. The returned array must have the same data type as `self`.
680677

681678
```{note}
682-
683679
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_invert(x)`](elementwise_functions.md#bitwise_invertx-).
684680
```
685681

@@ -705,7 +701,6 @@ Computes the truth value of `self_i <= other_i` for each element of an array ins
705701
- an array containing the element-wise results. The returned array must have a data type of `bool`.
706702

707703
```{note}
708-
709704
Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#less_equalx1-x2-).
710705
```
711706

@@ -736,7 +731,6 @@ Evaluates `self_i << other_i` for each element of an array instance with the res
736731
- an array containing the element-wise results. The returned array must have the same data type as `self`.
737732

738733
```{note}
739-
740734
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_left_shift(x1, x2)`](elementwise_functions.md#bitwise_left_shiftx1-x2-).
741735
```
742736

@@ -762,7 +756,6 @@ Computes the truth value of `self_i < other_i` for each element of an array inst
762756
- an array containing the element-wise results. The returned array must have a data type of `bool`.
763757

764758
```{note}
765-
766759
Element-wise results must equal the results returned by the equivalent element-wise function [`less(x1, x2)`](elementwise_functions.md#lessx1-x2-).
767760
```
768761

@@ -772,7 +765,6 @@ Element-wise results must equal the results returned by the equivalent element-w
772765
Computes the matrix product.
773766

774767
```{note}
775-
776768
The `matmul` function must implement the same semantics as the built-in `@` operator (see [PEP 465](https://www.python.org/dev/peps/pep-0465)).
777769
```
778770

@@ -801,7 +793,6 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
801793
The returned array must have a data type determined by {ref}`type-promotion`.
802794

803795
```{note}
804-
805796
Results must equal the results returned by the equivalent function [`matmul(x1, x2)`](linear_algebra_functions.md#matmulx1-x2-).
806797
```
807798
@@ -833,7 +824,6 @@ Evaluates `self_i % other_i` for each element of an array instance with the resp
833824
- an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `other_i`. The returned array must have a floating-point data type determined by {ref}`type-promotion`.
834825
835826
```{note}
836-
837827
Element-wise results must equal the results returned by the equivalent element-wise function [`remainder(x1, x2)`](elementwise_functions.md#remainderx1-x2-).
838828
```
839829

@@ -857,7 +847,6 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`.
857847
- In the remaining cases, where neither `infinity` nor `NaN` is involved, the product must be computed and rounded to the nearest representable value according to IEEE 754-2019 and a supported rounding mode. If the magnitude is too large to represent, the result is an `infinity` of appropriate mathematical sign. If the magnitude is too small to represent, the result is a zero of appropriate mathematical sign.
858848

859849
```{note}
860-
861850
Floating-point multiplication is not always associative due to finite precision.
862851
```
863852

@@ -878,7 +867,6 @@ Floating-point multiplication is not always associative due to finite precision.
878867
- an array containing the element-wise products. The returned array must have a data type determined by {ref}`type-promotion`.
879868

880869
```{note}
881-
882870
Element-wise results must equal the results returned by the equivalent element-wise function [`multiply(x1, x2)`](elementwise_functions.md#multiplyx1-x2-).
883871
```
884872

@@ -904,7 +892,6 @@ Computes the truth value of `self_i != other_i` for each element of an array ins
904892
- an array containing the element-wise results. The returned array must have a data type of `bool` (i.e., must be a boolean array).
905893

906894
```{note}
907-
908895
Element-wise results must equal the results returned by the equivalent element-wise function [`not_equal(x1, x2)`](elementwise_functions.md#not_equalx1-x2-).
909896
```
910897

@@ -926,7 +913,6 @@ Evaluates `-self_i` for each element of an array instance.
926913
- an array containing the evaluated result for each element in `self`. The returned array must have a data type determined by {ref}`type-promotion`.
927914

928915
```{note}
929-
930916
Element-wise results must equal the results returned by the equivalent element-wise function [`negative(x)`](elementwise_functions.md#negativex-).
931917
```
932918

@@ -952,7 +938,6 @@ Evaluates `self_i | other_i` for each element of an array instance with the resp
952938
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
953939

954940
```{note}
955-
956941
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_or(x1, x2)`](elementwise_functions.md#bitwise_orx1-x2-).
957942
```
958943

@@ -974,7 +959,6 @@ Evaluates `+self_i` for each element of an array instance.
974959
- an array containing the evaluated result for each element. The returned array must have the same data type as `self`.
975960

976961
```{note}
977-
978962
Element-wise results must equal the results returned by the equivalent element-wise function [`positive(x)`](elementwise_functions.md#positivex-).
979963
```
980964

@@ -1029,7 +1013,6 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`.
10291013
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
10301014

10311015
```{note}
1032-
10331016
Element-wise results must equal the results returned by the equivalent element-wise function [`pow(x1, x2)`](elementwise_functions.md#powx1-x2-).
10341017
```
10351018

@@ -1055,7 +1038,6 @@ Evaluates `self_i >> other_i` for each element of an array instance with the res
10551038
- an array containing the element-wise results. The returned array must have the same data type as `self`.
10561039

10571040
```{note}
1058-
10591041
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_right_shift(x1, x2)`](elementwise_functions.md#bitwise_right_shiftx1-x2-).
10601042
```
10611043

@@ -1079,7 +1061,6 @@ Sets `self[key]` to `value`.
10791061
- value(s) to set. Must be compatible with `self[key]` (see {ref}`broadcasting`).
10801062

10811063
```{note}
1082-
10831064
Setting array values must not affect the data type of `self`.
10841065
10851066
When `value` is a Python scalar (i.e., `int`, `float`, `bool`), behavior must follow specification guidance on mixing arrays with Python scalars (see {ref}`type-promotion`).
@@ -1109,7 +1090,6 @@ Calculates the difference for each element of an array instance with the respect
11091090
- an array containing the element-wise differences. The returned array must have a data type determined by {ref}`type-promotion`.
11101091

11111092
```{note}
1112-
11131093
Element-wise results must equal the results returned by the equivalent element-wise function [`subtract(x1, x2)`](elementwise_functions.md#subtractx1-x2-).
11141094
```
11151095

@@ -1162,7 +1142,6 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`.
11621142
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
11631143

11641144
```{note}
1165-
11661145
Element-wise results must equal the results returned by the equivalent element-wise function [`divide(x1, x2)`](elementwise_functions.md#dividex1-x2-).
11671146
```
11681147

@@ -1188,6 +1167,5 @@ Evaluates `self_i ^ other_i` for each element of an array instance with the resp
11881167
- an array containing the element-wise results. The returned array must have a data type determined by {ref}`type-promotion`.
11891168

11901169
```{note}
1191-
11921170
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_xor(x1, x2)`](elementwise_functions.md#bitwise_xorx1-x2-).
11931171
```

0 commit comments

Comments
 (0)