Skip to content

Commit

Permalink
Merge pull request #156 from SimonRohou/codac2_dev
Browse files Browse the repository at this point in the history
[mat] corrected bug in Gauss Jordan decomposition (thanks Damien Massé!)
  • Loading branch information
SimonRohou authored Dec 9, 2024
2 parents 639b848 + 6875f2f commit 0afe027
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/core/matrices/codac2_GaussJordan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* codac2_GaussJordan.cpp
* ----------------------------------------------------------------------------
* \date 2024
* \author Simon Rohou
* \author Luc Jaulin, Simon Rohou, Damien Massé
* \copyright Copyright 2024 Codac Team
* \license GNU Lesser General Public License (LGPL)
*/
Expand Down Expand Up @@ -40,17 +40,18 @@ namespace codac2

Matrix gauss_jordan(const Matrix& A)
{
Index n = A.rows();//, m = A.cols();
Index n = A.rows(), m = A.cols();
Eigen::FullPivLU<Matrix> lu(A);

Matrix L = Matrix::Identity(n,n);
//if(std::pow(L.determinant(),2) < 1e-5)
//{
// cout << "[Matrix gauss_jordan(const Matrix& A)] -> eye Matrix" << endl;
// return Matrix::eye(n,n);
//}
if(std::pow(L.determinant(),2) < 1e-5)
{
cout << "[Matrix gauss_jordan(const Matrix& A)] -> eye Matrix" << endl;
return Matrix::eye(n,n);
}

L.block(0,0,n,n).triangularView<Eigen::StrictlyLower>() = lu.matrixLU();
L.block(0,0,n,std::min(m,n)).triangularView<Eigen::StrictlyLower>() =
lu.matrixLU().block(0,0,n,std::min(m,n));

Matrix P = lu.permutationP();
Matrix U = lu.matrixLU().triangularView<Eigen::Upper>();
Expand Down
4 changes: 3 additions & 1 deletion src/core/matrices/codac2_GaussJordan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file codac2_GaussJordan.h
* ----------------------------------------------------------------------------
* \date 2024
* \author Simon Rohou
* \author Luc Jaulin, Simon Rohou, Damien Massé
* \copyright Copyright 2024 Codac Team
* \license GNU Lesser General Public License (LGPL)
*/
Expand All @@ -16,4 +16,6 @@ namespace codac2
{
// Gauss Jordan band diagonalization preconditioning
Matrix gauss_jordan(const Matrix& A);

// From https://www.ensta-bretagne.fr/jaulin/centered.html
}
2 changes: 1 addition & 1 deletion src/core/matrices/codac2_matrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Eigen
* (this is a standard C++ macro which disables all asserts).
* https://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html
*/
#define EIGEN_NO_DEBUG
//#define EIGEN_NO_DEBUG // uncomment to disable Eigen's assertions
#endif

#include <Eigen/Core>
Expand Down

0 comments on commit 0afe027

Please sign in to comment.