Hi Wolfgang,

The functions swap_row and swap_col work fine for a square matrix, as shown in 
the example below:

    FullMatrix<double> A(4,4);

    std::cout << "A: " << std::endl;
    for (unsigned int ii = 0; ii < A.m(); ii++) {
         for (unsigned int jj = 0; jj < A.n(); jj++) {
             A(ii,jj) = ii + jj;
             std::cout << A(ii,jj) << "\t";
         }
          std::cout << std::endl;
    }
    FullMatrix<double> B(A);
    B.swap_col(0,1);

   std::cout << "\nB : " << std::endl;
   for (unsigned int ii = 0; ii < B.m(); ii++) {
         for (unsigned int jj = 0; jj < B.n(); jj++) {
             std::cout << B(ii,jj) << "\t";
         }
         std::cout << std::endl;
    }

    B = A;
    B.swap_row(0,B.m()-1);

    std::cout << "\nB : " << std::endl;
    for (unsigned int ii = 0; ii < B.m(); ii++) {
         for (unsigned int jj = 0; jj < B.n(); jj++) {
             std::cout << B(ii,jj) << "\t";
         }
         std::cout << std::endl;
    }

which produces:

A: 
0       1       2       3       
1       2       3       4       
2       3       4       5       
3       4       5       6       

B : 
1       0       2       3       
2       1       3       4       
3       2       4       5       
4       3       5       6       

B : 
3       4       5       6       
1       2       3       4       
2       3       4       5       
0       1       2       3       

If I change the size of the matrix A so that it is non-square (i.e.  
FullMatrix<double> A(4,5); ), I get the following error:

An error occurred in line <2340> of file 
</home/andrew/software/deal_ii_svn/deal.II/base/include/base/table.h> in 
function
    T& dealii::Table<2, T>::operator()(unsigned int, unsigned int) [with T = 
double]
The violated condition was: 
    i < this->table_size[0]
The name and call sequence of the exception was:
    ExcIndexRange (i, 0, this->table_size[0])
Additional Information: 
Index 4 is not in [0,4[


So the problem is linked to the underlying Table class from which FullMatrix 
is inherited.

Kind regards
Andrew

On Wednesday 04 March 2009 06:31:59 Wolfgang Bangerth wrote:
> Andrew,
>
> > Some of the FullMatrix operations are clearly reserved for square
> > matrices, but why, for example, are the methods "swap_row" and
> > "swap_col" reserved?
>
> Are they? There isn't an assertion in the code that would enforce this.
> However, it seems to be that the functions are buggy (they use m() and n()
> when they should use the opposite functions) -- is that what you mean? If
> you agree with this, then I'll fix it as soon as possible.
>
> In general, the answer to this question is: it's historic, people did what
> they needed and if it hasn't been changed to be more general so far then
> it's most likely because nobody ever had a need for it. If someone has,
> however, then it's usually not hard to change -- in other words, if you
> think that you'd like to see something changed, please just send us a
> patch and we'll be happy to include it!
>
> Best
>  Wolfgang
>
> -------------------------------------------------------------------------
> Wolfgang Bangerth                email:            [email protected]
>                                  www: http://www.math.tamu.edu/~bangerth/

_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii

Reply via email to