[Numpy-discussion] Subclassing vs. dispatch

Israel, Daniel M dmi1 at lanl.gov
Fri Jan 15 13:38:27 EST 2021

I hope this is the right place to post this.

The numpy documentation talks about two methods for making ndarray-like objects, subclassing and dispatching, but it is not clear to me which one is most appropriate for which purpose.  Can someone provide, or point me to, some guidance, about this?  I’m particularly interested in what happens if there are multiple layers of subclassing.  Can you subclass from a subclass?  Dispatch from a dispatch?  Subclass from a dispatch and vice versa?

My specific application is a pair of classes, SpectralArray and PhysicalArray that uses numpy.fft to provides a to_physical() and to_spectral() method, respectively, to simplify writing pseudo-spectral codes.  Initially this will be serial, but the implementation will eventually use a mechanism similar to mpi4py-fft to allow the arrays to be distributed.  Further, it would be nice to be able to make the code interoperable with the cupy CUDA numpy implementation, so that the sub array on each MPI process could use GPU accelerated FFTs.

Advice?  Thanks.

Daniel M. Israel, Ph. D.
XCP-4: Methods & Algorithms
Mailstop F644
Los Alamos National Laboratory
505 665 5664<tel:505%20665%205664>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210115/eb0d9692/attachment.html>

More information about the NumPy-Discussion mailing list