Mercurial > octave
comparison liboctave/array/fMatrix.cc @ 30313:98400baa509f
Return Inf for inv(0) for compatibility with division operator and Matlab (bug #52285).
* CMatrix.cc, dMatrix.cc, fCMatrix.cc, fMatrix.cc (inverse): Check early
for MatrixType::Diagonal which implies a scalar. In scalar case, just
calculate 1 / *this.
* inv.cc (Finverse): Add BIST tests for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 21 Nov 2021 16:53:49 -0800 |
parents | 1e277c6b6626 |
children | f3f3e3793fb5 |
comparison
equal
deleted
inserted
replaced
30312:90ca4cd8e7e5 | 30313:98400baa509f |
---|---|
644 FloatMatrix ret; | 644 FloatMatrix ret; |
645 | 645 |
646 if (typ == MatrixType::Unknown) | 646 if (typ == MatrixType::Unknown) |
647 typ = mattype.type (*this); | 647 typ = mattype.type (*this); |
648 | 648 |
649 if (typ == MatrixType::Upper || typ == MatrixType::Lower) | 649 if (typ == MatrixType::Diagonal) // a scalar is also classified as Diagonal. |
650 ret = 1 / (*this); | |
651 else if (typ == MatrixType::Upper || typ == MatrixType::Lower) | |
650 ret = tinverse (mattype, info, rcon, force, calc_cond); | 652 ret = tinverse (mattype, info, rcon, force, calc_cond); |
651 else | 653 else |
652 { | 654 { |
653 if (mattype.ishermitian ()) | 655 if (mattype.ishermitian ()) |
654 { | 656 { |
666 } | 668 } |
667 | 669 |
668 if (! mattype.ishermitian ()) | 670 if (! mattype.ishermitian ()) |
669 ret = finverse (mattype, info, rcon, force, calc_cond); | 671 ret = finverse (mattype, info, rcon, force, calc_cond); |
670 | 672 |
671 if ((calc_cond || mattype.ishermitian ()) && rcon == 0.0 | 673 if ((calc_cond || mattype.ishermitian ()) && rcon == 0.0) |
672 && (numel () != 1)) | |
673 ret = FloatMatrix (rows (), columns (), | 674 ret = FloatMatrix (rows (), columns (), |
674 octave::numeric_limits<float>::Inf ()); | 675 octave::numeric_limits<float>::Inf ()); |
675 } | 676 } |
676 | 677 |
677 return ret; | 678 return ret; |