Commit 735f704b authored by Philippe FOUBERT's avatar Philippe FOUBERT

Add on optional parameter to the matx invert function to know if this operation…

Add on optional parameter to the matx invert function to know if this operation is successfull without having to analyse the matrix (it may fail in case of bad preconditioning or inappropriate decomposition method)
parent 41ae5d5f
...@@ -154,7 +154,7 @@ public: ...@@ -154,7 +154,7 @@ public:
Matx<_Tp, n, m> t() const; Matx<_Tp, n, m> t() const;
//! invert matrix the matrix //! invert matrix the matrix
Matx<_Tp, n, m> inv(int method=DECOMP_LU) const; Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const;
//! solve linear system //! solve linear system
template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const;
......
...@@ -186,7 +186,7 @@ Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) ...@@ -186,7 +186,7 @@ Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b)
} }
template<typename _Tp, int m, int n> inline template<typename _Tp, int m, int n> inline
Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method, bool *p_is_ok /*= NULL*/) const
{ {
Matx<_Tp, n, m> b; Matx<_Tp, n, m> b;
bool ok; bool ok;
...@@ -197,6 +197,7 @@ Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const ...@@ -197,6 +197,7 @@ Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method) const
Mat A(*this, false), B(b, false); Mat A(*this, false), B(b, false);
ok = (invert(A, B, method) != 0); ok = (invert(A, B, method) != 0);
} }
if( NULL != p_is_ok ) { *p_is_ok = ok; }
return ok ? b : Matx<_Tp, n, m>::zeros(); return ok ? b : Matx<_Tp, n, m>::zeros();
} }
......
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