$include_dir="/home/hyper-archives/ublas/include"; include("$include_dir/msg-header.inc") ?>
From: James Sutherland (James.Sutherland_at_[hidden])
Date: 2008-08-13 16:01:36
On Aug 13, 2008, at 12:40 PM, Nizar Khalifa Sallem wrote:
> James Sutherland wrote:
>>
>> On Aug 13, 2008, at 11:26 AM, Nizar Khalifa Sallem wrote:
>>>
>>> Second, the easy dirty way is to do something like :
>>> ublas::vector tmpRow = matrix_row<MatType> row( m, 1 );
>>> matrix_row<MatType> row( m, 1 ) = matrix_row<MatType> row( m,  3 );
>>> matrix_row<MatType> row( m, 3 ) = tmpRow;
>>>
>>> Finally, you may use iterators (you need to check for consistency):
>>> ublas::compressed_matrix<double>::iterator1 srcRowIt, dstRowIt
>>> ublas::compressed_matrix<double>::iterator2 src_ij, dst_ij, tmp_ij;
>>>  dstRowIt = srcRowIt = m.begin1();//iterator over row 0
>>> ++srcRowIt;//here will iterate over row 1;
>>>  dstRowIt+=3;//iterate over row 3;
>>>    for (src_ij = srcRowIt.begin(), dst_ij = dstRowIt.begin();
>>>           src_ij != srcRowIt.end();
>>>           ++src_ij,++dst_ij) {
>>>        tmp_ij = src_ij;
>>>        src_ij = dst_ij;
>>>        dst_ij = tmp_ij;
>>>        // if you do something like src_ij = dst_ij;  you will  
>>> loose your row 1 elements'
>>>    }
>>>
>>> I didn't check this code, if you want columns just invert  
>>> iterator1 and iterator 2
>>
>> Thanks for the suggestions.
>>
>> It seems to me that the examples you provide copy column 3 to  
>> column 1.  However, I want to *move* it.  In other words, I want  
>> move coefficients within a given matrix_row from one column to  
>> another.
>>
>> I don't see how the examples you provide do this.  Perhaps I am  
>> just confused???
>>
> in the first suggestion, I did copy content of row 3 into row 1
> in the second one, I move the iterator location (memory address), I  
> guess you understand functioning of iterators, if not you can assume  
> iterators as augmented pointers.
>
I do understand pointers.  I think that we have a miscommunication.   
Let me be more clear.  Assume I have the following:
          [ 1  1  0  0 ]
  m = [ 0  2  2  0 ]
          [ 0  0  3  3 ]
and I want to form
  [ 0  1  0  1 ]
  [ 0  2  2  0 ]
  [ 3  0  0  3 ]
Furthermore, since this is stored in a compressed matrix, I do not  
store zeros.  These matrices have two nonzero entries per row.
Thus, if I create a matrix_row for the first row,
   matrix_row<MatType> row1 = matrix_row( m, 1 );
   matrix_row<MatType>::iterator icol = row1.begin();
now "icol" iterates over the first two columns in this case.   
Furthermore, icol.index() returns the *column* index, since icol is a  
iterator over the columns.  What I want to do is modify icol.index().   
I cannot obtain a pointer to the fourth column of the first row since  
it does not exist.
How then can I move the first column of row 1 to the fourth column?   
As I said originally, I can use erase_entry(...)  and  
insert_entry(...) but I am hoping to accomplish this using a  
matrix_row object, since that is much more convenient in my  
application (the matrix itself is not readily available).
James