Mercurial > jwe > octave
changeset 27033:4a2cb3392014 stable
refactor minimum eigenvalue index search in qp (bug #56037)
* __qp__.cc (min_index): New function to return the index of a minimum value.
(qp): Use it.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 04 Apr 2019 11:29:13 -0700 |
parents | 2f3e8ea7e387 |
children | 3080dac8f660 df32e0cf0992 |
files | libinterp/corefcn/__qp__.cc |
diffstat | 1 files changed, 16 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/__qp__.cc Tue Apr 02 19:53:37 2019 -0700 +++ b/libinterp/corefcn/__qp__.cc Thu Apr 04 11:29:13 2019 -0700 @@ -40,6 +40,18 @@ #include "pr-output.h" #include "utils.h" +static octave_idx_type +min_index (const ColumnVector& x) +{ + double min_val = x.min (); + + for (octave_idx_type i = 0; i < x.numel (); i++) + if (min_val == x.xelem (i)) + return i; + + return 0; +} + static Matrix null (const Matrix& A, octave_idx_type& rank) { @@ -151,16 +163,7 @@ ColumnVector eigenvalH = real (eigH.eigenvalues ()); Matrix eigenvecH = real (eigH.right_eigenvectors ()); - double minReal = eigenvalH.min (); - octave_idx_type indminR = 0; - for (octave_idx_type i = 0; i < n; i++) - { - if (minReal == eigenvalH(i)) - { - indminR = i; - break; - } - } + octave_idx_type indminR = min_index (eigenvalH); bool done = false; @@ -187,6 +190,8 @@ { // There are no active constraints. + double minReal = eigenvalH.xelem (indminR); + if (minReal > 0.0) { // Inverting the Hessian. Using the Cholesky @@ -299,16 +304,7 @@ ColumnVector eigenvalrH = real (eigrH.eigenvalues ()); Matrix eigenvecrH = real (eigrH.right_eigenvectors ()); - double mRrH = eigenvalrH.min (); - indminR = 0; - for (octave_idx_type i = 0; i < n; i++) - { - if (mRrH == eigenvalrH(i)) - { - indminR = i; - break; - } - } + indminR = min_index (eigenvalrH); ColumnVector eVrH = eigenvecrH.column (indminR);