cumsum and cumprod modify the input array
See original GitHub issueWhile debugging a test failure in cupyimg
, I found that cupy.cumsum
unexpectedly modifies the input array. This did not used to be the case, so I suspect it may be due to recent changes from #4316 or #4366 (attn: @anaruse)
-
Conditions (you can just paste the output of
python -c 'import cupy; cupy.show_config()'
) CuPy 9.0.0a3 -
Code to reproduce
Here is a basic example to illustrate the issue:
a = cp.testing.shaped_arange((4, 4))
print(a)
b = np.cumsum(a, axis=1)
print(a) # a will now be equal to b (it was modified in-place)
array([[ 1., 2., 3., 4.], [ 5., 6., 7., 8.], [ 9., 10., 11., 12.], [13., 14., 15., 16.]], dtype=float32)
array([[ 1., 3., 6., 10.], [ 5., 11., 18., 26.], [ 9., 19., 30., 42.], [13., 27., 42., 58.]], dtype=float32)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Cumulative addition/multiplication in NumPy - Stack Overflow
Have a relatively simple block of code that loops through two arrays, multiplies, and adds cumulatively:
Read more >numpy.cumprod() in Python - GeeksforGeeks
numpy.cumprod() function is used when we want to compute the cumulative product of array elements over a given axis.
Read more >MATLAB cumprod - Cumulative product - MathWorks
This MATLAB function returns the cumulative product of A starting at the beginning of the first array dimension in A whose size does...
Read more >numpy.cumsum — NumPy v1.24 Manual
aarray_like. Input array. axisint, optional. Axis along which the cumulative sum is computed. The default (None) ...
Read more >cumsum: Cumulative Sums, Products, and Extremes - Rdrr.io
A vector of the same length and type as x (after coercion), except that cumprod returns a numeric vector for integer input (for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My environment was set to
CUPY_ACCELERATORS=cub,cutensor
when I encountered thisI guess the bug is this line (from #4316): https://github.com/cupy/cupy/blob/3388dcec8c939eb01baecb2a0459e4116db05b1d/cupy/core/_routines_math.pyx#L742
copy
should beTrue
.