[Numpy-discussion] segfaults when passing ndarray subclass to ufunc with out=None

Darren Dale dsdale24@gmail....
Sun Feb 8 10:49:12 CST 2009

I am seeing some really strange behavior when I try to pass an ndarray
subclass and out=None to numpy's ufuncs. This example will reproduce the
problem with svn numpy, the first print statement yields 1 as expected, the
second yields  "<type 'builtin_function_or_method'>" and the third yields a
segmentation fault:

import numpy as np

class MyArray(np.ndarray):

    __array_priority__ = 20

    def __new__(cls):
        return np.asarray(1).view(cls).copy()

    def __repr__(self):
        return 'my_array'

    __str__ = __repr__

    def __mul__(self, other):
        return super(MyArray, self).__mul__(other)

    def __rmul__(self, other):
        return super(MyArray, self).__rmul__(other)

mine = MyArray()
print np.multiply(1, 1, None)
x = np.multiply(mine, mine, None)
print type(x)
print x

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090208/154cef92/attachment.html 

More information about the Numpy-discussion mailing list