From ff45a507d380792b1bb7bc9789c2721bcc72febd Mon Sep 17 00:00:00 2001 From: Nirkan Date: Mon, 19 Jan 2026 16:26:54 +0100 Subject: [PATCH 1/5] Adding cumulative_sum function. --- src/blosc2/ndarray.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 3a33c54c..bae23624 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -6370,3 +6370,35 @@ def mygen(i): for a in myarrs: out += (broadcast_to(a, shape),) return out + +def cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False): + """Array API cumulative_sum. + + Parameters + ---------- + x : array-like or NDArray + Input array. + axis : int or None + Axis along which to compute the cumulative sum. For ndim > 1, this + must be provided. Default: None (flatten). + dtype : dtype or None + Accumulator/output dtype. If None, follow type-promotion rules. + include_initial : bool, default False + If True, include the additive identity (zero) as the first value along + the reduced axis (output length N+1). + + Returns + ------- + NDArray + Array containing the cumulative sums. + """ + # Accept blosc2.NDArray or array-like + if isinstance(x, NDArray): + arr = x[:] # read into NumPy array + else: + arr = np.asarray(x) + + # Use NumPy's Array API compatible cumulative_sum function + res = np.cumulative_sum(arr, axis=axis, dtype=dtype, include_initial=include_initial) + + return blosc2.asarray(res) \ No newline at end of file From b7b49087c3059a7efccb3e3c4887803ad4bcd478 Mon Sep 17 00:00:00 2001 From: Nirkan Date: Mon, 19 Jan 2026 16:29:54 +0100 Subject: [PATCH 2/5] Adding cumulative_sum to ndarray import. --- src/blosc2/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blosc2/__init__.py b/src/blosc2/__init__.py index 12a2a908..d5824fec 100644 --- a/src/blosc2/__init__.py +++ b/src/blosc2/__init__.py @@ -433,6 +433,7 @@ def _raise(exc): full_like, save, stack, + cumulative_sum, ) from .embed_store import EmbedStore, estore_from_cframe from .dict_store import DictStore From 085625161929c3aff34b84516609aeac8cc1574e Mon Sep 17 00:00:00 2001 From: Nirkan Date: Mon, 19 Jan 2026 16:39:22 +0100 Subject: [PATCH 3/5] fix pre-commit ruff warning. --- src/blosc2/ndarray.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index bae23624..2a05157d 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -6371,6 +6371,7 @@ def mygen(i): out += (broadcast_to(a, shape),) return out + def cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False): """Array API cumulative_sum. @@ -6401,4 +6402,4 @@ def cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False): # Use NumPy's Array API compatible cumulative_sum function res = np.cumulative_sum(arr, axis=axis, dtype=dtype, include_initial=include_initial) - return blosc2.asarray(res) \ No newline at end of file + return blosc2.asarray(res) From 3d2139ce7a7c4b77f1ab987e04a310481eb81b42 Mon Sep 17 00:00:00 2001 From: Nirkan Date: Mon, 19 Jan 2026 17:10:30 +0100 Subject: [PATCH 4/5] Adding cumulative_prod function. --- src/blosc2/ndarray.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 2a05157d..00b2def6 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -6403,3 +6403,36 @@ def cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False): res = np.cumulative_sum(arr, axis=axis, dtype=dtype, include_initial=include_initial) return blosc2.asarray(res) + + +def cumulative_prod(x, /, *, axis=None, dtype=None, include_initial=False): + """Array API cumulative_prod. + + Parameters + ---------- + x : array-like or NDArray + Input array. + axis : int or None + Axis along which to compute the cumulative product. For ndim > 1, this + must be provided. Default: None (flatten). + dtype : dtype or None + Accumulator/output dtype. If None, follow type-promotion rules. + include_initial : bool, default False + If True, include the multiplicative identity (one) as the first value along + the reduced axis (output length N+1). + + Returns + ------- + NDArray + Array containing the cumulative products. + """ + # Accept blosc2.NDArray or array-like + if isinstance(x, NDArray): + arr = x[:] # read into NumPy array + else: + arr = np.asarray(x) + + # Use NumPy's Array API compatible cumulative_prod function + res = np.cumulative_prod(arr, axis=axis, dtype=dtype, include_initial=include_initial) + + return blosc2.asarray(res) From 04c44d4c00d86c1662d5933e5996b134b3fa87e3 Mon Sep 17 00:00:00 2001 From: Nirkan Date: Mon, 19 Jan 2026 17:11:19 +0100 Subject: [PATCH 5/5] Adding cumulative_prod to ndarray import. --- src/blosc2/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blosc2/__init__.py b/src/blosc2/__init__.py index d5824fec..c820e199 100644 --- a/src/blosc2/__init__.py +++ b/src/blosc2/__init__.py @@ -434,6 +434,7 @@ def _raise(exc): save, stack, cumulative_sum, + cumulative_prod, ) from .embed_store import EmbedStore, estore_from_cframe from .dict_store import DictStore