views:

36

answers:

2

How much space is allocated by boost compressed_matrix? Is it true that it only allocates space for non-zero elements? If this is true, I don't understand why the following code gives bad_alloc error.

namespace bubla = boost::numeric::ublas; 
typedef double value_type; 
typedef bubla::compressed_matrix<value_type> SparseMatrix; 
unsigned int m = 10000*10000; 
SparseMatrix D(m,m,3*m), X; 

It should only allocate space for 3*m=3*10000*10000 elements right?

Could you please help clarify? What data structure in boost I could use to only allocate space for the non-zero elements. Secondly, how do I set values for the non-zero elements?

Many thanks.

A: 

3*m = 300000000

ybungalobill
not counting internal data structures to maintain the actual matrix from the non-empty list.
Diego Sevilla
I realize even with 3*m space, it is still going beyond my limit. Thanks for confirming.
+1  A: 

Note that you are defining m to be 10000*10000 in your above example which means you are trying to allocate 300 million doubles or 2.4 GB (assuming 8 bytes per double).

If you just want a sparse 10000 x 10000 matrix just define "m=10000".

uesp
yes thats correct.. its a N^2 x N^2 matrix where m=N^2. When N becomes this large, and I cannot allocate a full matrix. But I should be able to allocate sparse matrix to save space. For sparse matrix, space requirement is 3*N^2 which should be manageable.