Mercurial > jwe > octave
diff liboctave/array/dDiagMatrix.cc @ 21136:7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
* Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray.cc,
PermMatrix.cc, Sparse.cc, Sparse.h, chMatrix.cc, chNDArray.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
idx-vector.cc, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc,
CmplxLU.cc, CmplxQR.cc, CmplxSCHUR.cc, CmplxSVD.cc, DASPK.cc, EIG.cc, LSODE.cc,
Quad.cc, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc,
SparsedbleCHOL.cc, SparsedbleLU.cc, base-lu.cc, bsxfun-defs.cc, dbleAEPBAL.cc,
dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleSCHUR.cc,
dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxLU.cc,
fCmplxQR.cc, fCmplxSCHUR.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc,
floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatSCHUR.cc,
floatSVD.cc, lo-specfun.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc,
sparse-base-chol.cc, sparse-dmsolve.cc, file-ops.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, lo-ieee.cc, lo-regexp.cc, oct-base64.cc, oct-shlib.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-util.cc, unwind-prot.cc:
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 23 Jan 2016 13:52:03 -0800 |
parents | e39e05d90788 |
children | f7121e111991 |
line wrap: on
line diff
--- a/liboctave/array/dDiagMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dDiagMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -63,10 +63,7 @@ DiagMatrix::fill (double val, octave_idx_type beg, octave_idx_type end) { if (beg < 0 || end >= length () || end < beg) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); for (octave_idx_type i = beg; i <= end; i++) elem (i, i) = val; @@ -79,10 +76,7 @@ { octave_idx_type len = length (); if (a.numel () != len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); for (octave_idx_type i = 0; i < len; i++) elem (i, i) = a.elem (i); @@ -95,10 +89,7 @@ { octave_idx_type len = length (); if (a.numel () != len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); for (octave_idx_type i = 0; i < len; i++) elem (i, i) = a.elem (i); @@ -111,10 +102,7 @@ { octave_idx_type a_len = a.numel (); if (beg < 0 || beg + a_len >= length ()) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); for (octave_idx_type i = 0; i < a_len; i++) elem (i+beg, i+beg) = a.elem (i); @@ -127,10 +115,7 @@ { octave_idx_type a_len = a.numel (); if (beg < 0 || beg + a_len >= length ()) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); for (octave_idx_type i = 0; i < a_len; i++) elem (i+beg, i+beg) = a.elem (i); @@ -183,10 +168,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= r) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return RowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); RowVector retval (c, 0.0); if (r <= c || (r > c && i < c)) @@ -199,10 +181,7 @@ DiagMatrix::row (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return RowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); char c = *s; if (c == 'f' || c == 'F') @@ -210,10 +189,7 @@ else if (c == 'l' || c == 'L') return row (rows () - 1); else - { - (*current_liboctave_error_handler) ("invalid row selection"); - return RowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); } ColumnVector @@ -222,10 +198,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= c) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); ColumnVector retval (r, 0.0); if (r >= c || (r < c && i < r)) @@ -238,10 +211,7 @@ DiagMatrix::column (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); char c = *s; if (c == 'f' || c == 'F') @@ -249,10 +219,7 @@ else if (c == 'l' || c == 'L') return column (cols () - 1); else - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); } DiagMatrix @@ -269,10 +236,7 @@ octave_idx_type c = cols (); octave_idx_type len = length (); if (r != c) - { - (*current_liboctave_error_handler) ("inverse requires square matrix"); - return DiagMatrix (); - } + (*current_liboctave_error_handler) ("inverse requires square matrix"); DiagMatrix retval (r, c); @@ -345,16 +309,11 @@ { DET det (1.0); if (rows () != cols ()) - { - (*current_liboctave_error_handler) ("determinant requires square matrix"); - det = 0.0; - } - else - { - octave_idx_type len = length (); - for (octave_idx_type i = 0; i < len; i++) - det *= elem (i, i); - } + (*current_liboctave_error_handler) ("determinant requires square matrix"); + + octave_idx_type len = length (); + for (octave_idx_type i = 0; i < len; i++) + det *= elem (i, i); return det; }