- Hi,

could anyone explain me the difference between

sparse_matrix.filled() and sparse_matrix.non_zeros()?

I'm using

ublas::generalized_vector_of_vector< double, ublas::column_major,

ublas::vector<ublas::compressed_vector<double> > > MY_SPARSE;

for assembly of a larger sparse matrix, but for this type

there exists no M.filled();

typedef ublas::compressed_matrix<double > MY_COMPRESSED;

typedef ublas::generalized_vector_of_vector< double,

ublas::column_major, ublas::vector<ublas::compressed_vector<double> >> MY_SPARSE;

MY_COMPRESSED Mc(5,5,0);

MY_SPARSE Mvv(5,5,0);

cout << "Mc.filled()=" << Mc.filled() << endl;

cout << "Mc.non_zeros()=" << Mc.non_zeros() << endl;

//cout << "Mvv.filled()=" << Mvv.filled() << endl; // doesn't exists

cout << "Mvv.non_zeros()=" << Mvv.non_zeros() << endl;

Mc(2,2) = 1.0;

Mvv(2,2) = 1.0;

cout << "Mc.filled()=" << Mc.filled() << endl;

cout << "Mc.non_zeros()=" << Mc.non_zeros() << endl;

//cout << "Mvv.filled()=" << Mvv.filled() << endl; // doesn't exists

cout << "Mvv.non_zeros()=" << Mvv.non_zeros() << endl;

produces the following output:

Mc.filled()=0

Mc.non_zeros()=5

Mvv.non_zeros()=25

Mc.filled()=1

Mc.non_zeros()=5

Mvv.non_zeros()=25

Regards

Ralf - Zitat von ralfdenzer <denzer@...-kl.de>:

> could anyone explain me the difference between

filled() returns the number of used non zeros.

> sparse_matrix.filled() and sparse_matrix.non_zeros()?

non_zeros() returns the number of allocated (memory for) non zeros.

That means filled() <= non_zeros() and each new matrix entry increases

filled().

non_zeros() can be read as capacity, but is automatically increased if

necessary.

mfg

Gunter - On Wed, 21 Jan 2004 19:26, Gunter Winkler wrote:
> Zitat von ralfdenzer <denzer@...-kl.de>:

Gunter, do you know if this also applies to compressed matrices?

>

> > could anyone explain me the difference between

> > sparse_matrix.filled() and sparse_matrix.non_zeros()?

>

> filled() returns the number of used non zeros.

> non_zeros() returns the number of allocated (memory for) non zeros.

>

> That means filled() <= non_zeros() and each new matrix entry increases

> filled().

> non_zeros() can be read as capacity, but is automatically increased if

> necessary.

Thanks - Zitat von "Paul C. Leopardi" <leopardi@...>:
> Gunter, do you know if this also applies to compressed matrices?

AFAIK, yes. I cannot look at the code right now. But I am fairly sure. It has

the same meaning for all sparse matrix types. (See .insert(i,j,value) for

details.)

regards

Gunter - --- In ublas-dev@yahoogroups.com, Gunter Winkler <guwi17@g...> wrote:
> Zitat von "Paul C. Leopardi" <leopardi@b...>:

sure. It has

> > Gunter, do you know if this also applies to compressed matrices?

>

> AFAIK, yes. I cannot look at the code right now. But I am fairly

> the same meaning for all sparse matrix types. (See

.insert(i,j,value) for

> details.)

Yes, definitely. My example uses compressed_matrix and as Gunter

explained M.filled() <= M.non_zeros() for M sparse and M compressed.

But how do I calculate M.filled() for a vector of compressed_vector's,

i.e.

generalized_vector_of_vector< double, column_major,

vector<compressed_vector<double> > > M(n,n);

M.filled(); // ???? doesn't exists ????

They are much faster for 'random' matrix assembly as Gunter pointed

out on his homepage.

Regards

Ralf