[Numpy-discussion] Trouble subclassing ndarray

Sebastian Berg sebastian at sipsolutions.net
Fri Apr 10 13:43:50 EDT 2015


On Fr, 2015-04-10 at 11:40 -0500, Elliot Hallmark wrote:
> > You have a typo in your __array_finalize__ it misses the last
> underscore, that is probably why it is never called. About the
> infinite recursion, not sure on first sight.
> 
> Oh gosh, it was the underscrore!  infinite recursion no longer.  I was
> searching all over for a misspelled "_cacheable".
> 
> >Subclassing ndarray is almost always a bad idea (really it is always
> a bad idea, just sometimes you have absolutely no alternative), and
> multiple inheritance is almost always a bad idea (well, personally I
> think it actually always is a bad idea, but I recognize that opinions
> differ), and I am 99.999% sure that any design that can be described
> by the sentence quoted above is a design that you will look back on
> and regret.
> 
> 
> So, now that this works, I'm open to hear more about why this is an
> awful idea (if it is).  Why might I regret this later?  And will this
> add object creation overhead to every ufunc and slice or otherwise
> degrade performance?
> 

Performance wise it should not matter significantly, that is not the
problem.
However, know that you will never get it to work quite right with some
functionality. So if at some point you find a quirk and do not know how
to fix it.... It is quite likely there is no fix.
On the other hand, if you do not care much about losing your subclass
(i.e. getting a normal array) for some numpy functions, nor do weirder
things (messing with the shape or such) you are probably mostly fine.
For bigger projects I might still worry if it is the right path, but for
something more limited, maybe it is the simplest way to get to something
good enough.

- Sebastian

> 
> Thanks
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150410/45d7ccf4/attachment.sig>


More information about the NumPy-Discussion mailing list