Boost logo

Ublas :

From: Regis Behmo (regisb_at_[hidden])
Date: 2007-09-04 06:07:43


On 9/4/07, Regis Behmo <regisb_at_[hidden]> wrote:
> On 9/4/07, Karl Meerbergen <Karl.Meerbergen_at_[hidden]> wrote:
> >
> > To come to your question of removing a row/column from a sparse matrix:
> > I would do this by manipulating the index1_data(), index2_data(), and
> > value_data() of the matrix. But you need to be familiar with sparse
> > matrix formats to be able to do this swiftly. Unfortunately, I do not
> > have the time to write such routines for you.
>
> Yes, I understand. Is there any documentation at all concerning these
> methods on the web? I googled "index1_data
> site:http://www.boost.org/libs/numeric/ublas/" and didn't get any
> result.
>

Alright, I managed to edit the index1_data, index2_data and value_data
arrays with the following function:

template<class T,class F, unsigned int IB,class IA,class TA>
void remove_row( ublas::coordinate_matrix<T, F, IB, IA, TA>& M, int i )
{
        // it_index1_begin will be the beginning of the range of index1 that
contains value i
        typename IA::iterator it_index1 = M.index1_data().begin();
        typename IA::iterator it_index2 = M.index2_data().begin();
        typename TA::iterator it_value = M.value_data().begin();
        
        while( it_index1 != M.index1_data().end() )
        {
                if( *it_index1 == i )
                {
                        M.index1_data().erase(it_index1);
                        M.index2_data().erase(it_index2);
                        M.value_data().erase(it_value);
                        it_index1--;
                        it_index2--;
                        it_value--;
                }
                else if( *it_index1 > i )
                        (*it_index1)--;
                
                it_index1++;
                it_index2++;
                it_value++;
        }
}

However, when I apply this function to the following coordinate_matrix:
[row 0] [0]0 [1]1 [2]2 [3]3
[row 1] [0]4 [1]5 [2]6 [3]7
[row 2] [0]8 [1]9 [2]10 [3]11

I obtain:
[row 0] [0]0 [1]1 [2]2 [3]3
[row 1] [0]8 [1]9 [2]10 [3]11
[row 2] [0]0 [1]0 [2]0 [3]11

Which means the last row wasn't removed. I tried "resize" but ended up
with a matrix full of zeros.

What should I do in order to change the size of the matrix?

Régis