[Tutor] matrix-vector multiplication errors

Eike Welk eike.welk at post.rwth-aachen.de
Sat Feb 2 16:57:08 CET 2008


On Friday 01 February 2008 23:13, Dinesh B Vadhia wrote:
> I've posted this on the Scipy forum but maybe there are answers on
> Tutor too.  I'm performing a standard Scipy matrix* vector
> multiplication, b=Ax , (but not using the sparse module) with
> different sizes of A as follows:
>
>
> Assuming 8 bytes per float, then:
> 1. matrix A with M=10,000 and N=15,000 is of approximate size:
> 1.2Gb 2. matrix A with M=10,000 and N=5,000 is of approximate size:
> 390Mb 3. matrix A with M=10,000 and N=1,000 is of approximate size:
> 78Mb
>
> The Python/Scipy matrix initialization statements are:
> > A = scipy.asmatrix(scipy.empty((I,J), dtype=int))
> > x = scipy.asmatrix(scipy.empty((J,1), dtype=float))
> > b = scipy.asmatrix(scipy.empty((I,1), dtype=float))
>
> I'm using a Windows XP SP2 PC with 2Gb RAM.
>
> Both matrices 1. and 2. fail with INDeterminate values in b. 
> Matrix 3. works perfectly.  As I have 2Gb of RAM why are matrices
> 1. and 2. failing?
>
> The odd thing is that Python doesn't return any error messages with
> 1. and 2. but we know the results are garbage (literally!)
>
> Cheers!
>
> Dinesh

I suspect that you have some uninitialized elements accidentally left 
in A or x; similarly to what Matthieu said in the Scipy list. You 
could try to initialize all elements to zero, and see if the errors 
still happen. It'll take some additional time but it's not too bad:

In [1]:import numpy

In [2]:M=10000

In [3]:N=15000

In [4]:time A = numpy.matrix(numpy.zeros((M,N), dtype=int))
CPU times: user 1.14 s, sys: 3.01 s, total: 4.15 s
Wall time: 44.37

In [5]:time A = numpy.matrix(numpy.empty((M,N), dtype=int))
CPU times: user 0.65 s, sys: 1.12 s, total: 1.76 s
Wall time: 6.11


Regards, 
Eike.


More information about the Tutor mailing list