numpy.dot gives wrong results with floats?
Hi folks, I'm using numpy 0.95 and came across an odd error with numpy.dot and degenerate 2D floatingpoint arrays. See below for an illustration. In [1]: import numpy In [2]: numpy.version.version Out[2]: '0.9.5' In [3]: numpy.dot([[5]],[[1,1,1]]) # 2D int case OK Out[3]: array([[5, 5, 5]]) In [4]: numpy.dot([[5.]],[[1,1,1]]) # 2D float case: what??? Out[4]: array([[ 5.00000000e+000, 4.46601253e316, 5.42111867e306]]) In [5]: numpy.dot([5.],[1,1,1]) # 1D float case OK Out[5]: array([ 5., 5., 5.]) In [6]: numpy.dot([[[5.]]],[[[1,1,1]]]) # 3D float case OK Out[6]: array([[[[ 5., 5., 5.]]]]) Zach
Em Qua, 20060301 às 01:05 0800, Zachary Pincus escreveu:
In [4]: numpy.dot([[5.]],[[1,1,1]]) # 2D float case: what??? Out[4]: array([[ 5.00000000e+000, 4.46601253e316, 5.42111867e306]])
It seems fixed in the repository In [1]:import numpy In [2]:numpy.dot([[5]],[[1,1,1]]) # 2D int case OK Out[2]:array([[5, 5, 5]]) In [3]:numpy.dot([[5.]],[[1,1,1]]) # 2D float case: what??? Out[3]:array([[ 5., 5., 5.]]) In [4]:numpy.version.version Out[4]:'0.9.6.2179' Best, Paulo
Is there a test for this in the test suite.? It looks really bad for numpy if ppl cant do matrix multiplication properly on released versions. :( J. On 3/1/06, Paulo Jose da Silva e Silva <pjssilva@ime.usp.br> wrote:
Em Qua, 20060301 às 01:05 0800, Zachary Pincus escreveu:
In [4]: numpy.dot([[5.]],[[1,1,1]]) # 2D float case: what??? Out[4]: array([[ 5.00000000e+000, 4.46601253e316, 5.42111867e306]])
It seems fixed in the repository
In [1]:import numpy
In [2]:numpy.dot([[5]],[[1,1,1]]) # 2D int case OK Out[2]:array([[5, 5, 5]])
In [3]:numpy.dot([[5.]],[[1,1,1]]) # 2D float case: what??? Out[3]:array([[ 5., 5., 5.]])
In [4]:numpy.version.version Out[4]:'0.9.6.2179'
Best,
Paulo
 This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.asus.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Numpydiscussion mailing list Numpydiscussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpydiscussion
Jonathan Taylor wrote:
Is there a test for this in the test suite.? It looks really bad for numpy if ppl cant do matrix multiplication properly on released versions. :(
There are tests for matrix multiplication, just not one for this particular path through the code which is scalar multiplication by a row vector. (This is the optimized _dotblas.c code by the way which was just changed in 0.9.5 to try and make it faster  obviously some bugs crept in at the same time). But, these bugs were quickly fixed when they were made apparent. That's why we are still not at 1.0 yet. Feel free to contribute more tests. Travis
On 3/1/06, Travis Oliphant <oliphant.travis@ieee.org> wrote:
... Feel free to contribute more tests.
There are some things that we can do to help users contribute tests. Before I make specific suggestions, let me just express an opinion that developers are less likely to write effective tests than users because they tend to overlook in testing exactly the same cases that they get wrong in coding. Here are the things that we can do: 1. Documentation. Tell users how to submit bug reports that can be immediately converted into unit tests. 2. Improve NumpyTest: add facilities to generate test data with various shapes and datatypes and filled with wide range of values: extremely large/small numbers, IEEE special values, etc. Add routines to automatically test universal functions on all datatypes. Automate consistency checks  when appropriate check that computations on different datatypes produce similar results. 3. Add support for doctests. This is probably the simplest type of test that a user can produce  just cut and paste from python session. Doctests can be placed in separate files and don't need to clutter real documentation. Python 2.4 contains code integrating doctests and unit tests and that code has 95% of what is needed. If we have to support 2.3, it may be appropriate to distribute a backport with numpy. The remaining 5% include support for ipython sessions, maybe better output checking for printed arrays (such as scan through to a closing paren rather than an empty line etc.). Any volunteers? I guess the first step would be to put up a wiki page. Since this is really a developers/advanced users project it belongs to the "hard hat" area.
On Wed, Mar 01, 2006 at 02:28:28PM 0500, Sasha wrote:
On 3/1/06, Travis Oliphant <oliphant.travis@ieee.org> wrote:
... Feel free to contribute more tests.
3. Add support for doctests. This is probably the simplest type of test that a user can produce  just cut and paste from python session. Doctests can be placed in separate files and don't need to clutter real documentation. Python 2.4 contains code integrating doctests and unit tests and that code has 95% of what is needed. If we have to support 2.3, it may be appropriate to distribute a backport with numpy. The remaining 5% include support for ipython sessions, maybe better output checking for printed arrays (such as scan through to a closing paren rather than an empty line etc.).
Already there. See the tests in numpy/lib/tests/test_polynomial.py  >\/< /\ David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ cookedm@physics.mcmaster.ca
participants (6)

David M. Cooke

Jonathan Taylor

Paulo Jose da Silva e Silva

Sasha

Travis Oliphant

Zachary Pincus