diff --git a/src/lib/matrix/matrix/SquareMatrix.hpp b/src/lib/matrix/matrix/SquareMatrix.hpp index 20ecd67f2c..4a1d3d0a81 100644 --- a/src/lib/matrix/matrix/SquareMatrix.hpp +++ b/src/lib/matrix/matrix/SquareMatrix.hpp @@ -322,6 +322,19 @@ SquareMatrix expm(const Matrix &A, size_t order = 5) return res; } +/** + * Deal with the special case where the square matrix is 1 + */ +template +bool inv(const SquareMatrix &A, SquareMatrix &inv, size_t rank = 1) +{ + if (std::fabs(A(0, 0)) < Type(FLT_EPSILON)) { + return false; + } + + inv(0, 0) = Type(1) / A(0, 0); + return true; +} /** * inverse based on LU factorization with partial pivotting