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

James Bergstra james.bergstra@gmail....
Thu Dec 17 15:27:27 CST 2009

I develop another symbolic-over-numpy package called theano, and
somehow we avoid this problem.

In [1]: import theano

In [2]: import numpy

In [3]: numpy.ones(4) * theano.tensor.dmatrix()
Out[3]: Elemwise{mul,no_inplace}.0

In [4]: theano.tensor.dmatrix() * theano.tensor.dmatrix()
Out[4]: Elemwise{mul,no_inplace}.0

In [5]: theano.tensor.dmatrix() * numpy.ones(4)
Out[5]: Elemwise{mul,no_inplace}.0

The dmatrix() function returns an instance of the TensorVariable class
defined in this file:

I think the only thing we added  for numpy was __array_priority__ =
1000, which has already been suggested here.  I'm confused by why this
thread goes on.


2009/12/17 Dmitrey <tmp50@ukr.net>:
> От кого: Sebastian Walter <sebastian.walter@gmail.com>
> let me rephrase then. I don't understand why p * ones(2) should give
> Polynomial([ 0., 1., 1.], [-1., 1.]).
> A polynomial over the reals is a data type with a ring structure and
> should therefore behave "similarly" to floats IMHO.
> Since I'm not a numpy developer, I cannot give you irrefutable answer, but I
> guess it is much more useful for numpy users that are mostly engineering
> programmers, not researchers of a data type with a ring structure.
> Also, this is not only up to polynomials - as it has been mentioned, this
> issue is important for stacking with SAGE data types, oofuns etc, where
> users certainly want to get same type instead of an ndarray.
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev


More information about the SciPy-Dev mailing list