[SciPy-dev] Bug w.r.t. Addition of sparse matrices

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Mar 6 06:19:06 CST 2006


Robert Cimrman wrote:
> Nils Wagner wrote:
>   
>> The addition of sparse matrices results in wrong results (see add.py for 
>> details).
>>
>> Nils
>>
>>
>> ------------------------------------------------------------------------
>>
>> from scipy import *
>> from scipy.sparse import *
>> A = rand(3,3)
>> B = rand(3,3)
>> A_csr = csr_matrix(A)
>> B_csr = csr_matrix(B)
>> C_csr = A_csr+B_csr
>> C = A + B
>> print C[0,0], C_csr[0,0], 'should be zero',C[0,0]-C_csr[0,0]
>>     
>
> I think it works ok:
>
> $ python add.py
> 0.393709556483 0.393709570169 should be zero -1.36865185851e-08
>
> 1e-8 is the float precision... Try using doubles.
>
> r.
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>   
Am I missing something ?
I have used astype('d') to switch to double precision.

BTW, is there any reason why default is single precision ?

python -i add.py
0.561831531319 0.561831533909 should be zero -2.59017984838e-09

Nils

-------------- next part --------------
A non-text attachment was scrubbed...
Name: add.py
Type: text/x-python
Size: 234 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20060306/12d91974/attachment.py 


More information about the Scipy-dev mailing list