[SciPy-user] [Sparse matrix library] csr_matrix and
Dinesh B Vadhia
dineshbvadhia at hotmail.com
Mon Apr 28 11:57:55 EDT 2008
Okay, I see what is going on. Uhmmm! If I replace int8 with int16 or int32 then this will increase the size of A in memory which will defeat the purpose of the original exercise to minimize the size of A (as they are very large). Unless there is a way to coerce the calculation A.sum(0) into a int16 then looks like I'll have to evaluate A.sum(0) in brute force fashion at the time of A's creation, save it and read it into the program at execution.
Dinesh
--------------------------------------------------------------------------------
Message: 2
Date: Mon, 28 Apr 2008 00:29:29 -0500
From: "Nathan Bell" <wnbell at gmail.com>
Subject: Re: [SciPy-user] [Sparse matrix library] csr_matrix and
column sum
To: "SciPy Users List" <scipy-user at scipy.org>
Message-ID:
<d05265cb0804272229q5ca927b4l7d70ff338122a230 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Apr 27, 2008 at 11:57 PM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
>
> 0 , -44 , 84 , -116 , -121 , -43 , -44 , -116 , -115 , -79 , 70 , -86 , 39 ,
> -17 , -21 , -112 , 29 , -126 , -19 , 33 , 59 , -6 , 24 , 18 , 57
>
>
> 768 , 724 , 1108 , 652 , 1927 , 2005 , 724 , 908 , 1421 , 1457 , 2118 , 1450
> , 1575 , 3055 , 2283 , 656 , 1053 , 898 , 1517 , 1569 , 1339 , 762 , 3096 ,
> 530 , 1081
>
This is due to the fact that when integer arithmetic overflows (e.g. A
+ B is too large) the result "wraps around". The solution is to use a
data type with a greater range of values (more bits).
Replace your int8 data array with an int16 array and you will get the
expected results (albeit using one more byte per nonzero) provided
that the sums do not exceed 2^15 - 1.
To be safe, you might use int32 and not worry about ranges as much.
--
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080428/1c5cb883/attachment.html>
More information about the SciPy-User
mailing list