Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Convert array of class 'int8' to sparse
Date: Tue, 24 Mar 2009 16:03:02 +0000 (UTC)
Organization: University College Dublin
Lines: 87
Message-ID: <gqb07m$aau$1@fred.mathworks.com>
References: <gfhh6c$dvr$1@fred.mathworks.com> <gq9bg5$3ra$1@fred.mathworks.com> <gqa8th$7j0$1@fred.mathworks.com> <gqae67$vg$1@fred.mathworks.com> <gqaqc5$l2k$1@fred.mathworks.com> <gqarna$pv1$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1237910582 10590 172.30.248.37 (24 Mar 2009 16:03:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 24 Mar 2009 16:03:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 87230
Xref: news.mathworks.com comp.soft-sys.matlab:527297


"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gqarna$pv1$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gqaqc5$l2k$1@fred.mathworks.com>...
> > 
> > And change your example to this:
> > 
> > n = 1000; 
> > Sp16 = sprand(n,n,0.10);
> > Sp16(Sp16>0) = 1./Sp16(Sp16>0);
> > Sp16(Sp16>127) = 127;
> > Sp16 = floor(Sp16);
> > D16 = full(Sp16);
> > D8 = int8(D16);
> > Sp8 = int8tosparse(D8);
> > whos
> > isequal(D16,D8)
> > isequal(Sp16,Sp8)
> > 
> 
> Oops .. typo holdover from my small test. Try this instead:
> 
> n = 1000;
> Sp16 = sprand(n,n,0.001); % <-- changed 0.10 to 0.001
> Sp16(Sp16>0) = 1./Sp16(Sp16>0);
> Sp16(Sp16>127) = 127;
> Sp16 = floor(Sp16);
> D16 = full(Sp16);
> D8 = int8(D16);
> Sp8 = int8tosparse(D8);
> whos
> isequal(D16,D8)
> isequal(Sp16,Sp8)
> 
> James Tursa


Dear John,

Thanks for your very prompt reply. I made the changes you suggested and got this:

---------------------------------------
>> n = 1000;
Sp16 = sprand(n,n,0.001); % <-- changed 0.10 to 0.001
Sp16(Sp16>0) = 1./Sp16(Sp16>0);
Sp16(Sp16>127) = 127;
Sp16 = floor(Sp16);
D16 = full(Sp16);
D8 = int8(D16);
Sp8 = int8tosparse(D8);
>> whos
  Name         Size                    Bytes     Class     Attributes

  D16       1000x1000            8000000  double
  D8         1000x1000            1000000  int8
  Sp16      1000x1000               24008  double    sparse
  Sp8       1000x1000                24008  double    sparse

>> isequal(D16,D8)
isequal(Sp16,Sp8)
ans =
     1
ans =
     1
--------------------------------------

You can see that the size of Sp8 is the same as Sp16 so it
seems there is no advantage in converting.

Here is the type of problem I'm interested in:

A 10^8 x 10^8 distance (adjacency) matrix with 20 non-zeros per row,
and each non-zero is an integer in the range 1:127. Only addition
and subtraction performed on these, and the values are never changed.
This is typical of shortest path and network flow problems.

Storage for these values is 20 x 10^8  = 8 x 20 x 10^8 = 16 GB in double.
                                                                              =   2 GB in int8.

The storage for indexing information should be the same for both.

Is there some fundamental difference between sparse matrices whose 
non-zeros are in the rang 1:127 and those in the range 10^(-308) to 10^(308) ?
Or am I missing something here?


Regards,

Derek O'Connor