question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cumsum and cumprod modify the input array

See original GitHub issue

While 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
grlee77commented, Dec 17, 2020

My environment was set to CUPY_ACCELERATORS=cub,cutensor when I encountered this

1reaction
leofangcommented, Dec 17, 2020
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found