Commit 91c4e25
committed
feat(array-api): add cumulative_sum and cumulative_prod
These are the Array API standard equivalents of cumsum/cumprod with
three key differences that justify the separate names:
1. axis=None (default) flattens the input first; cumsum/cumprod require
an explicit axis.
2. include_initial=True prepends the identity element (0 for sum, 1 for
prod) so the output length along axis is len+1. This matches the
Array API spec's include_initial parameter and has no equivalent in
cumsum/cumprod.
3. dtype parameter casts the input before accumulating, matching NumPy
2.0 / Array API behaviour.
Docs and tests included.
Part of the array API split from ml-explore#3684.1 parent 602b535 commit 91c4e25
3 files changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5874 | 5874 | | |
5875 | 5875 | | |
5876 | 5876 | | |
| 5877 | + | |
| 5878 | + | |
| 5879 | + | |
| 5880 | + | |
5877 | 5881 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3446 | 3446 | | |
3447 | 3447 | | |
3448 | 3448 | | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
3449 | 3471 | | |
3450 | 3472 | | |
3451 | 3473 | | |
0 commit comments