thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

dot() non-symmetrical for scalar*matrix of objects (Trac #1876) #5674

Open numpy-gitbot opened 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1876 on 2011-06-21 by atmention:lebigot, assigned to unknown.

NumPy's dot() function has a non-symmetrical behavior for scalar multipliers, when one of the objects is a matrix of objects:

>>> arr = matrix([1, 2], dtype=object)
>>> dot(arr, 3)
matrix([[3, 6]], dtype=object)
>>> dot(3, arr)
NotImplemented

(My implementation of NumPy uses BLAS, but I think I remember also seeing this problem with the basic implementation.)

A consequence of this is the following failed simple multiplication:

>>> arr*3
matrix([[3, 6]], dtype=object)
>>> 3*arr
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'int' and 'matrix'

The final TypeError looks definitely like a bug. Mathematically, one also wants to have a symmetrical dot() product, for scalars (both dot(3, arr) and dot(arr, 3) should work), no? A symmetrical dot() product for matrices of objects would solve both problems.

numpy-gitbot commented 12 years ago

atmention:charris wrote on 2011-06-21

Confirmed in current development.