Add CuPy compress
See original GitHub issueWould be useful to have an compress
implementation for CuPy arrays.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
cupy.savez_compressed — CuPy 11.4.0 documentation
Saves one or more arrays into a file in compressed .npz format. It is equivalent to cupy.savez() function except the output file is...
Read more >cupy.append — CuPy 11.4.0 documentation
A copy of arr with values appended to axis . Note that append does not occur in-place: a new array is allocated and...
Read more >cupy.ndarray — CuPy 11.4.0 documentation
Returns selected slices of this array along given axis. Warning. This function may synchronize the device. See also. cupy.compress() for full documentation, ...
Read more >cupy.resize — CuPy 11.4.0 documentation
cupy.resize# ... Return a new array with the specified shape. If the new array is larger than the original array, then the new...
Read more >cupy.save — CuPy 11.4.0 documentation
cupy.save#. cupy.save(file, arr, allow_pickle=None)[source]#. Saves an array to a binary file in .npy format. Parameters.
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
Implementation can sometimes be tricky because you often need some familiarity with NumPy/C to determine what is going on there and then some familiarity with CUDA/C++ to be able to implement an equivalent function for CuPy.
In the case of
compress
, you could check whether maybe it can be implemented by adapting an existing function like_take
as defined in cupy/core/_routines_indexing.pyx. (NumPy’s compress ultimately calls PyArray_Compress)An easier, pure Python route is available in cases where a function can be defined in terms of other functions already implemented in CuPy. In the case of
compress
, it seems like the following the following might work:This is not computationally optimal as we have to call both
cupy.where
andcupy.take
instead of just a single underlying CUDA kernel, but it is better than nothing. I think a PR of that sort could potentially be accepted if good tests are added to make sure the functionality matches what is provided in NumPy.Tests would need to be added to the existing file
tests/cupy_tests/core_tests/test_ndarray_indexing.py
.Yep, it’s still open. Thanks for giving this a go Harshan 🙂