Mercurial > octave-nkf
comparison liboctave/array/fCDiagMatrix.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 |
---|---|
395 | 395 |
396 FloatComplexDiagMatrix retval (c, r); | 396 FloatComplexDiagMatrix retval (c, r); |
397 | 397 |
398 for (octave_idx_type i = 0; i < len; i++) | 398 for (octave_idx_type i = 0; i < len; i++) |
399 { | 399 { |
400 if (std::abs (elem (i, i)) < tol) | 400 float val = std::abs (elem (i, i)); |
401 if (val < tol || val == 0.0f) | |
401 retval.elem (i, i) = 0.0f; | 402 retval.elem (i, i) = 0.0f; |
402 else | 403 else |
403 retval.elem (i, i) = 1.0f / elem (i, i); | 404 retval.elem (i, i) = 1.0f / val; |
404 } | 405 } |
405 | 406 |
406 return retval; | 407 return retval; |
407 } | 408 } |
408 | 409 |