array-api
array-api copied to clipboard
RFC: add support for computing the cumulative product to the standard
This RFC requests to include a new API in the array API specification for the purpose of computing the cumulative product.
Overview
Based on array comparison data, the API is available in the majority of the libraries in the PyData ecosystem.
Prior art
- NumPy: https://numpy.org/doc/stable/reference/generated/numpy.cumprod.html
- PyTorch: https://pytorch.org/docs/stable/generated/torch.cumprod.html
- MXNet: https://mxnet.apache.org/versions/master/api/python/docs/api/np/generated/mxnet.np.cumprod.html
- TensorFlow: https://www.tensorflow.org/api_docs/python/tf/math/cumprod
Proposal:
def cumprod(x: array, /, *, axis: Optional[int] = None, dtype: Optional[dtype] = None) -> array
-
dtypekwarg is for consistency withsumet al
cc @oleksandr-pavlyk
@steff456 for the axis kwarg, this should be limited to just an int and not a Tuple. Based on the various docs, libraries seem to only support an int.
One thing to note is that PyTorch, e.g., requires an axis argument and does not support NumPy's default behavior of computing the cumulative sum over the flattened array.