[Numpy-discussion] Asking for opinions: Priops

Dag Sverre Seljebotn dagss@student.matnat.uio...
Thu Sep 23 10:11:41 CDT 2010

Friedrich Romstedt wrote:
> I just ran across the problem of priorities with ndarrays again and it
> keeps biting me.  I did once ago a workaround to get my ``undarray``
> class's methods be called when being the second operand of e.g.
> <ndarray> + <undarray>.  But since I wrote it, always Python crashes
> on exit with the message:
> Python-32(68665) malloc: *** error for object 0x239680: incorrect
> checksum for freed object - object was probably modified after being
> freed.
> *** set a breakpoint in malloc_error_break to debug
> (Of course only if I imported the module.  Occasionally I also
> observed Bus errors, and even segfaults.)
> I overloaded the numpy ops via numpy.set_numeric_ops() with
> self-written classes, which are *not* derived from numpy.ufunc, and do
> not resemble numpy ufuncs completely.
> So I want to do it properly this time.
> I therefore started with writing a Letter of Intent, and put it online
> on http://github.com/friedrichromstedt/priops .
> Opinions?
I haven't had time to go into the details, but I love the fact that 
somebody is about to deal with this problem, it's been bothering me as well.

Something that is slightly related that one might as well test is the 
Sage coercion model. If you haven't, you may want to see if you get 
anything useful out of http://wiki.sagemath.org/coercion.

Essentially, perhaps what you have sketched up + an ability to extend 
the graph with object conversion routes would be perfect for my own 
uses. So you can define a function with overloads (A, B) and (A, C), but 
also that objects of type D can be converted to C (and how). For 
instance, consider:

np.array([1,2,3]) + [1,2,3]

Here, list-> array could be handled through a defined coercion to array, 
rather than having to add an overload for list for every method taking 
an array.

Dag Sverre

More information about the NumPy-Discussion mailing list