Prev: Please help - Problem in Calling Matlab functions from C++
Next: How to get back data using Calllib to DLL
From: Bruno Luong on 26 Feb 2010 09:33 1. the codage of sparse matrix is not symmetric in row and column 2. The nzmax value might be adjusted after transpose (see NZMAX function) Bruno
From: Bruno Luong on 26 Feb 2010 13:01 singlepoint <singlepoint(a)gmail.com> wrote in message <740bced7-6b1f-494d-af80-b57bffb7eb45(a)u15g2000prd.googlegroups.com>... > > How a sparse matrix is saved and why transpose will take less space > than the original matrix, I have been trying to get hold of this > concept but couldn't get it. Internally a sparse matrix is represented by: - The non-zero elements are stored in Pr/Pi pointers, Pi is allocated for complex matrix ony, and NULL otherwise. The array(s) has(ve) NZMAX in length; and each element is a double (8 bytes) or logical (1 bytes). - the integer array JC has (number of columns + 1) entries; JC contains the linear index (zero-based) of the first non-zero elements of the column. The last element of JC is therefore the total number of non-zeros of sparse matrix. - The integer array IR has the same size as Pr/Pi (NZMAX) containing the row of the elements (zero-based). Integer arrays (JC and IR) are 4/8 bytes depending where as your Matlab is an 32/64 bit version. Element with 0 value MUST be removed from Pr/Pi. Bruno
From: us on 26 Feb 2010 13:08 singlepoint > How a sparse matrix is saved and why transpose will take less space > than the original matrix, I have been trying to get hold of this > concept but couldn't get it. Steve, yes you are right, size means the > size on disk not the size in terms of row/column stuff... again... here (r2009b), this behavior cannot be reproduced... s=sprandn(1000,1000,.25); st=s.'; save foo1 s; save foo2 st; dd=dir('foo*.mat'); disp([{dd.name}.',num2cell([dd.bytes].')]); %{ 'foo1.mat' [2658624] 'foo2.mat' [2658624] %} us
From: Matt J on 26 Feb 2010 13:14 singlepoint <singlepoint(a)gmail.com> wrote in message <740bced7-6b1f-494d-af80-b57bffb7eb45(a)u15g2000prd.googlegroups.com>... > How a sparse matrix is saved and why transpose will take less space > than the original matrix, I have been trying to get hold of this > concept but couldn't get it. Steve, yes you are right, size means the > size on disk not the size in terms of row/column stuff. One more > thing, which representation is more efficient (original or transposed, > in this case) and why? ================ Well, as we've told you, it is always most memory efficient to minimize the number of columns of a sparse matrix, so if you have an MxN matrix with M>N, then the original is more memory efficient. A conflicting consideration, however, is that when multiplying a sparse matrix with a full one, I have generally always found that sparse*full is much slower than full*sparse. If I need to do a sparse*full operation, I would therefore optimize it implementing it as (full*sparse.').' so if you again have an MxN matrix with M>N, you might nevertheless want to carry around the transpose regardless of the fact that it is less memory efficient.
From: Matt J on 26 Feb 2010 13:16 "us " <us(a)neurol.unizh.ch> wrote in message <hm92m4$ks8$1(a)fred.mathworks.com>... > again... > here (r2009b), this behavior cannot be reproduced... > > s=sprandn(1000,1000,.25); > st=s.'; > save foo1 s; > save foo2 st; > dd=dir('foo*.mat'); > disp([{dd.name}.',num2cell([dd.bytes].')]); > %{ > 'foo1.mat' [2658624] > 'foo2.mat' [2658624] > %} urs - this is not a representative example because your sparse matrix is square. It is only when the number of rows and number of columns are very different that you will see the memory footprint difference.
|
Next
|
Last
Pages: 1 2 3 Prev: Please help - Problem in Calling Matlab functions from C++ Next: How to get back data using Calllib to DLL |