[SciPy-dev] Suppressing of numpy __mul__, __div__ etc

josef.pktd at gmail.com josef.pktd at gmail.com
Sat Dec 12 17:06:15 EST 2009


On Sat, Dec 12, 2009 at 4:52 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
> On Sat, Dec 12, 2009 at 2:16 PM, Robert Kern <robert.kern at gmail.com> wrote:
>
> <snip>
>
>>
>> I think what he is asking for is an empty mixin class which other
>> folks could subclass to mark their classes. It would say "Hey,
>> ndarray! Let my __mul__, __rmul__, etc., take priority over yours,
>> regardless of which of us comes first in the expression." Otherwise,
>> ndarray will gladly consume pretty much any object on the other side
>> of the operator because it will treat it as an object scalar.
>>
>> We could also define a standard attribute that could mark
>>
>> such classes
>> instead of requiring a mixin subclass.
>>
>
> Ah, I completely misunderstood. Nevermind...
>
> I think such a mixin base class would be useful.

In a similar direction, I was recently thinking whether it would be
possible to get an attribute or some indication for classes that
implement a similar interface as numpy.arrays, i.e. same list of
methods. This would make it easier to write functions for any kind of
ducks.

Instead of converting with np.array or np.asarray, we could check
whether the instances in the function arguments implement the required
interface, and if yes just use the methods without converting to
arrays.
I would rule out matrices in this because it changes the meaning of
the multiplication completely.

I don't know whether this could be handled by a mixin class. ?

Josef

> Chuck
>
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>



More information about the SciPy-Dev mailing list