Skip to content

Move broadcast functions to list of functions for manipulating arrays #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions spec/API_specification/data_type_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Objects in API
:template: method.rst

astype
broadcast_arrays
broadcast_to
can_cast
finfo
iinfo
Expand Down
2 changes: 2 additions & 0 deletions spec/API_specification/manipulation_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Objects in API
:toctree: generated
:template: method.rst

broadcast_arrays
broadcast_to
concat
expand_dims
flip
Expand Down
36 changes: 2 additions & 34 deletions spec/API_specification/signatures/data_type_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._types import List, Tuple, Union, array, dtype, finfo_object, iinfo_object
from ._types import Union, array, dtype, finfo_object, iinfo_object

def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array:
"""
Expand Down Expand Up @@ -27,38 +27,6 @@ def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array:
an array having the specified data type. The returned array must have the same shape as ``x``.
"""

def broadcast_arrays(*arrays: array) -> List[array]:
"""
Broadcasts one or more arrays against one another.

Parameters
----------
arrays: array
an arbitrary number of to-be broadcasted arrays.

Returns
-------
out: List[array]
a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.
"""

def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array:
"""
Broadcasts an array to a specified shape.

Parameters
----------
x: array
array to broadcast.
shape: Tuple[int, ...]
array shape. Must be compatible with ``x`` (see :ref:`broadcasting`). If the array is incompatible with the specified shape, the function should raise an exception.

Returns
-------
out: array
an array having a specified shape. Must have the same data type as ``x``.
"""

def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool:
"""
Determines if one data type can be cast to another data type according :ref:`type-promotion` rules.
Expand Down Expand Up @@ -156,4 +124,4 @@ def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype:
the dtype resulting from an operation involving the input arrays and dtypes.
"""

__all__ = ['astype', 'broadcast_arrays', 'broadcast_to', 'can_cast', 'finfo', 'iinfo', 'result_type']
__all__ = ['astype', 'can_cast', 'finfo', 'iinfo', 'result_type']
34 changes: 33 additions & 1 deletion spec/API_specification/signatures/manipulation_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
from ._types import List, Optional, Tuple, Union, array

def broadcast_arrays(*arrays: array) -> List[array]:
"""
Broadcasts one or more arrays against one another.

Parameters
----------
arrays: array
an arbitrary number of to-be broadcasted arrays.

Returns
-------
out: List[array]
a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.
"""

def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array:
"""
Broadcasts an array to a specified shape.

Parameters
----------
x: array
array to broadcast.
shape: Tuple[int, ...]
array shape. Must be compatible with ``x`` (see :ref:`broadcasting`). If the array is incompatible with the specified shape, the function should raise an exception.

Returns
-------
out: array
an array having a specified shape. Must have the same data type as ``x``.
"""

def concat(arrays: Union[Tuple[array, ...], List[array]], /, *, axis: Optional[int] = 0) -> array:
"""
Joins a sequence of arrays along an existing axis.
Expand Down Expand Up @@ -146,4 +178,4 @@ def stack(arrays: Union[Tuple[array, ...], List[array]], /, *, axis: int = 0) ->
This specification leaves type promotion between data type families (i.e., ``intxx`` and ``floatxx``) unspecified.
"""

__all__ = ['concat', 'expand_dims', 'flip', 'permute_dims', 'reshape', 'roll', 'squeeze', 'stack']
__all__ = [ 'broadcast_arrays', 'broadcast_to', 'concat', 'expand_dims', 'flip', 'permute_dims', 'reshape', 'roll', 'squeeze', 'stack']