Boost logo

Ublas :

From: Pallav G (axl_fugazi_at_[hidden])
Date: 2007-04-26 00:45:04


i am trying to use the mapped_matrix to do some work.
while using this container in my application, i
noticed one shortcoming. this could be a possible
feature request but i don't know enough about this
container/its design to say that this should be

the problem i'm running in with this mapped_matrix is
as follows:

say i declare a 3 x 3 mapped_matrix. all of the
elements are initialized to 0. say i set the value of
2 elements to 1 so that the matrix is like this

0 0 0
0 1 0
0 0 1

the size1() and size2() function will report the size
of the matix as 3 which is right. however, often
people are interested in only the "real" data in this
matrices and consider "0" irrelevant. from that
perspective then, the number of rows and columns in
this matrix is actually 2 if we don't care about 0.

in my code, i have to do something like this to
calculate the new row/column length

typedef mapped_matrix<bool> CubeMatrix;
typedef CubeMatrix::const_iterator1 CubeMatrixRowItr;
typedef CubeMatrix::const_iterator2 CubeMatrixColItr;

int rows = 0;
int cols = 0;
int count = 0;
for (CubeMatrixRowItr row = m.begin1(); row !=
m.end1(); ++row)
   first = true;
   for (CubeMatrixColItr col = row.begin(); col !=
row.end(); ++col)
       if (first)
         first = false;
       ++count; // the row contains at least one
non-zero entry

for (CubeMatrixColItr col = m.begin2(); col !=
m.end2(); ++ col)
    first = true;
    for (CubeMatrixRowItr row = col.begin()); row !=
col.end(); ++row)
     if (first)
        first = false;

std::cout << "worthwhile rows = " << rows << " cols =
" << cols << " elem " << count << "\n";

this type of scenario arises often in circuit
minimization problems where we need a sparse matrix to
represent multiple functions (columns) and the inputs
to these fucntions (rows). i find myself having to
calculate these "new" sizes repeatedly. although i
have a function to do this, i was wondering that it
might be beneficial to provide a member function in
mapped_matrix that provides this information quickly.

also it would be nice to know how to many non-zero
elements are there in the matrix at any given time.

maybe these facilities already exist and i'm not aware
of them? please let me know.

just a thought.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around