[Numpy-discussion] Scalar-ndarray arguments passed to not_equal

Friedrich Romstedt friedrichromstedt at gmail.com
Thu Feb 11 16:12:18 EST 2010


2010/2/11  <josef.pktd at gmail.com>:
> If this is global it won't work, because only the last package that
> changes it wins. ??

Hm, at the current implementation of upy you're right, but I think you
can do in the resp. module like:

original_numpy_ops = numpy.set_numeric_ops()

[ ... implementation of my_add_object, calling
original_numpy_ops['add'] when it doesn't know what to do else ... ]

new_numpy_ops = copy.copy(original_numpy_ops)
new_numpy_ops['add'] = my_add_object

numpy.set_numeric_ops(new_numpy_ops)

When you code your my_add_object in such a way that it only act on the
special case you want to hande, e.g.:

class MyAddClass:
    __call__(self, a, b, *args, **kwargs):
        if isinstance(b, MyClass):
            [ ... do something special, preferring MyClass.__radd__
for instance ... ]
        else:
            return original_numpy_ops['add'](a, b, *args, **kwargs)
    [ ... some speciality left out ... ]

my_add_object = MyAddClass()

then even many packages may not interfere, given that they are in
principle compatible.  But as mentioned before, coercion will fail if
the functionality isn't implemented which would coerce the objects ...

Friedrich



More information about the NumPy-Discussion mailing list