Mercurial > octave-nkf
comparison liboctave/array/CDiagMatrix.cc @ 18481:16b0cd465ecd
Handle special case of 0 for pinv with Diagonal matrices.
* CDiagMatrix.cc (pseudo_inverse), dDiagMatrix.cc (pseudo_inverse),
fCDiagMatrix.cc (pseudo_inverse), fDiagMatrix.cc (pseudo_inverse):
Check for special case where element is 0 to avoid a division by
zero error.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 17 Feb 2014 10:04:27 -0800 |
parents | c5a101de2d88 |
children | 1fa5bba16218 |
comparison
equal
deleted
inserted
replaced
18471:b2a2f097c5e0 | 18481:16b0cd465ecd |
---|---|
391 | 391 |
392 ComplexDiagMatrix retval (c, r); | 392 ComplexDiagMatrix retval (c, r); |
393 | 393 |
394 for (octave_idx_type i = 0; i < len; i++) | 394 for (octave_idx_type i = 0; i < len; i++) |
395 { | 395 { |
396 if (std::abs (elem (i, i)) < tol) | 396 double val = std::abs (elem (i, i)); |
397 if (val < tol || val == 0.0) | |
397 retval.elem (i, i) = 0.0; | 398 retval.elem (i, i) = 0.0; |
398 else | 399 else |
399 retval.elem (i, i) = 1.0 / elem (i, i); | 400 retval.elem (i, i) = 1.0 / val; |
400 } | 401 } |
401 | 402 |
402 return retval; | 403 return retval; |
403 } | 404 } |
404 | 405 |