Skip to content

Commit 654d58d

Browse files
authored
Specify shape behavior (#289)
* Specify shape behavior * Update copy * Update guidance to remove support for arrays of unknown rank * Update copy
1 parent e3e1a46 commit 654d58d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

spec/API_specification/array_object.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,33 +275,43 @@ Number of array dimensions (axes).
275275

276276
- number of array dimensions (axes).
277277

278-
_TODO: need to more carefully consider this in order to accommodate, e.g., graph tensors where the number of dimensions may be dynamic._
279-
280278
(attribute-shape)=
281279
### shape
282280

283281
Array dimensions.
284282

285283
#### Returns
286284

287-
- **out**: _Union\[ Tuple\[ int, ...], <shape> ]_
285+
- **out**: _Tuple\[ Optional\[ int ], ... ]_
288286

289-
- array dimensions as either a tuple or a custom shape object. If a shape object, the object must be immutable and must support indexing for dimension retrieval.
287+
- array dimensions. An array dimension must be `None` if and only if a dimension is unknown.
290288

291-
_TODO: need to more carefully consider this in order to accommodate, e.g., graph tensors where a shape may be dynamic._
289+
```{note}
290+
For array libraries having graph-based computational models, array dimensions may be unknown due to data-dependent operations (e.g., boolean indexing; `A[:, B > 0]`) and thus cannot be statically resolved without knowing array contents.
291+
```
292+
293+
```{note}
294+
The returned value should be a tuple; however, where warranted, an array library may choose to return a custom shape object. If an array library returns a custom shape object, the object must be immutable, must support indexing for dimension retrieval, and must behave similarly to a tuple.
295+
```
292296

293297
(attribute-size)=
294298
### size
295299

296-
Number of elements in an array. This must equal the product of the array's dimensions.
300+
Number of elements in an array.
301+
302+
```{note}
303+
This must equal the product of the array's dimensions.
304+
```
297305

298306
#### Returns
299307

300-
- **out**: _int_
308+
- **out**: _Optional\[ int ]_
301309

302-
- number of elements in an array.
310+
- number of elements in an array. The returned value must be `None` if and only if one or more array dimensions are unknown.
303311

304-
_TODO: need to more carefully consider this in order to accommodate, e.g., graph tensors where the number of elements may be dynamic._
312+
```{note}
313+
For array libraries having graph-based computational models, an array may have unknown dimensions due to data-dependent operations.
314+
```
305315

306316
(attribute-T)=
307317
### T
@@ -783,11 +793,6 @@ Computes the truth value of `self_i <= other_i` for each element of an array ins
783793
Element-wise results must equal the results returned by the equivalent element-wise function [`less_equal(x1, x2)`](elementwise_functions.md#less_equalx1-x2-).
784794
```
785795

786-
(method-__len__)=
787-
### \_\_len\_\_(self, /)
788-
789-
_TODO: need to more carefully consider this in order to accommodate, e.g., graph tensors where a shape may be dynamic. Furthermore, not clear whether this should be implemented, as, e.g., NumPy's behavior of returning the size of the first dimension is not necessarily intuitive, as opposed to, say, the total number of elements._
790-
791796
(method-__lshift__)=
792797
### \_\_lshift\_\_(self, other, /)
793798

0 commit comments

Comments
 (0)