Commit 153f847a authored by Kutalmis Bercin's avatar Kutalmis Bercin Committed by Andrew Heather
Browse files

BUG: fix pinv() for single-element input matrices

  ENH: return zero-valued matrix when input zero-valued matrix in pinv()
parent af221634
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016 OpenFOAM Foundation Copyright (C) 2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -497,15 +497,17 @@ MatrixType Foam::pinv ...@@ -497,15 +497,17 @@ MatrixType Foam::pinv
{ {
typedef typename MatrixType::cmptType cmptType; typedef typename MatrixType::cmptType cmptType;
#if FULLDEBUG
if (A.empty()) if (A.empty())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Empty matrix." << abort(FatalError); << "Empty matrix found."
<< abort(FatalError);
} }
// Check if A is full-rank if (A.size() == 1)
#endif {
return MatrixType({1, 1}, cmptType(1.0)/(A(0,0) + cmptType(VSMALL)));
}
QRMatrix<MatrixType> QRM QRMatrix<MatrixType> QRM
( (
...@@ -534,9 +536,12 @@ MatrixType Foam::pinv ...@@ -534,9 +536,12 @@ MatrixType Foam::pinv
if (firstZeroElemi == 0) if (firstZeroElemi == 0)
{ {
FatalErrorInFunction WarningInFunction
<< "The largest (magnitude) diagonal element is (almost) zero." << "The largest (magnitude) diagonal element is (almost) zero."
<< abort(FatalError); << nl << "Returning a zero matrix."
<< endl;
return MatrixType(A.sizes(), Zero);
} }
// Exclude the first (almost) zero diagonal row and the rows below // Exclude the first (almost) zero diagonal row and the rows below
......
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