viennacl / pyviennacl-dev

Developer repository for PyViennaCL. Visit http://viennacl.sourceforge.net/ for latest releases.
MIT License
32 stars 6 forks source link

Problem with dot product #13

Closed unicolyon closed 10 years ago

unicolyon commented 10 years ago

Hi,

There is a weird bug with the matrix/vector dot product. When I multiply a nxm-matrix with a m-vector, I obtain a m vector as a result (instead of a n-vector). Ie when m<n I do not have all values (but the one I have are right) and when m>n, I get extra 0. I suppose this is only a problem of reshaping at some point.

Best,

tsmithe commented 10 years ago

Hi, this is indeed weird. I can't reproduce it with the following test code, so can you provide an example?

>>> import pyviennacl as p
>>> a = p.Matrix(10, 8, 2.0) # 10 x 8 matrix
>>> b = p.Vector(8, 5.0)     # 8 vector
>>> a*b
array([ 80.,  80.,  80.,  80.,  80.,  80.,  80.,  80.])
>>> len((a*b).value)
8
unicolyon commented 10 years ago

This test code provides me exactly what you mentioned. But if you test 'numpy.dot(a.value,b.value).shape' you will get '(10,)' So there is a bug in the library or in my understanding of the '' function. Is '' not equivalent to numpy.dot?

tsmithe commented 10 years ago

No, you're right and I misunderstood the original report. There is a bug in the code that determines the shape of the result object, and this is missed by the test suite since the test suite matrices are square. Thanks! I'll upload a fix tomorrow. In the meantime, you can work around this by explicitly specifying the size of the result object. Something like

>>> c = p.Assign(p.Vector(a.shape[0], dtype=a.dtype), p.Mul(a, b)).result

ought to do the trick.

tsmithe commented 10 years ago

Should be fixed in master bf3aa2b -- can you confirm?

unicolyon commented 10 years ago

I just tested the example of your first post and now I get a length of 10 as expected. Thx.

tsmithe commented 10 years ago

Great -- thanks for the report! Please don't hesitate to request features as well.