Skip to content

Commit 2257725

Browse files
committed
Add specification for asarray
Closes data-apisgh-122
1 parent 014cef6 commit 2257725

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spec/API_specification/creation_functions.md

+36
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ This function cannot guarantee that the interval does not include the `stop` val
4949

5050
- a one-dimensional array containing evenly spaced values. The length of the output array must be `ceil((stop-start)/step)`.
5151

52+
53+
(function-asarray)=
54+
### asarray(obj, /, *, dtype=None, device=None, copy=False)
55+
56+
Convert the input to an array.
57+
58+
#### Parameters
59+
60+
- **obj**: _Union\[ float, NestedSequence\[ bool | int | float ], SupportsDLPack, SupportsBufferProtocol, memoryview ]_
61+
62+
- Object to be converted to an array. Can be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting DLPack or the Python buffer protocol.
63+
64+
:::{tip}
65+
An object supporting DLPack has `__dlpack__` and `__dlpack_device__` methods.
66+
An object supporting the buffer protocol can be turned into a memoryview through `memoryview(obj)`.
67+
:::
68+
69+
- **dtype**: _Optional\[ <dtype> ]_
70+
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`.
72+
73+
- **device**: _Optional\[ <device> ]_
74+
75+
- device to place the created array on, if given. Default: `None`.
76+
77+
- **copy**: _bool_
78+
79+
- Whether or not to make a copy of the input. If `True`, always copies. If `False`, reuses existing memory buffer if possible. Default: `False`.
80+
81+
#### Returns
82+
83+
- **out**: _<array>_
84+
85+
- An array containing the data from `obj`.
86+
87+
5288
(function-empty)=
5389
### empty(shape, /, *, dtype=None, device=None)
5490

0 commit comments

Comments
 (0)