diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-08-04 16:47:05 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-08-04 16:50:30 -0600 |
commit | 6e57d829cb6628610e163524f203245b247a2839 (patch) | |
tree | f15f4900f995835bbd8526d7a4918a4d776d63e2 /numpy/array_api/_manipulation_functions.py | |
parent | 1596415c32f6008fcacc14a3a5394787aeb44265 (diff) | |
download | numpy-6e57d829cb6628610e163524f203245b247a2839.tar.gz |
Rename numpy._array_api to numpy.array_api
Instead of the leading underscore, the experimentalness of the module will be
indicated by omitting a warning on import. That we, we do not have to change
the API from underscore to no underscore when the module is no longer
experimental.
Diffstat (limited to 'numpy/array_api/_manipulation_functions.py')
-rw-r--r-- | numpy/array_api/_manipulation_functions.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/numpy/array_api/_manipulation_functions.py b/numpy/array_api/_manipulation_functions.py new file mode 100644 index 000000000..fa6344beb --- /dev/null +++ b/numpy/array_api/_manipulation_functions.py @@ -0,0 +1,71 @@ +from __future__ import annotations + +from ._array_object import Array +from ._data_type_functions import result_type + +from typing import List, Optional, Tuple, Union + +import numpy as np + +# Note: the function name is different here +def concat(arrays: Union[Tuple[Array, ...], List[Array]], /, *, axis: Optional[int] = 0) -> Array: + """ + Array API compatible wrapper for :py:func:`np.concatenate <numpy.concatenate>`. + + See its docstring for more information. + """ + arrays = tuple(a._array for a in arrays) + # Call result type here just to raise on disallowed type combinations + result_type(*arrays) + return Array._new(np.concatenate(arrays, axis=axis)) + +def expand_dims(x: Array, /, *, axis: int) -> Array: + """ + Array API compatible wrapper for :py:func:`np.expand_dims <numpy.expand_dims>`. + + See its docstring for more information. + """ + return Array._new(np.expand_dims(x._array, axis)) + +def flip(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: + """ + Array API compatible wrapper for :py:func:`np.flip <numpy.flip>`. + + See its docstring for more information. + """ + return Array._new(np.flip(x._array, axis=axis)) + +def reshape(x: Array, /, shape: Tuple[int, ...]) -> Array: + """ + Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`. + + See its docstring for more information. + """ + return Array._new(np.reshape(x._array, shape)) + +def roll(x: Array, /, shift: Union[int, Tuple[int, ...]], *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: + """ + Array API compatible wrapper for :py:func:`np.roll <numpy.roll>`. + + See its docstring for more information. + """ + return Array._new(np.roll(x._array, shift, axis=axis)) + +def squeeze(x: Array, /, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: + """ + Array API compatible wrapper for :py:func:`np.squeeze <numpy.squeeze>`. + + See its docstring for more information. + """ + return Array._new(np.squeeze(x._array, axis=axis)) + +def stack(arrays: Union[Tuple[Array, ...], List[Array]], /, *, axis: int = 0) -> Array: + """ + Array API compatible wrapper for :py:func:`np.stack <numpy.stack>`. + + See its docstring for more information. + """ + arrays = tuple(a._array for a in arrays) + # Call result type here just to raise on disallowed type combinations + result_type(*arrays) + return Array._new(np.stack(arrays, axis=axis)) |