Skip to content

Commit

Permalink
Add apidoc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Apr 15, 2024
1 parent 0041e34 commit 580461b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
36 changes: 35 additions & 1 deletion cubed/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,41 @@ def groupby_reduction(
num_groups=None,
extra_func_kwargs=None,
) -> "Array":
"""A reduction that performs groupby aggregations."""
"""A reduction that performs groupby aggregations.
Parameters
----------
x: Array
Array being grouped along one axis.
by: Array
Array of non-negative integers to be used as labels with which to group
the values in ``x`` along the reduction axis. Must be a 1D array.
func: callable
Function to apply to each chunk of data before reduction.
combine_func: callable
Function which may be applied recursively to intermediate chunks of
data. The number of chunks that are combined in each round is
determined by the ``split_every`` parameter. The output of the
function is a chunk with size ``num_groups`` along the reduction axis.
aggregate_func: callable, optional
Function to apply to each of the final chunks to produce the final output.
axis: int or sequence of ints, optional
Axis to aggregate along. Only supports a single axis.
intermediate_dtype: dtype
Data type of intermediate output.
dtype: dtype
Data type of output.
keepdims: boolean, optional
Whether the reduction function should preserve the reduced axes,
or remove them.
split_every: int >= 2 or dict(axis: int), optional
The number of chunks to combine in one round along each axis in the
recursive aggregation.
num_groups: int
The number of groups in the grouping array ``by``.
extra_func_kwargs: dict, optional
Extra keyword arguments to pass to ``func`` and ``combine_func``.
"""

if isinstance(axis, tuple):
if len(axis) != 1:
Expand Down
47 changes: 43 additions & 4 deletions cubed/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,41 @@ def reduction_new(
combine_sizes=None,
extra_func_kwargs=None,
) -> "Array":
"""Apply a function to reduce an array along one or more axes."""
"""Apply a function to reduce an array along one or more axes.
Parameters
----------
x: Array
Array being reduced along one or more axes.
func: callable
Function to apply to each chunk of data before reduction.
combine_func: callable, optional
Function which may be applied recursively to intermediate chunks of
data. The number of chunks that are combined in each round is
determined by the ``split_every`` parameter. The output of the
function is a chunk with size one (or the size specified in
``combine_sizes``) in each of the reduction axes. If omitted,
it defaults to ``func``.
aggregate_func: callable, optional
Function to apply to each of the final chunks to produce the final output.
axis: int or sequence of ints, optional
Axis or axes to aggregate upon. If omitted, aggregate along all axes.
intermediate_dtype: dtype
Data type of intermediate output.
dtype: dtype
Data type of output.
keepdims: boolean, optional
Whether the reduction function should preserve the reduced axes,
or remove them.
split_every: int >= 2 or dict(axis: int), optional
The number of chunks to combine in one round along each axis in the
recursive aggregation.
combine_sizes: dict(axis: int), optional
The resulting size of each axis after reduction. Each reduction axis
defaults to size one if not specified.
extra_func_kwargs: dict, optional
Extra keyword arguments to pass to ``func`` and ``combine_func``.
"""
if combine_func is None:
if func is None:
raise ValueError(
Expand Down Expand Up @@ -1138,13 +1172,18 @@ def partial_reduce(
Array being reduced along one or more axes
func: callable
Reduction function to apply to each chunk of data, resulting in a chunk
with size one in each of the reduction axes.
with size one (or the size specified in ``combine_sizes``) in each of
the reduction axes.
initial_func: callable, optional
Function to apply to each chunk of data before reduction.
split_every: int >= 2 or dict(axis: int), optional
The depth of the recursive aggregation.
dtype: DType
The number of chunks to combine in one round along each axis in the
recursive aggregation.
dtype: dtype
Output data type.
combine_sizes: dict(axis: int), optional
The resulting size of each axis after reduction. Each reduction axis
defaults to size one if not specified.
"""
# map over output chunks
axis = tuple(ax for ax in split_every.keys())
Expand Down

0 comments on commit 580461b

Please sign in to comment.