[Numpy-discussion] is __array_ufunc__ ready for prime-time?

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Thu Nov 2 17:05:08 EDT 2017


My 2¢ here is that all code should feel free to assume certain type of
input, as long as it is documented properly, but there is no reason to
enforce that by, e.g., putting `asarray` everywhere. Then, for some
pieces ducktypes and subclasses will just work like magic, and uses
you might never have foreseen become possible. For others, whoever
wants to use them has to do work (and up to a package maintainers to
decide whether or not to accept PRs that implement hooks, etc.)

I do see the argument that this way one becomes constrained in the
internal implementation, as a change may break an outward-looking
function, but while at times this may be inconvenient, in my
experience at others it may just make one realize an even better
implementation is possible. But then, I really like duck-typing...

-- Marten


More information about the NumPy-Discussion mailing list