Add support for subclassing cupy.ndarray
See original GitHub issueHi!
Many projects (including mine) use subclasses of numpy.ndarray, like this:
class Field(np.ndarray):
def __new__(cls, data, prefix=1):
data = np.asarray(data)
field = data.view(cls)
field.prefix = prefix
return field
def __array_finalize__(self, field):
if field is None:
return
self.prefix = getattr(field, 'prefix', 1)
If one tries to use cupy.ndarray as a numpy replacement, then at creation of the Field
instance an error is raised:
AttributeError: 'cupy.core.core.ndarray' object has no attribute 'prefix'
Are there plans to support in cupy subclassing similar to numpy approach? Maybe some workarounds are possible currently?
Regards, Marek
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:15 (14 by maintainers)
Top Results From Across the Web
How to subclass a CuPy array? - python
According to the documentation of numpy.ndarray.view, it takes two input arguments: dtype and type . If the dtype argument is a subclass of ......
Read more >cupy.asanyarray — CuPy 11.4.0 documentation
Converts an object to array. This is currently equivalent to cupy.asarray() , since there is no subclass of cupy.ndarray in CuPy. Note that...
Read more >ndarray subclass not preserved by real/imag · Issue #6887
Hi, just a small bug. I was testing v11.0.0rc1 as I was interested in ndarray subclassing. I noticed that the real and imag...
Read more >Standard array subclasses — NumPy v1.23 Manual
Subclassing a numpy.ndarray is possible but if your goal is to create an array with modified behavior, as do dask arrays for distributed...
Read more >CuPy Documentation
Supports the semantics identical to numpy.ndarray, including basic ... This requirement is optional if you install CuPy from conda-forge.
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 Free
Top 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
I’m trying to realize cupy.ndarray subclassing by workaround1 in the gist The following TODO is for managing its progress.
Yes.