Commit 1191e431 by Francois Gygi

implemented signature of permutation

git-svn-id: http://qboxcode.org/svn/qb/branches/efield@1611 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 0eb6ee46
......@@ -1981,6 +1981,7 @@ double DoubleMatrix::inverse_det(void)
double det = 1.0;
for ( int ii = 0; ii < n_; ii++ )
det *= diag[ii];
det *= signature(ipiv);
inverse_from_lu(ipiv);
return det;
......@@ -2073,6 +2074,7 @@ complex<double> ComplexMatrix::inverse_det(void)
complex<double> det = 1.0;
for ( int ii = 0; ii < n_; ii++ )
det *= diag[ii];
det *= signature(ipiv);
inverse_from_lu(ipiv);
return det;
......@@ -3427,3 +3429,45 @@ ostream& operator<<(ostream& os, const ComplexMatrix& a)
a.print(os);
return os;
}
////////////////////////////////////////////////////////////////////////////////
//
// signature: compute the signature of a row permutation
// defined by a distributed pivot vector ipiv
//
// the vector ipiv is computed by the lu decomposition
//
int DoubleMatrix::signature(valarray<int> ipiv)
{
// count the number of non-trivial transpositions in the local ipiv vector
int ntrans = 0;
for ( int i = 0; i < mloc_; i++ )
{
if ( ipiv[i] != iglobal(i) )
ntrans++;
}
// accumulate total number of transpositions
ctxt_.isum('c',1,1,&ntrans,1);
return 1 - 2 * ((m_ - ntrans)%2);
}
////////////////////////////////////////////////////////////////////////////////
//
// signature: compute the signature of a row permutation
// defined by a distributed pivot vector ipiv
//
// the vector ipiv is computed by the lu decomposition
//
int ComplexMatrix::signature(valarray<int> ipiv)
{
// count the number of non-trivial transpositions in the local ipiv vector
int ntrans = 0;
for ( int i = 0; i < mloc_; i++ )
{
if ( ipiv[i] != iglobal(i) )
ntrans++;
}
// accumulate total number of transpositions
ctxt_.isum('c',1,1,&ntrans,1);
return 1 - 2 * ((m_ - ntrans)%2);
}
......@@ -290,6 +290,8 @@ class DoubleMatrix
// permute the coeff of the matrix *this
void lapiv(char direc, char rowcol, const int *ipiv);
// signature of a permutation returned by lu
int signature(std::valarray<int> ipiv);
// compute eigenvalues (only) of symmetric matrix *this
// using the divide and conquer method of Tisseur and Dongarra
......@@ -559,6 +561,8 @@ class ComplexMatrix
// permute the coeff of the matrix *this
void lapiv(char direc, char rowcol, const int *ipiv);
// signature of a permutation returned by lu
int signature(std::valarray<int> ipiv);
};
std::ostream& operator << ( std::ostream& os, const ComplexMatrix& a );
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment