comparison liboctave/util/sparse-util.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 9d9270e2f98f
children f7121e111991
comparison
equal deleted inserted replaced
21135:95da3bc8a281 21136:7cac4e7458f2
42 #ifdef HAVE_CHOLMOD 42 #ifdef HAVE_CHOLMOD
43 43
44 void 44 void
45 SparseCholError (int status, const char *file, int line, const char *message) 45 SparseCholError (int status, const char *file, int line, const char *message)
46 { 46 {
47
48 // Ignore CHOLMOD_NOT_POSDEF, since we handle that in Fchol as an 47 // Ignore CHOLMOD_NOT_POSDEF, since we handle that in Fchol as an
49 // error or exit status. 48 // error or exit status.
50 if (status != CHOLMOD_NOT_POSDEF) 49 if (status != CHOLMOD_NOT_POSDEF)
51 (*current_liboctave_warning_with_id_handler) 50 (*current_liboctave_warning_with_id_handler)
52 ("Octave:cholmod-message", "warning %i, at line %i in file %s: %s", 51 ("Octave:cholmod-message", "warning %i, at line %i in file %s: %s",
79 octave_idx_type nnz) 78 octave_idx_type nnz)
80 { 79 {
81 if (nnz > 0) 80 if (nnz > 0)
82 { 81 {
83 if (c[0] != 0) 82 if (c[0] != 0)
84 { 83 (*current_liboctave_error_handler)
85 (*current_liboctave_error_handler) 84 ("invalid sparse matrix: cidx[0] must be zero");
86 ("invalid sparse matrix: cidx[0] must be zero");
87 return false;
88 }
89 85
90 octave_idx_type jold = 0; 86 octave_idx_type jold = 0;
91 87
92 for (octave_idx_type j = 1; j < ncols+1; j++) 88 for (octave_idx_type j = 1; j < ncols+1; j++)
93 { 89 {
94 if (c[j] < c[j-1]) 90 if (c[j] < c[j-1])
95 { 91 (*current_liboctave_error_handler)
96 (*current_liboctave_error_handler) 92 ("invalid sparse matrix: cidx elements must appear in ascending order");
97 ("invalid sparse matrix: cidx elements must appear in ascending order");
98 return false;
99 }
100 93
101 if (c[j] > nnz) 94 if (c[j] > nnz)
102 { 95 (*current_liboctave_error_handler)
103 (*current_liboctave_error_handler) 96 ("invalid sparse matrix: cidx[%d] = %d "
104 ("invalid sparse matrix: cidx[%d] = %d exceeds number of nonzero elements", 97 "exceeds number of nonzero elements", j, c[j]+1);
105 j, c[j]+1);
106 return false;
107 }
108 98
109 if (c[j] != jold) 99 if (c[j] != jold)
110 { 100 {
111 for (octave_idx_type i = jold+1; i < c[j]; i++) 101 for (octave_idx_type i = jold+1; i < c[j]; i++)
112 { 102 {
113 if (r[i] < r[i-1]) 103 if (r[i] < r[i-1])
114 { 104 (*current_liboctave_error_handler)
115 (*current_liboctave_error_handler) 105 ("invalid sparse matrix: ridx elements must appear "
116 ("invalid sparse matrix: ridx elements must appear in ascending order for each column"); 106 "in ascending order for each column");
117 return false;
118 }
119 107
120 if (r[i] >= nrows) 108 if (r[i] >= nrows)
121 { 109 (*current_liboctave_error_handler)
122 (*current_liboctave_error_handler) 110 ("invalid sparse matrix: ridx[%d] = %d out of range",
123 ("invalid sparse matrix: ridx[%d] = %d out of range", 111 i, r[i]+1);
124 i, r[i]+1);
125 return false;
126 }
127 } 112 }
128 113
129 jold = c[j]; 114 jold = c[j];
130 } 115 }
131 } 116 }