[SciPy-dev] Suppressing of numpy __mul__, __div__ etc
Dag Sverre Seljebotn
Thu Dec 17 03:45:49 CST 2009
Sebastian Walter wrote:
> I have also implemented/wrapped various automatic differentiation
> tools in python
> (http://github.com/b45ch1/algopy , http://github.com/b45ch1/pyadolc,
> http://github.com/b45ch1/pycppad if someone is interested)
> and I have also come across some numpy glitches and inconsistencies.
> However, this particular problem I have not encountered. I'm not sure
> I understand the rationale why an expression like numpy.array([1,2] *
> oofun(1) should call the oofun.__rmul__ operator.
> Hence, I'm a little sceptical about this enhancement.
> What is wrong with the following implementation? It works perfectly fine...
Well, if you feel that way, then simply don't use this feature. This
just leads to more flexibility for writers of libraries which depend on
The suggestion isn't really inconsistent with Python. Even if it is true
that left-mul takes precedence in Python, it is NOT common that an
object handles all arithmetic operations whether they make sense or not. So
2 * MyClassWhichKnowsAboutPythonIntegers()
works, because the "2" doesn't try to do anything and rmul is called!
NumPy is special because rmul never gets called with NumPy arrays, which
can be quite inconvenient at times.
More information about the SciPy-Dev