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

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Mar 6 07:12:49 CST 2006

```Nils Wagner wrote:
> 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:
>>
>> 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 ?
>
> 0.561831531319 0.561831533909 should be zero -2.59017984838e-09
>
> Nils
>
>
> ------------------------------------------------------------------------
>
> from scipy import *
> from scipy.sparse import *
> A = rand(3,3)
> B = rand(3,3)
> A_csr = csr_matrix(A).astype('d')
> B_csr = csr_matrix(B).astype('d')
> 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]
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>
It works with astype('D') double precision complex but astype('d')
doesn't work.
For what reason ?

Nils

-------------- next part --------------
A non-text attachment was scrubbed...