SquareMatrix<T, S> r = identity();
for(unsigned i=0; i<S; ++i)
{
- if(this->element(i, i)==T(0))
- {
- unsigned pivot = i;
- for(unsigned j=i+1; j<S; ++j)
- if(abs(this->element(j, i))>abs(this->element(pivot, i)))
- pivot = j;
+ unsigned pivot = i;
+ for(unsigned j=i+1; j<S; ++j)
+ if(abs(this->element(j, i))>abs(this->element(pivot, i)))
+ pivot = j;
- if(pivot==i)
- throw not_invertible();
+ if(this->element(pivot, i)==T(0))
+ throw not_invertible();
+ if(pivot!=i)
+ {
this->exchange_rows(i, pivot);
r.exchange_rows(i, pivot);
}