Mercurial > hg > octave-nkf
diff liboctave/array/fCDiagMatrix.cc @ 18535:c5a101de2d88
Allow pinv to work on Diagonal Matrices with a tolerance (bug #41546).
* pinv.cc (Fpinv): Validate tolerance argument and pass it through to
pseudo_inverse().
CDiagMatrix.h, dDiagMatrix.h, fCDiagMatrix.h, fDiagMatrix.h: Redefine
prototype for pseudo_inverse to accept a single argument for tolerance.
* CDiagMatrix.cc (pseudo_inverse), dDiagMatrix.cc(pseudo_inverse),
fCDiagMatrix.cc(pseudo_inverse), fDiagMatrix.cc(pseudo_inverse):
Use std::abs(elem) to get magnitude of element and only invert if
value is greater than tolerance.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 15 Feb 2014 14:42:07 -0800 |
parents | 8e056300994b |
children | 16b0cd465ecd |
line wrap: on
line diff
--- a/liboctave/array/fCDiagMatrix.cc +++ b/liboctave/array/fCDiagMatrix.cc @@ -387,7 +387,7 @@ } FloatComplexDiagMatrix -FloatComplexDiagMatrix::pseudo_inverse (void) const +FloatComplexDiagMatrix::pseudo_inverse (float tol) const { octave_idx_type r = rows (); octave_idx_type c = cols (); @@ -397,10 +397,10 @@ for (octave_idx_type i = 0; i < len; i++) { - if (elem (i, i) != 0.0f) + if (std::abs (elem (i, i)) < tol) + retval.elem (i, i) = 0.0f; + else retval.elem (i, i) = 1.0f / elem (i, i); - else - retval.elem (i, i) = 0.0f; } return retval;