Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6d827a

Browse files
authored
Update API specification for creation and manipulation functions (#167)
* Update specification for arange Addresses comments in gh-85 and gh-107 * Update the specification for `full` and `full_like` Addresses comments in gh-85 and gh-107 * Update specification for `linspace` Addresses comments in gh-85 and gh-107 * Update specification for `empty`, `ones`, `zeros` Addresses comments in gh-85 and gh-107 * Update specification for `eye` This is useful/needed because `M` is not a descriptive name and that name does not match between different array libraries. * Update specification for `expand_dims`, `roll` and `reshape` Address comment in gh-85 * One more change to `eye`, more descriptive positional arguments * Address the default integer dtype issue for 32/64-bit Python Closes gh-151 * Update signature of `broadcast_to` Address a review comment; makes it consistent with other functions using `shape`.
1 parent ad3156d commit e6d827a

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

spec/API_specification/creation_functions.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A conforming implementation of the array API standard must provide and support t
1212
<!-- NOTE: please keep the functions in alphabetical order -->
1313

1414
(function-arange)=
15-
### arange(start, /, *, stop=None, step=1, dtype=None, device=None)
15+
### arange(start, /, stop=None, step=1, *, dtype=None, device=None)
1616

1717
Returns evenly spaced values within the half-open interval `[start, stop)` as a one-dimensional array.
1818

@@ -33,11 +33,11 @@ This function cannot guarantee that the interval does not include the `stop` val
3333

3434
- **step**: _Union\[ int, float ]_
3535

36-
- the distance between two adjacent elements (`out[i+1] - out[i]`). Default: `1`.
36+
- the distance between two adjacent elements (`out[i+1] - out[i]`). Must not be `0`; may be negative, this results in an empty array if `stop >= start`. Default: `1`.
3737

3838
- **dtype**: _Optional\[ &lt;dtype&gt; ]_
3939

40-
- output array data type. If `dtype` is `None`, the output array data type must be the default floating-point data type. Default: `None`.
40+
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `start`, `stop` and `step`. If those are all integers, the output array dtype must be the default integer dtype; if one or more have type `float`, then the output array dtype must be the default floating-point data type. Default: `None`.
4141

4242
- **device**: _Optional\[ &lt;device&gt; ]_
4343

@@ -47,7 +47,7 @@ This function cannot guarantee that the interval does not include the `stop` val
4747

4848
- **out**: _&lt;array&gt;_
4949

50-
- a one-dimensional array containing evenly spaced values. The length of the output array must be `ceil((stop-start)/step)`.
50+
- a one-dimensional array containing evenly spaced values. The length of the output array must be `ceil((stop-start)/step)` if `stop - start` and `step` have the same sign, and length 0 otherwise.
5151

5252

5353
(function-asarray)=
@@ -68,7 +68,7 @@ Convert the input to an array.
6868

6969
- **dtype**: _Optional\[ &lt;dtype&gt; ]_
7070

71-
- output array data type. If `dtype` is `None`, the output array data type must be inferred from the data type(s) in `obj`. Default: `None`.
71+
- output array data type. If `dtype` is `None`, the output array data type must be inferred from the data type(s) in `obj`. If all input values are Python scalars, then if they're all `bool` the output dtype will be `bool`; if they're a mix of `bool`s and `int` the output dtype will be the default integer data type; if they contain `float`s the output dtype will be the default floating-point data type. Default: `None`.
7272

7373
- **device**: _Optional\[ &lt;device&gt; ]_
7474

@@ -86,7 +86,7 @@ Convert the input to an array.
8686

8787

8888
(function-empty)=
89-
### empty(shape, /, *, dtype=None, device=None)
89+
### empty(shape, *, dtype=None, device=None)
9090

9191
Returns an uninitialized array having a specified `shape`.
9292

@@ -136,19 +136,19 @@ Returns an uninitialized array with the same `shape` as an input array `x`.
136136
- an array having the same shape as `x` and containing uninitialized data.
137137

138138
(function-eye)=
139-
### eye(N, /, *, M=None, k=0, dtype=None, device=None)
139+
### eye(n_rows, n_cols=None, /, *, k=0, dtype=None, device=None)
140140

141141
Returns a two-dimensional array with ones on the `k`th diagonal and zeros elsewhere.
142142

143143
#### Parameters
144144

145-
- **N**: _int_
145+
- **n_rows**: _int_
146146

147147
- number of rows in the output array.
148148

149-
- **M**: _Optional\[ int ]_
149+
- **n_cols**: _Optional\[ int ]_
150150

151-
- number of columns in the output array. If `None`, the default number of columns in the output array is `N`. Default: `None`.
151+
- number of columns in the output array. If `None`, the default number of columns in the output array is equal to `n_rows`. Default: `None`.
152152

153153
- **k**: _Optional\[ int ]_
154154

@@ -190,7 +190,7 @@ Returns a new array containing the data from another (array) object with a `__dl
190190
```
191191
192192
(function-full)=
193-
### full(shape, fill_value, /, *, dtype=None, device=None)
193+
### full(shape, fill_value, *, dtype=None, device=None)
194194
195195
Returns a new array having a specified `shape` and filled with `fill_value`.
196196
@@ -206,7 +206,7 @@ Returns a new array having a specified `shape` and filled with `fill_value`.
206206
207207
- **dtype**: _Optional\[ &lt;dtype&gt; ]_
208208
209-
- output array data type. If `dtype` is `None`, the output array data type must be the default floating-point data type. Default: `None`.
209+
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `fill_value`. If it's an `int`, the output array dtype must be the default integer dtype; if it's a `float`, then the output array dtype must be the default floating-point data type; if it's a `bool` then the output array must have boolean dtype. Default: `None`.
210210
211211
- **device**: _Optional\[ &lt;device&gt; ]_
212212
@@ -219,7 +219,7 @@ Returns a new array having a specified `shape` and filled with `fill_value`.
219219
- an array where every element is equal to `fill_value`.
220220
221221
(function-full_like)=
222-
### full_like(x, fill_value, /, *, dtype=None, device=None)
222+
### full_like(x, /, fill_value, *, dtype=None, device=None)
223223
224224
Returns a new array filled with `fill_value` and having the same `shape` as an input array `x`.
225225
@@ -235,7 +235,7 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i
235235
236236
- **dtype**: _Optional\[ &lt;dtype&gt; ]_
237237
238-
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `x`. Default: `None`.
238+
- output array data type. If `dtype` is `None`, the output array data type must be inferred from `fill_value` (see {ref}`function-full`). Default: `None`.
239239
240240
- **device**: _Optional\[ &lt;device&gt; ]_
241241
@@ -248,7 +248,7 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i
248248
- an array having the same shape as `x` and where every element is equal to `fill_value`.
249249
250250
(function-linspace)=
251-
### linspace(start, stop, num, /, *, dtype=None, device=None, endpoint=True)
251+
### linspace(start, stop, /, num, *, dtype=None, device=None, endpoint=True)
252252
253253
Returns evenly spaced numbers over a specified interval.
254254
@@ -321,7 +321,7 @@ Returns coordinate matrices from coordinate vectors.
321321
The returned arrays must have a numeric data type determined by {ref}`type-promotion`.
322322
323323
(function-ones)=
324-
### ones(shape, /, *, dtype=None, device=None)
324+
### ones(shape, *, dtype=None, device=None)
325325
326326
Returns a new array having a specified `shape` and filled with ones.
327327
@@ -371,7 +371,7 @@ Returns a new array filled with ones and having the same `shape` as an input arr
371371
- an array having the same shape as `x` and filled with ones.
372372
373373
(function-zeros)=
374-
### zeros(shape, /, *, dtype=None, device=None)
374+
### zeros(shape, *, dtype=None, device=None)
375375
376376
Returns a new array having a specified `shape` and filled with zeros.
377377

spec/API_specification/data_type_functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Broadcasts one or more arrays against one another.
2525
- a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.
2626

2727
(function-broadcast_to)=
28-
### broadcast_to(x, shape, /)
28+
### broadcast_to(x, /, shape)
2929

3030
Broadcasts an array to a specified shape.
3131

spec/API_specification/data_types.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
77
A conforming implementation of the array API standard must provide and support the following data types.
88

9-
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`), as well as a default data type for an array index (either `int32` or `int64`).
9+
A conforming implementation of the array API standard must define a default floating-point data type (either `float32` or `float64`), as well as a default integer data type (`int32` or `int64`). These default data types must be the same across platforms. The default integer data type may vary depending on whether Python is 32-bit or 64-bit.
1010

1111
```{note}
12-
1312
The default floating-point and array index integer data types should be clearly defined in a conforming library's documentation.
1413
```
1514

spec/API_specification/manipulation_functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Joins a sequence of arrays along an existing axis.
3939
```
4040
4141
(function-expand_dims)=
42-
### expand_dims(x, axis, /)
42+
### expand_dims(x, /, *, axis)
4343
4444
Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by `axis`.
4545
@@ -81,7 +81,7 @@ Reverses the order of elements in an array along the given axis. The shape of th
8181
- an output array having the same data type and shape as `x` and whose elements, relative to `x`, are reordered.
8282
8383
(function-reshape)=
84-
### reshape(x, shape, /)
84+
### reshape(x, /, shape)
8585
8686
Reshapes an array without changing its data.
8787
@@ -102,7 +102,7 @@ Reshapes an array without changing its data.
102102
- an output array having the same data type, elements, and underlying element order as `x`.
103103
104104
(function-roll)=
105-
### roll(x, shift, /, *, axis=None)
105+
### roll(x, /, shift, *, axis=None)
106106
107107
Rolls array elements along a specified axis. Array elements that roll beyond the last position are re-introduced at the first position. Array elements that roll beyond the first position are re-introduced at the last position.
108108

spec/API_specification/set_functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ Returns the unique elements of an input array `x`.
5151
5252
- **indices**: _&lt;array&gt;_
5353
54-
- an array containing the indices (first occurrences) of `x` that result in `unique`. The returned array must have the default array index data type.
54+
- an array containing the indices (first occurrences) of `x` that result in `unique`. The returned array must have the default integer data type.
5555
5656
- **inverse**: _&lt;array&gt;_
5757
58-
- an array containing the indices of `unique` that reconstruct `x`. The returned array must have the default array index data type.
58+
- an array containing the indices of `unique` that reconstruct `x`. The returned array must have the default integer data type.
5959
6060
- **counts**: _&lt;array&gt;_
6161

0 commit comments

Comments
 (0)