# HG changeset patch # User Rik # Date 1453585923 28800 # Node ID 7cac4e7458f24d52969b231c179d5558480aa62d # Parent 95da3bc8a281962c480640391cbc8581066f7cd9 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. diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/Array-util.cc --- a/liboctave/array/Array-util.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/Array-util.cc Sat Jan 23 13:52:03 2016 -0800 @@ -538,83 +538,81 @@ idx_vector retval; octave_idx_type len = idxa.numel (); - if (len >= 1) - { - const dim_vector dvx = dv.redim (len); - bool all_ranges = true; - octave_idx_type clen = -1; + if (len == 0) + (*current_liboctave_error_handler) ("sub2ind: needs at least 2 indices"); + + const dim_vector dvx = dv.redim (len); + bool all_ranges = true; + octave_idx_type clen = -1; - for (octave_idx_type i = 0; i < len; i++) + for (octave_idx_type i = 0; i < len; i++) + { + try { - try - { - idx_vector idx = idxa(i); - octave_idx_type n = dvx(i); + idx_vector idx = idxa(i); + octave_idx_type n = dvx(i); - all_ranges = all_ranges && idx.is_range (); - if (clen < 0) - clen = idx.length (n); - else if (clen != idx.length (n)) - (*current_liboctave_error_handler) - ("sub2ind: lengths of indices must match"); + all_ranges = all_ranges && idx.is_range (); + if (clen < 0) + clen = idx.length (n); + else if (clen != idx.length (n)) + (*current_liboctave_error_handler) + ("sub2ind: lengths of indices must match"); - if (idx.extent (n) > n) - err_index_out_of_range (len, i+1, idx.extent (n), n); - } - catch (index_exception& e) - { - e.set_pos_if_unset (len, i+1); - e.set_var (); - std::string msg = e.message (); - (*current_liboctave_error_with_id_handler) - (e.err_id (), msg.c_str ()); - } + if (idx.extent (n) > n) + err_index_out_of_range (len, i+1, idx.extent (n), n); } - // idxa known to be valid. Shouldn't need to catch index_exception below here. + catch (index_exception& e) + { + e.set_pos_if_unset (len, i+1); + e.set_var (); + std::string msg = e.message (); + (*current_liboctave_error_with_id_handler) + (e.err_id (), msg.c_str ()); + } + } + // idxa known to be valid. Shouldn't need to catch index_exception below here. - if (len == 1) - retval = idxa(0); - else if (clen == 1) - { - // All scalars case - the result is a scalar. - octave_idx_type idx = idxa(len-1)(0); - for (octave_idx_type i = len - 2; i >= 0; i--) - idx = dvx(i) * idx + idxa(i)(0); - retval = idx_vector (idx); - } - else if (all_ranges && clen != 0) + if (len == 1) + retval = idxa(0); + else if (clen == 1) + { + // All scalars case - the result is a scalar. + octave_idx_type idx = idxa(len-1)(0); + for (octave_idx_type i = len - 2; i >= 0; i--) + idx = dvx(i) * idx + idxa(i)(0); + retval = idx_vector (idx); + } + else if (all_ranges && clen != 0) + { + // All ranges case - the result is a range. + octave_idx_type start = 0; + octave_idx_type step = 0; + for (octave_idx_type i = len - 1; i >= 0; i--) { - // All ranges case - the result is a range. - octave_idx_type start = 0; - octave_idx_type step = 0; - for (octave_idx_type i = len - 1; i >= 0; i--) - { - octave_idx_type xstart = idxa(i)(0); - octave_idx_type xstep = idxa(i)(1) - xstart; - start = dvx(i) * start + xstart; - step = dvx(i) * step + xstep; - } - retval = idx_vector::make_range (start, step, clen); + octave_idx_type xstart = idxa(i)(0); + octave_idx_type xstep = idxa(i)(1) - xstart; + start = dvx(i) * start + xstart; + step = dvx(i) * step + xstep; } - else - { - Array idx (idxa(0).orig_dimensions ()); - octave_idx_type *idx_vec = idx.fortran_vec (); - - for (octave_idx_type i = len - 1; i >= 0; i--) - { - if (i < len - 1) - idxa(i).loop (clen, sub2ind_helper (idx_vec, dvx(i))); - else - idxa(i).copy_data (idx_vec); - } - - retval = idx_vector (idx); - } + retval = idx_vector::make_range (start, step, clen); } else - (*current_liboctave_error_handler) ("sub2ind: needs at least 2 indices"); + { + Array idx (idxa(0).orig_dimensions ()); + octave_idx_type *idx_vec = idx.fortran_vec (); + + for (octave_idx_type i = len - 1; i >= 0; i--) + { + if (i < len - 1) + idxa(i).loop (clen, sub2ind_helper (idx_vec, dvx(i))); + else + idxa(i).copy_data (idx_vec); + } + + retval = idx_vector (idx); + } return retval; } @@ -629,41 +627,39 @@ if (idx.extent (numel) > numel) (*current_liboctave_error_handler) ("ind2sub: index out of range"); + + if (idx.is_scalar ()) + { + octave_idx_type k = idx(0); + for (octave_idx_type j = 0; j < n; j++) + { + retval(j) = k % dv(j); + k /= dv(j); + } + } else { - if (idx.is_scalar ()) + OCTAVE_LOCAL_BUFFER (Array, rdata, n); + + dim_vector odv = idx.orig_dimensions (); + for (octave_idx_type j = 0; j < n; j++) + rdata[j] = Array (odv); + + for (octave_idx_type i = 0; i < len; i++) { - octave_idx_type k = idx(0); + octave_idx_type k = idx(i); for (octave_idx_type j = 0; j < n; j++) { - retval(j) = k % dv(j); + rdata[j](i) = k % dv(j); k /= dv(j); } } - else - { - OCTAVE_LOCAL_BUFFER (Array, rdata, n); - dim_vector odv = idx.orig_dimensions (); - for (octave_idx_type j = 0; j < n; j++) - rdata[j] = Array (odv); - - for (octave_idx_type i = 0; i < len; i++) - { - octave_idx_type k = idx(i); - for (octave_idx_type j = 0; j < n; j++) - { - rdata[j](i) = k % dv(j); - k /= dv(j); - } - } - - for (octave_idx_type j = 0; j < n; j++) - retval(j) = rdata[j]; - } + for (octave_idx_type j = 0; j < n; j++) + retval(j) = rdata[j]; + } - } return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/Array.cc --- a/liboctave/array/Array.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/Array.cc Sat Jan 23 13:52:03 2016 -0800 @@ -467,22 +467,14 @@ { octave_idx_type perm_elt = perm_vec.elem (i); if (perm_elt >= perm_vec_len || perm_elt < 0) - { - (*current_liboctave_error_handler) - ("%s: permutation vector contains an invalid element", - inv ? "ipermute" : "permute"); - - return retval; - } + (*current_liboctave_error_handler) + ("%s: permutation vector contains an invalid element", + inv ? "ipermute" : "permute"); if (checked[perm_elt]) - { - (*current_liboctave_error_handler) - ("%s: permutation vector cannot contain identical elements", - inv ? "ipermute" : "permute"); - - return retval; - } + (*current_liboctave_error_handler) + ("%s: permutation vector cannot contain identical elements", + inv ? "ipermute" : "permute"); else { checked[perm_elt] = true; @@ -1446,11 +1438,7 @@ Array::delete_elements (int dim, const idx_vector& i) { if (dim < 0 || dim >= ndims ()) - { - (*current_liboctave_error_handler) - ("invalid dimension in delete_elements"); - return; - } + (*current_liboctave_error_handler) ("invalid dimension in delete_elements"); octave_idx_type n = dimensions(dim); if (i.is_colon ()) @@ -1779,11 +1767,7 @@ Array::sort (int dim, sortmode mode) const { if (dim < 0) - { - (*current_liboctave_error_handler) - ("sort: invalid dimension"); - return Array (); - } + (*current_liboctave_error_handler) ("sort: invalid dimension"); Array m (dims ()); @@ -1900,11 +1884,7 @@ sortmode mode) const { if (dim < 0 || dim >= ndims ()) - { - (*current_liboctave_error_handler) - ("sort: invalid dimension"); - return Array (); - } + (*current_liboctave_error_handler) ("sort: invalid dimension"); Array m (dims ()); @@ -2340,11 +2320,7 @@ Array::nth_element (const idx_vector& n, int dim) const { if (dim < 0) - { - (*current_liboctave_error_handler) - ("nth_element: invalid dimension"); - return Array (); - } + (*current_liboctave_error_handler) ("nth_element: invalid dimension"); dim_vector dv = dims (); if (dim >= dv.length ()) @@ -2391,20 +2367,13 @@ } if (mode == UNSORTED) - { - (*current_liboctave_error_handler) - ("nth_element: n must be a scalar or a contiguous range"); - return Array (); - } + (*current_liboctave_error_handler) + ("nth_element: n must be a scalar or a contiguous range"); octave_idx_type up = lo + nn; if (lo < 0 || up > ns) - { - (*current_liboctave_error_handler) - ("nth_element: invalid element index"); - return Array (); - } + (*current_liboctave_error_handler) ("nth_element: invalid element index"); octave_idx_type iter = numel () / ns; octave_idx_type stride = 1; @@ -2544,78 +2513,76 @@ if (nd > 2) (*current_liboctave_error_handler) ("Matrix must be 2-dimensional"); + + octave_idx_type nnr = dv(0); + octave_idx_type nnc = dv(1); + + if (nnr == 0 && nnc == 0) + ; // do nothing for empty matrix + else if (nnr != 1 && nnc != 1) + { + // Extract diag from matrix + if (k > 0) + nnc -= k; + else if (k < 0) + nnr += k; + + if (nnr > 0 && nnc > 0) + { + octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; + + d.resize (dim_vector (ndiag, 1)); + + if (k > 0) + { + for (octave_idx_type i = 0; i < ndiag; i++) + d.xelem (i) = elem (i, i+k); + } + else if (k < 0) + { + for (octave_idx_type i = 0; i < ndiag; i++) + d.xelem (i) = elem (i-k, i); + } + else + { + for (octave_idx_type i = 0; i < ndiag; i++) + d.xelem (i) = elem (i, i); + } + } + else // Matlab returns [] 0x1 for out-of-range diagonal + d.resize (dim_vector (0, 1)); + } else { - octave_idx_type nnr = dv(0); - octave_idx_type nnc = dv(1); - - if (nnr == 0 && nnc == 0) - ; // do nothing for empty matrix - else if (nnr != 1 && nnc != 1) + // Create diag matrix from vector + octave_idx_type roff = 0; + octave_idx_type coff = 0; + if (k > 0) + { + roff = 0; + coff = k; + } + else if (k < 0) { - // Extract diag from matrix - if (k > 0) - nnc -= k; - else if (k < 0) - nnr += k; - - if (nnr > 0 && nnc > 0) - { - octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; - - d.resize (dim_vector (ndiag, 1)); - - if (k > 0) - { - for (octave_idx_type i = 0; i < ndiag; i++) - d.xelem (i) = elem (i, i+k); - } - else if (k < 0) - { - for (octave_idx_type i = 0; i < ndiag; i++) - d.xelem (i) = elem (i-k, i); - } - else - { - for (octave_idx_type i = 0; i < ndiag; i++) - d.xelem (i) = elem (i, i); - } - } - else // Matlab returns [] 0x1 for out-of-range diagonal - d.resize (dim_vector (0, 1)); + roff = -k; + coff = 0; + } + + if (nnr == 1) + { + octave_idx_type n = nnc + std::abs (k); + d = Array (dim_vector (n, n), resize_fill_value ()); + + for (octave_idx_type i = 0; i < nnc; i++) + d.xelem (i+roff, i+coff) = elem (0, i); } else { - // Create diag matrix from vector - octave_idx_type roff = 0; - octave_idx_type coff = 0; - if (k > 0) - { - roff = 0; - coff = k; - } - else if (k < 0) - { - roff = -k; - coff = 0; - } - - if (nnr == 1) - { - octave_idx_type n = nnc + std::abs (k); - d = Array (dim_vector (n, n), resize_fill_value ()); - - for (octave_idx_type i = 0; i < nnc; i++) - d.xelem (i+roff, i+coff) = elem (0, i); - } - else - { - octave_idx_type n = nnr + std::abs (k); - d = Array (dim_vector (n, n), resize_fill_value ()); - - for (octave_idx_type i = 0; i < nnr; i++) - d.xelem (i+roff, i+coff) = elem (i, 0); - } + octave_idx_type n = nnr + std::abs (k); + d = Array (dim_vector (n, n), resize_fill_value ()); + + for (octave_idx_type i = 0; i < nnr; i++) + d.xelem (i+roff, i+coff) = elem (i, 0); } } @@ -2626,18 +2593,13 @@ Array Array::diag (octave_idx_type m, octave_idx_type n) const { - Array retval; - - if (ndims () == 2 && (rows () == 1 || cols () == 1)) - { - retval.resize (dim_vector (m, n), resize_fill_value ()); - - for (octave_idx_type i = 0; i < numel (); i++) - retval.xelem (i, i) = xelem (i); - } - else - (*current_liboctave_error_handler) - ("cat: invalid dimension"); + if (ndims () != 2 || (rows () != 1 && cols () != 1)) + (*current_liboctave_error_handler) ("cat: invalid dimension"); + + Array retval (dim_vector (m, n), resize_fill_value ()); + + for (octave_idx_type i = 0; i < numel (); i++) + retval.xelem (i, i) = xelem (i); return retval; } @@ -2655,8 +2617,7 @@ dim = -dim - 1; } else if (dim < 0) - (*current_liboctave_error_handler) - ("cat: invalid dimension"); + (*current_liboctave_error_handler) ("cat: invalid dimension"); if (n == 1) return array_list[0]; @@ -2707,8 +2668,7 @@ for (octave_idx_type i = istart; i < n; i++) if (! (dv.*concat_rule) (array_list[i].dims (), dim)) - (*current_liboctave_error_handler) - ("cat: dimension mismatch"); + (*current_liboctave_error_handler) ("cat: dimension mismatch"); Array retval (dv); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CColVector.cc --- a/liboctave/array/CColVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CColVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -80,10 +80,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -102,10 +99,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -157,10 +151,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } @@ -182,10 +173,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CDiagMatrix.cc --- a/liboctave/array/CDiagMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CDiagMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -79,10 +79,7 @@ ComplexDiagMatrix::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; @@ -95,10 +92,7 @@ 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; @@ -111,10 +105,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); @@ -127,10 +118,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); @@ -143,10 +131,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); @@ -159,10 +144,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); @@ -175,10 +157,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); @@ -191,10 +170,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); @@ -207,10 +183,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); @@ -223,10 +196,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); @@ -275,10 +245,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= r) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return ComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); ComplexRowVector retval (c, 0.0); if (r <= c || (r > c && i < c)) @@ -291,10 +258,7 @@ ComplexDiagMatrix::row (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return ComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); char c = *s; if (c == 'f' || c == 'F') @@ -302,10 +266,7 @@ else if (c == 'l' || c == 'L') return row (rows () - 1); else - { - (*current_liboctave_error_handler) ("invalid row selection"); - return ComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); } ComplexColumnVector @@ -314,10 +275,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= c) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); ComplexColumnVector retval (r, 0.0); if (r >= c || (r < c && i < r)) @@ -330,10 +288,7 @@ ComplexDiagMatrix::column (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); char c = *s; if (c == 'f' || c == 'F') @@ -341,10 +296,7 @@ else if (c == 'l' || c == 'L') return column (cols () - 1); else - { - (*current_liboctave_error_handler) ("invalid column selection"); - return ComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); } ComplexDiagMatrix @@ -360,10 +312,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (r != c) - { - (*current_liboctave_error_handler) ("inverse requires square matrix"); - return ComplexDiagMatrix (); - } + (*current_liboctave_error_handler) ("inverse requires square matrix"); ComplexDiagMatrix retval (r, c); @@ -524,16 +473,11 @@ { ComplexDET det (1.0); if (rows () != cols ()) - { - (*current_liboctave_error_handler) ("determinant requires square matrix"); - det = ComplexDET (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; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CMatrix.cc --- a/liboctave/array/CMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -403,10 +403,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_nr >0 && a_nc > 0) { @@ -426,10 +423,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -449,10 +443,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -473,10 +464,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -507,10 +495,7 @@ { octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); for (octave_idx_type i = 0; i < a_len; i++) elem (r, c+i) = a.elem (i); @@ -525,10 +510,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -549,10 +531,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -614,10 +593,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -643,10 +619,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -669,10 +642,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.cols ()); @@ -687,10 +657,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.numel ()); @@ -705,10 +672,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + 1); @@ -723,10 +687,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.cols ()); @@ -741,10 +702,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.cols ()); @@ -759,10 +717,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.numel ()); @@ -777,10 +732,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + 1); @@ -795,10 +747,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; ComplexMatrix retval (nr, nc + a.cols ()); @@ -813,11 +762,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.rows (), nc); @@ -832,11 +777,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + 1, nc); @@ -851,11 +792,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.numel (), nc); @@ -870,11 +807,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.rows (), nc); @@ -889,11 +822,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.rows (), nc); @@ -908,11 +837,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + 1, nc); @@ -927,11 +852,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.numel (), nc); @@ -946,11 +867,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; ComplexMatrix retval (nr + a.rows (), nc); @@ -1049,49 +966,47 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + int typ = mattype.type (); + char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); + char udiag = 'N'; + retval = *this; + Complex *tmp_data = retval.fortran_vec (); + + F77_XFCN (ztrtri, ZTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&udiag, 1), + nr, tmp_data, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) { - int typ = mattype.type (); - char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); - char udiag = 'N'; - retval = *this; - Complex *tmp_data = retval.fortran_vec (); - - F77_XFCN (ztrtri, ZTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + octave_idx_type ztrcon_info = 0; + char job = '1'; + + OCTAVE_LOCAL_BUFFER (Complex, cwork, 2*nr); + OCTAVE_LOCAL_BUFFER (double, rwork, nr); + + F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, info + nr, tmp_data, nr, rcon, + cwork, rwork, ztrcon_info + F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + if (ztrcon_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type ztrcon_info = 0; - char job = '1'; - - OCTAVE_LOCAL_BUFFER (Complex, cwork, 2*nr); - OCTAVE_LOCAL_BUFFER (double, rwork, nr); - - F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, rcon, - cwork, rwork, ztrcon_info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (ztrcon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. } + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. + return retval; } @@ -1106,77 +1021,75 @@ if (nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + retval = *this; + Complex *tmp_data = retval.fortran_vec (); + + Array z (dim_vector (1, 1)); + octave_idx_type lwork = -1; + + // Query the optimum work array size. + + F77_XFCN (zgetri, ZGETRI, (nc, tmp_data, nr, pipvt, + z.fortran_vec (), lwork, info)); + + lwork = static_cast (std::real (z(0))); + lwork = (lwork < 2 *nc ? 2*nc : lwork); + z.resize (dim_vector (lwork, 1)); + Complex *pz = z.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + double anorm; + //if (calc_cond) // Must always calculate anorm for bug #45577 + anorm = retval.abs ().sum ().row (static_cast(0)).max (); + + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -1; + else + F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) + { + // Now calculate the condition number for non-singular matrix. + octave_idx_type zgecon_info = 0; + char job = '1'; + Array rz (dim_vector (2 * nc, 1)); + double *prz = rz.fortran_vec (); + F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, + rcon, pz, prz, zgecon_info + F77_CHAR_ARG_LEN (1))); + + if (zgecon_info != 0) + info = -1; + } + + if (info == -1 && ! force) + retval = *this; // Restore contents. else { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - retval = *this; - Complex *tmp_data = retval.fortran_vec (); - - Array z (dim_vector (1, 1)); - octave_idx_type lwork = -1; - - // Query the optimum work array size. + octave_idx_type zgetri_info = 0; F77_XFCN (zgetri, ZGETRI, (nc, tmp_data, nr, pipvt, - z.fortran_vec (), lwork, info)); - - lwork = static_cast (std::real (z(0))); - lwork = (lwork < 2 *nc ? 2*nc : lwork); - z.resize (dim_vector (lwork, 1)); - Complex *pz = z.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - double anorm; - //if (calc_cond) // Must always calculate anorm for bug #45577 - anorm = retval.abs ().sum ().row (static_cast(0)).max (); - - // Work around bug #45577, LAPACK crashes Octave if norm is NaN - if (xisnan (anorm)) - info = -1; - else - F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + pz, lwork, zgetri_info)); + + if (zgetri_info != 0) info = -1; - else if (calc_cond) - { - // Now calculate the condition number for non-singular matrix. - octave_idx_type zgecon_info = 0; - char job = '1'; - Array rz (dim_vector (2 * nc, 1)); - double *prz = rz.fortran_vec (); - F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, prz, zgecon_info - F77_CHAR_ARG_LEN (1))); - - if (zgecon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore contents. - else - { - octave_idx_type zgetri_info = 0; - - F77_XFCN (zgetri, ZGETRI, (nc, tmp_data, nr, pipvt, - pz, lwork, zgetri_info)); - - if (zgetri_info != 0) - info = -1; - } - - if (info != 0) - mattype.mark_as_rectangular (); } + if (info != 0) + mattype.mark_as_rectangular (); + return retval; } @@ -1627,91 +1540,112 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else + + volatile int typ = mattype.type (); + + // Even though the matrix is marked as singular (Rectangular), we may + // still get a useful number from the LU factorization, because it always + // completes. + + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + else if (typ == MatrixType::Rectangular) + typ = MatrixType::Full; + + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { - volatile int typ = mattype.type (); - - // Even though the matrix is marked as singular (Rectangular), we may - // still get a useful number from the LU factorization, because it always - // completes. - - if (typ == MatrixType::Unknown) - typ = mattype.type (*this); - else if (typ == MatrixType::Rectangular) - typ = MatrixType::Full; - - if (typ == MatrixType::Lower || typ == MatrixType::Upper) + for (octave_idx_type i = 0; i < nc; i++) + retval *= elem (i,i); + } + else if (typ == MatrixType::Hermitian) + { + ComplexMatrix atmp = *this; + Complex *tmp_data = atmp.fortran_vec (); + + double anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + + char job = 'L'; + F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, + tmp_data, nr, info + F77_CHAR_ARG_LEN (1))); + + if (info != 0) { - for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + rcon = 0.0; + mattype.mark_as_unsymmetric (); + typ = MatrixType::Full; } - else if (typ == MatrixType::Hermitian) + else { - ComplexMatrix atmp = *this; - Complex *tmp_data = atmp.fortran_vec (); - - double anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - - char job = 'L'; - F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, - tmp_data, nr, info + Array z (dim_vector (2 * nc, 1)); + Complex *pz = z.fortran_vec (); + Array rz (dim_vector (nc, 1)); + double *prz = rz.fortran_vec (); + + F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), + nr, tmp_data, nr, anorm, + rcon, pz, prz, info F77_CHAR_ARG_LEN (1))); if (info != 0) + rcon = 0.0; + + for (octave_idx_type i = 0; i < nc; i++) + retval *= atmp (i,i); + + retval = retval.square (); + } + } + else if (typ != MatrixType::Full) + (*current_liboctave_error_handler) ("det: invalid dense matrix type"); + + if (typ == MatrixType::Full) + { + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + ComplexMatrix atmp = *this; + Complex *tmp_data = atmp.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + double anorm = 0; + //if (calc_cond) // Must always calculate anorm for bug #45577 + anorm = xnorm (*this, 1); + + // Work around bug #45577, LAPACK crashes Octave if norm is NaN + if (xisnan (anorm)) + info = -1; + else + F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + { + info = -1; + retval = ComplexDET (); + } + else + { + if (calc_cond) { - rcon = 0.0; - mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; - } - else - { + // Now calc the condition number for non-singular matrix. + char job = '1'; Array z (dim_vector (2 * nc, 1)); Complex *pz = z.fortran_vec (); - Array rz (dim_vector (nc, 1)); + Array rz (dim_vector (2 * nc, 1)); double *prz = rz.fortran_vec (); - F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), - nr, tmp_data, nr, anorm, + F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, rcon, pz, prz, info F77_CHAR_ARG_LEN (1))); - - if (info != 0) - rcon = 0.0; - - for (octave_idx_type i = 0; i < nc; i++) - retval *= atmp (i,i); - - retval = retval.square (); } - } - else if (typ != MatrixType::Full) - (*current_liboctave_error_handler) ("det: invalid dense matrix type"); - - if (typ == MatrixType::Full) - { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - ComplexMatrix atmp = *this; - Complex *tmp_data = atmp.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - double anorm = 0; - //if (calc_cond) // Must always calculate anorm for bug #45577 - anorm = xnorm (*this, 1); - - // Work around bug #45577, LAPACK crashes Octave if norm is NaN - if (xisnan (anorm)) - info = -1; - else - F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; + if (info != 0) { info = -1; @@ -1719,33 +1653,10 @@ } else { - if (calc_cond) + for (octave_idx_type i = 0; i < nc; i++) { - // Now calc the condition number for non-singular matrix. - char job = '1'; - Array z (dim_vector (2 * nc, 1)); - Complex *pz = z.fortran_vec (); - Array rz (dim_vector (2 * nc, 1)); - double *prz = rz.fortran_vec (); - - F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, prz, info - F77_CHAR_ARG_LEN (1))); - } - - if (info != 0) - { - info = -1; - retval = ComplexDET (); - } - else - { - for (octave_idx_type i = 0; i < nc; i++) - { - Complex c = atmp(i,i); - retval *= (ipvt(i) != (i+1)) ? -c : c; - } + Complex c = atmp(i,i); + retval *= (ipvt(i) != (i+1)) ? -c : c; } } } @@ -1770,7 +1681,8 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) rcon = octave_Inf; else { @@ -1944,82 +1856,77 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { volatile int typ = mattype.type (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + rcon = 1.; + info = 0; + + if (typ == MatrixType::Permuted_Upper) + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); + + const Complex *tmp_data = fortran_vec (); + + retval = b; + Complex *result = retval.fortran_vec (); + + char uplo = 'U'; + char trans = get_blas_char (transt); + char dia = 'N'; + + F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&trans, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, b_nc, tmp_data, nr, + result, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (calc_cond) { - octave_idx_type b_nc = b.cols (); - rcon = 1.; - info = 0; - - if (typ == MatrixType::Permuted_Upper) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } - else + char norm = '1'; + uplo = 'U'; + dia = 'N'; + + Array z (dim_vector (2 * nc, 1)); + Complex *pz = z.fortran_vec (); + Array rz (dim_vector (nc, 1)); + double *prz = rz.fortran_vec (); + + F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, tmp_data, nr, rcon, + pz, prz, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (info != 0) + info = -2; + + volatile double rcond_plus_one = rcon + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcon)) { - const Complex *tmp_data = fortran_vec (); - - retval = b; - Complex *result = retval.fortran_vec (); - - char uplo = 'U'; - char trans = get_blas_char (transt); - char dia = 'N'; - - F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&trans, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, b_nc, tmp_data, nr, - result, nr, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (calc_cond) - { - char norm = '1'; - uplo = 'U'; - dia = 'N'; - - Array z (dim_vector (2 * nc, 1)); - Complex *pz = z.fortran_vec (); - Array rz (dim_vector (nc, 1)); - double *prz = rz.fortran_vec (); - - F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, tmp_data, nr, rcon, - pz, prz, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (info != 0) - info = -2; - - volatile double rcond_plus_one = rcon + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcon)) - { - info = -2; - - if (sing_handler) - sing_handler (rcon); - else - warn_singular_matrix (rcon); - } - } + info = -2; + + if (sing_handler) + sing_handler (rcon); + else + warn_singular_matrix (rcon); } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); } return retval; @@ -2039,82 +1946,77 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { volatile int typ = mattype.type (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + rcon = 1.; + info = 0; + + if (typ == MatrixType::Permuted_Lower) + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); + + const Complex *tmp_data = fortran_vec (); + + retval = b; + Complex *result = retval.fortran_vec (); + + char uplo = 'L'; + char trans = get_blas_char (transt); + char dia = 'N'; + + F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&trans, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, b_nc, tmp_data, nr, + result, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (calc_cond) { - octave_idx_type b_nc = b.cols (); - rcon = 1.; - info = 0; - - if (typ == MatrixType::Permuted_Lower) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } - else + char norm = '1'; + uplo = 'L'; + dia = 'N'; + + Array z (dim_vector (2 * nc, 1)); + Complex *pz = z.fortran_vec (); + Array rz (dim_vector (nc, 1)); + double *prz = rz.fortran_vec (); + + F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, tmp_data, nr, rcon, + pz, prz, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (info != 0) + info = -2; + + volatile double rcond_plus_one = rcon + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcon)) { - const Complex *tmp_data = fortran_vec (); - - retval = b; - Complex *result = retval.fortran_vec (); - - char uplo = 'L'; - char trans = get_blas_char (transt); - char dia = 'N'; - - F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&trans, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, b_nc, tmp_data, nr, - result, nr, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (calc_cond) - { - char norm = '1'; - uplo = 'L'; - dia = 'N'; - - Array z (dim_vector (2 * nc, 1)); - Complex *pz = z.fortran_vec (); - Array rz (dim_vector (nc, 1)); - double *prz = rz.fortran_vec (); - - F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, tmp_data, nr, rcon, - pz, prz, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (info != 0) - info = -2; - - volatile double rcond_plus_one = rcon + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcon)) - { - info = -2; - - if (sing_handler) - sing_handler (rcon); - else - warn_singular_matrix (rcon); - } - } + info = -2; + + if (sing_handler) + sing_handler (rcon); + else + warn_singular_matrix (rcon); } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); } return retval; @@ -2135,7 +2037,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -2387,10 +2290,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, info, rcon, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); // Rectangular or one of the above solvers flags a singular matrix if (singular_fallback && mattype.type () == MatrixType::Rectangular) @@ -2666,7 +2566,8 @@ if (m != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m== 0 || n == 0 || b.cols () == 0) + + if (m== 0 || n == 0 || b.cols () == 0) retval = ComplexMatrix (n, b.cols (), Complex (0.0, 0.0)); else { @@ -2863,7 +2764,8 @@ if (m != b.numel ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0 || b.cols () == 0) + + if (m == 0 || n == 0 || b.cols () == 0) retval = ComplexColumnVector (n, Complex (0.0, 0.0)); else { @@ -3170,18 +3072,13 @@ ComplexDiagMatrix ComplexMatrix::diag (octave_idx_type m, octave_idx_type n) const { - ComplexDiagMatrix retval; - octave_idx_type nr = rows (); octave_idx_type nc = cols (); - if (nr == 1 || nc == 1) - retval = ComplexDiagMatrix (*this, m, n); - else - (*current_liboctave_error_handler) - ("diag: expecting vector argument"); - - return retval; + if (nr != 1 && nc != 1) + (*current_liboctave_error_handler) ("diag: expecting vector argument"); + + return ComplexDiagMatrix (*this, m, n); } bool @@ -3858,11 +3755,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg min requires same size arguments"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg min requires same size arguments"); EMPTY_RETURN_CHECK (ComplexMatrix); @@ -3946,11 +3840,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg max requires same size arguments"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg max requires same size arguments"); EMPTY_RETURN_CHECK (ComplexMatrix); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CNDArray.cc --- a/liboctave/array/CNDArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CNDArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -755,46 +755,41 @@ int n = a_dv.length (); - if (n == dimensions.length ()) - { - Array a_ra_idx (dim_vector (a_dv.length (), 1), 0); - - a_ra_idx.elem (0) = r; - a_ra_idx.elem (1) = c; - - for (int i = 0; i < n; i++) - { - if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i)) - { - (*current_liboctave_error_handler) - ("Array::insert: range error for insert"); - return *this; - } - } - - a_ra_idx.elem (0) = 0; - a_ra_idx.elem (1) = 0; - - octave_idx_type n_elt = a.numel (); - - // IS make_unique () NECESSARY HERE? - - for (octave_idx_type i = 0; i < n_elt; i++) - { - Array ra_idx = a_ra_idx; - - ra_idx.elem (0) = a_ra_idx(0) + r; - ra_idx.elem (1) = a_ra_idx(1) + c; - - elem (ra_idx) = a.elem (a_ra_idx); - - increment_index (a_ra_idx, a_dv); - } - } - else + if (n != dimensions.length ()) (*current_liboctave_error_handler) ("Array::insert: invalid indexing operation"); + Array a_ra_idx (dim_vector (a_dv.length (), 1), 0); + + a_ra_idx.elem (0) = r; + a_ra_idx.elem (1) = c; + + for (int i = 0; i < n; i++) + { + if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i)) + (*current_liboctave_error_handler) + ("Array::insert: range error for insert"); + } + + a_ra_idx.elem (0) = 0; + a_ra_idx.elem (1) = 0; + + octave_idx_type n_elt = a.numel (); + + // IS make_unique () NECESSARY HERE? + + for (octave_idx_type i = 0; i < n_elt; i++) + { + Array ra_idx = a_ra_idx; + + ra_idx.elem (0) = a_ra_idx(0) + r; + ra_idx.elem (1) = a_ra_idx(1) + c; + + elem (ra_idx) = a.elem (a_ra_idx); + + increment_index (a_ra_idx, a_dv); + } + return *this; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CRowVector.cc --- a/liboctave/array/CRowVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CRowVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -79,10 +79,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -101,10 +98,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -155,10 +149,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } @@ -180,10 +171,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/CSparse.cc --- a/liboctave/array/CSparse.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/CSparse.cc Sat Jan 23 13:52:03 2016 -0800 @@ -766,44 +766,40 @@ if (nr == 0 || nc == 0 || nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + // Print spparms("spumoni") info if requested + int typ = mattyp.type (); + mattyp.info (); + + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + if (typ == MatrixType::Permuted_Diagonal) + retval = transpose (); else + retval = *this; + + // Force make_unique to be called + Complex *v = retval.data (); + + if (calccond) { - // Print spparms("spumoni") info if requested - int typ = mattyp.type (); - mattyp.info (); - - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nr; i++) { - if (typ == MatrixType::Permuted_Diagonal) - retval = transpose (); - else - retval = *this; - - // Force make_unique to be called - Complex *v = retval.data (); - - if (calccond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nr; i++) - { - double tmp = std::abs (v[i]); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - - for (octave_idx_type i = 0; i < nr; i++) - v[i] = 1.0 / v[i]; + double tmp = std::abs (v[i]); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = dmin / dmax; } + for (octave_idx_type i = 0; i < nr; i++) + v[i] = 1.0 / v[i]; + return retval; } @@ -820,269 +816,243 @@ if (nr == 0 || nc == 0 || nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + // Print spparms("spumoni") info if requested + int typ = mattyp.type (); + mattyp.info (); + + if (typ != MatrixType::Upper && typ != MatrixType::Permuted_Upper + && typ != MatrixType::Lower && typ != MatrixType::Permuted_Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + + if (calccond) { - // Print spparms("spumoni") info if requested - int typ = mattyp.type (); - mattyp.info (); - - if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper - || typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nr; j++) { - double anorm = 0.; - double ainvnorm = 0.; - - if (calccond) - { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nr; j++) - { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Upper || typ == MatrixType::Lower) - { - octave_idx_type nz = nnz (); - octave_idx_type cx = 0; - octave_idx_type nz2 = nz; - retval = SparseComplexMatrix (nr, nc, nz2); - - for (octave_idx_type i = 0; i < nr; i++) + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Upper || typ == MatrixType::Lower) + { + octave_idx_type nz = nnz (); + octave_idx_type cx = 0; + octave_idx_type nz2 = nz; + retval = SparseComplexMatrix (nr, nc, nz2); + + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + // place the 1 in the identity position + octave_idx_type cx_colstart = cx; + + if (cx == nz2) + { + nz2 *= 2; + retval.change_capacity (nz2); + } + + retval.xcidx (i) = cx; + retval.xridx (cx) = i; + retval.xdata (cx) = 1.0; + cx++; + + // iterate accross columns of input matrix + for (octave_idx_type j = i+1; j < nr; j++) + { + Complex v = 0.; + // iterate to calculate sum + octave_idx_type colXp = retval.xcidx (i); + octave_idx_type colUp = cidx (j); + octave_idx_type rpX, rpU; + + if (cidx (j) == cidx (j+1)) + (*current_liboctave_error_handler) ("division by zero"); + + do { octave_quit (); - // place the 1 in the identity position - octave_idx_type cx_colstart = cx; - + rpX = retval.xridx (colXp); + rpU = ridx (colUp); + + if (rpX < rpU) + colXp++; + else if (rpX > rpU) + colUp++; + else + { + v -= retval.xdata (colXp) * data (colUp); + colXp++; + colUp++; + } + } + while (rpX < j && rpU < j && colXp < cx && colUp < nz); + + + // get A(m,m) + if (typ == MatrixType::Upper) + colUp = cidx (j+1) - 1; + else + colUp = cidx (j); + Complex pivot = data (colUp); + if (pivot == 0. || ridx (colUp) != j) + (*current_liboctave_error_handler) ("division by zero"); + + if (v != 0.) + { if (cx == nz2) { nz2 *= 2; retval.change_capacity (nz2); } - retval.xcidx (i) = cx; - retval.xridx (cx) = i; - retval.xdata (cx) = 1.0; + retval.xridx (cx) = j; + retval.xdata (cx) = v / pivot; cx++; - - // iterate accross columns of input matrix - for (octave_idx_type j = i+1; j < nr; j++) - { - Complex v = 0.; - // iterate to calculate sum - octave_idx_type colXp = retval.xcidx (i); - octave_idx_type colUp = cidx (j); - octave_idx_type rpX, rpU; - - if (cidx (j) == cidx (j+1)) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - do - { - octave_quit (); - rpX = retval.xridx (colXp); - rpU = ridx (colUp); - - if (rpX < rpU) - colXp++; - else if (rpX > rpU) - colUp++; - else - { - v -= retval.xdata (colXp) * data (colUp); - colXp++; - colUp++; - } - } - while (rpX < j && rpU < j && colXp < cx && colUp < nz); - - - // get A(m,m) - if (typ == MatrixType::Upper) - colUp = cidx (j+1) - 1; - else - colUp = cidx (j); - Complex pivot = data (colUp); - if (pivot == 0. || ridx (colUp) != j) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - if (v != 0.) - { - if (cx == nz2) - { - nz2 *= 2; - retval.change_capacity (nz2); - } - - retval.xridx (cx) = j; - retval.xdata (cx) = v / pivot; - cx++; - } - } - - // get A(m,m) - octave_idx_type colUp; - if (typ == MatrixType::Upper) - colUp = cidx (i+1) - 1; - else - colUp = cidx (i); - Complex pivot = data (colUp); - if (pivot == 0. || ridx (colUp) != i) - { - (*current_liboctave_error_handler) ("division by zero"); - goto inverse_singular; - } - - if (pivot != 1.0) - for (octave_idx_type j = cx_colstart; j < cx; j++) - retval.xdata (j) /= pivot; } - retval.xcidx (nr) = cx; - retval.maybe_compress (); - } + } + + // get A(m,m) + octave_idx_type colUp; + if (typ == MatrixType::Upper) + colUp = cidx (i+1) - 1; else - { - octave_idx_type nz = nnz (); - octave_idx_type cx = 0; - octave_idx_type nz2 = nz; - retval = SparseComplexMatrix (nr, nc, nz2); - - OCTAVE_LOCAL_BUFFER (Complex, work, nr); - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nr); - - octave_idx_type *perm = mattyp.triangular_perm (); - if (typ == MatrixType::Permuted_Upper) - { - for (octave_idx_type i = 0; i < nr; i++) - rperm[perm[i]] = i; - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - rperm[i] = perm[i]; - for (octave_idx_type i = 0; i < nr; i++) - perm[rperm[i]] = i; - } - - for (octave_idx_type i = 0; i < nr; i++) + colUp = cidx (i); + Complex pivot = data (colUp); + if (pivot == 0. || ridx (colUp) != i) + (*current_liboctave_error_handler) ("division by zero"); + + if (pivot != 1.0) + for (octave_idx_type j = cx_colstart; j < cx; j++) + retval.xdata (j) /= pivot; + } + retval.xcidx (nr) = cx; + retval.maybe_compress (); + } + else + { + octave_idx_type nz = nnz (); + octave_idx_type cx = 0; + octave_idx_type nz2 = nz; + retval = SparseComplexMatrix (nr, nc, nz2); + + OCTAVE_LOCAL_BUFFER (Complex, work, nr); + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nr); + + octave_idx_type *perm = mattyp.triangular_perm (); + if (typ == MatrixType::Permuted_Upper) + { + for (octave_idx_type i = 0; i < nr; i++) + rperm[perm[i]] = i; + } + else + { + for (octave_idx_type i = 0; i < nr; i++) + rperm[i] = perm[i]; + for (octave_idx_type i = 0; i < nr; i++) + perm[rperm[i]] = i; + } + + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + octave_idx_type iidx = rperm[i]; + + for (octave_idx_type j = 0; j < nr; j++) + work[j] = 0.; + + // place the 1 in the identity position + work[iidx] = 1.0; + + // iterate accross columns of input matrix + for (octave_idx_type j = iidx+1; j < nr; j++) + { + Complex v = 0.; + octave_idx_type jidx = perm[j]; + // iterate to calculate sum + for (octave_idx_type k = cidx (jidx); + k < cidx (jidx+1); k++) { octave_quit (); - octave_idx_type iidx = rperm[i]; - - for (octave_idx_type j = 0; j < nr; j++) - work[j] = 0.; - - // place the 1 in the identity position - work[iidx] = 1.0; - - // iterate accross columns of input matrix - for (octave_idx_type j = iidx+1; j < nr; j++) - { - Complex v = 0.; - octave_idx_type jidx = perm[j]; - // iterate to calculate sum - for (octave_idx_type k = cidx (jidx); - k < cidx (jidx+1); k++) - { - octave_quit (); - v -= work[ridx (k)] * data (k); - } - - // get A(m,m) - Complex pivot; - if (typ == MatrixType::Permuted_Upper) - pivot = data (cidx (jidx+1) - 1); - else - pivot = data (cidx (jidx)); - if (pivot == 0.) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - work[j] = v / pivot; - } - - // get A(m,m) - octave_idx_type colUp; - if (typ == MatrixType::Permuted_Upper) - colUp = cidx (perm[iidx]+1) - 1; - else - colUp = cidx (perm[iidx]); - - Complex pivot = data (colUp); - if (pivot == 0.) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - octave_idx_type new_cx = cx; - for (octave_idx_type j = iidx; j < nr; j++) - if (work[j] != 0.0) - { - new_cx++; - if (pivot != 1.0) - work[j] /= pivot; - } - - if (cx < new_cx) - { - nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2); - retval.change_capacity (nz2); - } - - retval.xcidx (i) = cx; - for (octave_idx_type j = iidx; j < nr; j++) - if (work[j] != 0.) - { - retval.xridx (cx) = j; - retval.xdata (cx++) = work[j]; - } + v -= work[ridx (k)] * data (k); } - retval.xcidx (nr) = cx; - retval.maybe_compress (); - } - - if (calccond) - { - // Calculate the 1-norm of inverse matrix for rcond calculation - for (octave_idx_type j = 0; j < nr; j++) - { - double atmp = 0.; - for (octave_idx_type i = retval.cidx (j); - i < retval.cidx (j+1); i++) - atmp += std::abs (retval.data (i)); - if (atmp > ainvnorm) - ainvnorm = atmp; - } - - rcond = 1. / ainvnorm / anorm; - } + // get A(m,m) + Complex pivot; + if (typ == MatrixType::Permuted_Upper) + pivot = data (cidx (jidx+1) - 1); + else + pivot = data (cidx (jidx)); + if (pivot == 0.) + (*current_liboctave_error_handler) ("division by zero"); + + work[j] = v / pivot; + } + + // get A(m,m) + octave_idx_type colUp; + if (typ == MatrixType::Permuted_Upper) + colUp = cidx (perm[iidx]+1) - 1; + else + colUp = cidx (perm[iidx]); + + Complex pivot = data (colUp); + if (pivot == 0.) + (*current_liboctave_error_handler) ("division by zero"); + + octave_idx_type new_cx = cx; + for (octave_idx_type j = iidx; j < nr; j++) + if (work[j] != 0.0) + { + new_cx++; + if (pivot != 1.0) + work[j] /= pivot; + } + + if (cx < new_cx) + { + nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2); + retval.change_capacity (nz2); + } + + retval.xcidx (i) = cx; + for (octave_idx_type j = iidx; j < nr; j++) + if (work[j] != 0.) + { + retval.xridx (cx) = j; + retval.xdata (cx++) = work[j]; + } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.xcidx (nr) = cx; + retval.maybe_compress (); + } + + if (calccond) + { + // Calculate the 1-norm of inverse matrix for rcond calculation + for (octave_idx_type j = 0; j < nr; j++) + { + double atmp = 0.; + for (octave_idx_type i = retval.cidx (j); + i < retval.cidx (j+1); i++) + atmp += std::abs (retval.data (i)); + if (atmp > ainvnorm) + ainvnorm = atmp; + } + + rcond = 1. / ainvnorm / anorm; } return retval; - -inverse_singular: - return SparseComplexMatrix (); } SparseComplexMatrix @@ -1227,13 +1197,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexMatrix::determinant symbolic factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_symbolic) (&Symbolic); + + (*current_liboctave_error_handler) + ("SparseComplexMatrix::determinant symbolic factorization failed"); } else { @@ -1250,13 +1220,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexMatrix::determinant numeric factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseComplexMatrix::determinant numeric factorization failed"); } else { @@ -1269,11 +1239,11 @@ if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + UMFPACK_ZNAME (report_info) (control, info); + (*current_liboctave_error_handler) ("SparseComplexMatrix::determinant error calculating determinant"); - - UMFPACK_ZNAME (report_status) (control, status); - UMFPACK_ZNAME (report_info) (control, info); } else retval = ComplexDET (Complex (c10[0], c10[1]), e10, 10); @@ -1305,7 +1275,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -1313,38 +1284,36 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.resize (nc, b.cols (), Complex (0.,0.)); + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type i = 0; i < nm; i++) + retval(i,j) = b(i,j) / data (i); + else + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type k = 0; k < nc; k++) + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + retval(k,j) = b(ridx (i),j) / data (i); + + if (calc_cond) { - retval.resize (nc, b.cols (), Complex (0.,0.)); - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type i = 0; i < nm; i++) - retval(i,j) = b(i,j) / data (i); - else - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type k = 0; k < nc; k++) - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) - retval(k,j) = b(ridx (i),j) / data (i); - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = std::abs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - else - rcond = 1.0; + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = std::abs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.0; } return retval; @@ -1366,7 +1335,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -1374,68 +1344,66 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) - { - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) { - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - { - if (b.ridx (i) >= nm) - break; - retval.xridx (ii) = b.ridx (i); - retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); - } - retval.xcidx (j+1) = ii; + if (b.ridx (i) >= nm) + break; + retval.xridx (ii) = b.ridx (i); + retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); } - else - for (octave_idx_type j = 0; j < b.cols (); j++) - { - for (octave_idx_type l = 0; l < nc; l++) - for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + retval.xcidx (j+1) = ii; + } + else + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type l = 0; l < nc; l++) + for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + { + bool found = false; + octave_idx_type k; + for (k = b.cidx (j); k < b.cidx (j+1); k++) + if (ridx (i) == b.ridx (k)) + { + found = true; + break; + } + if (found) { - bool found = false; - octave_idx_type k; - for (k = b.cidx (j); k < b.cidx (j+1); k++) - if (ridx (i) == b.ridx (k)) - { - found = true; - break; - } - if (found) - { - retval.xridx (ii) = l; - retval.xdata (ii++) = b.data (k) / data (i); - } + retval.xridx (ii) = l; + retval.xdata (ii++) = b.data (k) / data (i); } - retval.xcidx (j+1) = ii; - } - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = std::abs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; } - rcond = dmin / dmax; - } - else - rcond = 1.0; + retval.xcidx (j+1) = ii; + } + + if (calc_cond) + { + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = std::abs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.0; } return retval; @@ -1457,7 +1425,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -1465,38 +1434,36 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.resize (nc, b.cols (), Complex (0.,0.)); + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type i = 0; i < nm; i++) + retval(i,j) = b(i,j) / data (i); + else + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type k = 0; k < nc; k++) + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + retval(k,j) = b(ridx (i),j) / data (i); + + if (calc_cond) { - retval.resize (nc, b.cols (), Complex (0.,0.)); - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type i = 0; i < nm; i++) - retval(i,j) = b(i,j) / data (i); - else - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type k = 0; k < nc; k++) - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) - retval(k,j) = b(ridx (i),j) / data (i); - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nr; i++) - { - double tmp = std::abs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - else - rcond = 1.0; + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nr; i++) + { + double tmp = std::abs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.0; } return retval; @@ -1518,7 +1485,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -1526,68 +1494,66 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) - { - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) { - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - { - if (b.ridx (i) >= nm) - break; - retval.xridx (ii) = b.ridx (i); - retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); - } - retval.xcidx (j+1) = ii; + if (b.ridx (i) >= nm) + break; + retval.xridx (ii) = b.ridx (i); + retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); } - else - for (octave_idx_type j = 0; j < b.cols (); j++) - { - for (octave_idx_type l = 0; l < nc; l++) - for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + retval.xcidx (j+1) = ii; + } + else + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type l = 0; l < nc; l++) + for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + { + bool found = false; + octave_idx_type k; + for (k = b.cidx (j); k < b.cidx (j+1); k++) + if (ridx (i) == b.ridx (k)) + { + found = true; + break; + } + if (found) { - bool found = false; - octave_idx_type k; - for (k = b.cidx (j); k < b.cidx (j+1); k++) - if (ridx (i) == b.ridx (k)) - { - found = true; - break; - } - if (found) - { - retval.xridx (ii) = l; - retval.xdata (ii++) = b.data (k) / data (i); - } + retval.xridx (ii) = l; + retval.xdata (ii++) = b.data (k) / data (i); } - retval.xcidx (j+1) = ii; - } - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = std::abs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; } - rcond = dmin / dmax; - } - else - rcond = 1.0; + retval.xcidx (j+1) = ii; + } + + if (calc_cond) + { + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = std::abs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.0; } return retval; @@ -1609,7 +1575,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -1617,208 +1584,206 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(perm[i], j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Upper) - { - retval.resize (nc, b_nc); - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + Complex tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } - - Complex tmp = work[k] / data (cidx (kidx+1)-1); + } + } + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + retval.resize (nc, b_nc); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + if (work[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) + { + if (work[k] != 0.) + { + Complex tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval(perm[i], j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } + rcond = 1. / ainvnorm / anorm; + } + } + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); } else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - retval.resize (nc, b_nc); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) - { - if (work[k] != 0.) - { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } + warn_singular_matrix (rcond); } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -1840,7 +1805,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -1848,260 +1814,258 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); + for (octave_idx_type i = 0; i < nc; i++) + rperm[perm[i]] = i; + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[rperm[i]] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[rperm[i]]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Upper) - { - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); - for (octave_idx_type i = 0; i < nc; i++) - rperm[perm[i]] = i; - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + Complex tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } - - Complex tmp = work[k] / data (cidx (kidx+1)-1); + } + } + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + if (work[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) + { + if (work[k] != 0.) + { + Complex tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += std::abs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[rperm[i]] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[rperm[i]]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } + rcond = 1. / ainvnorm / anorm; + } + } + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); } else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) - { - if (work[k] != 0.) - { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } + warn_singular_matrix (rcond); } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; } @@ -2122,7 +2086,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -2130,208 +2095,206 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(perm[i], j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Upper) - { - retval.resize (nc, b_nc); - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + Complex tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } - - Complex tmp = work[k] / data (cidx (kidx+1)-1); + } + } + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + retval.resize (nc, b_nc); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + if (work[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) + { + if (work[k] != 0.) + { + Complex tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval(perm[i], j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } + rcond = 1. / ainvnorm / anorm; + } + } + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); } else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - retval.resize (nc, b_nc); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) - { - if (work[k] != 0.) - { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } + warn_singular_matrix (rcond); } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2353,7 +2316,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -2361,260 +2325,258 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); + for (octave_idx_type i = 0; i < nc; i++) + rperm[perm[i]] = i; + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[rperm[i]] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[rperm[i]]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Upper) - { - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); - for (octave_idx_type i = 0; i < nc; i++) - rperm[perm[i]] = i; - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + Complex tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } - - Complex tmp = work[k] / data (cidx (kidx+1)-1); + } + } + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nr-1; k >= 0; k--) + { + if (work[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) + { + if (work[k] != 0.) + { + Complex tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += std::abs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[rperm[i]] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[rperm[i]]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } + rcond = 1. / ainvnorm / anorm; + } + } + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); } else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nr-1; k >= 0; k--) - { - if (work[k] != 0.) - { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } + warn_singular_matrix (rcond); } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2636,7 +2598,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -2644,38 +2607,86 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = 0; i < nr; i++) + work[perm[i]] = b(i,j); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(i, j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Lower) - { - retval.resize (nc, b_nc); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = 0; i < nr; i++) - work[perm[i]] = b(i,j); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -2684,22 +2695,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -2710,161 +2717,115 @@ } } - for (octave_idx_type i = 0; i < nc; i++) - retval(i, j) = work[i]; + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; } - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + retval.resize (nc, b_nc, 0.); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - Complex tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - retval.resize (nc, b_nc, 0.); - - for (octave_idx_type j = 0; j < b_nc; j++) + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (cidx (k)); work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; - } - } - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); + if (atmp > ainvnorm) + ainvnorm = atmp; } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2887,7 +2848,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -2895,43 +2857,113 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[perm[b.ridx (i)]] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Lower) - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[perm[b.ridx (i)]] = b.data (i); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -2940,22 +2972,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -2966,207 +2994,139 @@ } } - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += std::abs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - Complex tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (cidx (k)); work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3188,7 +3148,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -3196,38 +3157,86 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = 0; i < nr; i++) + work[perm[i]] = b(i,j); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(i, j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Lower) - { - retval.resize (nc, b_nc); - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = 0; i < nr; i++) - work[perm[i]] = b(i,j); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -3236,22 +3245,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -3262,165 +3267,119 @@ } } - for (octave_idx_type i = 0; i < nc; i++) - retval(i, j) = work[i]; + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) + { + atmp += std::abs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; } - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + retval.resize (nc, b_nc, 0.); + + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - Complex tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - retval.resize (nc, b_nc, 0.); - - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (cidx (k)); work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3442,7 +3401,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -3450,43 +3410,113 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += std::abs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[perm[b.ridx (i)]] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += std::abs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Lower) - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[perm[b.ridx (i)]] = b.data (i); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -3495,22 +3525,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -3521,207 +3547,139 @@ } } - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += std::abs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - Complex tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - Complex tmp = work[k] / data (cidx (k)); work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - Complex tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += std::abs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += std::abs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3742,7 +3700,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else if (calc_cond) (*current_liboctave_error_handler) @@ -3892,7 +3851,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else if (calc_cond) (*current_liboctave_error_handler) @@ -4037,7 +3997,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else if (calc_cond) (*current_liboctave_error_handler) @@ -4189,7 +4150,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else if (calc_cond) (*current_liboctave_error_handler) @@ -4289,6 +4251,8 @@ if (err != 0) { + // FIXME: This should probably be a warning so that + // error value can be passed back. (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); @@ -4346,7 +4310,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -4448,6 +4413,7 @@ if (err != 0) { + // FIXME: Probably should be a warning. (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -4589,7 +4555,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -4701,6 +4668,7 @@ if (err != 0) { + // FIXME: Probably should be a warning. (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); err = -1; @@ -4901,7 +4869,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -5004,6 +4973,7 @@ if (err != 0) { + // FIXME: Probably should be a warning. (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); err = -1; @@ -5142,7 +5112,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -5258,6 +5229,7 @@ if (err != 0) { + // FIXME: Probably should be a warning. (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -5500,14 +5472,15 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexMatrix::solve symbolic factorization failed"); - err = -1; - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_symbolic) (&Symbolic); + + // FIXME: Should this be a warning? + (*current_liboctave_error_handler) + ("SparseComplexMatrix::solve symbolic factorization failed"); + err = -1; } else { @@ -5538,12 +5511,13 @@ } else if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + UMFPACK_ZNAME (report_info) (control, info); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseComplexMatrix::solve numeric factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); - UMFPACK_ZNAME (report_info) (control, info); - err = -1; } else @@ -5578,7 +5552,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -5777,13 +5752,13 @@ if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); - UMFPACK_ZNAME (report_status) (control, status); - err = -1; - break; } } @@ -5823,7 +5798,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -6049,13 +6025,13 @@ #endif if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); - UMFPACK_ZNAME (report_status) (control, status); - err = -1; - break; } @@ -6116,7 +6092,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -6294,13 +6271,13 @@ if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); - UMFPACK_ZNAME (report_status) (control, status); - err = -1; - break; } } @@ -6340,7 +6317,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -6544,13 +6522,13 @@ if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseComplexMatrix::solve solve failed"); - UMFPACK_ZNAME (report_status) (control, status); - err = -1; - break; } @@ -6659,10 +6637,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { @@ -6727,10 +6702,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return SparseComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { @@ -6795,10 +6767,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { @@ -6864,10 +6833,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return SparseComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/DiagArray2.cc --- a/liboctave/array/DiagArray2.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/DiagArray2.cc Sat Jan 23 13:52:03 2016 -0800 @@ -94,10 +94,7 @@ const T& rfv) { if (r < 0 || c < 0) - { - (*current_liboctave_error_handler) ("can't resize to negative dimensions"); - return; - } + (*current_liboctave_error_handler) ("can't resize to negative dimensions"); if (r != dim1 () || c != dim2 ()) { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/MArray.cc --- a/liboctave/array/MArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/MArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -165,8 +165,7 @@ sdv(dim) = ddv(dim) = 0; if (ddv != sdv) - (*current_liboctave_error_handler) - ("accumdim: dimension mismatch"); + (*current_liboctave_error_handler) ("accumdim: dimension mismatch"); T *dst = Array::fortran_vec (); const T *src = vals.data (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/PermMatrix.cc --- a/liboctave/array/PermMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/PermMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -33,8 +33,7 @@ void err_invalid_permutation (void) { - (*current_liboctave_error_handler) - ("PermMatrix: invalid permutation vector"); + (*current_liboctave_error_handler) ("PermMatrix: invalid permutation vector"); } void @@ -102,12 +101,9 @@ { octave_idx_type len = Array::numel (); if (i < 0 || j < 0 || i > len || j > len) - { - (*current_liboctave_error_handler) ("index out of range"); - return 0; - } - else - return elem (i, j); + (*current_liboctave_error_handler) ("index out of range"); + + return elem (i, j); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/Sparse.cc --- a/liboctave/array/Sparse.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/Sparse.cc Sat Jan 23 13:52:03 2016 -0800 @@ -76,47 +76,39 @@ { octave_idx_type i; - if (nzmx > 0) + if (nzmx <= 0) + (*current_liboctave_error_handler) + ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); + + for (i = c[_c]; i < c[_c + 1]; i++) + if (r[i] == _r) + return d[i]; + else if (r[i] > _r) + break; + + // Ok, If we've gotten here, we're in trouble.. Have to create a + // new element in the sparse array. This' gonna be slow!!! + if (c[ncols] == nzmx) + (*current_liboctave_error_handler) + ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); + + octave_idx_type to_move = c[ncols] - i; + if (to_move != 0) { - for (i = c[_c]; i < c[_c + 1]; i++) - if (r[i] == _r) - return d[i]; - else if (r[i] > _r) - break; - - // Ok, If we've gotten here, we're in trouble.. Have to create a - // new element in the sparse array. This' gonna be slow!!! - if (c[ncols] == nzmx) - { - (*current_liboctave_error_handler) - ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); - return *d; - } - - octave_idx_type to_move = c[ncols] - i; - if (to_move != 0) + for (octave_idx_type j = c[ncols]; j > i; j--) { - for (octave_idx_type j = c[ncols]; j > i; j--) - { - d[j] = d[j-1]; - r[j] = r[j-1]; - } + d[j] = d[j-1]; + r[j] = r[j-1]; } - - for (octave_idx_type j = _c + 1; j < ncols + 1; j++) - c[j] = c[j] + 1; - - d[i] = 0.; - r[i] = _r; - - return d[i]; } - else - { - (*current_liboctave_error_handler) - ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); - return *d; - } + + for (octave_idx_type j = _c + 1; j < ncols + 1; j++) + c[j] = c[j] + 1; + + d[i] = 0.; + r[i] = _r; + + return d[i]; } template @@ -227,8 +219,8 @@ if (dv.length () != 2) (*current_liboctave_error_handler) ("Sparse::Sparse (const dim_vector&): dimension mismatch"); - else - rep = new typename Sparse::SparseRep (dv(0), dv(1), 0); + + rep = new typename Sparse::SparseRep (dv(0), dv(1), 0); } template @@ -245,34 +237,32 @@ if (a_nel != dv_nel) (*current_liboctave_error_handler) ("Sparse::Sparse (const Sparse&, const dim_vector&): dimension mismatch"); - else - { - dim_vector old_dims = a.dims (); - octave_idx_type new_nzmx = a.nnz (); - octave_idx_type new_nr = dv(0); - octave_idx_type new_nc = dv(1); - octave_idx_type old_nr = old_dims(0); - octave_idx_type old_nc = old_dims(1); - - rep = new typename Sparse::SparseRep (new_nr, new_nc, new_nzmx); - - octave_idx_type kk = 0; - xcidx (0) = 0; - for (octave_idx_type i = 0; i < old_nc; i++) - for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) - { - octave_idx_type tmp = i * old_nr + a.ridx (j); - octave_idx_type ii = tmp % new_nr; - octave_idx_type jj = (tmp - ii) / new_nr; - for (octave_idx_type k = kk; k < jj; k++) - xcidx (k+1) = j; - kk = jj; - xdata (j) = a.data (j); - xridx (j) = ii; - } - for (octave_idx_type k = kk; k < new_nc; k++) - xcidx (k+1) = new_nzmx; - } + + dim_vector old_dims = a.dims (); + octave_idx_type new_nzmx = a.nnz (); + octave_idx_type new_nr = dv(0); + octave_idx_type new_nc = dv(1); + octave_idx_type old_nr = old_dims(0); + octave_idx_type old_nc = old_dims(1); + + rep = new typename Sparse::SparseRep (new_nr, new_nc, new_nzmx); + + octave_idx_type kk = 0; + xcidx (0) = 0; + for (octave_idx_type i = 0; i < old_nc; i++) + for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) + { + octave_idx_type tmp = i * old_nr + a.ridx (j); + octave_idx_type ii = tmp % new_nr; + octave_idx_type jj = (tmp - ii) / new_nr; + for (octave_idx_type k = kk; k < jj; k++) + xcidx (k+1) = j; + kk = jj; + xdata (j) = a.data (j); + xridx (j) = ii; + } + for (octave_idx_type k = kk; k < new_nc; k++) + xcidx (k+1) = new_nzmx; } template @@ -642,32 +632,30 @@ if (dimensions.length () > 2) (*current_liboctave_error_handler) ("Sparse::Sparse (const Array&): dimension mismatch"); - else + + octave_idx_type nr = rows (); + octave_idx_type nc = cols (); + octave_idx_type len = a.numel (); + octave_idx_type new_nzmx = 0; + + // First count the number of nonzero terms + for (octave_idx_type i = 0; i < len; i++) + if (a(i) != T ()) + new_nzmx++; + + rep = new typename Sparse::SparseRep (nr, nc, new_nzmx); + + octave_idx_type ii = 0; + xcidx (0) = 0; + for (octave_idx_type j = 0; j < nc; j++) { - octave_idx_type nr = rows (); - octave_idx_type nc = cols (); - octave_idx_type len = a.numel (); - octave_idx_type new_nzmx = 0; - - // First count the number of nonzero terms - for (octave_idx_type i = 0; i < len; i++) - if (a(i) != T ()) - new_nzmx++; - - rep = new typename Sparse::SparseRep (nr, nc, new_nzmx); - - octave_idx_type ii = 0; - xcidx (0) = 0; - for (octave_idx_type j = 0; j < nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - if (a.elem (i,j) != T ()) - { - xdata (ii) = a.elem (i,j); - xridx (ii++) = i; - } - xcidx (j+1) = ii; - } + for (octave_idx_type i = 0; i < nr; i++) + if (a.elem (i,j) != T ()) + { + xdata (ii) = a.elem (i,j); + xridx (ii++) = i; + } + xcidx (j+1) = ii; } } @@ -700,24 +688,22 @@ octave_idx_type Sparse::compute_index (const Array& ra_idx) const { - octave_idx_type retval = -1; - octave_idx_type n = dimensions.length (); - if (n > 0 && n == ra_idx.numel ()) - { - retval = ra_idx(--n); - - while (--n >= 0) - { - retval *= dimensions(n); - retval += ra_idx(n); - } - } - else + if (n <= 0 || n != ra_idx.numel ()) (*current_liboctave_error_handler) ("Sparse::compute_index: invalid ra_idxing operation"); + octave_idx_type retval = -1; + + retval = ra_idx(--n); + + while (--n >= 0) + { + retval *= dimensions(n); + retval += ra_idx(n); + } + return retval; } @@ -726,7 +712,6 @@ Sparse::range_error (const char *fcn, octave_idx_type n) const { (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n); - return T (); } template @@ -734,8 +719,6 @@ Sparse::range_error (const char *fcn, octave_idx_type n) { (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n); - static T foo; - return foo; } template @@ -743,19 +726,14 @@ Sparse::range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const { - (*current_liboctave_error_handler) - ("%s (%d, %d): range error", fcn, i, j); - return T (); + (*current_liboctave_error_handler) ("%s (%d, %d): range error", fcn, i, j); } template T& Sparse::range_error (const char *fcn, octave_idx_type i, octave_idx_type j) { - (*current_liboctave_error_handler) - ("%s (%d, %d): range error", fcn, i, j); - static T foo; - return foo; + (*current_liboctave_error_handler) ("%s (%d, %d): range error", fcn, i, j); } template @@ -780,8 +758,6 @@ std::string buf_str = buf.str (); (*current_liboctave_error_handler) (buf_str.c_str ()); - - return T (); } template @@ -805,9 +781,6 @@ std::string buf_str = buf.str (); (*current_liboctave_error_handler) (buf_str.c_str ()); - - static T foo; - return foo; } template @@ -931,10 +904,7 @@ octave_idx_type n = dv.length (); if (n != 2) - { - (*current_liboctave_error_handler) ("sparse array must be 2-D"); - return; - } + (*current_liboctave_error_handler) ("sparse array must be 2-D"); resize (dv(0), dv(1)); } @@ -944,11 +914,7 @@ Sparse::resize (octave_idx_type r, octave_idx_type c) { if (r < 0 || c < 0) - { - (*current_liboctave_error_handler) - ("can't resize to negative dimension"); - return; - } + (*current_liboctave_error_handler) ("can't resize to negative dimension"); if (r == dim1 () && c == dim2 ()) return; @@ -1003,10 +969,7 @@ octave_idx_type nc = cols (); if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); // First count the number of elements in the final array octave_idx_type nel = cidx (c) + a.nnz (); @@ -1083,10 +1046,7 @@ { if (ra_idx.numel () != 2) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); return insert (a, ra_idx(0), ra_idx(1)); } @@ -1376,11 +1336,7 @@ else if (dim == 1) delete_elements (idx_vector::colon, idx); else - { - (*current_liboctave_error_handler) - ("invalid dimension in delete_elements"); - return; - } + (*current_liboctave_error_handler) ("invalid dimension in delete_elements"); } template @@ -2595,28 +2551,25 @@ dim = -dim - 1; } else if (dim < 0) - (*current_liboctave_error_handler) - ("cat: invalid dimension"); + (*current_liboctave_error_handler) ("cat: invalid dimension"); dim_vector dv; octave_idx_type total_nz = 0; - if (dim == 0 || dim == 1) - { - if (n == 1) - return sparse_list[0]; - - for (octave_idx_type i = 0; i < n; i++) - { - if (! (dv.*concat_rule) (sparse_list[i].dims (), dim)) - (*current_liboctave_error_handler) - ("cat: dimension mismatch"); - total_nz += sparse_list[i].nnz (); - } - } - else + if (dim != 0 && dim != 1) (*current_liboctave_error_handler) ("cat: invalid dimension for sparse concatenation"); + if (n == 1) + return sparse_list[0]; + + for (octave_idx_type i = 0; i < n; i++) + { + if (! (dv.*concat_rule) (sparse_list[i].dims (), dim)) + (*current_liboctave_error_handler) ("cat: dimension mismatch"); + + total_nz += sparse_list[i].nnz (); + } + Sparse retval (dv, total_nz); if (retval.is_empty ()) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/Sparse.h --- a/liboctave/array/Sparse.h Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/Sparse.h Sat Jan 23 13:52:03 2016 -0800 @@ -722,28 +722,29 @@ if (itmp < 0 || itmp >= nr) { + is.setstate (std::ios::failbit); + (*current_liboctave_error_handler) ("invalid sparse matrix: row index = %d out of range", itmp + 1); - is.setstate (std::ios::failbit); - goto done; } if (jtmp < 0 || jtmp >= nc) { + is.setstate (std::ios::failbit); + (*current_liboctave_error_handler) ("invalid sparse matrix: column index = %d out of range", jtmp + 1); - is.setstate (std::ios::failbit); - goto done; } if (jtmp < jold) { + is.setstate (std::ios::failbit); + (*current_liboctave_error_handler) - ("invalid sparse matrix: column indices must appear in ascending order"); - is.setstate (std::ios::failbit); - goto done; + ("invalid sparse matrix: " + "column indices must appear in ascending order"); } else if (jtmp > jold) { @@ -752,10 +753,11 @@ } else if (itmp < iold) { + is.setstate (std::ios::failbit); + (*current_liboctave_error_handler) - ("invalid sparse matrix: row indices must appear in ascending order in each column"); - is.setstate (std::ios::failbit); - goto done; + ("invalid sparse matrix: " + "row indices must appear in ascending order in each column"); } iold = itmp; @@ -763,22 +765,16 @@ tmp = read_fcn (is); - if (is) - { - a.data (ii) = tmp; - a.ridx (ii++) = itmp; - } - else - goto done; + if (! is) + return is; // Problem, return is in error state + + a.data (ii) = tmp; + a.ridx (ii++) = itmp; } for (octave_idx_type j = jold; j < nc; j++) a.cidx (j+1) = ii; } - -done: - - return is; } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/chMatrix.cc --- a/liboctave/array/chMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/chMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -62,10 +62,7 @@ octave_idx_type s_len = strlen (s); if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); for (octave_idx_type i = 0; i < s_len; i++) elem (r, c+i) = s[i]; @@ -92,10 +89,7 @@ return retval; if (r < 0 || r >= nr) - { - (*current_liboctave_error_handler) ("range error for row_as_string"); - return retval; - } + (*current_liboctave_error_handler) ("range error for row_as_string"); retval.resize (nc, '\0'); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/chNDArray.cc --- a/liboctave/array/chNDArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/chNDArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -120,21 +120,16 @@ double d = rb.elem (i); if (xisnan (d)) - { - (*current_liboctave_error_handler) - ("invalid conversion from NaN to character"); - return *this; - } - else - { - octave_idx_type ival = NINTbig (d); + (*current_liboctave_error_handler) + ("invalid conversion from NaN to character"); + + octave_idx_type ival = NINTbig (d); - if (ival < 0 || ival > std::numeric_limits::max ()) - // FIXME: is there something better to do? Should we warn the user? - ival = 0; + if (ival < 0 || ival > std::numeric_limits::max ()) + // FIXME: is there something better to do? Should we warn the user? + ival = 0; - tmp.elem (i) = static_cast(ival); - } + tmp.elem (i) = static_cast(ival); } insert (tmp, ra_idx); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dColVector.cc --- a/liboctave/array/dColVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dColVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -73,10 +73,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -111,10 +108,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dDiagMatrix.cc --- 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; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dMatrix.cc --- a/liboctave/array/dMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -344,10 +344,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -366,10 +363,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -389,10 +383,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -436,10 +427,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -462,10 +450,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return Matrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; Matrix retval (nr, nc + a.cols ()); @@ -480,10 +465,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return Matrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; Matrix retval (nr, nc + a.numel ()); @@ -498,10 +480,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return Matrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; Matrix retval (nr, nc + 1); @@ -516,10 +495,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; Matrix retval (nr, nc + a.cols ()); @@ -534,11 +510,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return Matrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; Matrix retval (nr + a.rows (), nc); @@ -553,11 +525,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return Matrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; Matrix retval (nr + 1, nc); @@ -572,11 +540,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return Matrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; Matrix retval (nr + a.numel (), nc); @@ -591,11 +555,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return Matrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; Matrix retval (nr + a.rows (), nc); @@ -698,49 +658,47 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + int typ = mattype.type (); + char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); + char udiag = 'N'; + retval = *this; + double *tmp_data = retval.fortran_vec (); + + F77_XFCN (dtrtri, DTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&udiag, 1), + nr, tmp_data, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) { - int typ = mattype.type (); - char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); - char udiag = 'N'; - retval = *this; - double *tmp_data = retval.fortran_vec (); - - F77_XFCN (dtrtri, DTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + octave_idx_type dtrcon_info = 0; + char job = '1'; + + OCTAVE_LOCAL_BUFFER (double, work, 3 * nr); + OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, nr); + + F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, info + nr, tmp_data, nr, rcon, + work, iwork, dtrcon_info + F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + if (dtrcon_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type dtrcon_info = 0; - char job = '1'; - - OCTAVE_LOCAL_BUFFER (double, work, 3 * nr); - OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, nr); - - F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, rcon, - work, iwork, dtrcon_info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (dtrcon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. } + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. + return retval; } @@ -756,74 +714,72 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + retval = *this; + double *tmp_data = retval.fortran_vec (); + + Array z (dim_vector (1, 1)); + octave_idx_type lwork = -1; + + // Query the optimum work array size. + F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, + z.fortran_vec (), lwork, info)); + + lwork = static_cast (z(0)); + lwork = (lwork < 2 *nc ? 2*nc : lwork); + z.resize (dim_vector (lwork, 1)); + double *pz = z.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + double anorm = 0; + if (calc_cond) + anorm = retval.abs ().sum ().row (static_cast(0)) + .max (); + + F77_XFCN (dgetrf, DGETRF, (nc, nc, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) + { + octave_idx_type dgecon_info = 0; + + // Now calculate the condition number for non-singular matrix. + char job = '1'; + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, + rcon, pz, piz, dgecon_info + F77_CHAR_ARG_LEN (1))); + + if (dgecon_info != 0) + info = -1; + } + + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. else { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - retval = *this; - double *tmp_data = retval.fortran_vec (); - - Array z (dim_vector (1, 1)); - octave_idx_type lwork = -1; - - // Query the optimum work array size. + octave_idx_type dgetri_info = 0; + F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, - z.fortran_vec (), lwork, info)); - - lwork = static_cast (z(0)); - lwork = (lwork < 2 *nc ? 2*nc : lwork); - z.resize (dim_vector (lwork, 1)); - double *pz = z.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - double anorm = 0; - if (calc_cond) - anorm = retval.abs ().sum ().row (static_cast(0)) - .max (); - - F77_XFCN (dgetrf, DGETRF, (nc, nc, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + pz, lwork, dgetri_info)); + + if (dgetri_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type dgecon_info = 0; - - // Now calculate the condition number for non-singular matrix. - char job = '1'; - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, piz, dgecon_info - F77_CHAR_ARG_LEN (1))); - - if (dgecon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. - else - { - octave_idx_type dgetri_info = 0; - - F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, - pz, lwork, dgetri_info)); - - if (dgetri_info != 0) - info = -1; - } - - if (info != 0) - mattype.mark_as_rectangular (); } + if (info != 0) + mattype.mark_as_rectangular (); + return retval; } @@ -1266,86 +1222,107 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else + + volatile int typ = mattype.type (); + + // Even though the matrix is marked as singular (Rectangular), we may + // still get a useful number from the LU factorization, because it always + // completes. + + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + else if (typ == MatrixType::Rectangular) + typ = MatrixType::Full; + + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { - volatile int typ = mattype.type (); - - // Even though the matrix is marked as singular (Rectangular), we may - // still get a useful number from the LU factorization, because it always - // completes. - - if (typ == MatrixType::Unknown) - typ = mattype.type (*this); - else if (typ == MatrixType::Rectangular) - typ = MatrixType::Full; - - if (typ == MatrixType::Lower || typ == MatrixType::Upper) + for (octave_idx_type i = 0; i < nc; i++) + retval *= elem (i,i); + } + else if (typ == MatrixType::Hermitian) + { + Matrix atmp = *this; + double *tmp_data = atmp.fortran_vec (); + + double anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + + char job = 'L'; + F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, + tmp_data, nr, info + F77_CHAR_ARG_LEN (1))); + + if (info != 0) { - for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + rcon = 0.0; + mattype.mark_as_unsymmetric (); + typ = MatrixType::Full; } - else if (typ == MatrixType::Hermitian) + else { - Matrix atmp = *this; - double *tmp_data = atmp.fortran_vec (); - - double anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - - char job = 'L'; - F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, - tmp_data, nr, info + Array z (dim_vector (3 * nc, 1)); + double *pz = z.fortran_vec (); + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + + F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), + nr, tmp_data, nr, anorm, + rcon, pz, piz, info F77_CHAR_ARG_LEN (1))); if (info != 0) + rcon = 0.0; + + for (octave_idx_type i = 0; i < nc; i++) + retval *= atmp (i,i); + + retval = retval.square (); + } + } + else if (typ != MatrixType::Full) + (*current_liboctave_error_handler) ("det: invalid dense matrix type"); + + if (typ == MatrixType::Full) + { + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + Matrix atmp = *this; + double *tmp_data = atmp.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + double anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + { + info = -1; + retval = DET (); + } + else + { + if (calc_cond) { - rcon = 0.0; - mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; - } - else - { - Array z (dim_vector (3 * nc, 1)); + // Now calc the condition number for non-singular matrix. + char job = '1'; + Array z (dim_vector (4 * nc, 1)); double *pz = z.fortran_vec (); Array iz (dim_vector (nc, 1)); octave_idx_type *piz = iz.fortran_vec (); - F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), - nr, tmp_data, nr, anorm, + F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, rcon, pz, piz, info F77_CHAR_ARG_LEN (1))); - - if (info != 0) - rcon = 0.0; - - for (octave_idx_type i = 0; i < nc; i++) - retval *= atmp (i,i); - - retval = retval.square (); } - } - else if (typ != MatrixType::Full) - (*current_liboctave_error_handler) ("det: invalid dense matrix type"); - - if (typ == MatrixType::Full) - { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - Matrix atmp = *this; - double *tmp_data = atmp.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - double anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; + if (info != 0) { info = -1; @@ -1353,33 +1330,10 @@ } else { - if (calc_cond) + for (octave_idx_type i = 0; i < nc; i++) { - // Now calc the condition number for non-singular matrix. - char job = '1'; - Array z (dim_vector (4 * nc, 1)); - double *pz = z.fortran_vec (); - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - - F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, piz, info - F77_CHAR_ARG_LEN (1))); - } - - if (info != 0) - { - info = -1; - retval = DET (); - } - else - { - for (octave_idx_type i = 0; i < nc; i++) - { - double c = atmp(i,i); - retval *= (ipvt(i) != (i+1)) ? -c : c; - } + double c = atmp(i,i); + retval *= (ipvt(i) != (i+1)) ? -c : c; } } } @@ -1404,7 +1358,8 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) rcon = octave_Inf; else { @@ -1439,7 +1394,7 @@ if (info != 0) rcon = 0.0; } - else if (typ == MatrixType::Permuted_Upper) + else if (typ == MatrixType::Permuted_Upper) (*current_liboctave_error_handler) ("permuted triangular matrix not implemented"); else if (typ == MatrixType::Lower) @@ -1571,82 +1526,77 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { volatile int typ = mattype.type (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + rcon = 1.; + info = 0; + + if (typ == MatrixType::Permuted_Upper) + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); + + const double *tmp_data = fortran_vec (); + + retval = b; + double *result = retval.fortran_vec (); + + char uplo = 'U'; + char trans = get_blas_char (transt); + char dia = 'N'; + + F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&trans, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, b_nc, tmp_data, nr, + result, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (calc_cond) { - octave_idx_type b_nc = b.cols (); - rcon = 1.; - info = 0; - - if (typ == MatrixType::Permuted_Upper) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } - else + char norm = '1'; + uplo = 'U'; + dia = 'N'; + + Array z (dim_vector (3 * nc, 1)); + double *pz = z.fortran_vec (); + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + + F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, tmp_data, nr, rcon, + pz, piz, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (info != 0) + info = -2; + + volatile double rcond_plus_one = rcon + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcon)) { - const double *tmp_data = fortran_vec (); - - retval = b; - double *result = retval.fortran_vec (); - - char uplo = 'U'; - char trans = get_blas_char (transt); - char dia = 'N'; - - F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&trans, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, b_nc, tmp_data, nr, - result, nr, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (calc_cond) - { - char norm = '1'; - uplo = 'U'; - dia = 'N'; - - Array z (dim_vector (3 * nc, 1)); - double *pz = z.fortran_vec (); - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - - F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, tmp_data, nr, rcon, - pz, piz, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (info != 0) - info = -2; - - volatile double rcond_plus_one = rcon + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcon)) - { - info = -2; - - if (sing_handler) - sing_handler (rcon); - else - warn_singular_matrix (rcon); - } - } + info = -2; + + if (sing_handler) + sing_handler (rcon); + else + warn_singular_matrix (rcon); } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); } return retval; @@ -1665,82 +1615,77 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { volatile int typ = mattype.type (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + rcon = 1.; + info = 0; + + if (typ == MatrixType::Permuted_Lower) + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); + + const double *tmp_data = fortran_vec (); + + retval = b; + double *result = retval.fortran_vec (); + + char uplo = 'L'; + char trans = get_blas_char (transt); + char dia = 'N'; + + F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&trans, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, b_nc, tmp_data, nr, + result, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (calc_cond) { - octave_idx_type b_nc = b.cols (); - rcon = 1.; - info = 0; - - if (typ == MatrixType::Permuted_Lower) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } - else + char norm = '1'; + uplo = 'L'; + dia = 'N'; + + Array z (dim_vector (3 * nc, 1)); + double *pz = z.fortran_vec (); + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + + F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&dia, 1), + nr, tmp_data, nr, rcon, + pz, piz, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + if (info != 0) + info = -2; + + volatile double rcond_plus_one = rcon + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcon)) { - const double *tmp_data = fortran_vec (); - - retval = b; - double *result = retval.fortran_vec (); - - char uplo = 'L'; - char trans = get_blas_char (transt); - char dia = 'N'; - - F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&trans, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, b_nc, tmp_data, nr, - result, nr, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (calc_cond) - { - char norm = '1'; - uplo = 'L'; - dia = 'N'; - - Array z (dim_vector (3 * nc, 1)); - double *pz = z.fortran_vec (); - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - - F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&dia, 1), - nr, tmp_data, nr, rcon, - pz, piz, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (info != 0) - info = -2; - - volatile double rcond_plus_one = rcon + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcon)) - { - info = -2; - - if (sing_handler) - sing_handler (rcon); - else - warn_singular_matrix (rcon); - } - } + info = -2; + + if (sing_handler) + sing_handler (rcon); + else + warn_singular_matrix (rcon); } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); } return retval; @@ -1759,7 +1704,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -1970,10 +1916,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, info, rcon, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return Matrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); // Rectangular or one of the above solvers flags a singular matrix if (singular_fallback && mattype.type () == MatrixType::Rectangular) @@ -2275,7 +2218,8 @@ if (m != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0 || b.cols () == 0) + + if (m == 0 || n == 0 || b.cols () == 0) retval = Matrix (n, b.cols (), 0.0); else { @@ -2470,7 +2414,8 @@ if (m != b.numel ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0) + + if (m == 0 || n == 0) retval = ColumnVector (n, 0.0); else { @@ -2719,8 +2664,7 @@ if (nr == 1 || nc == 1) retval = DiagMatrix (*this, m, n); else - (*current_liboctave_error_handler) - ("diag: expecting vector argument"); + (*current_liboctave_error_handler) ("diag: expecting vector argument"); return retval; } @@ -3230,11 +3174,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg min requires same size arguments"); - return Matrix (); - } + (*current_liboctave_error_handler) + ("two-arg min requires same size arguments"); EMPTY_RETURN_CHECK (Matrix); @@ -3297,11 +3238,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg max requires same size arguments"); - return Matrix (); - } + (*current_liboctave_error_handler) + ("two-arg max requires same size arguments"); EMPTY_RETURN_CHECK (Matrix); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dNDArray.cc --- a/liboctave/array/dNDArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dNDArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -767,21 +767,16 @@ double d = elem (i); if (xisnan (d)) - { - (*current_liboctave_error_handler) - ("invalid conversion from NaN to character"); - return retval; - } - else - { - octave_idx_type ival = NINTbig (d); + (*current_liboctave_error_handler) + ("invalid conversion from NaN to character"); + + octave_idx_type ival = NINTbig (d); - if (ival < 0 || ival > std::numeric_limits::max ()) - // FIXME: is there something better to do? Should we warn the user? - ival = 0; + if (ival < 0 || ival > std::numeric_limits::max ()) + // FIXME: is there something better to do? Should we warn the user? + ival = 0; - retval.elem (i) = static_cast(ival); - } + retval.elem (i) = static_cast(ival); } if (rb.is_empty ()) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dRowVector.cc --- a/liboctave/array/dRowVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dRowVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -76,10 +76,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -114,10 +111,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/dSparse.cc --- a/liboctave/array/dSparse.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/dSparse.cc Sat Jan 23 13:52:03 2016 -0800 @@ -751,73 +751,71 @@ SparseMatrix atan2 (const SparseMatrix& x, const SparseMatrix& y) { + if ((x.rows () != y.rows ()) || (x.cols () != y.cols ())) + (*current_liboctave_error_handler) ("matrix size mismatch"); + + octave_idx_type x_nr = x.rows (); + octave_idx_type x_nc = x.cols (); + + octave_idx_type y_nr = y.rows (); + octave_idx_type y_nc = y.cols (); + + if (x_nr != y_nr || x_nc != y_nc) + err_nonconformant ("atan2", x_nr, x_nc, y_nr, y_nc); + SparseMatrix r; - if ((x.rows () == y.rows ()) && (x.cols () == y.cols ())) + r = SparseMatrix (x_nr, x_nc, (x.nnz () + y.nnz ())); + + octave_idx_type jx = 0; + r.cidx (0) = 0; + for (octave_idx_type i = 0 ; i < x_nc ; i++) { - octave_idx_type x_nr = x.rows (); - octave_idx_type x_nc = x.cols (); - - octave_idx_type y_nr = y.rows (); - octave_idx_type y_nc = y.cols (); - - if (x_nr != y_nr || x_nc != y_nc) - err_nonconformant ("atan2", x_nr, x_nc, y_nr, y_nc); - - r = SparseMatrix (x_nr, x_nc, (x.nnz () + y.nnz ())); - - octave_idx_type jx = 0; - r.cidx (0) = 0; - for (octave_idx_type i = 0 ; i < x_nc ; i++) + octave_idx_type ja = x.cidx (i); + octave_idx_type ja_max = x.cidx (i+1); + bool ja_lt_max= ja < ja_max; + + octave_idx_type jb = y.cidx (i); + octave_idx_type jb_max = y.cidx (i+1); + bool jb_lt_max = jb < jb_max; + + while (ja_lt_max || jb_lt_max) { - octave_idx_type ja = x.cidx (i); - octave_idx_type ja_max = x.cidx (i+1); - bool ja_lt_max= ja < ja_max; - - octave_idx_type jb = y.cidx (i); - octave_idx_type jb_max = y.cidx (i+1); - bool jb_lt_max = jb < jb_max; - - while (ja_lt_max || jb_lt_max) - { - octave_quit (); - if ((! jb_lt_max) - || (ja_lt_max && (x.ridx (ja) < y.ridx (jb)))) + octave_quit (); + if ((! jb_lt_max) + || (ja_lt_max && (x.ridx (ja) < y.ridx (jb)))) + { + r.ridx (jx) = x.ridx (ja); + r.data (jx) = atan2 (x.data (ja), 0.); + jx++; + ja++; + ja_lt_max= ja < ja_max; + } + else if ((! ja_lt_max) + || (jb_lt_max && (y.ridx (jb) < x.ridx (ja)))) + { + jb++; + jb_lt_max= jb < jb_max; + } + else + { + double tmp = atan2 (x.data (ja), y.data (jb)); + if (tmp != 0.) { + r.data (jx) = tmp; r.ridx (jx) = x.ridx (ja); - r.data (jx) = atan2 (x.data (ja), 0.); jx++; - ja++; - ja_lt_max= ja < ja_max; - } - else if ((! ja_lt_max) - || (jb_lt_max && (y.ridx (jb) < x.ridx (ja)))) - { - jb++; - jb_lt_max= jb < jb_max; } - else - { - double tmp = atan2 (x.data (ja), y.data (jb)); - if (tmp != 0.) - { - r.data (jx) = tmp; - r.ridx (jx) = x.ridx (ja); - jx++; - } - ja++; - ja_lt_max= ja < ja_max; - jb++; - jb_lt_max= jb < jb_max; - } - } - r.cidx (i+1) = jx; + ja++; + ja_lt_max= ja < ja_max; + jb++; + jb_lt_max= jb < jb_max; + } } - - r.maybe_compress (); + r.cidx (i+1) = jx; } - else - (*current_liboctave_error_handler) ("matrix size mismatch"); + + r.maybe_compress (); return r; } @@ -859,44 +857,40 @@ if (nr == 0 || nc == 0 || nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + // Print spparms("spumoni") info if requested + int typ = mattyp.type (); + mattyp.info (); + + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + if (typ == MatrixType::Permuted_Diagonal) + retval = transpose (); else + retval = *this; + + // Force make_unique to be called + double *v = retval.data (); + + if (calccond) { - // Print spparms("spumoni") info if requested - int typ = mattyp.type (); - mattyp.info (); - - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nr; i++) { - if (typ == MatrixType::Permuted_Diagonal) - retval = transpose (); - else - retval = *this; - - // Force make_unique to be called - double *v = retval.data (); - - if (calccond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nr; i++) - { - double tmp = fabs (v[i]); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - - for (octave_idx_type i = 0; i < nr; i++) - v[i] = 1.0 / v[i]; + double tmp = fabs (v[i]); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = dmin / dmax; } + for (octave_idx_type i = 0; i < nr; i++) + v[i] = 1.0 / v[i]; + return retval; } @@ -913,262 +907,239 @@ if (nr == 0 || nc == 0 || nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + // Print spparms("spumoni") info if requested + int typ = mattyp.type (); + mattyp.info (); + + if (typ != MatrixType::Upper && typ != MatrixType::Permuted_Upper + && typ != MatrixType::Lower && typ != MatrixType::Permuted_Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + + if (calccond) { - // Print spparms("spumoni") info if requested - int typ = mattyp.type (); - mattyp.info (); - - if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper - || typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nr; j++) { - double anorm = 0.; - double ainvnorm = 0.; - - if (calccond) - { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nr; j++) - { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Upper || typ == MatrixType::Lower) - { - octave_idx_type nz = nnz (); - octave_idx_type cx = 0; - octave_idx_type nz2 = nz; - retval = SparseMatrix (nr, nc, nz2); - - for (octave_idx_type i = 0; i < nr; i++) + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Upper || typ == MatrixType::Lower) + { + octave_idx_type nz = nnz (); + octave_idx_type cx = 0; + octave_idx_type nz2 = nz; + retval = SparseMatrix (nr, nc, nz2); + + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + // place the 1 in the identity position + octave_idx_type cx_colstart = cx; + + if (cx == nz2) + { + nz2 *= 2; + retval.change_capacity (nz2); + } + + retval.xcidx (i) = cx; + retval.xridx (cx) = i; + retval.xdata (cx) = 1.0; + cx++; + + // iterate accross columns of input matrix + for (octave_idx_type j = i+1; j < nr; j++) + { + double v = 0.; + // iterate to calculate sum + octave_idx_type colXp = retval.xcidx (i); + octave_idx_type colUp = cidx (j); + octave_idx_type rpX, rpU; + + if (cidx (j) == cidx (j+1)) + (*current_liboctave_error_handler) ("division by zero"); + + do { octave_quit (); - // place the 1 in the identity position - octave_idx_type cx_colstart = cx; - + rpX = retval.xridx (colXp); + rpU = ridx (colUp); + + if (rpX < rpU) + colXp++; + else if (rpX > rpU) + colUp++; + else + { + v -= retval.xdata (colXp) * data (colUp); + colXp++; + colUp++; + } + } + while (rpX < j && rpU < j && colXp < cx && colUp < nz); + + // get A(m,m) + if (typ == MatrixType::Upper) + colUp = cidx (j+1) - 1; + else + colUp = cidx (j); + double pivot = data (colUp); + if (pivot == 0. || ridx (colUp) != j) + (*current_liboctave_error_handler) ("division by zero"); + + if (v != 0.) + { if (cx == nz2) { nz2 *= 2; retval.change_capacity (nz2); } - retval.xcidx (i) = cx; - retval.xridx (cx) = i; - retval.xdata (cx) = 1.0; + retval.xridx (cx) = j; + retval.xdata (cx) = v / pivot; cx++; - - // iterate accross columns of input matrix - for (octave_idx_type j = i+1; j < nr; j++) - { - double v = 0.; - // iterate to calculate sum - octave_idx_type colXp = retval.xcidx (i); - octave_idx_type colUp = cidx (j); - octave_idx_type rpX, rpU; - - if (cidx (j) == cidx (j+1)) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - do - { - octave_quit (); - rpX = retval.xridx (colXp); - rpU = ridx (colUp); - - if (rpX < rpU) - colXp++; - else if (rpX > rpU) - colUp++; - else - { - v -= retval.xdata (colXp) * data (colUp); - colXp++; - colUp++; - } - } - while (rpX < j && rpU < j && colXp < cx && colUp < nz); - - // get A(m,m) - if (typ == MatrixType::Upper) - colUp = cidx (j+1) - 1; - else - colUp = cidx (j); - double pivot = data (colUp); - if (pivot == 0. || ridx (colUp) != j) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - if (v != 0.) - { - if (cx == nz2) - { - nz2 *= 2; - retval.change_capacity (nz2); - } - - retval.xridx (cx) = j; - retval.xdata (cx) = v / pivot; - cx++; - } - } - - // get A(m,m) - octave_idx_type colUp; - if (typ == MatrixType::Upper) - colUp = cidx (i+1) - 1; - else - colUp = cidx (i); - double pivot = data (colUp); - if (pivot == 0. || ridx (colUp) != i) - { - (*current_liboctave_error_handler) ("division by zero"); - goto inverse_singular; - } - - if (pivot != 1.0) - for (octave_idx_type j = cx_colstart; j < cx; j++) - retval.xdata (j) /= pivot; } - retval.xcidx (nr) = cx; - retval.maybe_compress (); - } + } + + // get A(m,m) + octave_idx_type colUp; + if (typ == MatrixType::Upper) + colUp = cidx (i+1) - 1; else - { - octave_idx_type nz = nnz (); - octave_idx_type cx = 0; - octave_idx_type nz2 = nz; - retval = SparseMatrix (nr, nc, nz2); - - OCTAVE_LOCAL_BUFFER (double, work, nr); - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nr); - - octave_idx_type *perm = mattyp.triangular_perm (); - if (typ == MatrixType::Permuted_Upper) - { - for (octave_idx_type i = 0; i < nr; i++) - rperm[perm[i]] = i; - } - else - { - for (octave_idx_type i = 0; i < nr; i++) - rperm[i] = perm[i]; - for (octave_idx_type i = 0; i < nr; i++) - perm[rperm[i]] = i; - } - - for (octave_idx_type i = 0; i < nr; i++) + colUp = cidx (i); + double pivot = data (colUp); + if (pivot == 0. || ridx (colUp) != i) + (*current_liboctave_error_handler) ("division by zero"); + + if (pivot != 1.0) + for (octave_idx_type j = cx_colstart; j < cx; j++) + retval.xdata (j) /= pivot; + } + retval.xcidx (nr) = cx; + retval.maybe_compress (); + } + else + { + octave_idx_type nz = nnz (); + octave_idx_type cx = 0; + octave_idx_type nz2 = nz; + retval = SparseMatrix (nr, nc, nz2); + + OCTAVE_LOCAL_BUFFER (double, work, nr); + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nr); + + octave_idx_type *perm = mattyp.triangular_perm (); + if (typ == MatrixType::Permuted_Upper) + { + for (octave_idx_type i = 0; i < nr; i++) + rperm[perm[i]] = i; + } + else + { + for (octave_idx_type i = 0; i < nr; i++) + rperm[i] = perm[i]; + for (octave_idx_type i = 0; i < nr; i++) + perm[rperm[i]] = i; + } + + for (octave_idx_type i = 0; i < nr; i++) + { + octave_quit (); + octave_idx_type iidx = rperm[i]; + + for (octave_idx_type j = 0; j < nr; j++) + work[j] = 0.; + + // place the 1 in the identity position + work[iidx] = 1.0; + + // iterate accross columns of input matrix + for (octave_idx_type j = iidx+1; j < nr; j++) + { + double v = 0.; + octave_idx_type jidx = perm[j]; + // iterate to calculate sum + for (octave_idx_type k = cidx (jidx); + k < cidx (jidx+1); k++) { octave_quit (); - octave_idx_type iidx = rperm[i]; - - for (octave_idx_type j = 0; j < nr; j++) - work[j] = 0.; - - // place the 1 in the identity position - work[iidx] = 1.0; - - // iterate accross columns of input matrix - for (octave_idx_type j = iidx+1; j < nr; j++) - { - double v = 0.; - octave_idx_type jidx = perm[j]; - // iterate to calculate sum - for (octave_idx_type k = cidx (jidx); - k < cidx (jidx+1); k++) - { - octave_quit (); - v -= work[ridx (k)] * data (k); - } - - // get A(m,m) - double pivot; - if (typ == MatrixType::Permuted_Upper) - pivot = data (cidx (jidx+1) - 1); - else - pivot = data (cidx (jidx)); - if (pivot == 0.) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - work[j] = v / pivot; - } - - // get A(m,m) - octave_idx_type colUp; - if (typ == MatrixType::Permuted_Upper) - colUp = cidx (perm[iidx]+1) - 1; - else - colUp = cidx (perm[iidx]); - - double pivot = data (colUp); - if (pivot == 0.) - { - (*current_liboctave_error_handler) - ("division by zero"); - goto inverse_singular; - } - - octave_idx_type new_cx = cx; - for (octave_idx_type j = iidx; j < nr; j++) - if (work[j] != 0.0) - { - new_cx++; - if (pivot != 1.0) - work[j] /= pivot; - } - - if (cx < new_cx) - { - nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2); - retval.change_capacity (nz2); - } - - retval.xcidx (i) = cx; - for (octave_idx_type j = iidx; j < nr; j++) - if (work[j] != 0.) - { - retval.xridx (cx) = j; - retval.xdata (cx++) = work[j]; - } + v -= work[ridx (k)] * data (k); } - retval.xcidx (nr) = cx; - retval.maybe_compress (); - } - - if (calccond) - { - // Calculate the 1-norm of inverse matrix for rcond calculation - for (octave_idx_type j = 0; j < nr; j++) - { - double atmp = 0.; - for (octave_idx_type i = retval.cidx (j); - i < retval.cidx (j+1); i++) - atmp += fabs (retval.data (i)); - if (atmp > ainvnorm) - ainvnorm = atmp; - } - - rcond = 1. / ainvnorm / anorm; - } + // get A(m,m) + double pivot; + if (typ == MatrixType::Permuted_Upper) + pivot = data (cidx (jidx+1) - 1); + else + pivot = data (cidx (jidx)); + if (pivot == 0.) + (*current_liboctave_error_handler) ("division by zero"); + + work[j] = v / pivot; + } + + // get A(m,m) + octave_idx_type colUp; + if (typ == MatrixType::Permuted_Upper) + colUp = cidx (perm[iidx]+1) - 1; + else + colUp = cidx (perm[iidx]); + + double pivot = data (colUp); + if (pivot == 0.) + (*current_liboctave_error_handler) ("division by zero"); + + octave_idx_type new_cx = cx; + for (octave_idx_type j = iidx; j < nr; j++) + if (work[j] != 0.0) + { + new_cx++; + if (pivot != 1.0) + work[j] /= pivot; + } + + if (cx < new_cx) + { + nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2); + retval.change_capacity (nz2); + } + + retval.xcidx (i) = cx; + for (octave_idx_type j = iidx; j < nr; j++) + if (work[j] != 0.) + { + retval.xridx (cx) = j; + retval.xdata (cx++) = work[j]; + } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.xcidx (nr) = cx; + retval.maybe_compress (); + } + + if (calccond) + { + // Calculate the 1-norm of inverse matrix for rcond calculation + for (octave_idx_type j = 0; j < nr; j++) + { + double atmp = 0.; + for (octave_idx_type i = retval.cidx (j); + i < retval.cidx (j+1); i++) + atmp += fabs (retval.data (i)); + if (atmp > ainvnorm) + ainvnorm = atmp; + } + + rcond = 1. / ainvnorm / anorm; } return retval; @@ -1312,13 +1283,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseMatrix::determinant symbolic factorization failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_symbolic) (&Symbolic); + + (*current_liboctave_error_handler) + ("SparseMatrix::determinant symbolic factorization failed"); } else { @@ -1333,13 +1304,12 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseMatrix::determinant numeric factorization failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_numeric) (&Numeric); + (*current_liboctave_error_handler) + ("SparseMatrix::determinant numeric factorization failed"); } else { @@ -1352,11 +1322,11 @@ if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + UMFPACK_DNAME (report_info) (control, info); + (*current_liboctave_error_handler) ("SparseMatrix::determinant error calculating determinant"); - - UMFPACK_DNAME (report_status) (control, status); - UMFPACK_DNAME (report_info) (control, info); } else retval = DET (c10, e10, 10); @@ -1391,7 +1361,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -1399,38 +1370,36 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.resize (nc, b.cols (), 0.); + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type i = 0; i < nm; i++) + retval(i,j) = b(i,j) / data (i); + else + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type k = 0; k < nc; k++) + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + retval(k,j) = b(ridx (i),j) / data (i); + + if (calc_cond) { - retval.resize (nc, b.cols (), 0.); - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type i = 0; i < nm; i++) - retval(i,j) = b(i,j) / data (i); - else - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type k = 0; k < nc; k++) - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) - retval(k,j) = b(ridx (i),j) / data (i); - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = fabs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - else - rcond = 1.; + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = fabs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.; } return retval; @@ -1451,7 +1420,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else { @@ -1459,68 +1429,66 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) - { - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseMatrix (nc, b_nc, b_nz); - - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b_nc; j++) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseMatrix (nc, b_nc, b_nz); + + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) { - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - { - if (b.ridx (i) >= nm) - break; - retval.xridx (ii) = b.ridx (i); - retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); - } - retval.xcidx (j+1) = ii; + if (b.ridx (i) >= nm) + break; + retval.xridx (ii) = b.ridx (i); + retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); } - else - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type l = 0; l < nc; l++) - for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + retval.xcidx (j+1) = ii; + } + else + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type l = 0; l < nc; l++) + for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + { + bool found = false; + octave_idx_type k; + for (k = b.cidx (j); k < b.cidx (j+1); k++) + if (ridx (i) == b.ridx (k)) + { + found = true; + break; + } + if (found) { - bool found = false; - octave_idx_type k; - for (k = b.cidx (j); k < b.cidx (j+1); k++) - if (ridx (i) == b.ridx (k)) - { - found = true; - break; - } - if (found) - { - retval.xridx (ii) = l; - retval.xdata (ii++) = b.data (k) / data (i); - } + retval.xridx (ii) = l; + retval.xdata (ii++) = b.data (k) / data (i); } - retval.xcidx (j+1) = ii; - } - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = fabs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; } - rcond = dmin / dmax; - } - else - rcond = 1.; + retval.xcidx (j+1) = ii; + } + + if (calc_cond) + { + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = fabs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.; } return retval; @@ -1541,7 +1509,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -1549,38 +1518,36 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + retval.resize (nc, b.cols (), 0); + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type i = 0; i < nm; i++) + retval(i,j) = b(i,j) / data (i); + else + for (octave_idx_type j = 0; j < b.cols (); j++) + for (octave_idx_type k = 0; k < nc; k++) + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + retval(k,j) = b(ridx (i),j) / data (i); + + if (calc_cond) { - retval.resize (nc, b.cols (), 0); - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type i = 0; i < nm; i++) - retval(i,j) = b(i,j) / data (i); - else - for (octave_idx_type j = 0; j < b.cols (); j++) - for (octave_idx_type k = 0; k < nc; k++) - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) - retval(k,j) = b(ridx (i),j) / data (i); - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = fabs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; - } - rcond = dmin / dmax; - } - else - rcond = 1.; + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = fabs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.; } return retval; @@ -1601,7 +1568,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -1609,68 +1577,66 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) - { - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - if (typ == MatrixType::Diagonal) - for (octave_idx_type j = 0; j < b.cols (); j++) + if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + if (typ == MatrixType::Diagonal) + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) { - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - { - if (b.ridx (i) >= nm) - break; - retval.xridx (ii) = b.ridx (i); - retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); - } - retval.xcidx (j+1) = ii; + if (b.ridx (i) >= nm) + break; + retval.xridx (ii) = b.ridx (i); + retval.xdata (ii++) = b.data (i) / data (b.ridx (i)); } - else - for (octave_idx_type j = 0; j < b.cols (); j++) - { - for (octave_idx_type l = 0; l < nc; l++) - for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + retval.xcidx (j+1) = ii; + } + else + for (octave_idx_type j = 0; j < b.cols (); j++) + { + for (octave_idx_type l = 0; l < nc; l++) + for (octave_idx_type i = cidx (l); i < cidx (l+1); i++) + { + bool found = false; + octave_idx_type k; + for (k = b.cidx (j); k < b.cidx (j+1); k++) + if (ridx (i) == b.ridx (k)) + { + found = true; + break; + } + if (found) { - bool found = false; - octave_idx_type k; - for (k = b.cidx (j); k < b.cidx (j+1); k++) - if (ridx (i) == b.ridx (k)) - { - found = true; - break; - } - if (found) - { - retval.xridx (ii) = l; - retval.xdata (ii++) = b.data (k) / data (i); - } + retval.xridx (ii) = l; + retval.xdata (ii++) = b.data (k) / data (i); } - retval.xcidx (j+1) = ii; - } - - if (calc_cond) - { - double dmax = 0.; - double dmin = octave_Inf; - for (octave_idx_type i = 0; i < nm; i++) - { - double tmp = fabs (data (i)); - if (tmp > dmax) - dmax = tmp; - if (tmp < dmin) - dmin = tmp; } - rcond = dmin / dmax; - } - else - rcond = 1.; + retval.xcidx (j+1) = ii; + } + + if (calc_cond) + { + double dmax = 0.; + double dmin = octave_Inf; + for (octave_idx_type i = 0; i < nm; i++) + { + double tmp = fabs (data (i)); + if (tmp > dmax) + dmax = tmp; + if (tmp < dmin) + dmin = tmp; + } + rcond = dmin / dmax; } else - (*current_liboctave_error_handler) ("incorrect matrix type"); + rcond = 1.; } return retval; @@ -1692,7 +1658,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -1700,128 +1667,157 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (double, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (perm[i], j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Upper) - { - retval.resize (nc, b_nc); - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (double, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + double tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; - } - - double tmp = work[k] / data (cidx (kidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (perm[i], j) = work[i]; + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += fabs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; } - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (double, work, nm); + retval.resize (nc, b_nc); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } + err = -2; + goto triangular_error; } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) + + double tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) { - atmp += fabs (work[i]); - work[i] = 0.; + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (double, work, nm); - retval.resize (nc, b_nc); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { if (work[k] != 0.) { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - double tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) @@ -1831,76 +1827,45 @@ } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -1922,7 +1887,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else { @@ -1930,260 +1896,258 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (double, work, nm); + + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); + for (octave_idx_type i = 0; i < nc; i++) + rperm[perm[i]] = i; + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (work[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (cidx (kidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[rperm[i]] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[rperm[i]]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Upper) - { - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (double, work, nm); - - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); - for (octave_idx_type i = 0; i < nc; i++) - rperm[perm[i]] = i; - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; + octave_idx_type iidx = perm[k]; if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + double tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } - - double tmp = work[k] / data (cidx (kidx+1)-1); + } + } + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) + { + atmp += fabs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (double, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + if (work[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) + { + if (work[k] != 0.) + { + double tmp = work[k] / data (cidx (k+1)-1); work[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += fabs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[rperm[i]] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[rperm[i]]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } + rcond = 1. / ainvnorm / anorm; + } + } + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); } else - { - OCTAVE_LOCAL_BUFFER (double, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) - { - if (work[k] != 0.) - { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - double tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) - { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } + warn_singular_matrix (rcond); } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; } @@ -2204,7 +2168,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -2212,210 +2177,208 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + cwork[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + cwork[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (cwork[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (cidx (kidx+1)-1); + cwork[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (perm[i], j) = cwork[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) - { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Upper) - { - retval.resize (nc, b_nc); - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - cwork[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - cwork[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; - - if (cwork[k] != 0.) + octave_idx_type iidx = perm[k]; + + if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + double tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (kidx+1)-1); - cwork[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (perm[i], j) = cwork[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) + atmp += fabs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; + } + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + retval.resize (nc, b_nc); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + cwork[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + cwork[i] = 0.; + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + if (cwork[k] != 0.) + { + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) { - atmp += fabs (work[i]); - work[i] = 0.; + err = -2; + goto triangular_error; } - if (atmp > ainvnorm) - ainvnorm = atmp; + + Complex tmp = cwork[k] / data (cidx (k+1)-1); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); + } } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - retval.resize (nc, b_nc); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = cwork[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - cwork[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - cwork[i] = 0.; - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - if (cwork[k] != 0.) + if (work[k] != 0.) { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (k+1)-1); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + double tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = cwork[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2437,7 +2400,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -2445,262 +2409,260 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper) + if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Upper) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + octave_idx_type *perm = mattype.triangular_perm (); + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + + OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); + for (octave_idx_type i = 0; i < nc; i++) + rperm[perm[i]] = i; + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + cwork[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + cwork[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) + { + octave_idx_type kidx = perm[k]; + + if (cwork[k] != 0.) + { + if (ridx (cidx (kidx+1)-1) != k + || data (cidx (kidx+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (cidx (kidx+1)-1); + cwork[k] = tmp; + for (octave_idx_type i = cidx (kidx); + i < cidx (kidx+1)-1; i++) + { + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[rperm[i]] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = cwork[rperm[i]]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Upper) - { - octave_idx_type *perm = mattype.triangular_perm (); - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - - OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc); - for (octave_idx_type i = 0; i < nc; i++) - rperm[perm[i]] = i; - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - cwork[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - cwork[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - octave_idx_type kidx = perm[k]; - - if (cwork[k] != 0.) + octave_idx_type iidx = perm[k]; + + if (work[k] != 0.) { - if (ridx (cidx (kidx+1)-1) != k - || data (cidx (kidx+1)-1) == 0.) + double tmp = work[k] / data (cidx (iidx+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (iidx); + i < cidx (iidx+1)-1; i++) { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (kidx+1)-1); - cwork[k] = tmp; - for (octave_idx_type i = cidx (kidx); - i < cidx (kidx+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + octave_idx_type idx2 = ridx (i); + work[idx2] = work[idx2] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += fabs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[rperm[i]] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = cwork[rperm[i]]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + cwork[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + cwork[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = nc-1; k >= 0; k--) { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (cwork[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) + if (ridx (cidx (k+1)-1) != k + || data (cidx (k+1)-1) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (cidx (k+1)-1); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) { - octave_idx_type iidx = perm[k]; - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (iidx+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (iidx); - i < cidx (iidx+1)-1; i++) - { - octave_idx_type idx2 = ridx (i); - work[idx2] = work[idx2] - tmp * data (i); - } - } + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = cwork[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nm; i++) - cwork[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - cwork[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = nc-1; k >= 0; k--) + work[j] = 1.; + + for (octave_idx_type k = j; k >= 0; k--) { - if (cwork[k] != 0.) + if (work[k] != 0.) { - if (ridx (cidx (k+1)-1) != k - || data (cidx (k+1)-1) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (k+1)-1); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++) + double tmp = work[k] / data (cidx (k+1)-1); + work[k] = tmp; + for (octave_idx_type i = cidx (k); + i < cidx (k+1)-1; i++) { octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = cwork[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = 0; i < j+1; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k >= 0; k--) - { - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k+1)-1); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1)-1; i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = 0; i < j+1; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2722,7 +2684,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -2730,39 +2693,87 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + OCTAVE_LOCAL_BUFFER (double, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + if (nc > nr) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = 0; i < nr; i++) + work[perm[i]] = b(i,j); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(i, j) = work[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Lower) - { - retval.resize (nc, b_nc); - OCTAVE_LOCAL_BUFFER (double, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - if (nc > nr) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = 0; i < nr; i++) - work[perm[i]] = b(i,j); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -2771,22 +2782,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0) - { - err = -2; - goto triangular_error; - } - double tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -2797,82 +2804,69 @@ } } - for (octave_idx_type i = 0; i < nc; i++) - retval(i, j) = work[i]; + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) + { + atmp += fabs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; } - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (double, work, nm); + retval.resize (nc, b_nc, 0.); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + work[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + work[i] = 0.; + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - double tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) + { + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (double, work, nm); - retval.resize (nc, b_nc, 0.); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = work[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - work[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - work[i] = 0.; - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - double tmp = work[k] / data (cidx (k)); work[k] = tmp; for (octave_idx_type i = cidx (k)+1; @@ -2883,78 +2877,45 @@ } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = work[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -2976,7 +2937,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else { @@ -2984,43 +2946,113 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + OCTAVE_LOCAL_BUFFER (double, work, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[perm[b.ridx (i)]] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (work[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + work[iidx] = work[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Lower) - { - OCTAVE_LOCAL_BUFFER (double, work, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[perm[b.ridx (i)]] = b.data (i); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { @@ -3029,22 +3061,18 @@ octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0) - { - err = -2; - goto triangular_error; - } - double tmp = work[k] / data (mini); work[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; @@ -3055,207 +3083,139 @@ } } - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = j; i < nr; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += fabs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (double, work, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + work[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (work[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) + { + err = -2; + goto triangular_error; + } + + double tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - double tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + octave_idx_type iidx = ridx (i); + work[iidx] = work[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nr; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; } - } - else - { - OCTAVE_LOCAL_BUFFER (double, work, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + if (work[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = work[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - work[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - double tmp = work[k] / data (cidx (k)); work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (work[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = work[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3277,7 +3237,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -3285,232 +3246,230 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + octave_idx_type b_nc = b.cols (); + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - octave_idx_type b_nc = b.cols (); - rcond = 1.; + retval.resize (nc, b_nc); + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + cwork[i] = 0.; + for (octave_idx_type i = 0; i < nr; i++) + cwork[perm[i]] = b(i,j); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (cwork[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (mini); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + cwork[iidx] = cwork[iidx] - tmp * data (i); + } + } + } + + for (octave_idx_type i = 0; i < nc; i++) + retval(i, j) = cwork[i]; + } if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - if (typ == MatrixType::Permuted_Lower) - { - retval.resize (nc, b_nc); - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - cwork[i] = 0.; - for (octave_idx_type i = 0; i < nr; i++) - cwork[perm[i]] = b(i,j); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { - if (cwork[k] != 0.) + if (work[k] != 0.) { octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (mini); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + double tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; octave_idx_type iidx = perm[ridx (i)]; - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - for (octave_idx_type i = 0; i < nc; i++) - retval(i, j) = cwork[i]; + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) + { + atmp += fabs (work[i]); + work[i] = 0.; + } + if (atmp > ainvnorm) + ainvnorm = atmp; } - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + retval.resize (nc, b_nc, 0.); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nr; i++) + cwork[i] = b(i,j); + for (octave_idx_type i = nr; i < nc; i++) + cwork[i] = 0.; + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (cwork[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - double tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + err = -2; + goto triangular_error; } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) + Complex tmp = cwork[k] / data (cidx (k)); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) { - atmp += fabs (work[i]); - work[i] = 0.; + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); } - if (atmp > ainvnorm) - ainvnorm = atmp; } - rcond = 1. / ainvnorm / anorm; } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - retval.resize (nc, b_nc, 0.); - - for (octave_idx_type j = 0; j < b_nc; j++) + + for (octave_idx_type i = 0; i < nc; i++) + retval.xelem (i, j) = cwork[i]; + } + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - for (octave_idx_type i = 0; i < nr; i++) - cwork[i] = b(i,j); - for (octave_idx_type i = nr; i < nc; i++) - cwork[i] = 0.; - - for (octave_idx_type k = 0; k < nc; k++) + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) { - if (cwork[k] != 0.) + + if (work[k] != 0.) { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (k)); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + double tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - - for (octave_idx_type i = 0; i < nc; i++) - retval.xelem (i, j) = cwork[i]; - } - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3532,7 +3491,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -3540,280 +3500,278 @@ int typ = mattype.type (); mattype.info (); - if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower) + if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) + (*current_liboctave_error_handler) ("incorrect matrix type"); + + double anorm = 0.; + double ainvnorm = 0.; + rcond = 1.; + + if (calc_cond) + { + // Calculate the 1-norm of matrix for rcond calculation + for (octave_idx_type j = 0; j < nc; j++) + { + double atmp = 0.; + for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) + atmp += fabs (data (i)); + if (atmp > anorm) + anorm = atmp; + } + } + + octave_idx_type b_nc = b.cols (); + octave_idx_type b_nz = b.nnz (); + retval = SparseComplexMatrix (nc, b_nc, b_nz); + retval.xcidx (0) = 0; + octave_idx_type ii = 0; + octave_idx_type x_nz = b_nz; + + if (typ == MatrixType::Permuted_Lower) { - double anorm = 0.; - double ainvnorm = 0.; - rcond = 1.; + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + octave_idx_type *perm = mattype.triangular_perm (); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + cwork[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + cwork[perm[b.ridx (i)]] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) + { + if (cwork[k] != 0.) + { + octave_idx_type minr = nr; + octave_idx_type mini = 0; + + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + if (perm[ridx (i)] < minr) + { + minr = perm[ridx (i)]; + mini = i; + } + + if (minr != k || data (mini) == 0) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (mini); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + { + if (i == mini) + continue; + + octave_idx_type iidx = perm[ridx (i)]; + cwork[iidx] = cwork[iidx] - tmp * data (i); + } + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = cwork[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); if (calc_cond) { - // Calculate the 1-norm of matrix for rcond calculation - for (octave_idx_type j = 0; j < nc; j++) + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) { - double atmp = 0.; - for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) - atmp += fabs (data (i)); - if (atmp > anorm) - anorm = atmp; - } - } - - octave_idx_type b_nc = b.cols (); - octave_idx_type b_nz = b.nnz (); - retval = SparseComplexMatrix (nc, b_nc, b_nz); - retval.xcidx (0) = 0; - octave_idx_type ii = 0; - octave_idx_type x_nz = b_nz; - - if (typ == MatrixType::Permuted_Lower) - { - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - octave_idx_type *perm = mattype.triangular_perm (); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - cwork[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - cwork[perm[b.ridx (i)]] = b.data (i); + work[j] = 1.; for (octave_idx_type k = 0; k < nc; k++) { - if (cwork[k] != 0.) + if (work[k] != 0.) { octave_idx_type minr = nr; octave_idx_type mini = 0; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) if (perm[ridx (i)] < minr) { minr = perm[ridx (i)]; mini = i; } - if (minr != k || data (mini) == 0) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (mini); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k); i < cidx (k+1); i++) + double tmp = work[k] / data (mini); + work[k] = tmp; + for (octave_idx_type i = cidx (k); + i < cidx (k+1); i++) { if (i == mini) continue; octave_idx_type iidx = perm[ridx (i)]; - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; + atmp += fabs (work[i]); + work[i] = 0.; } - - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = cwork[i]; - } - retval.xcidx (j+1) = ii; + if (atmp > ainvnorm) + ainvnorm = atmp; } - - retval.maybe_compress (); - - if (calc_cond) + rcond = 1. / ainvnorm / anorm; + } + } + else + { + OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); + + for (octave_idx_type j = 0; j < b_nc; j++) + { + for (octave_idx_type i = 0; i < nm; i++) + cwork[i] = 0.; + for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) + cwork[b.ridx (i)] = b.data (i); + + for (octave_idx_type k = 0; k < nc; k++) { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + if (cwork[k] != 0.) { - work[j] = 1.; - - for (octave_idx_type k = 0; k < nc; k++) + if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) + { + err = -2; + goto triangular_error; + } + + Complex tmp = cwork[k] / data (cidx (k)); + cwork[k] = tmp; + for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) { - if (work[k] != 0.) - { - octave_idx_type minr = nr; - octave_idx_type mini = 0; - - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - if (perm[ridx (i)] < minr) - { - minr = perm[ridx (i)]; - mini = i; - } - - double tmp = work[k] / data (mini); - work[k] = tmp; - for (octave_idx_type i = cidx (k); - i < cidx (k+1); i++) - { - if (i == mini) - continue; - - octave_idx_type iidx = perm[ridx (i)]; - work[iidx] = work[iidx] - tmp * data (i); - } - } + octave_idx_type iidx = ridx (i); + cwork[iidx] = cwork[iidx] - tmp * data (i); } - - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) + } + } + + // Count nonzeros in work vector and adjust space in + // retval if needed + octave_idx_type new_nnz = 0; + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + new_nnz++; + + if (ii + new_nnz > x_nz) + { + // Resize the sparse matrix + octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; + retval.change_capacity (sz); + x_nz = sz; + } + + for (octave_idx_type i = 0; i < nc; i++) + if (cwork[i] != 0.) + { + retval.xridx (ii) = i; + retval.xdata (ii++) = cwork[i]; + } + retval.xcidx (j+1) = ii; + } + + retval.maybe_compress (); + + if (calc_cond) + { + // Calculation of 1-norm of inv(*this) + OCTAVE_LOCAL_BUFFER (double, work, nm); + for (octave_idx_type i = 0; i < nm; i++) + work[i] = 0.; + + for (octave_idx_type j = 0; j < nr; j++) + { + work[j] = 1.; + + for (octave_idx_type k = j; k < nc; k++) + { + + if (work[k] != 0.) { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; - } - rcond = 1. / ainvnorm / anorm; - } - } - else - { - OCTAVE_LOCAL_BUFFER (Complex, cwork, nm); - - for (octave_idx_type j = 0; j < b_nc; j++) - { - for (octave_idx_type i = 0; i < nm; i++) - cwork[i] = 0.; - for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) - cwork[b.ridx (i)] = b.data (i); - - for (octave_idx_type k = 0; k < nc; k++) - { - if (cwork[k] != 0.) - { - if (ridx (cidx (k)) != k || data (cidx (k)) == 0.) - { - err = -2; - goto triangular_error; - } - - Complex tmp = cwork[k] / data (cidx (k)); - cwork[k] = tmp; - for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++) + double tmp = work[k] / data (cidx (k)); + work[k] = tmp; + for (octave_idx_type i = cidx (k)+1; + i < cidx (k+1); i++) { octave_idx_type iidx = ridx (i); - cwork[iidx] = cwork[iidx] - tmp * data (i); + work[iidx] = work[iidx] - tmp * data (i); } } } - - // Count nonzeros in work vector and adjust space in - // retval if needed - octave_idx_type new_nnz = 0; - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - new_nnz++; - - if (ii + new_nnz > x_nz) - { - // Resize the sparse matrix - octave_idx_type sz = new_nnz * (b_nc - j) + x_nz; - retval.change_capacity (sz); - x_nz = sz; - } - - for (octave_idx_type i = 0; i < nc; i++) - if (cwork[i] != 0.) - { - retval.xridx (ii) = i; - retval.xdata (ii++) = cwork[i]; - } - retval.xcidx (j+1) = ii; - } - - retval.maybe_compress (); - - if (calc_cond) - { - // Calculation of 1-norm of inv(*this) - OCTAVE_LOCAL_BUFFER (double, work, nm); - for (octave_idx_type i = 0; i < nm; i++) - work[i] = 0.; - - for (octave_idx_type j = 0; j < nr; j++) + double atmp = 0; + for (octave_idx_type i = j; i < nc; i++) { - work[j] = 1.; - - for (octave_idx_type k = j; k < nc; k++) - { - - if (work[k] != 0.) - { - double tmp = work[k] / data (cidx (k)); - work[k] = tmp; - for (octave_idx_type i = cidx (k)+1; - i < cidx (k+1); i++) - { - octave_idx_type iidx = ridx (i); - work[iidx] = work[iidx] - tmp * data (i); - } - } - } - double atmp = 0; - for (octave_idx_type i = j; i < nc; i++) - { - atmp += fabs (work[i]); - work[i] = 0.; - } - if (atmp > ainvnorm) - ainvnorm = atmp; + atmp += fabs (work[i]); + work[i] = 0.; } - rcond = 1. / ainvnorm / anorm; + if (atmp > ainvnorm) + ainvnorm = atmp; } - } - - triangular_error: - if (err != 0) - { - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); - } - - volatile double rcond_plus_one = rcond + 1.0; - - if (rcond_plus_one == 1.0 || xisnan (rcond)) - { - err = -2; - - if (sing_handler) - { - sing_handler (rcond); - mattype.mark_as_rectangular (); - } - else - warn_singular_matrix (rcond); + rcond = 1. / ainvnorm / anorm; } } - else - (*current_liboctave_error_handler) ("incorrect matrix type"); + + triangular_error: + if (err != 0) + { + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } + + volatile double rcond_plus_one = rcond + 1.0; + + if (rcond_plus_one == 1.0 || xisnan (rcond)) + { + err = -2; + + if (sing_handler) + { + sing_handler (rcond); + mattype.mark_as_rectangular (); + } + else + warn_singular_matrix (rcond); + } } return retval; @@ -3834,7 +3792,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else if (calc_cond) (*current_liboctave_error_handler) @@ -3983,7 +3942,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else if (calc_cond) (*current_liboctave_error_handler) @@ -4128,7 +4088,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else if (calc_cond) (*current_liboctave_error_handler) @@ -4279,7 +4240,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else if (calc_cond) (*current_liboctave_error_handler) @@ -4384,6 +4346,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); @@ -4399,6 +4362,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); @@ -4457,7 +4421,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -4559,6 +4524,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -4700,7 +4666,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else { @@ -4812,6 +4779,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -5012,7 +4980,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -5127,6 +5096,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -5141,6 +5111,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -5305,7 +5276,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -5426,6 +5398,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); err = -1; @@ -5440,6 +5413,7 @@ if (err != 0) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); @@ -5694,14 +5668,15 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseMatrix::solve symbolic factorization failed"); - err = -1; - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_symbolic) (&Symbolic); + + // FIXME: Should this be a warning? + (*current_liboctave_error_handler) + ("SparseMatrix::solve symbolic factorization failed"); + err = -1; } else { @@ -5731,12 +5706,13 @@ } else if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + UMFPACK_DNAME (report_info) (control, info); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve numeric factorization failed"); - UMFPACK_DNAME (report_status) (control, status); - UMFPACK_DNAME (report_info) (control, info); - err = -1; } else @@ -5772,7 +5748,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = Matrix (nc, b.cols (), 0.0); else { @@ -5945,13 +5922,13 @@ info); if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); - UMFPACK_DNAME (report_status) (control, status); - err = -1; - break; } } @@ -5991,7 +5968,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseMatrix (nc, b.cols ()); else { @@ -6188,13 +6166,13 @@ control, info); if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); - UMFPACK_DNAME (report_status) (control, status); - err = -1; - break; } @@ -6255,7 +6233,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); else { @@ -6442,13 +6421,13 @@ if (status < 0 || status2 < 0) { + UMFPACK_DNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); - UMFPACK_DNAME (report_status) (control, status); - err = -1; - break; } @@ -6491,7 +6470,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = SparseComplexMatrix (nc, b.cols ()); else { @@ -6699,13 +6679,13 @@ if (status < 0 || status2 < 0) { + UMFPACK_DNAME (report_status) (control, status); + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("SparseMatrix::solve solve failed"); - UMFPACK_DNAME (report_status) (control, status); - err = -1; - break; } @@ -6799,10 +6779,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return Matrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); // Rectangular or one of the above solvers flags a singular matrix if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) @@ -6867,10 +6844,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return SparseMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { @@ -6935,10 +6909,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return ComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { @@ -7003,10 +6974,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, err, rcond, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return SparseComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); if (singular_fallback && mattype.type (false) == MatrixType::Rectangular) { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fCColVector.cc --- a/liboctave/array/fCColVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fCColVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -80,10 +80,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -103,10 +100,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -159,10 +153,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } @@ -184,10 +175,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fCDiagMatrix.cc --- a/liboctave/array/fCDiagMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fCDiagMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -80,10 +80,7 @@ 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; @@ -96,10 +93,7 @@ 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; @@ -112,10 +106,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); @@ -128,10 +119,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); @@ -144,10 +132,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); @@ -160,10 +145,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); @@ -176,10 +158,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); @@ -193,10 +172,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); @@ -209,10 +185,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); @@ -226,10 +199,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); @@ -279,10 +249,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= r) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); FloatComplexRowVector retval (c, 0.0); if (r <= c || (r > c && i < c)) @@ -295,10 +262,7 @@ FloatComplexDiagMatrix::row (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); char c = *s; if (c == 'f' || c == 'F') @@ -306,10 +270,7 @@ else if (c == 'l' || c == 'L') return row (rows () - 1); else - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatComplexRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); } FloatComplexColumnVector @@ -318,10 +279,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (i < 0 || i >= c) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); FloatComplexColumnVector retval (r, 0.0); if (r >= c || (r < c && i < r)) @@ -334,10 +292,7 @@ FloatComplexDiagMatrix::column (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); char c = *s; if (c == 'f' || c == 'F') @@ -345,10 +300,7 @@ else if (c == 'l' || c == 'L') return column (cols () - 1); else - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatComplexColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); } FloatComplexDiagMatrix @@ -364,10 +316,7 @@ octave_idx_type r = rows (); octave_idx_type c = cols (); if (r != c) - { - (*current_liboctave_error_handler) ("inverse requires square matrix"); - return FloatComplexDiagMatrix (); - } + (*current_liboctave_error_handler) ("inverse requires square matrix"); FloatComplexDiagMatrix retval (r, c); @@ -528,16 +477,11 @@ { FloatComplexDET det (1.0f); if (rows () != cols ()) - { - (*current_liboctave_error_handler) ("determinant requires square matrix"); - det = FloatComplexDET (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; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fCMatrix.cc --- a/liboctave/array/fCMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fCMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -407,10 +407,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_nr >0 && a_nc > 0) { @@ -431,10 +428,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -454,10 +448,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -478,10 +469,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -512,10 +500,7 @@ { octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); for (octave_idx_type i = 0; i < a_len; i++) elem (r, c+i) = a.elem (i); @@ -530,10 +515,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -554,10 +536,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -619,10 +598,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -649,10 +625,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -675,10 +648,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.cols ()); @@ -693,10 +663,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.numel ()); @@ -711,10 +678,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + 1); @@ -729,10 +693,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.cols ()); @@ -747,10 +708,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.cols ()); @@ -765,10 +723,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.numel ()); @@ -783,10 +738,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + 1); @@ -801,10 +753,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatComplexMatrix retval (nr, nc + a.cols ()); @@ -819,11 +768,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.rows (), nc); @@ -838,11 +783,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + 1, nc); @@ -857,11 +798,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.numel (), nc); @@ -876,11 +813,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.rows (), nc); @@ -895,11 +828,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.rows (), nc); @@ -914,11 +843,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + 1, nc); @@ -933,11 +858,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.numel (), nc); @@ -952,11 +873,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return *this; - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatComplexMatrix retval (nr + a.rows (), nc); @@ -1055,49 +972,47 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + int typ = mattype.type (); + char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); + char udiag = 'N'; + retval = *this; + FloatComplex *tmp_data = retval.fortran_vec (); + + F77_XFCN (ctrtri, CTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&udiag, 1), + nr, tmp_data, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) { - int typ = mattype.type (); - char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); - char udiag = 'N'; - retval = *this; - FloatComplex *tmp_data = retval.fortran_vec (); - - F77_XFCN (ctrtri, CTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + octave_idx_type ztrcon_info = 0; + char job = '1'; + + OCTAVE_LOCAL_BUFFER (FloatComplex, cwork, 2*nr); + OCTAVE_LOCAL_BUFFER (float, rwork, nr); + + F77_XFCN (ctrcon, CTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, info + nr, tmp_data, nr, rcon, + cwork, rwork, ztrcon_info + F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + if (ztrcon_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type ztrcon_info = 0; - char job = '1'; - - OCTAVE_LOCAL_BUFFER (FloatComplex, cwork, 2*nr); - OCTAVE_LOCAL_BUFFER (float, rwork, nr); - - F77_XFCN (ctrcon, CTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, rcon, - cwork, rwork, ztrcon_info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (ztrcon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. } + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. + return retval; } @@ -1112,74 +1027,72 @@ if (nr != nc) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + retval = *this; + FloatComplex *tmp_data = retval.fortran_vec (); + + Array z (dim_vector (1, 1)); + octave_idx_type lwork = -1; + + // Query the optimum work array size. + + F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, + z.fortran_vec (), lwork, info)); + + lwork = static_cast (std::real (z(0))); + lwork = (lwork < 2 *nc ? 2*nc : lwork); + z.resize (dim_vector (lwork, 1)); + FloatComplex *pz = z.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + float anorm; + if (calc_cond) + anorm = retval.abs ().sum ().row (static_cast(0)) + .max (); + + F77_XFCN (cgetrf, CGETRF, (nc, nc, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) + { + // Now calculate the condition number for non-singular matrix. + octave_idx_type zgecon_info = 0; + char job = '1'; + Array rz (dim_vector (2 * nc, 1)); + float *prz = rz.fortran_vec (); + F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, + rcon, pz, prz, zgecon_info + F77_CHAR_ARG_LEN (1))); + + if (zgecon_info != 0) + info = -1; + } + + if (info == -1 && ! force) + retval = *this; // Restore contents. else { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - retval = *this; - FloatComplex *tmp_data = retval.fortran_vec (); - - Array z (dim_vector (1, 1)); - octave_idx_type lwork = -1; - - // Query the optimum work array size. + octave_idx_type zgetri_info = 0; F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, - z.fortran_vec (), lwork, info)); - - lwork = static_cast (std::real (z(0))); - lwork = (lwork < 2 *nc ? 2*nc : lwork); - z.resize (dim_vector (lwork, 1)); - FloatComplex *pz = z.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - float anorm; - if (calc_cond) - anorm = retval.abs ().sum ().row (static_cast(0)) - .max (); - - F77_XFCN (cgetrf, CGETRF, (nc, nc, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + pz, lwork, zgetri_info)); + + if (zgetri_info != 0) info = -1; - else if (calc_cond) - { - // Now calculate the condition number for non-singular matrix. - octave_idx_type zgecon_info = 0; - char job = '1'; - Array rz (dim_vector (2 * nc, 1)); - float *prz = rz.fortran_vec (); - F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, prz, zgecon_info - F77_CHAR_ARG_LEN (1))); - - if (zgecon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore contents. - else - { - octave_idx_type zgetri_info = 0; - - F77_XFCN (cgetri, CGETRI, (nc, tmp_data, nr, pipvt, - pz, lwork, zgetri_info)); - - if (zgetri_info != 0) - info = -1; - } - - if (info != 0) - mattype.mark_as_rectangular (); } + if (info != 0) + mattype.mark_as_rectangular (); + return retval; } @@ -1628,86 +1541,107 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else + + volatile int typ = mattype.type (); + + // Even though the matrix is marked as singular (Rectangular), we may + // still get a useful number from the LU factorization, because it always + // completes. + + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + else if (typ == MatrixType::Rectangular) + typ = MatrixType::Full; + + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { - volatile int typ = mattype.type (); - - // Even though the matrix is marked as singular (Rectangular), we may - // still get a useful number from the LU factorization, because it always - // completes. - - if (typ == MatrixType::Unknown) - typ = mattype.type (*this); - else if (typ == MatrixType::Rectangular) - typ = MatrixType::Full; - - if (typ == MatrixType::Lower || typ == MatrixType::Upper) + for (octave_idx_type i = 0; i < nc; i++) + retval *= elem (i,i); + } + else if (typ == MatrixType::Hermitian) + { + FloatComplexMatrix atmp = *this; + FloatComplex *tmp_data = atmp.fortran_vec (); + + float anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + + char job = 'L'; + F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, + tmp_data, nr, info + F77_CHAR_ARG_LEN (1))); + + if (info != 0) { - for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + rcon = 0.0; + mattype.mark_as_unsymmetric (); + typ = MatrixType::Full; } - else if (typ == MatrixType::Hermitian) + else { - FloatComplexMatrix atmp = *this; - FloatComplex *tmp_data = atmp.fortran_vec (); - - float anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - - char job = 'L'; - F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, - tmp_data, nr, info + Array z (dim_vector (2 * nc, 1)); + FloatComplex *pz = z.fortran_vec (); + Array rz (dim_vector (nc, 1)); + float *prz = rz.fortran_vec (); + + F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), + nr, tmp_data, nr, anorm, + rcon, pz, prz, info F77_CHAR_ARG_LEN (1))); if (info != 0) + rcon = 0.0; + + for (octave_idx_type i = 0; i < nc; i++) + retval *= atmp (i,i); + + retval = retval.square (); + } + } + else if (typ != MatrixType::Full) + (*current_liboctave_error_handler) ("det: invalid dense matrix type"); + + if (typ == MatrixType::Full) + { + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + FloatComplexMatrix atmp = *this; + FloatComplex *tmp_data = atmp.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + float anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + F77_XFCN (cgetrf, CGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + { + info = -1; + retval = FloatComplexDET (); + } + else + { + if (calc_cond) { - rcon = 0.0; - mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; - } - else - { + // Now calc the condition number for non-singular matrix. + char job = '1'; Array z (dim_vector (2 * nc, 1)); FloatComplex *pz = z.fortran_vec (); - Array rz (dim_vector (nc, 1)); + Array rz (dim_vector (2 * nc, 1)); float *prz = rz.fortran_vec (); - F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), - nr, tmp_data, nr, anorm, + F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, rcon, pz, prz, info F77_CHAR_ARG_LEN (1))); - - if (info != 0) - rcon = 0.0; - - for (octave_idx_type i = 0; i < nc; i++) - retval *= atmp (i,i); - - retval = retval.square (); } - } - else if (typ != MatrixType::Full) - (*current_liboctave_error_handler) ("det: invalid dense matrix type"); - - if (typ == MatrixType::Full) - { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - FloatComplexMatrix atmp = *this; - FloatComplex *tmp_data = atmp.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - float anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - F77_XFCN (cgetrf, CGETRF, (nr, nr, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; + if (info != 0) { info = -1; @@ -1715,33 +1649,10 @@ } else { - if (calc_cond) + for (octave_idx_type i = 0; i < nc; i++) { - // Now calc the condition number for non-singular matrix. - char job = '1'; - Array z (dim_vector (2 * nc, 1)); - FloatComplex *pz = z.fortran_vec (); - Array rz (dim_vector (2 * nc, 1)); - float *prz = rz.fortran_vec (); - - F77_XFCN (cgecon, CGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, prz, info - F77_CHAR_ARG_LEN (1))); - } - - if (info != 0) - { - info = -1; - retval = FloatComplexDET (); - } - else - { - for (octave_idx_type i = 0; i < nc; i++) - { - FloatComplex c = atmp(i,i); - retval *= (ipvt(i) != (i+1)) ? -c : c; - } + FloatComplex c = atmp(i,i); + retval *= (ipvt(i) != (i+1)) ? -c : c; } } } @@ -1766,7 +1677,8 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) rcon = octave_Inf; else { @@ -1936,7 +1848,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); else { @@ -1949,10 +1862,8 @@ info = 0; if (typ == MatrixType::Permuted_Upper) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); else { const FloatComplex *tmp_data = fortran_vec (); @@ -2031,7 +1942,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); else { @@ -2044,10 +1956,8 @@ info = 0; if (typ == MatrixType::Permuted_Lower) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); else { const FloatComplex *tmp_data = fortran_vec (); @@ -2127,7 +2037,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = FloatComplexMatrix (nc, b.cols (), FloatComplex (0.0, 0.0)); else { @@ -2377,10 +2288,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, info, rcon, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return FloatComplexMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); // Rectangular or one of the above solvers flags a singular matrix if (singular_fallback && mattype.type () == MatrixType::Rectangular) @@ -2665,7 +2573,8 @@ if (m != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m== 0 || n == 0 || b.cols () == 0) + + if (m== 0 || n == 0 || b.cols () == 0) retval = FloatComplexMatrix (n, b.cols (), FloatComplex (0.0, 0.0)); else { @@ -2865,7 +2774,8 @@ if (m != b.numel ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0 || b.cols () == 0) + + if (m == 0 || n == 0 || b.cols () == 0) retval = FloatComplexColumnVector (n, FloatComplex (0.0, 0.0)); else { @@ -3179,8 +3089,7 @@ if (nr == 1 || nc == 1) retval = FloatComplexDiagMatrix (*this, m, n); else - (*current_liboctave_error_handler) - ("diag: expecting vector argument"); + (*current_liboctave_error_handler) ("diag: expecting vector argument"); return retval; } @@ -3862,11 +3771,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg min requires same size arguments"); - return FloatComplexMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg min requires same size arguments"); EMPTY_RETURN_CHECK (FloatComplexMatrix); @@ -3950,11 +3856,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg max requires same size arguments"); - return FloatComplexMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg max requires same size arguments"); EMPTY_RETURN_CHECK (FloatComplexMatrix); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fCNDArray.cc --- a/liboctave/array/fCNDArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fCNDArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -776,11 +776,8 @@ for (int i = 0; i < n; i++) { if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i)) - { - (*current_liboctave_error_handler) - ("Array::insert: range error for insert"); - return *this; - } + (*current_liboctave_error_handler) + ("Array::insert: range error for insert"); } a_ra_idx.elem (0) = 0; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fCRowVector.cc --- a/liboctave/array/fCRowVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fCRowVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -79,10 +79,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -102,10 +99,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -156,10 +150,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } @@ -181,10 +172,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fColVector.cc --- a/liboctave/array/fColVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fColVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -72,10 +72,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -110,10 +107,7 @@ octave_idx_type len = numel (); if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fDiagMatrix.cc --- a/liboctave/array/fDiagMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fDiagMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -63,10 +63,7 @@ FloatDiagMatrix::fill (float 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 FloatRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); FloatRowVector retval (c, 0.0); if (r <= c || (r > c && i < c)) @@ -199,10 +181,7 @@ FloatDiagMatrix::row (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid row selection"); - return FloatRowVector (); - } + (*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 FloatRowVector (); - } + (*current_liboctave_error_handler) ("invalid row selection"); } FloatColumnVector @@ -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 FloatColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); FloatColumnVector retval (r, 0.0); if (r >= c || (r < c && i < r)) @@ -238,10 +211,7 @@ FloatDiagMatrix::column (char *s) const { if (! s) - { - (*current_liboctave_error_handler) ("invalid column selection"); - return FloatColumnVector (); - } + (*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 FloatColumnVector (); - } + (*current_liboctave_error_handler) ("invalid column selection"); } FloatDiagMatrix @@ -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 FloatDiagMatrix (); - } + (*current_liboctave_error_handler) ("inverse requires square matrix"); FloatDiagMatrix retval (r, c); @@ -345,16 +309,11 @@ { FloatDET det (1.0f); if (rows () != cols ()) - { - (*current_liboctave_error_handler) ("determinant requires square matrix"); - det = 0.0f; - } - 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; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fMatrix.cc --- a/liboctave/array/fMatrix.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fMatrix.cc Sat Jan 23 13:52:03 2016 -0800 @@ -349,10 +349,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -372,10 +369,7 @@ octave_idx_type a_len = a.numel (); if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -396,10 +390,7 @@ octave_idx_type a_nc = a.cols (); if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); @@ -443,10 +434,7 @@ if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (r1 > r2) { std::swap (r1, r2); } if (c1 > c2) { std::swap (c1, c2); } @@ -469,10 +457,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatMatrix retval (nr, nc + a.cols ()); @@ -487,10 +472,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != 1) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatMatrix retval (nr, nc + a.numel ()); @@ -505,10 +487,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.numel ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatMatrix retval (nr, nc + 1); @@ -523,10 +502,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nr != a.rows ()) - { - (*current_liboctave_error_handler) ("row dimension mismatch for append"); - return *this; - } + (*current_liboctave_error_handler) ("row dimension mismatch for append"); octave_idx_type nc_insert = nc; FloatMatrix retval (nr, nc + a.cols ()); @@ -541,11 +517,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatMatrix retval (nr + a.rows (), nc); @@ -560,11 +532,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.numel ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatMatrix retval (nr + 1, nc); @@ -579,11 +547,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != 1) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatMatrix retval (nr + a.numel (), nc); @@ -598,11 +562,7 @@ octave_idx_type nr = rows (); octave_idx_type nc = cols (); if (nc != a.cols ()) - { - (*current_liboctave_error_handler) - ("column dimension mismatch for stack"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("column dimension mismatch for stack"); octave_idx_type nr_insert = nr; FloatMatrix retval (nr + a.rows (), nc); @@ -705,49 +665,47 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); - else + + int typ = mattype.type (); + char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); + char udiag = 'N'; + retval = *this; + float *tmp_data = retval.fortran_vec (); + + F77_XFCN (strtri, STRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + F77_CONST_CHAR_ARG2 (&udiag, 1), + nr, tmp_data, nr, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) { - int typ = mattype.type (); - char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); - char udiag = 'N'; - retval = *this; - float *tmp_data = retval.fortran_vec (); - - F77_XFCN (strtri, STRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), + octave_idx_type dtrcon_info = 0; + char job = '1'; + + OCTAVE_LOCAL_BUFFER (float, work, 3 * nr); + OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, nr); + + F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&job, 1), + F77_CONST_CHAR_ARG2 (&uplo, 1), F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, info + nr, tmp_data, nr, rcon, + work, iwork, dtrcon_info + F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + if (dtrcon_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type dtrcon_info = 0; - char job = '1'; - - OCTAVE_LOCAL_BUFFER (float, work, 3 * nr); - OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, nr); - - F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&job, 1), - F77_CONST_CHAR_ARG2 (&uplo, 1), - F77_CONST_CHAR_ARG2 (&udiag, 1), - nr, tmp_data, nr, rcon, - work, iwork, dtrcon_info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); - - if (dtrcon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. } + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. + return retval; } @@ -763,74 +721,72 @@ if (nr != nc || nr == 0 || nc == 0) (*current_liboctave_error_handler) ("inverse requires square matrix"); + + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + retval = *this; + float *tmp_data = retval.fortran_vec (); + + Array z(dim_vector (1, 1)); + octave_idx_type lwork = -1; + + // Query the optimum work array size. + F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt, + z.fortran_vec (), lwork, info)); + + lwork = static_cast (z(0)); + lwork = (lwork < 2 *nc ? 2*nc : lwork); + z.resize (dim_vector (lwork, 1)); + float *pz = z.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + float anorm = 0; + if (calc_cond) + anorm = retval.abs ().sum ().row (static_cast(0)) + .max (); + + F77_XFCN (sgetrf, SGETRF, (nc, nc, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + info = -1; + else if (calc_cond) + { + octave_idx_type dgecon_info = 0; + + // Now calculate the condition number for non-singular matrix. + char job = '1'; + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, + rcon, pz, piz, dgecon_info + F77_CHAR_ARG_LEN (1))); + + if (dgecon_info != 0) + info = -1; + } + + if (info == -1 && ! force) + retval = *this; // Restore matrix contents. else { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - retval = *this; - float *tmp_data = retval.fortran_vec (); - - Array z(dim_vector (1, 1)); - octave_idx_type lwork = -1; - - // Query the optimum work array size. + octave_idx_type dgetri_info = 0; + F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt, - z.fortran_vec (), lwork, info)); - - lwork = static_cast (z(0)); - lwork = (lwork < 2 *nc ? 2*nc : lwork); - z.resize (dim_vector (lwork, 1)); - float *pz = z.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - float anorm = 0; - if (calc_cond) - anorm = retval.abs ().sum ().row (static_cast(0)) - .max (); - - F77_XFCN (sgetrf, SGETRF, (nc, nc, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; - if (info != 0) + pz, lwork, dgetri_info)); + + if (dgetri_info != 0) info = -1; - else if (calc_cond) - { - octave_idx_type dgecon_info = 0; - - // Now calculate the condition number for non-singular matrix. - char job = '1'; - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, piz, dgecon_info - F77_CHAR_ARG_LEN (1))); - - if (dgecon_info != 0) - info = -1; - } - - if (info == -1 && ! force) - retval = *this; // Restore matrix contents. - else - { - octave_idx_type dgetri_info = 0; - - F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt, - pz, lwork, dgetri_info)); - - if (dgetri_info != 0) - info = -1; - } - - if (info != 0) - mattype.mark_as_rectangular (); } + if (info != 0) + mattype.mark_as_rectangular (); + return retval; } @@ -1277,86 +1233,107 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else + + volatile int typ = mattype.type (); + + // Even though the matrix is marked as singular (Rectangular), we may + // still get a useful number from the LU factorization, because it always + // completes. + + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + else if (typ == MatrixType::Rectangular) + typ = MatrixType::Full; + + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { - volatile int typ = mattype.type (); - - // Even though the matrix is marked as singular (Rectangular), we may - // still get a useful number from the LU factorization, because it always - // completes. - - if (typ == MatrixType::Unknown) - typ = mattype.type (*this); - else if (typ == MatrixType::Rectangular) - typ = MatrixType::Full; - - if (typ == MatrixType::Lower || typ == MatrixType::Upper) + for (octave_idx_type i = 0; i < nc; i++) + retval *= elem (i,i); + } + else if (typ == MatrixType::Hermitian) + { + FloatMatrix atmp = *this; + float *tmp_data = atmp.fortran_vec (); + + float anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + + char job = 'L'; + F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, + tmp_data, nr, info + F77_CHAR_ARG_LEN (1))); + + if (info != 0) { - for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + rcon = 0.0; + mattype.mark_as_unsymmetric (); + typ = MatrixType::Full; } - else if (typ == MatrixType::Hermitian) + else { - FloatMatrix atmp = *this; - float *tmp_data = atmp.fortran_vec (); - - float anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - - char job = 'L'; - F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, - tmp_data, nr, info + Array z (dim_vector (3 * nc, 1)); + float *pz = z.fortran_vec (); + Array iz (dim_vector (nc, 1)); + octave_idx_type *piz = iz.fortran_vec (); + + F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), + nr, tmp_data, nr, anorm, + rcon, pz, piz, info F77_CHAR_ARG_LEN (1))); if (info != 0) + rcon = 0.0; + + for (octave_idx_type i = 0; i < nc; i++) + retval *= atmp (i,i); + + retval = retval.square (); + } + } + else if (typ != MatrixType::Full) + (*current_liboctave_error_handler) ("det: invalid dense matrix type"); + + if (typ == MatrixType::Full) + { + Array ipvt (dim_vector (nr, 1)); + octave_idx_type *pipvt = ipvt.fortran_vec (); + + FloatMatrix atmp = *this; + float *tmp_data = atmp.fortran_vec (); + + info = 0; + + // Calculate the norm of the matrix, for later use. + float anorm = 0; + if (calc_cond) anorm = xnorm (*this, 1); + + F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, info)); + + // Throw-away extra info LAPACK gives so as to not change output. + rcon = 0.0; + if (info != 0) + { + info = -1; + retval = FloatDET (); + } + else + { + if (calc_cond) { - rcon = 0.0; - mattype.mark_as_unsymmetric (); - typ = MatrixType::Full; - } - else - { - Array z (dim_vector (3 * nc, 1)); + // Now calc the condition number for non-singular matrix. + char job = '1'; + Array z (dim_vector (4 * nc, 1)); float *pz = z.fortran_vec (); Array iz (dim_vector (nc, 1)); octave_idx_type *piz = iz.fortran_vec (); - F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), - nr, tmp_data, nr, anorm, + F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1), + nc, tmp_data, nr, anorm, rcon, pz, piz, info F77_CHAR_ARG_LEN (1))); - - if (info != 0) - rcon = 0.0; - - for (octave_idx_type i = 0; i < nc; i++) - retval *= atmp (i,i); - - retval = retval.square (); } - } - else if (typ != MatrixType::Full) - (*current_liboctave_error_handler) ("det: invalid dense matrix type"); - - if (typ == MatrixType::Full) - { - Array ipvt (dim_vector (nr, 1)); - octave_idx_type *pipvt = ipvt.fortran_vec (); - - FloatMatrix atmp = *this; - float *tmp_data = atmp.fortran_vec (); - - info = 0; - - // Calculate the norm of the matrix, for later use. - float anorm = 0; - if (calc_cond) anorm = xnorm (*this, 1); - - F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, info)); - - // Throw-away extra info LAPACK gives so as to not change output. - rcon = 0.0; + if (info != 0) { info = -1; @@ -1364,33 +1341,10 @@ } else { - if (calc_cond) + for (octave_idx_type i = 0; i < nc; i++) { - // Now calc the condition number for non-singular matrix. - char job = '1'; - Array z (dim_vector (4 * nc, 1)); - float *pz = z.fortran_vec (); - Array iz (dim_vector (nc, 1)); - octave_idx_type *piz = iz.fortran_vec (); - - F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1), - nc, tmp_data, nr, anorm, - rcon, pz, piz, info - F77_CHAR_ARG_LEN (1))); - } - - if (info != 0) - { - info = -1; - retval = FloatDET (); - } - else - { - for (octave_idx_type i = 0; i < nc; i++) - { - float c = atmp(i,i); - retval *= (ipvt(i) != (i+1)) ? -c : c; - } + float c = atmp(i,i); + retval *= (ipvt(i) != (i+1)) ? -c : c; } } } @@ -1415,7 +1369,8 @@ if (nr != nc) (*current_liboctave_error_handler) ("matrix must be square"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) rcon = octave_Inf; else { @@ -1450,7 +1405,7 @@ if (info != 0) rcon = 0.0; } - else if (typ == MatrixType::Permuted_Upper) + else if (typ == MatrixType::Permuted_Upper) (*current_liboctave_error_handler) ("permuted triangular matrix not implemented"); else if (typ == MatrixType::Lower) @@ -1583,7 +1538,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = FloatMatrix (nc, b.cols (), 0.0); else { @@ -1596,10 +1552,8 @@ info = 0; if (typ == MatrixType::Permuted_Upper) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); else { const float *tmp_data = fortran_vec (); @@ -1679,7 +1633,8 @@ if (nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || nc == 0 || b.cols () == 0) + + if (nr == 0 || nc == 0 || b.cols () == 0) retval = FloatMatrix (nc, b.cols (), 0.0); else { @@ -1692,10 +1647,8 @@ info = 0; if (typ == MatrixType::Permuted_Lower) - { - (*current_liboctave_error_handler) - ("permuted triangular matrix not implemented"); - } + (*current_liboctave_error_handler) + ("permuted triangular matrix not implemented"); else { const float *tmp_data = fortran_vec (); @@ -1774,7 +1727,8 @@ if (nr != nc || nr != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (nr == 0 || b.cols () == 0) + + if (nr == 0 || b.cols () == 0) retval = FloatMatrix (nc, b.cols (), 0.0); else { @@ -1987,10 +1941,7 @@ else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) retval = fsolve (mattype, b, info, rcon, sing_handler, true); else if (typ != MatrixType::Rectangular) - { - (*current_liboctave_error_handler) ("unknown matrix type"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) ("unknown matrix type"); // Rectangular or one of the above solvers flags a singular matrix if (singular_fallback && mattype.type () == MatrixType::Rectangular) @@ -2299,7 +2250,8 @@ if (m != b.rows ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0 || b.cols () == 0) + + if (m == 0 || n == 0 || b.cols () == 0) retval = FloatMatrix (n, b.cols (), 0.0); else { @@ -2494,7 +2446,8 @@ if (m != b.numel ()) (*current_liboctave_error_handler) ("matrix dimension mismatch solution of linear equations"); - else if (m == 0 || n == 0) + + if (m == 0 || n == 0) retval = FloatColumnVector (n, 0.0); else { @@ -2728,8 +2681,7 @@ if (nr == 1 || nc == 1) retval = FloatDiagMatrix (*this, m, n); else - (*current_liboctave_error_handler) - ("diag: expecting vector argument"); + (*current_liboctave_error_handler) ("diag: expecting vector argument"); return retval; } @@ -3235,11 +3187,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg min requires same size arguments"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg min requires same size arguments"); EMPTY_RETURN_CHECK (FloatMatrix); @@ -3302,11 +3251,8 @@ octave_idx_type nc = a.columns (); if (nr != b.rows () || nc != b.columns ()) - { - (*current_liboctave_error_handler) - ("two-arg max requires same size arguments"); - return FloatMatrix (); - } + (*current_liboctave_error_handler) + ("two-arg max requires same size arguments"); EMPTY_RETURN_CHECK (FloatMatrix); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fNDArray.cc --- a/liboctave/array/fNDArray.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fNDArray.cc Sat Jan 23 13:52:03 2016 -0800 @@ -736,21 +736,16 @@ float d = elem (i); if (xisnan (d)) - { - (*current_liboctave_error_handler) - ("invalid conversion from NaN to character"); - return retval; - } - else - { - octave_idx_type ival = NINTbig (d); + (*current_liboctave_error_handler) + ("invalid conversion from NaN to character"); + + octave_idx_type ival = NINTbig (d); - if (ival < 0 || ival > std::numeric_limits::max ()) - // FIXME: is there something better to do? Should we warn the user? - ival = 0; + if (ival < 0 || ival > std::numeric_limits::max ()) + // FIXME: is there something better to do? Should we warn the user? + ival = 0; - retval.elem (i) = static_cast(ival); - } + retval.elem (i) = static_cast(ival); } if (rb.is_empty ()) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/fRowVector.cc --- a/liboctave/array/fRowVector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/fRowVector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -76,10 +76,7 @@ octave_idx_type a_len = a.numel (); if (c < 0 || c + a_len > numel ()) - { - (*current_liboctave_error_handler) ("range error for insert"); - return *this; - } + (*current_liboctave_error_handler) ("range error for insert"); if (a_len > 0) { @@ -114,10 +111,7 @@ octave_idx_type len = numel (); if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) - { - (*current_liboctave_error_handler) ("range error for fill"); - return *this; - } + (*current_liboctave_error_handler) ("range error for fill"); if (c1 > c2) { std::swap (c1, c2); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/array/idx-vector.cc --- a/liboctave/array/idx-vector.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/array/idx-vector.cc Sat Jan 23 13:52:03 2016 -0800 @@ -59,8 +59,6 @@ { (*current_liboctave_error_handler) ("internal error: as_array not allowed for this index class"); - - return Array (); } @@ -70,6 +68,7 @@ { (*current_liboctave_error_handler) ("internal error: invalid character converted to idx_vector; must be ':'"); + // FIXME: this is unreachable now. err = true; } } @@ -88,9 +87,6 @@ { (*current_liboctave_error_handler) ("internal error: idx_colon_rep::sort_idx"); - - count++; - return this; } std::ostream& @@ -1266,6 +1262,7 @@ { (*current_liboctave_error_handler) ("invalid matrix index = %d", extent (z_len)); + // FIXME: Should we call this before calling error_handler? rep->err = true; chkerr (); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxAEPBAL.cc --- a/liboctave/numeric/CmplxAEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxAEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -58,10 +58,7 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); - return; - } + (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); octave_idx_type info; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxCHOL.cc --- a/liboctave/numeric/CmplxCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -92,11 +92,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("ComplexCHOL requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("ComplexCHOL requires square matrix"); octave_idx_type n = a_nc; octave_idx_type info; @@ -165,41 +161,39 @@ octave_idx_type r_nr = r.rows (); octave_idx_type r_nc = r.cols (); - if (r_nr == r_nc) - { - octave_idx_type n = r_nc; - octave_idx_type info; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - ComplexMatrix tmp = r; + octave_idx_type n = r_nc; + octave_idx_type info; + + ComplexMatrix tmp = r; - if (is_upper) - F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - tmp.fortran_vec (), n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - tmp.fortran_vec (), n, info - F77_CHAR_ARG_LEN (1))); + if (is_upper) + F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + tmp.fortran_vec (), n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + tmp.fortran_vec (), n, info + F77_CHAR_ARG_LEN (1))); - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } - retval = tmp; - } - else - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + retval = tmp; return retval; } @@ -227,17 +221,15 @@ { octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - ComplexColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (double, rw, n); + ComplexColumnVector utmp = u; - F77_XFCN (zch1up, ZCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), rw)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (double, rw, n); + + F77_XFCN (zch1up, ZCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), rw)); } octave_idx_type @@ -247,17 +239,15 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - ComplexColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (double, rw, n); + ComplexColumnVector utmp = u; - F77_XFCN (zch1dn, ZCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), rw, info)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (double, rw, n); + + F77_XFCN (zch1dn, ZCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), rw, info)); return info; } @@ -271,19 +261,17 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); - else - { - ComplexColumnVector utmp = u; + + ComplexColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, rw, n); - - chol_mat.resize (n+1, n+1); + OCTAVE_LOCAL_BUFFER (double, rw, n); - F77_XFCN (zchinx, ZCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, utmp.fortran_vec (), rw, info)); - } + chol_mat.resize (n+1, n+1); + + F77_XFCN (zchinx, ZCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, utmp.fortran_vec (), rw, info)); return info; } @@ -295,15 +283,13 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (double, rw, n); + + OCTAVE_LOCAL_BUFFER (double, rw, n); - F77_XFCN (zchdex, ZCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, rw)); + F77_XFCN (zchdex, ZCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, rw)); - chol_mat.resize (n-1, n-1); - } + chol_mat.resize (n-1, n-1); } void @@ -313,14 +299,12 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (Complex, w, n); - OCTAVE_LOCAL_BUFFER (double, rw, n); - F77_XFCN (zchshx, ZCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - i + 1, j + 1, w, rw)); - } + OCTAVE_LOCAL_BUFFER (Complex, w, n); + OCTAVE_LOCAL_BUFFER (double, rw, n); + + F77_XFCN (zchshx, ZCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + i + 1, j + 1, w, rw)); } #else @@ -332,13 +316,11 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - init (chol_mat.hermitian () * chol_mat - + ComplexMatrix (u) * ComplexMatrix (u).hermitian (), true, false); - } - else + if (u.numel () != n) (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + init (chol_mat.hermitian () * chol_mat + + ComplexMatrix (u) * ComplexMatrix (u).hermitian (), true, false); } static bool @@ -358,20 +340,18 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + if (singular (chol_mat)) + info = 2; + else { - if (singular (chol_mat)) - info = 2; - else - { - info = init (chol_mat.hermitian () * chol_mat - - ComplexMatrix (u) * ComplexMatrix (u).hermitian (), - true, false); - if (info) info = 1; - } + info = init (chol_mat.hermitian () * chol_mat + - ComplexMatrix (u) * ComplexMatrix (u).hermitian (), + true, false); + if (info) info = 1; } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); return info; } @@ -387,31 +367,29 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); + + if (singular (chol_mat)) + info = 2; + else if (u(j).imag () != 0.0) + info = 3; else { - if (singular (chol_mat)) - info = 2; - else if (u(j).imag () != 0.0) - info = 3; - else - { - ComplexMatrix a = chol_mat.hermitian () * chol_mat; - ComplexMatrix a1 (n+1, n+1); - for (octave_idx_type k = 0; k < n+1; k++) - for (octave_idx_type l = 0; l < n+1; l++) - { - if (l == j) - a1(k, l) = u(k); - else if (k == j) - a1(k, l) = std::conj (u(l)); - else - a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); - } - info = init (a1, true, false); - if (info) info = 1; - } + ComplexMatrix a = chol_mat.hermitian () * chol_mat; + ComplexMatrix a1 (n+1, n+1); + for (octave_idx_type k = 0; k < n+1; k++) + for (octave_idx_type l = 0; l < n+1; l++) + { + if (l == j) + a1(k, l) = u(k); + else if (k == j) + a1(k, l) = std::conj (u(l)); + else + a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); + } + info = init (a1, true, false); + if (info) info = 1; } return info; @@ -426,13 +404,11 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - ComplexMatrix a = chol_mat.hermitian () * chol_mat; - a.delete_elements (1, idx_vector (j)); - a.delete_elements (0, idx_vector (j)); - init (a, true, false); - } + + ComplexMatrix a = chol_mat.hermitian () * chol_mat; + a.delete_elements (1, idx_vector (j)); + a.delete_elements (0, idx_vector (j)); + init (a, true, false); } void @@ -444,24 +420,22 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else + + ComplexMatrix a = chol_mat.hermitian () * chol_mat; + Array p (dim_vector (n, 1)); + for (octave_idx_type k = 0; k < n; k++) p(k) = k; + if (i < j) { - ComplexMatrix a = chol_mat.hermitian () * chol_mat; - Array p (dim_vector (n, 1)); - for (octave_idx_type k = 0; k < n; k++) p(k) = k; - if (i < j) - { - for (octave_idx_type k = i; k < j; k++) p(k) = k+1; - p(j) = i; - } - else if (j < i) - { - p(j) = i; - for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; - } + for (octave_idx_type k = i; k < j; k++) p(k) = k+1; + p(j) = i; + } + else if (j < i) + { + p(j) = i; + for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; + } - init (a.index (idx_vector (p), idx_vector (p)), true, false); - } + init (a.index (idx_vector (p), idx_vector (p)), true, false); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxGEPBAL.cc --- a/liboctave/numeric/CmplxGEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxGEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -65,11 +65,8 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) - ("ComplexGEPBALANCE requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) + ("ComplexGEPBALANCE requires square matrix"); if (a.dims () != b.dims ()) err_nonconformant ("ComplexGEPBALANCE", n, n, b.rows(), b.cols()); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxHESS.cc --- a/liboctave/numeric/CmplxHESS.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxHESS.cc Sat Jan 23 13:52:03 2016 -0800 @@ -67,11 +67,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("ComplexHESS requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("ComplexHESS requires square matrix"); char job = 'N'; char side = 'R'; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxLU.cc --- a/liboctave/numeric/CmplxLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -98,15 +98,13 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - ComplexColumnVector utmp = u; - ComplexColumnVector vtmp = v; - F77_XFCN (zlu1up, ZLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + ComplexColumnVector utmp = u; + ComplexColumnVector vtmp = v; + F77_XFCN (zlu1up, ZLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } void ComplexLU::update (const ComplexMatrix& u, const ComplexMatrix& v) @@ -121,19 +119,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ComplexColumnVector utmp = u.column (i); - ComplexColumnVector vtmp = v.column (i); - F77_XFCN (zlu1up, ZLU1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } + ComplexColumnVector utmp = u.column (i); + ComplexColumnVector vtmp = v.column (i); + F77_XFCN (zlu1up, ZLU1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); } void ComplexLU::update_piv (const ComplexColumnVector& u, @@ -149,20 +145,18 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - ComplexColumnVector utmp = u; - ComplexColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (Complex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - F77_XFCN (zlup1up, ZLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + ComplexColumnVector utmp = u; + ComplexColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (Complex, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + F77_XFCN (zlup1up, ZLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } void ComplexLU::update_piv (const ComplexMatrix& u, const ComplexMatrix& v) @@ -177,23 +171,21 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (Complex, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (Complex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ComplexColumnVector utmp = u.column (i); - ComplexColumnVector vtmp = v.column (i); - F77_XFCN (zlup1up, ZLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + ComplexColumnVector utmp = u.column (i); + ComplexColumnVector vtmp = v.column (i); + F77_XFCN (zlup1up, ZLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #else diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxQR.cc --- a/liboctave/numeric/CmplxQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -212,19 +212,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.numel () == m && v.numel () == n) - { - ComplexColumnVector utmp = u; - ComplexColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (Complex, w, k); - OCTAVE_LOCAL_BUFFER (double, rw, k); - F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w, rw)); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + ComplexColumnVector utmp = u; + ComplexColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (Complex, w, k); + OCTAVE_LOCAL_BUFFER (double, rw, k); + F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w, rw)); } void @@ -234,22 +232,20 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (Complex, w, k); + OCTAVE_LOCAL_BUFFER (double, rw, k); + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (Complex, w, k); - OCTAVE_LOCAL_BUFFER (double, rw, k); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ComplexColumnVector utmp = u.column (i); - ComplexColumnVector vtmp = v.column (i); - F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w, rw)); - } + ComplexColumnVector utmp = u.column (i); + ComplexColumnVector vtmp = v.column (i); + F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w, rw)); } - else - (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); } void @@ -261,26 +257,24 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); + + if (k < m) + { + q.resize (m, k+1); + r.resize (k+1, n+1); + } else { - if (k < m) - { - q.resize (m, k+1); - r.resize (k+1, n+1); - } - else - { - r.resize (k, n+1); - } + r.resize (k, n+1); + } - ComplexColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, rw, k); - F77_XFCN (zqrinc, ZQRINC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - utmp.data (), rw)); - } + ComplexColumnVector utmp = u; + OCTAVE_LOCAL_BUFFER (double, rw, k); + F77_XFCN (zqrinc, ZQRINC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + utmp.data (), rw)); } void @@ -299,11 +293,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { octave_idx_type kmax = std::min (k + nj, m); if (k < m) @@ -338,21 +333,19 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); + + OCTAVE_LOCAL_BUFFER (double, rw, k); + F77_XFCN (zqrdec, ZQRDEC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, rw)); + + if (k < m) + { + q.resize (m, k-1); + r.resize (k-1, n-1); + } else { - OCTAVE_LOCAL_BUFFER (double, rw, k); - F77_XFCN (zqrdec, ZQRDEC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, rw)); - - if (k < m) - { - q.resize (m, k-1); - r.resize (k-1, n-1); - } - else - { - r.resize (k, n-1); - } + r.resize (k, n-1); } } @@ -372,9 +365,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { OCTAVE_LOCAL_BUFFER (double, rw, k); for (volatile octave_idx_type i = 0; i < js.numel (); i++) @@ -407,19 +401,17 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - q.resize (m + 1, m + 1); - r.resize (m + 1, n); - ComplexRowVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, rw, k); - F77_XFCN (zqrinr, ZQRINR, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - j + 1, utmp.fortran_vec (), rw)); - } + q.resize (m + 1, m + 1); + r.resize (m + 1, n); + ComplexRowVector utmp = u; + OCTAVE_LOCAL_BUFFER (double, rw, k); + F77_XFCN (zqrinr, ZQRINR, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + j + 1, utmp.fortran_vec (), rw)); + } void @@ -430,19 +422,17 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (Complex, w, m); - OCTAVE_LOCAL_BUFFER (double, rw, m); - F77_XFCN (zqrder, ZQRDER, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - w, rw)); - q.resize (m - 1, m - 1); - r.resize (m - 1, n); - } + OCTAVE_LOCAL_BUFFER (Complex, w, m); + OCTAVE_LOCAL_BUFFER (double, rw, m); + F77_XFCN (zqrder, ZQRDER, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + w, rw)); + + q.resize (m - 1, m - 1); + r.resize (m - 1, n); } void @@ -454,15 +444,13 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (Complex, w, k); - OCTAVE_LOCAL_BUFFER (double, rw, k); - F77_XFCN (zqrshc, ZQRSHC, (m, n, k, - q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - i + 1, j + 1, w, rw)); - } + + OCTAVE_LOCAL_BUFFER (Complex, w, k); + OCTAVE_LOCAL_BUFFER (double, rw, k); + F77_XFCN (zqrshc, ZQRSHC, (m, n, k, + q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + i + 1, j + 1, w, rw)); } #else @@ -477,13 +465,11 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.numel () == m && v.numel () == n) - { - init (q*r + ComplexMatrix (u) * ComplexMatrix (v).hermitian (), - get_type ()); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + ComplexMatrix (u) * ComplexMatrix (v).hermitian (), + get_type ()); } void @@ -494,12 +480,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) - { - init (q*r + u * v.hermitian (), get_type ()); - } - else + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + u * v.hermitian (), get_type ()); } static @@ -575,12 +559,10 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_col (q*r, j, u), get_type ()); - } + + init (::insert_col (q*r, j, u), get_type ()); } void @@ -600,11 +582,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { ComplexMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -622,10 +605,8 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_col (q*r, j), get_type ()); - } + + init (::delete_col (q*r, j), get_type ()); } void @@ -644,9 +625,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { ComplexMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -665,12 +647,10 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_row (q*r, j, u), get_type ()); - } + + init (::insert_row (q*r, j, u), get_type ()); } void @@ -682,12 +662,10 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_row (q*r, j), get_type ()); - } + + init (::delete_row (q*r, j), get_type ()); } void @@ -699,10 +677,8 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - init (::shift_cols (q*r, i, j), get_type ()); - } + + init (::shift_cols (q*r, i, j), get_type ()); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxSCHUR.cc --- a/liboctave/numeric/CmplxSCHUR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxSCHUR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -71,12 +71,9 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("ComplexSCHUR requires square matrix"); - return -1; - } - else if (a_nr == 0) + (*current_liboctave_error_handler) ("ComplexSCHUR requires square matrix"); + + if (a_nr == 0) { schur_mat.clear (); unitary_mat.clear (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/CmplxSVD.cc --- a/liboctave/numeric/CmplxSVD.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/CmplxSVD.cc Sat Jan 23 13:52:03 2016 -0800 @@ -57,26 +57,20 @@ ComplexSVD::left_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("ComplexSVD: U not computed because type == SVD::sigma_only"); - return ComplexMatrix (); - } - else - return left_sm; + (*current_liboctave_error_handler) + ("ComplexSVD: U not computed because type == SVD::sigma_only"); + + return left_sm; } ComplexMatrix ComplexSVD::right_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("ComplexSVD: V not computed because type == SVD::sigma_only"); - return ComplexMatrix (); - } - else - return right_sm; + (*current_liboctave_error_handler) + ("ComplexSVD: V not computed because type == SVD::sigma_only"); + + return right_sm; } octave_idx_type diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/DASPK.cc --- a/liboctave/numeric/DASPK.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/DASPK.cc Sat Jan 23 13:52:03 2016 -0800 @@ -198,6 +198,7 @@ if (res.numel () != x.numel ()) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: inconsistent sizes for state and residual vectors"); @@ -207,6 +208,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: no user supplied RHS subroutine!"); @@ -253,6 +255,8 @@ } else { + + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: inconsistent sizes for tolerance arrays"); @@ -288,6 +292,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid value for maximum order"); integration_error = true; @@ -309,6 +314,7 @@ octave_idx_type val = ict(i); if (val < -2 || val > 2) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid value for inequality constraint type"); integration_error = true; @@ -319,6 +325,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: inequality constraint types size mismatch"); integration_error = true; @@ -333,6 +340,7 @@ break; default: + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid value for enforce inequality constraints option"); integration_error = true; @@ -362,6 +370,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: algebraic variables size mismatch"); integration_error = true; @@ -370,6 +379,7 @@ } else if (ccic != 2) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid value for compute consistent initial condition option"); integration_error = true; @@ -418,6 +428,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid initial condition heuristics option"); integration_error = true; @@ -437,6 +448,7 @@ break; default: + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("daspk: invalid value for print initial condition info option"); integration_error = true; @@ -518,8 +530,7 @@ default: integration_error = true; (*current_liboctave_error_handler) - ("unrecognized value of istate (= %d) returned from ddaspk", - istate); + ("unrecognized value of istate (= %d) returned from ddaspk", istate); break; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/EIG.cc --- a/liboctave/numeric/EIG.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/EIG.cc Sat Jan 23 13:52:03 2016 -0800 @@ -140,11 +140,8 @@ EIG::init (const Matrix& a, bool calc_ev) { if (a.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); if (a.is_symmetric ()) return symmetric_init (a, calc_ev); @@ -152,10 +149,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -185,67 +179,56 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - double *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("dgeev workspace query failed"); - F77_XFCN (dgeev, DGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, tmp_data, n, pwr, pwi, dummy, - idummy, pvr, n, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + double *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in dgeev"); - return info; - } + F77_XFCN (dgeev, DGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, tmp_data, n, pwr, pwi, dummy, + idummy, pvr, n, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("dgeev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in dgeev"); - lambda.resize (n); - octave_idx_type nvr = calc_ev ? n : 0; - v.resize (nvr, nvr); + if (info > 0) + (*current_liboctave_error_handler) ("dgeev failed to converge"); + + lambda.resize (n); + octave_idx_type nvr = calc_ev ? n : 0; + v.resize (nvr, nvr); - for (octave_idx_type j = 0; j < n; j++) + for (octave_idx_type j = 0; j < n; j++) + { + if (wi.elem (j) == 0.0) { - if (wi.elem (j) == 0.0) - { - lambda.elem (j) = Complex (wr.elem (j)); - for (octave_idx_type i = 0; i < nvr; i++) - v.elem (i, j) = vr.elem (i, j); - } - else + lambda.elem (j) = Complex (wr.elem (j)); + for (octave_idx_type i = 0; i < nvr; i++) + v.elem (i, j) = vr.elem (i, j); + } + else + { + if (j+1 >= n) + (*current_liboctave_error_handler) ("EIG: internal error"); + + lambda.elem (j) = Complex (wr.elem (j), wi.elem (j)); + lambda.elem (j+1) = Complex (wr.elem (j+1), wi.elem (j+1)); + + for (octave_idx_type i = 0; i < nvr; i++) { - if (j+1 >= n) - { - (*current_liboctave_error_handler) ("EIG: internal error"); - return -1; - } - - lambda.elem (j) = Complex (wr.elem (j), wi.elem (j)); - lambda.elem (j+1) = Complex (wr.elem (j+1), wi.elem (j+1)); - - for (octave_idx_type i = 0; i < nvr; i++) - { - double real_part = vr.elem (i, j); - double imag_part = vr.elem (i, j+1); - v.elem (i, j) = Complex (real_part, imag_part); - v.elem (i, j+1) = Complex (real_part, -imag_part); - } - j++; + double real_part = vr.elem (i, j); + double imag_part = vr.elem (i, j+1); + v.elem (i, j) = Complex (real_part, imag_part); + v.elem (i, j+1) = Complex (real_part, -imag_part); } + j++; } } - else - (*current_liboctave_error_handler) ("dgeev workspace query failed"); return info; } @@ -256,10 +239,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -278,35 +258,27 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - double *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("dsyev workspace query failed"); - F77_XFCN (dsyev, DSYEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, tmp_data, n, pwr, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + double *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in dsyev"); - return info; - } + F77_XFCN (dsyev, DSYEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, tmp_data, n, pwr, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("dsyev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in dsyev"); - lambda = ComplexColumnVector (wr); - v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("dsyev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("dsyev failed to converge"); + + lambda = ComplexColumnVector (wr); + v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); return info; } @@ -315,11 +287,8 @@ EIG::init (const ComplexMatrix& a, bool calc_ev) { if (a.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); if (a.is_hermitian ()) return hermitian_init (a, calc_ev); @@ -327,10 +296,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -361,36 +327,28 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - Complex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("zgeev workspace query failed"); - F77_XFCN (zgeev, ZGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, tmp_data, n, pw, dummy, idummy, - pv, n, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + Complex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in zgeev"); - return info; - } + F77_XFCN (zgeev, ZGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, tmp_data, n, pw, dummy, idummy, + pv, n, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("zgeev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in zgeev"); - lambda = w; - v = vtmp; - } - else - (*current_liboctave_error_handler) ("zgeev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("zgeev failed to converge"); + + lambda = w; + v = vtmp; return info; } @@ -401,10 +359,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -428,35 +383,27 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - Complex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("zheev workspace query failed"); - F77_XFCN (zheev, ZHEEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, tmp_data, n, pwr, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + Complex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in zheev"); - return info; - } + F77_XFCN (zheev, ZHEEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, tmp_data, n, pwr, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("zheev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in zheev"); - lambda = ComplexColumnVector (wr); - v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("zheev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("zheev failed to converge"); + + lambda = ComplexColumnVector (wr); + v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); return info; } @@ -465,26 +412,17 @@ EIG::init (const Matrix& a, const Matrix& b, bool calc_ev) { if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); octave_idx_type n = a.rows (); octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -534,71 +472,60 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - double *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("dggev workspace query failed"); - F77_XFCN (dggev, DGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, atmp_data, n, btmp_data, n, - par, pai, pbeta, - dummy, idummy, pvr, n, - pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + double *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in dggev"); - return info; - } + F77_XFCN (dggev, DGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, atmp_data, n, btmp_data, n, + par, pai, pbeta, + dummy, idummy, pvr, n, + pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("dggev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in dggev"); - lambda.resize (n); - octave_idx_type nvr = calc_ev ? n : 0; - v.resize (nvr, nvr); + if (info > 0) + (*current_liboctave_error_handler) ("dggev failed to converge"); + + lambda.resize (n); + octave_idx_type nvr = calc_ev ? n : 0; + v.resize (nvr, nvr); - for (octave_idx_type j = 0; j < n; j++) + for (octave_idx_type j = 0; j < n; j++) + { + if (ai.elem (j) == 0.0) + { + lambda.elem (j) = Complex (ar.elem (j) / beta.elem (j)); + for (octave_idx_type i = 0; i < nvr; i++) + v.elem (i, j) = vr.elem (i, j); + } + else { - if (ai.elem (j) == 0.0) - { - lambda.elem (j) = Complex (ar.elem (j) / beta.elem (j)); - for (octave_idx_type i = 0; i < nvr; i++) - v.elem (i, j) = vr.elem (i, j); - } - else + if (j+1 >= n) + (*current_liboctave_error_handler) ("EIG: internal error"); + + lambda.elem (j) = Complex (ar.elem (j) / beta.elem (j), + ai.elem (j) / beta.elem (j)); + lambda.elem (j+1) = Complex (ar.elem (j+1) / beta.elem (j+1), + ai.elem (j+1) / beta.elem (j+1)); + + for (octave_idx_type i = 0; i < nvr; i++) { - if (j+1 >= n) - { - (*current_liboctave_error_handler) ("EIG: internal error"); - return -1; - } - - lambda.elem (j) = Complex (ar.elem (j) / beta.elem (j), - ai.elem (j) / beta.elem (j)); - lambda.elem (j+1) = Complex (ar.elem (j+1) / beta.elem (j+1), - ai.elem (j+1) / beta.elem (j+1)); - - for (octave_idx_type i = 0; i < nvr; i++) - { - double real_part = vr.elem (i, j); - double imag_part = vr.elem (i, j+1); - v.elem (i, j) = Complex (real_part, imag_part); - v.elem (i, j+1) = Complex (real_part, -imag_part); - } - j++; + double real_part = vr.elem (i, j); + double imag_part = vr.elem (i, j+1); + v.elem (i, j) = Complex (real_part, imag_part); + v.elem (i, j+1) = Complex (real_part, -imag_part); } + j++; } } - else - (*current_liboctave_error_handler) ("dggev workspace query failed"); return info; } @@ -610,16 +537,10 @@ octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -643,37 +564,29 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - double *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("dsygv workspace query failed"); - F77_XFCN (dsygv, DSYGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, atmp_data, n, - btmp_data, n, - pwr, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + double *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in dsygv"); - return info; - } + F77_XFCN (dsygv, DSYGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, atmp_data, n, + btmp_data, n, + pwr, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("dsygv failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in dsygv"); - lambda = ComplexColumnVector (wr); - v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("dsygv workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("dsygv failed to converge"); + + lambda = ComplexColumnVector (wr); + v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); return info; } @@ -682,26 +595,17 @@ EIG::init (const ComplexMatrix& a, const ComplexMatrix& b, bool calc_ev) { if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); octave_idx_type n = a.rows (); octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -751,41 +655,33 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - Complex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("zggev workspace query failed"); - F77_XFCN (zggev, ZGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, atmp_data, n, btmp_data, n, - palpha, pbeta, dummy, idummy, - pv, n, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + Complex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in zggev"); - return info; - } + F77_XFCN (zggev, ZGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, atmp_data, n, btmp_data, n, + palpha, pbeta, dummy, idummy, + pv, n, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("zggev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in zggev"); - lambda.resize (n); + if (info > 0) + (*current_liboctave_error_handler) ("zggev failed to converge"); - for (octave_idx_type j = 0; j < n; j++) - lambda.elem (j) = alpha.elem (j) / beta.elem (j); + lambda.resize (n); - v = vtmp; - } - else - (*current_liboctave_error_handler) ("zggev workspace query failed"); + for (octave_idx_type j = 0; j < n; j++) + lambda.elem (j) = alpha.elem (j) / beta.elem (j); + + v = vtmp; return info; } @@ -798,16 +694,10 @@ octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -836,37 +726,29 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - Complex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("zhegv workspace query failed"); - F77_XFCN (zhegv, ZHEGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, atmp_data, n, - btmp_data, n, - pwr, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + Complex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in zhegv"); - return info; - } + F77_XFCN (zhegv, ZHEGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, atmp_data, n, + btmp_data, n, + pwr, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("zhegv failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in zhegv"); - lambda = ComplexColumnVector (wr); - v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("zhegv workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("zhegv failed to converge"); + + lambda = ComplexColumnVector (wr); + v = calc_ev ? ComplexMatrix (atmp) : ComplexMatrix (); return info; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/LSODE.cc --- a/liboctave/numeric/LSODE.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/LSODE.cc Sat Jan 23 13:52:03 2016 -0800 @@ -175,6 +175,7 @@ } else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("lsode: invalid value for maximum order"); integration_error = true; @@ -210,6 +211,7 @@ if (x.numel () != xdot.numel ()) { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("lsode: inconsistent sizes for state and derivative vectors"); @@ -232,6 +234,7 @@ itol = 2; else { + // FIXME: Should this be a warning? (*current_liboctave_error_handler) ("lsode: inconsistent sizes for state and absolute tolerance vectors"); @@ -304,8 +307,7 @@ default: integration_error = true; (*current_liboctave_error_handler) - ("unrecognized value of istate (= %d) returned from lsode", - istate); + ("unrecognized value of istate (= %d) returned from lsode", istate); break; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/Quad.cc --- a/liboctave/numeric/Quad.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/Quad.cc Sat Jan 23 13:52:03 2016 -0800 @@ -156,7 +156,6 @@ DefQuad::do_integrate (octave_idx_type&, octave_idx_type&, float&) { (*current_liboctave_error_handler) ("incorrect integration function called"); - return 0.0; } double @@ -210,14 +209,12 @@ IndefQuad::do_integrate (octave_idx_type&, octave_idx_type&, float&) { (*current_liboctave_error_handler) ("incorrect integration function called"); - return 0.0; } double FloatDefQuad::do_integrate (octave_idx_type&, octave_idx_type&, double&) { (*current_liboctave_error_handler) ("incorrect integration function called"); - return 0.0; } float @@ -254,7 +251,6 @@ FloatIndefQuad::do_integrate (octave_idx_type&, octave_idx_type&, double&) { (*current_liboctave_error_handler) ("incorrect integration function called"); - return 0.0; } float diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparseCmplxCHOL.cc --- a/liboctave/numeric/SparseCmplxCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparseCmplxCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -39,32 +39,29 @@ { octave_idx_type r_nr = r.rows (); octave_idx_type r_nc = r.cols (); - SparseComplexMatrix retval; - if (r_nr == r_nc) - { - MatrixType mattype (r); - int typ = mattype.type (false); - double rcond; - octave_idx_type info; - SparseComplexMatrix rinv; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("U must be a square matrix"); - if (typ == MatrixType::Upper) - { - rinv = r.inverse (mattype, info, rcond, true, false); - retval = rinv.transpose () * rinv; - } - else if (typ == MatrixType::Lower) - { - rinv = r.transpose ().inverse (mattype, info, rcond, true, false); - retval = rinv.transpose () * rinv; - } - else - (*current_liboctave_error_handler) - ("U must be a triangular matrix"); + SparseComplexMatrix retval; + MatrixType mattype (r); + int typ = mattype.type (false); + double rcond; + octave_idx_type info; + SparseComplexMatrix rinv; + + if (typ == MatrixType::Upper) + { + rinv = r.inverse (mattype, info, rcond, true, false); + retval = rinv.transpose () * rinv; + } + else if (typ == MatrixType::Lower) + { + rinv = r.transpose ().inverse (mattype, info, rcond, true, false); + retval = rinv.transpose () * rinv; } else - (*current_liboctave_error_handler) ("U must be a square matrix"); + (*current_liboctave_error_handler) ("U must be a triangular matrix"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparseCmplxLU.cc --- a/liboctave/numeric/SparseCmplxLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparseCmplxLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -109,13 +109,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU symbolic factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_symbolic) (&Symbolic); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU symbolic factorization failed"); } else { @@ -132,13 +132,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU numeric factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU numeric factorization failed"); } else { @@ -150,13 +150,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); } else { @@ -209,10 +209,10 @@ if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + (*current_liboctave_error_handler) ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); - - UMFPACK_ZNAME (report_status) (control, status); } else { @@ -256,229 +256,227 @@ if (milu) (*current_liboctave_error_handler) ("Modified incomplete LU not implemented"); + + octave_idx_type nr = a.rows (); + octave_idx_type nc = a.cols (); + + // Setup the control parameters + Matrix Control (UMFPACK_CONTROL, 1); + double *control = Control.fortran_vec (); + UMFPACK_ZNAME (defaults) (control); + + double tmp = octave_sparse_params::get_key ("spumoni"); + if (! xisnan (tmp)) + Control (UMFPACK_PRL) = tmp; + if (piv_thres.numel () == 2) + { + tmp = (piv_thres (0) > 1. ? 1. : piv_thres (0)); + if (! xisnan (tmp)) + Control (UMFPACK_PIVOT_TOLERANCE) = tmp; + tmp = (piv_thres (1) > 1. ? 1. : piv_thres (1)); + if (! xisnan (tmp)) + Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + } + else + { + tmp = octave_sparse_params::get_key ("piv_tol"); + if (! xisnan (tmp)) + Control (UMFPACK_PIVOT_TOLERANCE) = tmp; + + tmp = octave_sparse_params::get_key ("sym_tol"); + if (! xisnan (tmp)) + Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + } + + if (droptol >= 0.) + Control (UMFPACK_DROPTOL) = droptol; + + // Set whether we are allowed to modify Q or not + if (FixedQ) + Control (UMFPACK_FIXQ) = 1.0; else { - octave_idx_type nr = a.rows (); - octave_idx_type nc = a.cols (); - - // Setup the control parameters - Matrix Control (UMFPACK_CONTROL, 1); - double *control = Control.fortran_vec (); - UMFPACK_ZNAME (defaults) (control); - - double tmp = octave_sparse_params::get_key ("spumoni"); + tmp = octave_sparse_params::get_key ("autoamd"); if (! xisnan (tmp)) - Control (UMFPACK_PRL) = tmp; - if (piv_thres.numel () == 2) + Control (UMFPACK_FIXQ) = tmp; + } + + // Turn-off UMFPACK scaling for LU + if (scale) + Control (UMFPACK_SCALE) = UMFPACK_SCALE_SUM; + else + Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE; + + UMFPACK_ZNAME (report_control) (control); + + const octave_idx_type *Ap = a.cidx (); + const octave_idx_type *Ai = a.ridx (); + const Complex *Ax = a.data (); + + UMFPACK_ZNAME (report_matrix) (nr, nc, Ap, Ai, + reinterpret_cast (Ax), 0, + 1, control); + + void *Symbolic; + Matrix Info (1, UMFPACK_INFO); + double *info = Info.fortran_vec (); + int status; + + // Null loop so that qinit is imediately deallocated when not + // needed + do + { + OCTAVE_LOCAL_BUFFER (octave_idx_type, qinit, nc); + + for (octave_idx_type i = 0; i < nc; i++) + qinit[i] = static_cast (Qinit (i)); + + status = UMFPACK_ZNAME (qsymbolic) (nr, nc, Ap, Ai, + reinterpret_cast (Ax), + 0, qinit, &Symbolic, control, + info); + } + while (0); + + if (status < 0) + { + UMFPACK_ZNAME (report_status) (control, status); + UMFPACK_ZNAME (report_info) (control, info); + + UMFPACK_ZNAME (free_symbolic) (&Symbolic); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU symbolic factorization failed"); + } + else + { + UMFPACK_ZNAME (report_symbolic) (Symbolic, control); + + void *Numeric; + status = UMFPACK_ZNAME (numeric) (Ap, Ai, + reinterpret_cast (Ax), 0, + Symbolic, &Numeric, control, info); + UMFPACK_ZNAME (free_symbolic) (&Symbolic); + + cond = Info (UMFPACK_RCOND); + + if (status < 0) { - tmp = (piv_thres (0) > 1. ? 1. : piv_thres (0)); - if (! xisnan (tmp)) - Control (UMFPACK_PIVOT_TOLERANCE) = tmp; - tmp = (piv_thres (1) > 1. ? 1. : piv_thres (1)); - if (! xisnan (tmp)) - Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + UMFPACK_ZNAME (report_status) (control, status); + UMFPACK_ZNAME (report_info) (control, info); + + UMFPACK_ZNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU numeric factorization failed"); } else { - tmp = octave_sparse_params::get_key ("piv_tol"); - if (! xisnan (tmp)) - Control (UMFPACK_PIVOT_TOLERANCE) = tmp; - - tmp = octave_sparse_params::get_key ("sym_tol"); - if (! xisnan (tmp)) - Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; - } - - if (droptol >= 0.) - Control (UMFPACK_DROPTOL) = droptol; - - // Set whether we are allowed to modify Q or not - if (FixedQ) - Control (UMFPACK_FIXQ) = 1.0; - else - { - tmp = octave_sparse_params::get_key ("autoamd"); - if (! xisnan (tmp)) - Control (UMFPACK_FIXQ) = tmp; - } - - // Turn-off UMFPACK scaling for LU - if (scale) - Control (UMFPACK_SCALE) = UMFPACK_SCALE_SUM; - else - Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE; - - UMFPACK_ZNAME (report_control) (control); - - const octave_idx_type *Ap = a.cidx (); - const octave_idx_type *Ai = a.ridx (); - const Complex *Ax = a.data (); - - UMFPACK_ZNAME (report_matrix) (nr, nc, Ap, Ai, - reinterpret_cast (Ax), 0, - 1, control); + UMFPACK_ZNAME (report_numeric) (Numeric, control); - void *Symbolic; - Matrix Info (1, UMFPACK_INFO); - double *info = Info.fortran_vec (); - int status; - - // Null loop so that qinit is imediately deallocated when not - // needed - do - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, qinit, nc); - - for (octave_idx_type i = 0; i < nc; i++) - qinit[i] = static_cast (Qinit (i)); - - status = UMFPACK_ZNAME (qsymbolic) (nr, nc, Ap, Ai, - reinterpret_cast (Ax), - 0, qinit, &Symbolic, control, - info); - } - while (0); - - if (status < 0) - { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU symbolic factorization failed"); - - UMFPACK_ZNAME (report_status) (control, status); - UMFPACK_ZNAME (report_info) (control, info); - - UMFPACK_ZNAME (free_symbolic) (&Symbolic); - } - else - { - UMFPACK_ZNAME (report_symbolic) (Symbolic, control); - - void *Numeric; - status = UMFPACK_ZNAME (numeric) (Ap, Ai, - reinterpret_cast (Ax), 0, - Symbolic, &Numeric, control, info); - UMFPACK_ZNAME (free_symbolic) (&Symbolic); - - cond = Info (UMFPACK_RCOND); + octave_idx_type lnz, unz, ignore1, ignore2, ignore3; + status = UMFPACK_ZNAME (get_lunz) (&lnz, &unz, + &ignore1, &ignore2, &ignore3, + Numeric); if (status < 0) { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU numeric factorization failed"); - UMFPACK_ZNAME (report_status) (control, status); UMFPACK_ZNAME (report_info) (control, info); UMFPACK_ZNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); } else { - UMFPACK_ZNAME (report_numeric) (Numeric, control); + octave_idx_type n_inner = (nr < nc ? nr : nc); + + if (lnz < 1) + Lfact = SparseComplexMatrix (n_inner, nr, + static_cast (1)); + else + Lfact = SparseComplexMatrix (n_inner, nr, lnz); + + octave_idx_type *Ltp = Lfact.cidx (); + octave_idx_type *Ltj = Lfact.ridx (); + Complex *Ltx = Lfact.data (); + + if (unz < 1) + Ufact = SparseComplexMatrix (n_inner, nc, + static_cast (1)); + else + Ufact = SparseComplexMatrix (n_inner, nc, unz); + + octave_idx_type *Up = Ufact.cidx (); + octave_idx_type *Uj = Ufact.ridx (); + Complex *Ux = Ufact.data (); - octave_idx_type lnz, unz, ignore1, ignore2, ignore3; - status = UMFPACK_ZNAME (get_lunz) (&lnz, &unz, - &ignore1, &ignore2, &ignore3, - Numeric); + Rfact = SparseMatrix (nr, nr, nr); + for (octave_idx_type i = 0; i < nr; i++) + { + Rfact.xridx (i) = i; + Rfact.xcidx (i) = i; + } + Rfact.xcidx (nr) = nr; + double *Rx = Rfact.data (); + + P.resize (dim_vector (nr, 1)); + octave_idx_type *p = P.fortran_vec (); + + Q.resize (dim_vector (nc, 1)); + octave_idx_type *q = Q.fortran_vec (); + + octave_idx_type do_recip; + status = + UMFPACK_ZNAME (get_numeric) (Ltp, Ltj, + reinterpret_cast (Ltx), + 0, Up, Uj, + reinterpret_cast (Ux), + 0, p, q, 0, 0, + &do_recip, Rx, Numeric); + + UMFPACK_ZNAME (free_numeric) (&Numeric); if (status < 0) { + UMFPACK_ZNAME (report_status) (control, status); + (*current_liboctave_error_handler) ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); - - UMFPACK_ZNAME (report_status) (control, status); - UMFPACK_ZNAME (report_info) (control, info); - - UMFPACK_ZNAME (free_numeric) (&Numeric); } else { - octave_idx_type n_inner = (nr < nc ? nr : nc); - - if (lnz < 1) - Lfact = SparseComplexMatrix (n_inner, nr, - static_cast (1)); - else - Lfact = SparseComplexMatrix (n_inner, nr, lnz); - - octave_idx_type *Ltp = Lfact.cidx (); - octave_idx_type *Ltj = Lfact.ridx (); - Complex *Ltx = Lfact.data (); - - if (unz < 1) - Ufact = SparseComplexMatrix (n_inner, nc, - static_cast (1)); - else - Ufact = SparseComplexMatrix (n_inner, nc, unz); + Lfact = Lfact.transpose (); - octave_idx_type *Up = Ufact.cidx (); - octave_idx_type *Uj = Ufact.ridx (); - Complex *Ux = Ufact.data (); - - Rfact = SparseMatrix (nr, nr, nr); - for (octave_idx_type i = 0; i < nr; i++) - { - Rfact.xridx (i) = i; - Rfact.xcidx (i) = i; - } - Rfact.xcidx (nr) = nr; - double *Rx = Rfact.data (); - - P.resize (dim_vector (nr, 1)); - octave_idx_type *p = P.fortran_vec (); - - Q.resize (dim_vector (nc, 1)); - octave_idx_type *q = Q.fortran_vec (); + if (do_recip) + for (octave_idx_type i = 0; i < nr; i++) + Rx[i] = 1.0 / Rx[i]; - octave_idx_type do_recip; - status = - UMFPACK_ZNAME (get_numeric) (Ltp, Ltj, - reinterpret_cast (Ltx), - 0, Up, Uj, - reinterpret_cast (Ux), - 0, p, q, 0, 0, - &do_recip, Rx, Numeric); - - UMFPACK_ZNAME (free_numeric) (&Numeric); - - if (status < 0) - { - (*current_liboctave_error_handler) - ("SparseComplexLU::SparseComplexLU extracting LU factors failed"); - - UMFPACK_ZNAME (report_status) (control, status); - } - else - { - Lfact = Lfact.transpose (); + UMFPACK_ZNAME (report_matrix) (nr, n_inner, + Lfact.cidx (), + Lfact.ridx (), + reinterpret_cast (Lfact.data ()), + 0, 1, control); - if (do_recip) - for (octave_idx_type i = 0; i < nr; i++) - Rx[i] = 1.0 / Rx[i]; - - UMFPACK_ZNAME (report_matrix) (nr, n_inner, - Lfact.cidx (), - Lfact.ridx (), - reinterpret_cast (Lfact.data ()), - 0, 1, control); + UMFPACK_ZNAME (report_matrix) (n_inner, nc, + Ufact.cidx (), + Ufact.ridx (), + reinterpret_cast (Ufact.data ()), + 0, 1, control); + UMFPACK_ZNAME (report_perm) (nr, p, control); + UMFPACK_ZNAME (report_perm) (nc, q, control); + } - UMFPACK_ZNAME (report_matrix) (n_inner, nc, - Ufact.cidx (), - Ufact.ridx (), - reinterpret_cast (Ufact.data ()), - 0, 1, control); - UMFPACK_ZNAME (report_perm) (nr, p, control); - UMFPACK_ZNAME (report_perm) (nc, q, control); - } - - UMFPACK_ZNAME (report_info) (control, info); - } + UMFPACK_ZNAME (report_info) (control, info); } } + } - if (udiag) - (*current_liboctave_error_handler) - ("Option udiag of incomplete LU not implemented"); - } + if (udiag) + (*current_liboctave_error_handler) + ("Option udiag of incomplete LU not implemented"); #else (*current_liboctave_error_handler) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparseCmplxQR.cc --- a/liboctave/numeric/SparseCmplxQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparseCmplxQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -79,6 +79,7 @@ if (! N) (*current_liboctave_error_handler) ("SparseComplexQR: sparse matrix QR factorization filled"); + count = 1; #else @@ -203,7 +204,8 @@ Complex *vec = ret.fortran_vec (); if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) ret = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0)); else { @@ -249,7 +251,8 @@ Complex *vec = ret.fortran_vec (); if (nr < 0 || nc < 0) (*current_liboctave_error_handler) ("matrix dimension mismatch"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) ret = ComplexMatrix (nc, nr, Complex (0.0, 0.0)); else { @@ -304,7 +307,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0)); else if (nr >= nc) { @@ -432,7 +436,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = SparseComplexMatrix (nc, b_nc); else if (nr >= nc) { @@ -608,7 +613,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0)); else if (nr >= nc) { @@ -728,7 +734,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = SparseComplexMatrix (nc, b_nc); else if (nr >= nc) { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparseQR.cc --- a/liboctave/numeric/SparseQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparseQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -59,6 +59,7 @@ if (! N) (*current_liboctave_error_handler) ("SparseQR: sparse matrix QR factorization filled"); + count = 1; #else @@ -184,7 +185,8 @@ double *vec = ret.fortran_vec (); if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) ret = Matrix (nc, b_nc, 0.0); else { @@ -230,7 +232,8 @@ double *vec = ret.fortran_vec (); if (nr < 0 || nc < 0) (*current_liboctave_error_handler) ("matrix dimension mismatch"); - else if (nr == 0 || nc == 0) + + if (nr == 0 || nc == 0) ret = Matrix (nc, nr, 0.0); else { @@ -286,7 +289,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = Matrix (nc, b_nc, 0.0); else if (nr >= nc) { @@ -390,7 +394,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = SparseMatrix (nc, b_nc); else if (nr >= nc) { @@ -540,7 +545,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0)); else if (nr >= nc) { @@ -709,7 +715,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) x = SparseComplexMatrix (nc, b_nc); else if (nr >= nc) { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparsedbleCHOL.cc --- a/liboctave/numeric/SparsedbleCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparsedbleCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -41,30 +41,27 @@ octave_idx_type r_nc = r.cols (); SparseMatrix retval; - if (r_nr == r_nc) - { - MatrixType mattype (r); - int typ = mattype.type (false); - double rcond; - octave_idx_type info; - SparseMatrix rinv; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("U must be a square matrix"); + + MatrixType mattype (r); + int typ = mattype.type (false); + double rcond; + octave_idx_type info; + SparseMatrix rinv; - if (typ == MatrixType::Upper) - { - rinv = r.inverse (mattype, info, rcond, true, false); - retval = rinv.transpose () * rinv; - } - else if (typ == MatrixType::Lower) - { - rinv = r.transpose ().inverse (mattype, info, rcond, true, false); - retval = rinv.transpose () * rinv; - } - else - (*current_liboctave_error_handler) - ("U must be a triangular matrix"); + if (typ == MatrixType::Upper) + { + rinv = r.inverse (mattype, info, rcond, true, false); + retval = rinv.transpose () * rinv; + } + else if (typ == MatrixType::Lower) + { + rinv = r.transpose ().inverse (mattype, info, rcond, true, false); + retval = rinv.transpose () * rinv; } else - (*current_liboctave_error_handler) ("U must be a square matrix"); + (*current_liboctave_error_handler) ("U must be a triangular matrix"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/SparsedbleLU.cc --- a/liboctave/numeric/SparsedbleLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/SparsedbleLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -103,13 +103,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU symbolic factorization failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_symbolic) (&Symbolic) ; + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU symbolic factorization failed"); } else { @@ -124,13 +124,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU numeric factorization failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU numeric factorization failed"); } else { @@ -142,13 +142,13 @@ if (status < 0) { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU extracting LU factors failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU extracting LU factors failed"); } else { @@ -199,10 +199,10 @@ if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + (*current_liboctave_error_handler) ("SparseLU::SparseLU extracting LU factors failed"); - - UMFPACK_DNAME (report_status) (control, status); } else { @@ -241,221 +241,219 @@ if (milu) (*current_liboctave_error_handler) ("Modified incomplete LU not implemented"); + + octave_idx_type nr = a.rows (); + octave_idx_type nc = a.cols (); + + // Setup the control parameters + Matrix Control (UMFPACK_CONTROL, 1); + double *control = Control.fortran_vec (); + UMFPACK_DNAME (defaults) (control); + + double tmp = octave_sparse_params::get_key ("spumoni"); + if (! xisnan (tmp)) + Control (UMFPACK_PRL) = tmp; + + if (piv_thres.numel () == 2) + { + tmp = (piv_thres (0) > 1. ? 1. : piv_thres (0)); + if (! xisnan (tmp)) + Control (UMFPACK_PIVOT_TOLERANCE) = tmp; + tmp = (piv_thres (1) > 1. ? 1. : piv_thres (1)); + if (! xisnan (tmp)) + Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + } + else + { + tmp = octave_sparse_params::get_key ("piv_tol"); + if (! xisnan (tmp)) + Control (UMFPACK_PIVOT_TOLERANCE) = tmp; + + tmp = octave_sparse_params::get_key ("sym_tol"); + if (! xisnan (tmp)) + Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + } + + if (droptol >= 0.) + Control (UMFPACK_DROPTOL) = droptol; + + + // Set whether we are allowed to modify Q or not + if (FixedQ) + Control (UMFPACK_FIXQ) = 1.0; else { - octave_idx_type nr = a.rows (); - octave_idx_type nc = a.cols (); - - // Setup the control parameters - Matrix Control (UMFPACK_CONTROL, 1); - double *control = Control.fortran_vec (); - UMFPACK_DNAME (defaults) (control); - - double tmp = octave_sparse_params::get_key ("spumoni"); + tmp = octave_sparse_params::get_key ("autoamd"); if (! xisnan (tmp)) - Control (UMFPACK_PRL) = tmp; + Control (UMFPACK_FIXQ) = tmp; + } + + if (scale) + Control (UMFPACK_SCALE) = UMFPACK_SCALE_SUM; + else + Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE; + + UMFPACK_DNAME (report_control) (control); + + const octave_idx_type *Ap = a.cidx (); + const octave_idx_type *Ai = a.ridx (); + const double *Ax = a.data (); + + UMFPACK_DNAME (report_matrix) (nr, nc, Ap, Ai, Ax, 1, + control); + + void *Symbolic; + Matrix Info (1, UMFPACK_INFO); + double *info = Info.fortran_vec (); + int status; + + // Null loop so that qinit is imediately deallocated when not needed + do + { + OCTAVE_LOCAL_BUFFER (octave_idx_type, qinit, nc); - if (piv_thres.numel () == 2) + for (octave_idx_type i = 0; i < nc; i++) + qinit[i] = static_cast (Qinit (i)); + + status = UMFPACK_DNAME (qsymbolic) (nr, nc, Ap, Ai, Ax, + qinit, &Symbolic, control, info); + } + while (0); + + if (status < 0) + { + UMFPACK_DNAME (report_status) (control, status); + UMFPACK_DNAME (report_info) (control, info); + + UMFPACK_DNAME (free_symbolic) (&Symbolic) ; + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU symbolic factorization failed"); + } + else + { + UMFPACK_DNAME (report_symbolic) (Symbolic, control); + + void *Numeric; + status = UMFPACK_DNAME (numeric) (Ap, Ai, Ax, Symbolic, + &Numeric, control, info) ; + UMFPACK_DNAME (free_symbolic) (&Symbolic) ; + + cond = Info (UMFPACK_RCOND); + + if (status < 0) { - tmp = (piv_thres (0) > 1. ? 1. : piv_thres (0)); - if (! xisnan (tmp)) - Control (UMFPACK_PIVOT_TOLERANCE) = tmp; - tmp = (piv_thres (1) > 1. ? 1. : piv_thres (1)); - if (! xisnan (tmp)) - Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; + UMFPACK_DNAME (report_status) (control, status); + UMFPACK_DNAME (report_info) (control, info); + + UMFPACK_DNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU numeric factorization failed"); } else { - tmp = octave_sparse_params::get_key ("piv_tol"); - if (! xisnan (tmp)) - Control (UMFPACK_PIVOT_TOLERANCE) = tmp; - - tmp = octave_sparse_params::get_key ("sym_tol"); - if (! xisnan (tmp)) - Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp; - } - - if (droptol >= 0.) - Control (UMFPACK_DROPTOL) = droptol; - - - // Set whether we are allowed to modify Q or not - if (FixedQ) - Control (UMFPACK_FIXQ) = 1.0; - else - { - tmp = octave_sparse_params::get_key ("autoamd"); - if (! xisnan (tmp)) - Control (UMFPACK_FIXQ) = tmp; - } - - if (scale) - Control (UMFPACK_SCALE) = UMFPACK_SCALE_SUM; - else - Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE; - - UMFPACK_DNAME (report_control) (control); - - const octave_idx_type *Ap = a.cidx (); - const octave_idx_type *Ai = a.ridx (); - const double *Ax = a.data (); - - UMFPACK_DNAME (report_matrix) (nr, nc, Ap, Ai, Ax, 1, - control); + UMFPACK_DNAME (report_numeric) (Numeric, control); - void *Symbolic; - Matrix Info (1, UMFPACK_INFO); - double *info = Info.fortran_vec (); - int status; - - // Null loop so that qinit is imediately deallocated when not needed - do - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, qinit, nc); - - for (octave_idx_type i = 0; i < nc; i++) - qinit[i] = static_cast (Qinit (i)); - - status = UMFPACK_DNAME (qsymbolic) (nr, nc, Ap, Ai, Ax, - qinit, &Symbolic, control, info); - } - while (0); - - if (status < 0) - { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU symbolic factorization failed"); - - UMFPACK_DNAME (report_status) (control, status); - UMFPACK_DNAME (report_info) (control, info); - - UMFPACK_DNAME (free_symbolic) (&Symbolic) ; - } - else - { - UMFPACK_DNAME (report_symbolic) (Symbolic, control); - - void *Numeric; - status = UMFPACK_DNAME (numeric) (Ap, Ai, Ax, Symbolic, - &Numeric, control, info) ; - UMFPACK_DNAME (free_symbolic) (&Symbolic) ; - - cond = Info (UMFPACK_RCOND); + octave_idx_type lnz, unz, ignore1, ignore2, ignore3; + status = UMFPACK_DNAME (get_lunz) (&lnz, &unz, + &ignore1, &ignore2, &ignore3, + Numeric) ; if (status < 0) { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU numeric factorization failed"); - UMFPACK_DNAME (report_status) (control, status); UMFPACK_DNAME (report_info) (control, info); UMFPACK_DNAME (free_numeric) (&Numeric); + + (*current_liboctave_error_handler) + ("SparseLU::SparseLU extracting LU factors failed"); } else { - UMFPACK_DNAME (report_numeric) (Numeric, control); + octave_idx_type n_inner = (nr < nc ? nr : nc); + + if (lnz < 1) + Lfact = SparseMatrix (n_inner, nr, + static_cast (1)); + else + Lfact = SparseMatrix (n_inner, nr, lnz); + + octave_idx_type *Ltp = Lfact.cidx (); + octave_idx_type *Ltj = Lfact.ridx (); + double *Ltx = Lfact.data (); + + if (unz < 1) + Ufact = SparseMatrix (n_inner, nc, + static_cast (1)); + else + Ufact = SparseMatrix (n_inner, nc, unz); + + octave_idx_type *Up = Ufact.cidx (); + octave_idx_type *Uj = Ufact.ridx (); + double *Ux = Ufact.data (); - octave_idx_type lnz, unz, ignore1, ignore2, ignore3; - status = UMFPACK_DNAME (get_lunz) (&lnz, &unz, - &ignore1, &ignore2, &ignore3, - Numeric) ; + Rfact = SparseMatrix (nr, nr, nr); + for (octave_idx_type i = 0; i < nr; i++) + { + Rfact.xridx (i) = i; + Rfact.xcidx (i) = i; + } + Rfact.xcidx (nr) = nr; + double *Rx = Rfact.data (); + + P.resize (dim_vector (nr, 1)); + octave_idx_type *p = P.fortran_vec (); + + Q.resize (dim_vector (nc, 1)); + octave_idx_type *q = Q.fortran_vec (); + + octave_idx_type do_recip; + status = UMFPACK_DNAME (get_numeric) (Ltp, Ltj, + Ltx, Up, Uj, Ux, p, q, + 0, &do_recip, + Rx, Numeric) ; + + UMFPACK_DNAME (free_numeric) (&Numeric) ; if (status < 0) { + UMFPACK_DNAME (report_status) (control, status); + (*current_liboctave_error_handler) ("SparseLU::SparseLU extracting LU factors failed"); - - UMFPACK_DNAME (report_status) (control, status); - UMFPACK_DNAME (report_info) (control, info); - - UMFPACK_DNAME (free_numeric) (&Numeric); } else { - octave_idx_type n_inner = (nr < nc ? nr : nc); - - if (lnz < 1) - Lfact = SparseMatrix (n_inner, nr, - static_cast (1)); - else - Lfact = SparseMatrix (n_inner, nr, lnz); - - octave_idx_type *Ltp = Lfact.cidx (); - octave_idx_type *Ltj = Lfact.ridx (); - double *Ltx = Lfact.data (); - - if (unz < 1) - Ufact = SparseMatrix (n_inner, nc, - static_cast (1)); - else - Ufact = SparseMatrix (n_inner, nc, unz); + Lfact = Lfact.transpose (); - octave_idx_type *Up = Ufact.cidx (); - octave_idx_type *Uj = Ufact.ridx (); - double *Ux = Ufact.data (); - - Rfact = SparseMatrix (nr, nr, nr); - for (octave_idx_type i = 0; i < nr; i++) - { - Rfact.xridx (i) = i; - Rfact.xcidx (i) = i; - } - Rfact.xcidx (nr) = nr; - double *Rx = Rfact.data (); - - P.resize (dim_vector (nr, 1)); - octave_idx_type *p = P.fortran_vec (); - - Q.resize (dim_vector (nc, 1)); - octave_idx_type *q = Q.fortran_vec (); + if (do_recip) + for (octave_idx_type i = 0; i < nr; i++) + Rx[i] = 1.0 / Rx[i]; - octave_idx_type do_recip; - status = UMFPACK_DNAME (get_numeric) (Ltp, Ltj, - Ltx, Up, Uj, Ux, p, q, - 0, &do_recip, - Rx, Numeric) ; - - UMFPACK_DNAME (free_numeric) (&Numeric) ; - - if (status < 0) - { - (*current_liboctave_error_handler) - ("SparseLU::SparseLU extracting LU factors failed"); - - UMFPACK_DNAME (report_status) (control, status); - } - else - { - Lfact = Lfact.transpose (); + UMFPACK_DNAME (report_matrix) (nr, n_inner, + Lfact.cidx (), + Lfact.ridx (), + Lfact.data (), + 1, control); + UMFPACK_DNAME (report_matrix) (n_inner, nc, + Ufact.cidx (), + Ufact.ridx (), + Ufact.data (), + 1, control); + UMFPACK_DNAME (report_perm) (nr, p, control); + UMFPACK_DNAME (report_perm) (nc, q, control); + } - if (do_recip) - for (octave_idx_type i = 0; i < nr; i++) - Rx[i] = 1.0 / Rx[i]; - - UMFPACK_DNAME (report_matrix) (nr, n_inner, - Lfact.cidx (), - Lfact.ridx (), - Lfact.data (), - 1, control); - UMFPACK_DNAME (report_matrix) (n_inner, nc, - Ufact.cidx (), - Ufact.ridx (), - Ufact.data (), - 1, control); - UMFPACK_DNAME (report_perm) (nr, p, control); - UMFPACK_DNAME (report_perm) (nc, q, control); - } - - UMFPACK_DNAME (report_info) (control, info); - } + UMFPACK_DNAME (report_info) (control, info); } } + } - if (udiag) - (*current_liboctave_error_handler) - ("Option udiag of incomplete LU not implemented"); - } + if (udiag) + (*current_liboctave_error_handler) + ("Option udiag of incomplete LU not implemented"); #else (*current_liboctave_error_handler) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/base-lu.cc --- a/liboctave/numeric/base-lu.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/base-lu.cc Sat Jan 23 13:52:03 2016 -0800 @@ -113,6 +113,7 @@ if (! packed ()) (*current_liboctave_error_handler) ("lu: Y () not implemented for unpacked form"); + return a_fact; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/bsxfun-defs.cc --- a/liboctave/numeric/bsxfun-defs.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/bsxfun-defs.cc Sat Jan 23 13:52:03 2016 -0800 @@ -56,12 +56,9 @@ else if (yk == 1 || xk == yk) dvr(i) = xk; else - { - (*current_liboctave_error_handler) - ("bsxfun: nonconformant dimensions: %s and %s", - x.dims ().str ().c_str (), y.dims ().str ().c_str ()); - break; - } + (*current_liboctave_error_handler) + ("bsxfun: nonconformant dimensions: %s and %s", + x.dims ().str ().c_str (), y.dims ().str ().c_str ()); } Array retval (dvr); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleAEPBAL.cc --- a/liboctave/numeric/dbleAEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleAEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -56,10 +56,7 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); - return; - } + (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); octave_idx_type info; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleCHOL.cc --- a/liboctave/numeric/dbleCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -93,10 +93,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("CHOL requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("CHOL requires square matrix"); octave_idx_type n = a_nc; octave_idx_type info; @@ -170,45 +167,43 @@ octave_idx_type r_nr = r.rows (); octave_idx_type r_nc = r.cols (); - if (r_nr == r_nc) - { - octave_idx_type n = r_nc; - octave_idx_type info = 0; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + octave_idx_type n = r_nc; + octave_idx_type info = 0; + + Matrix tmp = r; + double *v = tmp.fortran_vec (); - Matrix tmp = r; - double *v = tmp.fortran_vec (); + if (info == 0) + { + if (is_upper) + F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); - if (info == 0) + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! + + if (n > 1) { if (is_upper) - F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); else - F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } - - retval = tmp; - } + retval = tmp; } - else - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); return retval; } @@ -223,10 +218,10 @@ void CHOL::set (const Matrix& R) { - if (R.is_square ()) - chol_mat = R; - else + if (! R.is_square ()) (*current_liboctave_error_handler) ("CHOL requires square matrix"); + + chol_mat = R; } #ifdef HAVE_QRUPDATE @@ -236,17 +231,15 @@ { octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - ColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (double, w, n); + ColumnVector utmp = u; - F77_XFCN (dch1up, DCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), w)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (double, w, n); + + F77_XFCN (dch1up, DCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), w)); } octave_idx_type @@ -256,17 +249,15 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - ColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (double, w, n); + ColumnVector utmp = u; - F77_XFCN (dch1dn, DCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), w, info)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (double, w, n); + + F77_XFCN (dch1dn, DCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), w, info)); return info; } @@ -280,19 +271,17 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); - else - { - ColumnVector utmp = u; + + ColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, w, n); - - chol_mat.resize (n+1, n+1); + OCTAVE_LOCAL_BUFFER (double, w, n); - F77_XFCN (dchinx, DCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, utmp.fortran_vec (), w, info)); - } + chol_mat.resize (n+1, n+1); + + F77_XFCN (dchinx, DCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, utmp.fortran_vec (), w, info)); return info; } @@ -304,15 +293,13 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (double, w, n); + + OCTAVE_LOCAL_BUFFER (double, w, n); - F77_XFCN (dchdex, DCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, w)); + F77_XFCN (dchdex, DCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, w)); - chol_mat.resize (n-1, n-1); - } + chol_mat.resize (n-1, n-1); } void @@ -322,13 +309,11 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (double, w, 2*n); + + OCTAVE_LOCAL_BUFFER (double, w, 2*n); - F77_XFCN (dchshx, DCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - i + 1, j + 1, w)); - } + F77_XFCN (dchshx, DCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + i + 1, j + 1, w)); } #else @@ -340,13 +325,11 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - init (chol_mat.transpose () * chol_mat - + Matrix (u) * Matrix (u).transpose (), true, false); - } - else + if (u.numel () != n) (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + init (chol_mat.transpose () * chol_mat + + Matrix (u) * Matrix (u).transpose (), true, false); } static bool @@ -366,19 +349,17 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + if (singular (chol_mat)) + info = 2; + else { - if (singular (chol_mat)) - info = 2; - else - { - info = init (chol_mat.transpose () * chol_mat - - Matrix (u) * Matrix (u).transpose (), true, false); - if (info) info = 1; - } + info = init (chol_mat.transpose () * chol_mat + - Matrix (u) * Matrix (u).transpose (), true, false); + if (info) info = 1; } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); return info; } @@ -394,29 +375,27 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); + + if (singular (chol_mat)) + info = 2; else { - if (singular (chol_mat)) - info = 2; - else - { - Matrix a = chol_mat.transpose () * chol_mat; - Matrix a1 (n+1, n+1); - for (octave_idx_type k = 0; k < n+1; k++) - for (octave_idx_type l = 0; l < n+1; l++) - { - if (l == j) - a1(k, l) = u(k); - else if (k == j) - a1(k, l) = u(l); - else - a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); - } - info = init (a1, true, false); - if (info) info = 1; - } + Matrix a = chol_mat.transpose () * chol_mat; + Matrix a1 (n+1, n+1); + for (octave_idx_type k = 0; k < n+1; k++) + for (octave_idx_type l = 0; l < n+1; l++) + { + if (l == j) + a1(k, l) = u(k); + else if (k == j) + a1(k, l) = u(l); + else + a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); + } + info = init (a1, true, false); + if (info) info = 1; } return info; @@ -431,13 +410,11 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - Matrix a = chol_mat.transpose () * chol_mat; - a.delete_elements (1, idx_vector (j)); - a.delete_elements (0, idx_vector (j)); - init (a, true, false); - } + + Matrix a = chol_mat.transpose () * chol_mat; + a.delete_elements (1, idx_vector (j)); + a.delete_elements (0, idx_vector (j)); + init (a, true, false); } void @@ -449,24 +426,22 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else + + Matrix a = chol_mat.transpose () * chol_mat; + Array p (dim_vector (n, 1)); + for (octave_idx_type k = 0; k < n; k++) p(k) = k; + if (i < j) { - Matrix a = chol_mat.transpose () * chol_mat; - Array p (dim_vector (n, 1)); - for (octave_idx_type k = 0; k < n; k++) p(k) = k; - if (i < j) - { - for (octave_idx_type k = i; k < j; k++) p(k) = k+1; - p(j) = i; - } - else if (j < i) - { - p(j) = i; - for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; - } + for (octave_idx_type k = i; k < j; k++) p(k) = k+1; + p(j) = i; + } + else if (j < i) + { + p(j) = i; + for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; + } - init (a.index (idx_vector (p), idx_vector (p)), true, false); - } + init (a.index (idx_vector (p), idx_vector (p)), true, false); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleGEPBAL.cc --- a/liboctave/numeric/dbleGEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleGEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -65,10 +65,7 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) ("GEPBALANCE requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("GEPBALANCE requires square matrix"); if (a.dims () != b.dims ()) err_nonconformant ("GEPBALANCE", n, n, b.rows(), b.cols()); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleHESS.cc --- a/liboctave/numeric/dbleHESS.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleHESS.cc Sat Jan 23 13:52:03 2016 -0800 @@ -67,10 +67,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("HESS requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("HESS requires square matrix"); char job = 'N'; char side = 'R'; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleLU.cc --- a/liboctave/numeric/dbleLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -97,15 +97,13 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - ColumnVector utmp = u; - ColumnVector vtmp = v; - F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + ColumnVector utmp = u; + ColumnVector vtmp = v; + F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } void LU::update (const Matrix& u, const Matrix& v) @@ -120,19 +118,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ColumnVector utmp = u.column (i); - ColumnVector vtmp = v.column (i); - F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } + ColumnVector utmp = u.column (i); + ColumnVector vtmp = v.column (i); + F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); } void LU::update_piv (const ColumnVector& u, const ColumnVector& v) @@ -147,20 +143,18 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - ColumnVector utmp = u; - ColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (double, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + ColumnVector utmp = u; + ColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (double, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } void LU::update_piv (const Matrix& u, const Matrix& v) @@ -175,23 +169,21 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (double, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (double, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ColumnVector utmp = u.column (i); - ColumnVector vtmp = v.column (i); - F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + ColumnVector utmp = u.column (i); + ColumnVector vtmp = v.column (i); + F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #else diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleQR.cc --- a/liboctave/numeric/dbleQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -213,17 +213,15 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.numel () == m && v.numel () == n) - { - ColumnVector utmp = u; - ColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (double, w, 2*k); - F77_XFCN (dqr1up, DQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), w)); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + ColumnVector utmp = u; + ColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (double, w, 2*k); + F77_XFCN (dqr1up, DQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), w)); } void @@ -233,21 +231,19 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (double, w, 2*k); + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (double, w, 2*k); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - ColumnVector utmp = u.column (i); - ColumnVector vtmp = v.column (i); - F77_XFCN (dqr1up, DQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w)); - } + ColumnVector utmp = u.column (i); + ColumnVector vtmp = v.column (i); + F77_XFCN (dqr1up, DQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w)); } - else - (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); } void @@ -259,26 +255,24 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); + + if (k < m) + { + q.resize (m, k+1); + r.resize (k+1, n+1); + } else { - if (k < m) - { - q.resize (m, k+1); - r.resize (k+1, n+1); - } - else - { - r.resize (k, n+1); - } + r.resize (k, n+1); + } - ColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, w, k); - F77_XFCN (dqrinc, DQRINC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - utmp.data (), w)); - } + ColumnVector utmp = u; + OCTAVE_LOCAL_BUFFER (double, w, k); + F77_XFCN (dqrinc, DQRINC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + utmp.data (), w)); } void @@ -297,11 +291,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { octave_idx_type kmax = std::min (k + nj, m); if (k < m) @@ -336,21 +331,19 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); + + OCTAVE_LOCAL_BUFFER (double, w, k); + F77_XFCN (dqrdec, DQRDEC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, w)); + + if (k < m) + { + q.resize (m, k-1); + r.resize (k-1, n-1); + } else { - OCTAVE_LOCAL_BUFFER (double, w, k); - F77_XFCN (dqrdec, DQRDEC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, w)); - - if (k < m) - { - q.resize (m, k-1); - r.resize (k-1, n-1); - } - else - { - r.resize (k, n-1); - } + r.resize (k, n-1); } } @@ -370,9 +363,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { OCTAVE_LOCAL_BUFFER (double, w, k); for (volatile octave_idx_type i = 0; i < js.numel (); i++) @@ -405,19 +399,17 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - q.resize (m + 1, m + 1); - r.resize (m + 1, n); - RowVector utmp = u; - OCTAVE_LOCAL_BUFFER (double, w, k); - F77_XFCN (dqrinr, DQRINR, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - j + 1, utmp.fortran_vec (), w)); - } + q.resize (m + 1, m + 1); + r.resize (m + 1, n); + RowVector utmp = u; + OCTAVE_LOCAL_BUFFER (double, w, k); + F77_XFCN (dqrinr, DQRINR, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + j + 1, utmp.fortran_vec (), w)); + } void @@ -428,18 +420,16 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (double, w, 2*m); - F77_XFCN (dqrder, DQRDER, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - w)); - q.resize (m - 1, m - 1); - r.resize (m - 1, n); - } + OCTAVE_LOCAL_BUFFER (double, w, 2*m); + F77_XFCN (dqrder, DQRDER, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + w)); + + q.resize (m - 1, m - 1); + r.resize (m - 1, n); } void @@ -451,14 +441,12 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (double, w, 2*k); - F77_XFCN (dqrshc, DQRSHC, (m, n, k, - q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - i + 1, j + 1, w)); - } + + OCTAVE_LOCAL_BUFFER (double, w, 2*k); + F77_XFCN (dqrshc, DQRSHC, (m, n, k, + q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + i + 1, j + 1, w)); } #else @@ -473,12 +461,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.numel () == m && v.numel () == n) - { - init (q*r + Matrix (u) * Matrix (v).transpose (), get_type ()); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + Matrix (u) * Matrix (v).transpose (), get_type ()); } void @@ -489,12 +475,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) - { - init (q*r + u * v.transpose (), get_type ()); - } - else + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + u * v.transpose (), get_type ()); } static @@ -570,12 +554,10 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_col (q*r, j, u), get_type ()); - } + + init (::insert_col (q*r, j, u), get_type ()); } void @@ -595,11 +577,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { Matrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -617,10 +600,8 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_col (q*r, j), get_type ()); - } + + init (::delete_col (q*r, j), get_type ()); } void @@ -639,9 +620,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { Matrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -660,12 +642,10 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_row (q*r, j, u), get_type ()); - } + + init (::insert_row (q*r, j, u), get_type ()); } void @@ -675,12 +655,10 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_row (q*r, j), get_type ()); - } + + init (::delete_row (q*r, j), get_type ()); } void @@ -692,10 +670,8 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - init (::shift_cols (q*r, i, j), get_type ()); - } + + init (::shift_cols (q*r, i, j), get_type ()); } void warn_qrupdate_once (void) diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleSCHUR.cc --- a/liboctave/numeric/dbleSCHUR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleSCHUR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -67,11 +67,9 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("SCHUR requires square matrix"); - return -1; - } - else if (a_nr == 0) + (*current_liboctave_error_handler) ("SCHUR requires square matrix"); + + if (a_nr == 0) { schur_mat.clear (); unitary_mat.clear (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/dbleSVD.cc --- a/liboctave/numeric/dbleSVD.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/dbleSVD.cc Sat Jan 23 13:52:03 2016 -0800 @@ -58,26 +58,20 @@ SVD::left_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("SVD: U not computed because type == SVD::sigma_only"); - return Matrix (); - } - else - return left_sm; + (*current_liboctave_error_handler) + ("SVD: U not computed because type == SVD::sigma_only"); + + return left_sm; } Matrix SVD::right_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("SVD: V not computed because type == SVD::sigma_only"); - return Matrix (); - } - else - return right_sm; + (*current_liboctave_error_handler) + ("SVD: V not computed because type == SVD::sigma_only"); + + return right_sm; } octave_idx_type diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/eigs-base.cc --- a/liboctave/numeric/eigs-base.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/eigs-base.cc Sat Jan 23 13:52:03 2016 -0800 @@ -308,13 +308,9 @@ F77_CHAR_ARG_LEN (1))); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable error in dgemv"); - return false; - } - else - return true; + (*current_liboctave_error_handler) ("eigs: unrecoverable error in dgemv"); + + return true; } static bool @@ -345,13 +341,9 @@ F77_CHAR_ARG_LEN (1))); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable error in zgemv"); - return false; - } - else - return true; + (*current_liboctave_error_handler) ("eigs: unrecoverable error in zgemv"); + + return true; } static bool @@ -777,16 +769,10 @@ M bt; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); if (resid.is_empty ()) { @@ -797,11 +783,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -815,62 +797,38 @@ } if (k < 1 || k > n - 2) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check the we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - { - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for real symmetric problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for real symmetric problem"); if (have_b) { @@ -890,11 +848,8 @@ else { if (! make_cholb (b, bt, permB)) - { - (*current_liboctave_error_handler) - ("eigs: The matrix B is not positive definite"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: The matrix B is not positive definite"); } } @@ -936,11 +891,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dsaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dsaupd"); if (disp > 0 && ! xisnan (workl[iptr (5)-1])) { @@ -982,11 +934,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -1018,62 +968,53 @@ F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dseupd"); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dseupd"); - return -1; - } - else - { - if (info2 == 0) + octave_idx_type k2 = k / 2; + if (typ != "SM" && typ != "BE") { - octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) + { + double dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + } + + if (rvec) + { if (typ != "SM" && typ != "BE") { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - double dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } } - if (rvec) - { - if (typ != "SM" && typ != "BE") - { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) - { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; - } - } - - if (note3) - eig_vec = ltsolve (b, permB, eig_vec); - } - } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dseupd", info2); - return -1; + if (note3) + eig_vec = ltsolve (b, permB, eig_vec); } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dseupd", info2); return ip(4); } @@ -1095,16 +1036,10 @@ std::string typ = "LM"; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); // FIXME: The "SM" type for mode 1 seems unstable though faster!! //if (! std::abs (sigma)) @@ -1121,19 +1056,12 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" + " Use 'eig (full (A))' instead"); if (p < 0) { @@ -1147,35 +1075,22 @@ } if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check the we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } @@ -1229,11 +1144,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dsaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dsaupd"); if (disp > 0 && ! xisnan (workl[iptr (5)-1])) { @@ -1319,11 +1231,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -1355,53 +1265,44 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dseupd"); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dseupd"); - return -1; - } - else - { - if (info2 == 0) + octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) { - octave_idx_type k2 = k / 2; + double dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + + if (rvec) + { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - double dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; - } - - if (rvec) - { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) - { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; - } + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dseupd", info2); - return -1; - } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dseupd", info2); return ip(4); } @@ -1430,11 +1331,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -1448,34 +1345,24 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (! have_sigma) { if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for real symmetric problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for real symmetric problem"); if (typ == "SM") { @@ -1530,11 +1417,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dsaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dsaupd"); if (disp > 0 && ! xisnan (workl[iptr (5)-1])) { @@ -1577,11 +1461,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -1613,59 +1495,50 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dseupd"); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dseupd"); - return -1; - } - else - { - if (info2 == 0) + octave_idx_type k2 = k / 2; + if (typ != "SM" && typ != "BE") { - octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) + { + double dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + } + + if (rvec) + { if (typ != "SM" && typ != "BE") { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - double dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; - } - } - - if (rvec) - { - if (typ != "SM" && typ != "BE") - { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) - { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; - } + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } } } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dseupd", info2); - return -1; - } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dseupd", info2); return ip(4); } @@ -1691,16 +1564,10 @@ M bt; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); if (resid.is_empty ()) { @@ -1711,11 +1578,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -1729,62 +1592,38 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check the we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - { - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LA" || typ == "SA" || typ == "BE") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for unsymmetric problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for unsymmetric problem"); if (have_b) { @@ -1804,11 +1643,8 @@ else { if (! make_cholb (b, bt, permB)) - { - (*current_liboctave_error_handler) - ("eigs: The matrix B is not positive definite"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: The matrix B is not positive definite"); } } @@ -1850,11 +1686,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dnaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dnaupd"); if (disp > 0 && ! xisnan(workl[iptr(5)-1])) { @@ -1896,11 +1729,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dnaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dnaupd", info); + break; } } @@ -1942,99 +1773,90 @@ F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dneupd"); + + eig_val.resize (k+1); + Complex *d = eig_val.fortran_vec (); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dneupd"); - return -1; - } - else - { - eig_val.resize (k+1); - Complex *d = eig_val.fortran_vec (); - - if (info2 == 0) + octave_idx_type jj = 0; + for (octave_idx_type i = 0; i < k+1; i++) { - octave_idx_type jj = 0; - for (octave_idx_type i = 0; i < k+1; i++) - { - if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) - jj++; - else - d[i-jj] = Complex (dr[i], di[i]); - } - if (jj == 0 && ! rvec) - for (octave_idx_type i = 0; i < k; i++) - d[i] = d[i+1]; - - octave_idx_type k2 = k / 2; + if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) + jj++; + else + d[i-jj] = Complex (dr[i], di[i]); + } + if (jj == 0 && ! rvec) + for (octave_idx_type i = 0; i < k; i++) + d[i] = d[i+1]; + + octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) + { + Complex dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + eig_val.resize (k); + + if (rvec) + { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - Complex dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } - eig_val.resize (k); - - if (rvec) + + eig_vec.resize (n, k); + octave_idx_type i = 0; + while (i < k) { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) - { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; - } - - eig_vec.resize (n, k); - octave_idx_type i = 0; - while (i < k) + octave_idx_type off1 = i * n; + octave_idx_type off2 = (i+1) * n; + if (std::imag (eig_val(i)) == 0) { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (i+1) * n; - if (std::imag (eig_val(i)) == 0) - { - for (octave_idx_type j = 0; j < n; j++) - eig_vec(j,i) = - Complex (z[j+off1],0.); - i++; - } - else + for (octave_idx_type j = 0; j < n; j++) + eig_vec(j,i) = + Complex (z[j+off1],0.); + i++; + } + else + { + for (octave_idx_type j = 0; j < n; j++) { - for (octave_idx_type j = 0; j < n; j++) - { - eig_vec(j,i) = - Complex (z[j+off1],z[j+off2]); - if (i < k - 1) - eig_vec(j,i+1) = - Complex (z[j+off1],-z[j+off2]); - } - i+=2; + eig_vec(j,i) = + Complex (z[j+off1],z[j+off2]); + if (i < k - 1) + eig_vec(j,i+1) = + Complex (z[j+off1],-z[j+off2]); } + i+=2; } - - if (note3) - eig_vec = ltsolve (M(b), permB, eig_vec); } - } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dneupd", info2); - return -1; + + if (note3) + eig_vec = ltsolve (M(b), permB, eig_vec); } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dneupd", info2); return ip(4); } @@ -2058,16 +1880,10 @@ double sigmai = 0.; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); // FIXME: The "SM" type for mode 1 seems unstable though faster!! //if (! std::abs (sigmar)) @@ -2084,11 +1900,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -2102,43 +1914,27 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check that we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } @@ -2192,11 +1988,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dsaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dsaupd"); if (disp > 0 && ! xisnan (workl[iptr (5)-1])) { @@ -2282,11 +2075,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -2328,96 +2119,87 @@ F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dneupd"); + + eig_val.resize (k+1); + Complex *d = eig_val.fortran_vec (); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dneupd"); - return -1; - } - else - { - eig_val.resize (k+1); - Complex *d = eig_val.fortran_vec (); - - if (info2 == 0) + octave_idx_type jj = 0; + for (octave_idx_type i = 0; i < k+1; i++) { - octave_idx_type jj = 0; - for (octave_idx_type i = 0; i < k+1; i++) - { - if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) - jj++; - else - d[i-jj] = Complex (dr[i], di[i]); - } - if (jj == 0 && ! rvec) - for (octave_idx_type i = 0; i < k; i++) - d[i] = d[i+1]; - - octave_idx_type k2 = k / 2; + if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) + jj++; + else + d[i-jj] = Complex (dr[i], di[i]); + } + if (jj == 0 && ! rvec) + for (octave_idx_type i = 0; i < k; i++) + d[i] = d[i+1]; + + octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) + { + Complex dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + eig_val.resize (k); + + if (rvec) + { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - Complex dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } - eig_val.resize (k); - - if (rvec) + + eig_vec.resize (n, k); + octave_idx_type i = 0; + while (i < k) { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) + octave_idx_type off1 = i * n; + octave_idx_type off2 = (i+1) * n; + if (std::imag (eig_val(i)) == 0) { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; + eig_vec(j,i) = + Complex (z[j+off1],0.); + i++; } - - eig_vec.resize (n, k); - octave_idx_type i = 0; - while (i < k) + else { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (i+1) * n; - if (std::imag (eig_val(i)) == 0) + for (octave_idx_type j = 0; j < n; j++) { - for (octave_idx_type j = 0; j < n; j++) - eig_vec(j,i) = - Complex (z[j+off1],0.); - i++; + eig_vec(j,i) = + Complex (z[j+off1],z[j+off2]); + if (i < k - 1) + eig_vec(j,i+1) = + Complex (z[j+off1],-z[j+off2]); } - else - { - for (octave_idx_type j = 0; j < n; j++) - { - eig_vec(j,i) = - Complex (z[j+off1],z[j+off2]); - if (i < k - 1) - eig_vec(j,i+1) = - Complex (z[j+off1],-z[j+off2]); - } - i+=2; - } + i+=2; } } } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dneupd", info2); - return -1; - } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dneupd", info2); return ip(4); } @@ -2447,11 +2229,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -2465,19 +2243,13 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (! have_sigma) @@ -2485,15 +2257,11 @@ if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LA" || typ == "SA" || typ == "BE") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for unsymmetric problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for unsymmetric problem"); if (typ == "SM") { @@ -2548,11 +2316,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dnaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dnaupd"); if (disp > 0 && ! xisnan(workl[iptr(5)-1])) { @@ -2594,11 +2359,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -2640,96 +2403,87 @@ F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in dneupd"); + + eig_val.resize (k+1); + Complex *d = eig_val.fortran_vec (); + + if (info2 == 0) { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in dneupd"); - return -1; - } - else - { - eig_val.resize (k+1); - Complex *d = eig_val.fortran_vec (); - - if (info2 == 0) + octave_idx_type jj = 0; + for (octave_idx_type i = 0; i < k+1; i++) { - octave_idx_type jj = 0; - for (octave_idx_type i = 0; i < k+1; i++) - { - if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) - jj++; - else - d[i-jj] = Complex (dr[i], di[i]); - } - if (jj == 0 && ! rvec) - for (octave_idx_type i = 0; i < k; i++) - d[i] = d[i+1]; - - octave_idx_type k2 = k / 2; + if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) + jj++; + else + d[i-jj] = Complex (dr[i], di[i]); + } + if (jj == 0 && ! rvec) + for (octave_idx_type i = 0; i < k; i++) + d[i] = d[i+1]; + + octave_idx_type k2 = k / 2; + for (octave_idx_type i = 0; i < k2; i++) + { + Complex dtmp = d[i]; + d[i] = d[k - i - 1]; + d[k - i - 1] = dtmp; + } + eig_val.resize (k); + + if (rvec) + { + OCTAVE_LOCAL_BUFFER (double, dtmp, n); + for (octave_idx_type i = 0; i < k2; i++) { - Complex dtmp = d[i]; - d[i] = d[k - i - 1]; - d[k - i - 1] = dtmp; + octave_idx_type off1 = i * n; + octave_idx_type off2 = (k - i - 1) * n; + + if (off1 == off2) + continue; + + for (octave_idx_type j = 0; j < n; j++) + dtmp[j] = z[off1 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off1 + j] = z[off2 + j]; + + for (octave_idx_type j = 0; j < n; j++) + z[off2 + j] = dtmp[j]; } - eig_val.resize (k); - - if (rvec) + + eig_vec.resize (n, k); + octave_idx_type i = 0; + while (i < k) { - OCTAVE_LOCAL_BUFFER (double, dtmp, n); - - for (octave_idx_type i = 0; i < k2; i++) + octave_idx_type off1 = i * n; + octave_idx_type off2 = (i+1) * n; + if (std::imag (eig_val(i)) == 0) { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (k - i - 1) * n; - - if (off1 == off2) - continue; - for (octave_idx_type j = 0; j < n; j++) - dtmp[j] = z[off1 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off1 + j] = z[off2 + j]; - - for (octave_idx_type j = 0; j < n; j++) - z[off2 + j] = dtmp[j]; + eig_vec(j,i) = + Complex (z[j+off1],0.); + i++; } - - eig_vec.resize (n, k); - octave_idx_type i = 0; - while (i < k) + else { - octave_idx_type off1 = i * n; - octave_idx_type off2 = (i+1) * n; - if (std::imag (eig_val(i)) == 0) + for (octave_idx_type j = 0; j < n; j++) { - for (octave_idx_type j = 0; j < n; j++) - eig_vec(j,i) = - Complex (z[j+off1],0.); - i++; + eig_vec(j,i) = + Complex (z[j+off1],z[j+off2]); + if (i < k - 1) + eig_vec(j,i+1) = + Complex (z[j+off1],-z[j+off2]); } - else - { - for (octave_idx_type j = 0; j < n; j++) - { - eig_vec(j,i) = - Complex (z[j+off1],z[j+off2]); - if (i < k - 1) - eig_vec(j,i+1) = - Complex (z[j+off1],-z[j+off2]); - } - i+=2; - } + i+=2; } } } - else - { - (*current_liboctave_error_handler) - ("eigs: error %d in dneupd", info2); - return -1; - } } + else + (*current_liboctave_error_handler) ("eigs: error %d in dneupd", info2); return ip(4); } @@ -2755,16 +2509,10 @@ M bt; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); if (cresid.is_empty ()) { @@ -2779,11 +2527,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -2797,62 +2541,38 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check the we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - { - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LA" || typ == "SA" || typ == "BE") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for complex problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for complex problem"); if (have_b) { @@ -2872,11 +2592,8 @@ else { if (! make_cholb (b, bt, permB)) - { - (*current_liboctave_error_handler) - ("eigs: The matrix B is not positive definite"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: The matrix B is not positive definite"); } } @@ -2919,11 +2636,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in znaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in znaupd"); if (disp > 0 && ! xisnan (workl[iptr (5)-1])) { @@ -2964,11 +2678,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in znaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in znaupd", info); + break; } } @@ -3002,11 +2714,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in zneupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in zneupd"); if (info2 == 0) { @@ -3046,11 +2755,7 @@ } } else - { - (*current_liboctave_error_handler) - ("eigs: error %d in zneupd", info2); - return -1; - } + (*current_liboctave_error_handler) ("eigs: error %d in zneupd", info2); return ip(4); } @@ -3074,16 +2779,10 @@ std::string typ = "LM"; if (m.rows () != m.cols ()) - { - (*current_liboctave_error_handler) ("eigs: A must be square"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: A must be square"); if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) - { - (*current_liboctave_error_handler) - ("eigs: B must be square and the same size as A"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: B must be square and the same size as A"); // FIXME: The "SM" type for mode 1 seems unstable though faster!! //if (! std::abs (sigma)) @@ -3104,11 +2803,7 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) ("eigs: n must be at least 3"); if (p < 0) { @@ -3122,43 +2817,27 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (have_b && cholB && ! permB.is_empty ()) { // Check that we really have a permutation vector if (permB.numel () != n) - { - (*current_liboctave_error_handler) ("eigs: permB vector invalid"); - return -1; - } - else + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); + + Array checked (dim_vector (n, 1), false); + for (octave_idx_type i = 0; i < n; i++) { - Array checked (dim_vector (n, 1), false); - for (octave_idx_type i = 0; i < n; i++) - { - octave_idx_type bidx = - static_cast (permB(i)); - if (checked(bidx) || bidx < 0 || bidx >= n - || D_NINT (bidx) != bidx) - { - (*current_liboctave_error_handler) - ("eigs: permB vector invalid"); - return -1; - } - } + octave_idx_type bidx = static_cast (permB(i)); + + if (checked(bidx) || bidx < 0 || bidx >= n || D_NINT (bidx) != bidx) + (*current_liboctave_error_handler) ("eigs: permB vector invalid"); } } @@ -3213,11 +2892,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in znaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in znaupd"); if (disp > 0 && ! xisnan(workl[iptr(5)-1])) { @@ -3304,11 +2980,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -3342,11 +3016,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in zneupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in zneupd"); if (info2 == 0) { @@ -3383,11 +3054,8 @@ } } else - { - (*current_liboctave_error_handler) - ("eigs: error %d in zneupd", info2); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in zneupd", info2); return ip(4); } @@ -3421,11 +3089,8 @@ } if (n < 3) - { - (*current_liboctave_error_handler) - ("eigs: n must be at least 3"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: n must be at least 3"); if (p < 0) { @@ -3439,34 +3104,24 @@ } if (k <= 0 || k >= n - 1) - { - (*current_liboctave_error_handler) - ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" - " Use 'eig (full (A))' instead"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" + " Use 'eig (full (A))' instead"); if (p <= k || p >= n) - { - (*current_liboctave_error_handler) - ("eigs: opts.p must be greater than k and less than n"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: opts.p must be greater than k and less than n"); if (! have_sigma) { if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && typ != "SI") - (*current_liboctave_error_handler) - ("eigs: unrecognized sigma value"); + (*current_liboctave_error_handler) ("eigs: unrecognized sigma value"); if (typ == "LA" || typ == "SA" || typ == "BE") - { - (*current_liboctave_error_handler) - ("eigs: invalid sigma value for complex problem"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: invalid sigma value for complex problem"); if (typ == "SM") { @@ -3522,11 +3177,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in znaupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in znaupd"); if (disp > 0 && ! xisnan(workl[iptr(5)-1])) { @@ -3568,11 +3220,9 @@ else { if (info < 0) - { - (*current_liboctave_error_handler) - ("eigs: error %d in dsaupd", info); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: error %d in dsaupd", info); + break; } } @@ -3606,11 +3256,8 @@ F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); if (f77_exception_encountered) - { - (*current_liboctave_error_handler) - ("eigs: unrecoverable exception encountered in zneupd"); - return -1; - } + (*current_liboctave_error_handler) + ("eigs: unrecoverable exception encountered in zneupd"); if (info2 == 0) { @@ -3647,11 +3294,7 @@ } } else - { - (*current_liboctave_error_handler) - ("eigs: error %d in zneupd", info2); - return -1; - } + (*current_liboctave_error_handler) ("eigs: error %d in zneupd", info2); return ip(4); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fCmplxAEPBAL.cc --- a/liboctave/numeric/fCmplxAEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fCmplxAEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -58,10 +58,7 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); - return; - } + (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); octave_idx_type info; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fCmplxCHOL.cc --- a/liboctave/numeric/fCmplxCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fCmplxCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -92,11 +92,8 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("FloatComplexCHOL requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) + ("FloatComplexCHOL requires square matrix"); octave_idx_type n = a_nc; octave_idx_type info; @@ -165,41 +162,39 @@ octave_idx_type r_nr = r.rows (); octave_idx_type r_nc = r.cols (); - if (r_nr == r_nc) - { - octave_idx_type n = r_nc; - octave_idx_type info; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); - FloatComplexMatrix tmp = r; + octave_idx_type n = r_nc; + octave_idx_type info; + + FloatComplexMatrix tmp = r; - if (is_upper) - F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - tmp.fortran_vec (), n, info - F77_CHAR_ARG_LEN (1))); - else - F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - tmp.fortran_vec (), n, info - F77_CHAR_ARG_LEN (1))); + if (is_upper) + F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + tmp.fortran_vec (), n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + tmp.fortran_vec (), n, info + F77_CHAR_ARG_LEN (1))); - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } + if (n > 1) + { + if (is_upper) + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); + else + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } - retval = tmp; - } - else - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + retval = tmp; return retval; } @@ -214,10 +209,10 @@ void FloatComplexCHOL::set (const FloatComplexMatrix& R) { - if (R.is_square ()) - chol_mat = R; - else + if (! R.is_square ()) (*current_liboctave_error_handler) ("CHOL requires square matrix"); + + chol_mat = R; } #ifdef HAVE_QRUPDATE @@ -227,17 +222,15 @@ { octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - FloatComplexColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (float, rw, n); + FloatComplexColumnVector utmp = u; - F77_XFCN (cch1up, CCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), rw)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (float, rw, n); + + F77_XFCN (cch1up, CCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), rw)); } octave_idx_type @@ -247,17 +240,15 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - FloatComplexColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (float, rw, n); + FloatComplexColumnVector utmp = u; - F77_XFCN (cch1dn, CCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), rw, info)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (float, rw, n); + + F77_XFCN (cch1dn, CCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), rw, info)); return info; } @@ -272,19 +263,17 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); - else - { - FloatComplexColumnVector utmp = u; + + FloatComplexColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, rw, n); - - chol_mat.resize (n+1, n+1); + OCTAVE_LOCAL_BUFFER (float, rw, n); - F77_XFCN (cchinx, CCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, utmp.fortran_vec (), rw, info)); - } + chol_mat.resize (n+1, n+1); + + F77_XFCN (cchinx, CCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, utmp.fortran_vec (), rw, info)); return info; } @@ -296,15 +285,13 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (float, rw, n); + + OCTAVE_LOCAL_BUFFER (float, rw, n); - F77_XFCN (cchdex, CCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, rw)); + F77_XFCN (cchdex, CCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, rw)); - chol_mat.resize (n-1, n-1); - } + chol_mat.resize (n-1, n-1); } void @@ -314,14 +301,12 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (FloatComplex, w, n); - OCTAVE_LOCAL_BUFFER (float, rw, n); - F77_XFCN (cchshx, CCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - i + 1, j + 1, w, rw)); - } + OCTAVE_LOCAL_BUFFER (FloatComplex, w, n); + OCTAVE_LOCAL_BUFFER (float, rw, n); + + F77_XFCN (cchshx, CCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + i + 1, j + 1, w, rw)); } #else @@ -333,14 +318,12 @@ octave_idx_type n = chol_mat.rows (); - if (u.length () == n) - { - init (chol_mat.hermitian () * chol_mat - + FloatComplexMatrix (u) * FloatComplexMatrix (u).hermitian (), - true, false); - } - else + if (u.length () != n) (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + init (chol_mat.hermitian () * chol_mat + + FloatComplexMatrix (u) * FloatComplexMatrix (u).hermitian (), + true, false); } static bool @@ -360,21 +343,19 @@ octave_idx_type n = chol_mat.rows (); - if (u.length () == n) + if (u.length () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + if (singular (chol_mat)) + info = 2; + else { - if (singular (chol_mat)) - info = 2; - else - { - info = init (chol_mat.hermitian () * chol_mat - - FloatComplexMatrix (u) - * FloatComplexMatrix (u).hermitian (), - true, false); - if (info) info = 1; - } + info = init (chol_mat.hermitian () * chol_mat + - FloatComplexMatrix (u) + * FloatComplexMatrix (u).hermitian (), + true, false); + if (info) info = 1; } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); return info; } @@ -391,31 +372,29 @@ if (u.length () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); + + if (singular (chol_mat)) + info = 2; + else if (u(j).imag () != 0.0) + info = 3; else { - if (singular (chol_mat)) - info = 2; - else if (u(j).imag () != 0.0) - info = 3; - else - { - FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; - FloatComplexMatrix a1 (n+1, n+1); - for (octave_idx_type k = 0; k < n+1; k++) - for (octave_idx_type l = 0; l < n+1; l++) - { - if (l == j) - a1(k, l) = u(k); - else if (k == j) - a1(k, l) = std::conj (u(l)); - else - a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); - } - info = init (a1, true, false); - if (info) info = 1; - } + FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; + FloatComplexMatrix a1 (n+1, n+1); + for (octave_idx_type k = 0; k < n+1; k++) + for (octave_idx_type l = 0; l < n+1; l++) + { + if (l == j) + a1(k, l) = u(k); + else if (k == j) + a1(k, l) = std::conj (u(l)); + else + a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); + } + info = init (a1, true, false); + if (info) info = 1; } return info; @@ -430,13 +409,11 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; - a.delete_elements (1, idx_vector (j)); - a.delete_elements (0, idx_vector (j)); - init (a, true, false); - } + + FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; + a.delete_elements (1, idx_vector (j)); + a.delete_elements (0, idx_vector (j)); + init (a, true, false); } void @@ -448,24 +425,22 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else + + FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; + Array p (dim_vector (n, 1)); + for (octave_idx_type k = 0; k < n; k++) p(k) = k; + if (i < j) { - FloatComplexMatrix a = chol_mat.hermitian () * chol_mat; - Array p (dim_vector (n, 1)); - for (octave_idx_type k = 0; k < n; k++) p(k) = k; - if (i < j) - { - for (octave_idx_type k = i; k < j; k++) p(k) = k+1; - p(j) = i; - } - else if (j < i) - { - p(j) = i; - for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; - } + for (octave_idx_type k = i; k < j; k++) p(k) = k+1; + p(j) = i; + } + else if (j < i) + { + p(j) = i; + for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; + } - init (a.index (idx_vector (p), idx_vector (p)), true, false); - } + init (a.index (idx_vector (p), idx_vector (p)), true, false); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fCmplxLU.cc --- a/liboctave/numeric/fCmplxLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fCmplxLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -122,19 +122,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatComplexColumnVector utmp = u.column (i); - FloatComplexColumnVector vtmp = v.column (i); - F77_XFCN (clu1up, CLU1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } + FloatComplexColumnVector utmp = u.column (i); + FloatComplexColumnVector vtmp = v.column (i); + F77_XFCN (clu1up, CLU1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); } void FloatComplexLU::update_piv (const FloatComplexColumnVector& u, @@ -150,20 +148,18 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - FloatComplexColumnVector utmp = u; - FloatComplexColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + FloatComplexColumnVector utmp = u; + FloatComplexColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } void FloatComplexLU::update_piv (const FloatComplexMatrix& u, @@ -179,23 +175,21 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatComplexColumnVector utmp = u.column (i); - FloatComplexColumnVector vtmp = v.column (i); - F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + FloatComplexColumnVector utmp = u.column (i); + FloatComplexColumnVector vtmp = v.column (i); + F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #else diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fCmplxQR.cc --- a/liboctave/numeric/fCmplxQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fCmplxQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -216,19 +216,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.numel () == m && v.numel () == n) - { - FloatComplexColumnVector utmp = u; - FloatComplexColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); - OCTAVE_LOCAL_BUFFER (float, rw, k); - F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w, rw)); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + FloatComplexColumnVector utmp = u; + FloatComplexColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); + OCTAVE_LOCAL_BUFFER (float, rw, k); + F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w, rw)); } void @@ -239,22 +237,20 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); + OCTAVE_LOCAL_BUFFER (float, rw, k); + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); - OCTAVE_LOCAL_BUFFER (float, rw, k); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatComplexColumnVector utmp = u.column (i); - FloatComplexColumnVector vtmp = v.column (i); - F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w, rw)); - } + FloatComplexColumnVector utmp = u.column (i); + FloatComplexColumnVector vtmp = v.column (i); + F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w, rw)); } - else - (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); } void @@ -267,26 +263,24 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); + + if (k < m) + { + q.resize (m, k+1); + r.resize (k+1, n+1); + } else { - if (k < m) - { - q.resize (m, k+1); - r.resize (k+1, n+1); - } - else - { - r.resize (k, n+1); - } + r.resize (k, n+1); + } - FloatComplexColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, rw, k); - F77_XFCN (cqrinc, CQRINC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - utmp.data (), rw)); - } + FloatComplexColumnVector utmp = u; + OCTAVE_LOCAL_BUFFER (float, rw, k); + F77_XFCN (cqrinc, CQRINC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + utmp.data (), rw)); } void @@ -306,11 +300,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { octave_idx_type kmax = std::min (k + nj, m); if (k < m) @@ -344,21 +339,19 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); + + OCTAVE_LOCAL_BUFFER (float, rw, k); + F77_XFCN (cqrdec, CQRDEC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, rw)); + + if (k < m) + { + q.resize (m, k-1); + r.resize (k-1, n-1); + } else { - OCTAVE_LOCAL_BUFFER (float, rw, k); - F77_XFCN (cqrdec, CQRDEC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, rw)); - - if (k < m) - { - q.resize (m, k-1); - r.resize (k-1, n-1); - } - else - { - r.resize (k, n-1); - } + r.resize (k, n-1); } } @@ -378,9 +371,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { OCTAVE_LOCAL_BUFFER (float, rw, k); for (volatile octave_idx_type i = 0; i < js.numel (); i++) @@ -413,19 +407,17 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - q.resize (m + 1, m + 1); - r.resize (m + 1, n); - FloatComplexRowVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, rw, k); - F77_XFCN (cqrinr, CQRINR, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - j + 1, utmp.fortran_vec (), rw)); - } + q.resize (m + 1, m + 1); + r.resize (m + 1, n); + FloatComplexRowVector utmp = u; + OCTAVE_LOCAL_BUFFER (float, rw, k); + F77_XFCN (cqrinr, CQRINR, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + j + 1, utmp.fortran_vec (), rw)); + } void @@ -436,19 +428,17 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); - OCTAVE_LOCAL_BUFFER (float, rw, m); - F77_XFCN (cqrder, CQRDER, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - w, rw)); - q.resize (m - 1, m - 1); - r.resize (m - 1, n); - } + OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); + OCTAVE_LOCAL_BUFFER (float, rw, m); + F77_XFCN (cqrder, CQRDER, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + w, rw)); + + q.resize (m - 1, m - 1); + r.resize (m - 1, n); } void @@ -460,15 +450,13 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); - OCTAVE_LOCAL_BUFFER (float, rw, k); - F77_XFCN (cqrshc, CQRSHC, (m, n, k, - q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - i + 1, j + 1, w, rw)); - } + + OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); + OCTAVE_LOCAL_BUFFER (float, rw, k); + F77_XFCN (cqrshc, CQRSHC, (m, n, k, + q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + i + 1, j + 1, w, rw)); } #else @@ -484,13 +472,11 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.numel () == m && v.numel () == n) - { - init (q*r + FloatComplexMatrix (u) * FloatComplexMatrix (v).hermitian (), - get_type ()); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + FloatComplexMatrix (u) * FloatComplexMatrix (v).hermitian (), + get_type ()); } void @@ -502,12 +488,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) - { - init (q*r + u * v.hermitian (), get_type ()); - } - else + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + u * v.hermitian (), get_type ()); } static @@ -584,12 +568,10 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_col (q*r, j, u), get_type ()); - } + + init (::insert_col (q*r, j, u), get_type ()); } void @@ -610,11 +592,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { FloatComplexMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -632,10 +615,8 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_col (q*r, j), get_type ()); - } + + init (::delete_col (q*r, j), get_type ()); } void @@ -654,9 +635,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { FloatComplexMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -675,12 +657,10 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_row (q*r, j, u), get_type ()); - } + + init (::insert_row (q*r, j, u), get_type ()); } void @@ -692,12 +672,10 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_row (q*r, j), get_type ()); - } + + init (::delete_row (q*r, j), get_type ()); } void @@ -709,10 +687,8 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - init (::shift_cols (q*r, i, j), get_type ()); - } + + init (::shift_cols (q*r, i, j), get_type ()); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fCmplxSCHUR.cc --- a/liboctave/numeric/fCmplxSCHUR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fCmplxSCHUR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -70,12 +70,10 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("FloatComplexSCHUR requires square matrix"); - return -1; - } - else if (a_nr == 0) + (*current_liboctave_error_handler) + ("FloatComplexSCHUR requires square matrix"); + + if (a_nr == 0) { schur_mat.clear (); unitary_mat.clear (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/fEIG.cc --- a/liboctave/numeric/fEIG.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/fEIG.cc Sat Jan 23 13:52:03 2016 -0800 @@ -137,11 +137,8 @@ FloatEIG::init (const FloatMatrix& a, bool calc_ev) { if (a.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); if (a.is_symmetric ()) return symmetric_init (a, calc_ev); @@ -149,10 +146,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -182,66 +176,55 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - float *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("sgeev workspace query failed"); - F77_XFCN (sgeev, SGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, tmp_data, n, pwr, pwi, dummy, - idummy, pvr, n, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + float *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in sgeev"); - return info; - } + F77_XFCN (sgeev, SGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, tmp_data, n, pwr, pwi, dummy, + idummy, pvr, n, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("sgeev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in sgeev"); - lambda.resize (n); - v.resize (nvr, nvr); + if (info > 0) + (*current_liboctave_error_handler) ("sgeev failed to converge"); + + lambda.resize (n); + v.resize (nvr, nvr); - for (octave_idx_type j = 0; j < n; j++) + for (octave_idx_type j = 0; j < n; j++) + { + if (wi.elem (j) == 0.0) { - if (wi.elem (j) == 0.0) - { - lambda.elem (j) = FloatComplex (wr.elem (j)); - for (octave_idx_type i = 0; i < nvr; i++) - v.elem (i, j) = vr.elem (i, j); - } - else + lambda.elem (j) = FloatComplex (wr.elem (j)); + for (octave_idx_type i = 0; i < nvr; i++) + v.elem (i, j) = vr.elem (i, j); + } + else + { + if (j+1 >= n) + (*current_liboctave_error_handler) ("EIG: internal error"); + + lambda.elem (j) = FloatComplex (wr.elem (j), wi.elem (j)); + lambda.elem (j+1) = FloatComplex (wr.elem (j+1), wi.elem (j+1)); + + for (octave_idx_type i = 0; i < nvr; i++) { - if (j+1 >= n) - { - (*current_liboctave_error_handler) ("EIG: internal error"); - return -1; - } - - lambda.elem (j) = FloatComplex (wr.elem (j), wi.elem (j)); - lambda.elem (j+1) = FloatComplex (wr.elem (j+1), wi.elem (j+1)); - - for (octave_idx_type i = 0; i < nvr; i++) - { - float real_part = vr.elem (i, j); - float imag_part = vr.elem (i, j+1); - v.elem (i, j) = FloatComplex (real_part, imag_part); - v.elem (i, j+1) = FloatComplex (real_part, -imag_part); - } - j++; + float real_part = vr.elem (i, j); + float imag_part = vr.elem (i, j+1); + v.elem (i, j) = FloatComplex (real_part, imag_part); + v.elem (i, j+1) = FloatComplex (real_part, -imag_part); } + j++; } } - else - (*current_liboctave_error_handler) ("sgeev workspace query failed"); return info; } @@ -252,10 +235,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -274,35 +254,27 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - float *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("ssyev workspace query failed"); - F77_XFCN (ssyev, SSYEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, tmp_data, n, pwr, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + float *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in ssyev"); - return info; - } + F77_XFCN (ssyev, SSYEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, tmp_data, n, pwr, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("ssyev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in ssyev"); - lambda = FloatComplexColumnVector (wr); - v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("ssyev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("ssyev failed to converge"); + + lambda = FloatComplexColumnVector (wr); + v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); return info; } @@ -311,11 +283,8 @@ FloatEIG::init (const FloatComplexMatrix& a, bool calc_ev) { if (a.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); if (a.is_hermitian ()) return hermitian_init (a, calc_ev); @@ -323,10 +292,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -357,36 +323,28 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - FloatComplex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("cgeev workspace query failed"); - F77_XFCN (cgeev, CGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, tmp_data, n, pw, dummy, idummy, - pv, n, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + FloatComplex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in cgeev"); - return info; - } + F77_XFCN (cgeev, CGEEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, tmp_data, n, pw, dummy, idummy, + pv, n, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("cgeev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in cgeev"); - lambda = w; - v = vtmp; - } - else - (*current_liboctave_error_handler) ("cgeev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("cgeev failed to converge"); + + lambda = w; + v = vtmp; return info; } @@ -397,10 +355,7 @@ octave_idx_type n = a.rows (); if (n != a.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); octave_idx_type info = 0; @@ -424,35 +379,27 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - FloatComplex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("cheev workspace query failed"); - F77_XFCN (cheev, CHEEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, tmp_data, n, pwr, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + FloatComplex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in cheev"); - return info; - } + F77_XFCN (cheev, CHEEV, (F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, tmp_data, n, pwr, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("cheev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in cheev"); - lambda = FloatComplexColumnVector (wr); - v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("cheev workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("cheev failed to converge"); + + lambda = FloatComplexColumnVector (wr); + v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); return info; } @@ -461,26 +408,17 @@ FloatEIG::init (const FloatMatrix& a, const FloatMatrix& b, bool calc_ev) { if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); octave_idx_type n = a.rows (); octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -530,70 +468,59 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - float *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("sggev workspace query failed"); - F77_XFCN (sggev, SGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, atmp_data, n, btmp_data, n, - par, pai, pbeta, - dummy, idummy, pvr, n, - pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + float *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in sggev"); - return info; - } + F77_XFCN (sggev, SGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, atmp_data, n, btmp_data, n, + par, pai, pbeta, + dummy, idummy, pvr, n, + pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("sggev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in sggev"); - lambda.resize (n); - v.resize (nvr, nvr); + if (info > 0) + (*current_liboctave_error_handler) ("sggev failed to converge"); + + lambda.resize (n); + v.resize (nvr, nvr); - for (octave_idx_type j = 0; j < n; j++) + for (octave_idx_type j = 0; j < n; j++) + { + if (ai.elem (j) == 0.0) + { + lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j)); + for (octave_idx_type i = 0; i < nvr; i++) + v.elem (i, j) = vr.elem (i, j); + } + else { - if (ai.elem (j) == 0.0) - { - lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j)); - for (octave_idx_type i = 0; i < nvr; i++) - v.elem (i, j) = vr.elem (i, j); - } - else + if (j+1 >= n) + (*current_liboctave_error_handler) ("EIG: internal error"); + + lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j), + ai.elem (j) / beta.elem (j)); + lambda.elem (j+1) = FloatComplex (ar.elem (j+1) / beta.elem (j+1), + ai.elem (j+1) / beta.elem (j+1)); + + for (octave_idx_type i = 0; i < nvr; i++) { - if (j+1 >= n) - { - (*current_liboctave_error_handler) ("EIG: internal error"); - return -1; - } - - lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j), - ai.elem (j) / beta.elem (j)); - lambda.elem (j+1) = FloatComplex (ar.elem (j+1) / beta.elem (j+1), - ai.elem (j+1) / beta.elem (j+1)); - - for (octave_idx_type i = 0; i < nvr; i++) - { - float real_part = vr.elem (i, j); - float imag_part = vr.elem (i, j+1); - v.elem (i, j) = FloatComplex (real_part, imag_part); - v.elem (i, j+1) = FloatComplex (real_part, -imag_part); - } - j++; + float real_part = vr.elem (i, j); + float imag_part = vr.elem (i, j+1); + v.elem (i, j) = FloatComplex (real_part, imag_part); + v.elem (i, j+1) = FloatComplex (real_part, -imag_part); } + j++; } } - else - (*current_liboctave_error_handler) ("sggev workspace query failed"); return info; } @@ -606,16 +533,10 @@ octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -639,37 +560,29 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work); - Array work (dim_vector (lwork, 1)); - float *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("ssygv workspace query failed"); - F77_XFCN (ssygv, SSYGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, atmp_data, n, - btmp_data, n, - pwr, pwork, lwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work); + Array work (dim_vector (lwork, 1)); + float *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in ssygv"); - return info; - } + F77_XFCN (ssygv, SSYGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, atmp_data, n, + btmp_data, n, + pwr, pwork, lwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("ssygv failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in ssygv"); - lambda = FloatComplexColumnVector (wr); - v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("ssygv workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("ssygv failed to converge"); + + lambda = FloatComplexColumnVector (wr); + v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); return info; } @@ -679,26 +592,17 @@ bool calc_ev) { if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ()) - { - (*current_liboctave_error_handler) - ("EIG: matrix contains Inf or NaN values"); - return -1; - } + (*current_liboctave_error_handler) + ("EIG: matrix contains Inf or NaN values"); octave_idx_type n = a.rows (); octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -748,41 +652,33 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - FloatComplex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("cggev workspace query failed"); - F77_XFCN (cggev, CGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), - F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - n, atmp_data, n, btmp_data, n, - palpha, pbeta, dummy, idummy, - pv, n, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + FloatComplex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in cggev"); - return info; - } + F77_XFCN (cggev, CGGEV, (F77_CONST_CHAR_ARG2 ("N", 1), + F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + n, atmp_data, n, btmp_data, n, + palpha, pbeta, dummy, idummy, + pv, n, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("cggev failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in cggev"); - lambda.resize (n); + if (info > 0) + (*current_liboctave_error_handler) ("cggev failed to converge"); - for (octave_idx_type j = 0; j < n; j++) - lambda.elem (j) = alpha.elem (j) / beta.elem (j); + lambda.resize (n); - v = vtmp; - } - else - (*current_liboctave_error_handler) ("cggev workspace query failed"); + for (octave_idx_type j = 0; j < n; j++) + lambda.elem (j) = alpha.elem (j) / beta.elem (j); + + v = vtmp; return info; } @@ -795,16 +691,10 @@ octave_idx_type nb = b.rows (); if (n != a.cols () || nb != b.cols ()) - { - (*current_liboctave_error_handler) ("EIG requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires square matrix"); if (n != nb) - { - (*current_liboctave_error_handler) ("EIG requires same size matrices"); - return -1; - } + (*current_liboctave_error_handler) ("EIG requires same size matrices"); octave_idx_type info = 0; @@ -833,37 +723,29 @@ F77_CHAR_ARG_LEN (1) F77_CHAR_ARG_LEN (1))); - if (info == 0) - { - lwork = static_cast (dummy_work.real ()); - Array work (dim_vector (lwork, 1)); - FloatComplex *pwork = work.fortran_vec (); + if (info != 0) + (*current_liboctave_error_handler) ("zhegv workspace query failed"); - F77_XFCN (chegv, CHEGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), - F77_CONST_CHAR_ARG2 ("U", 1), - n, atmp_data, n, - btmp_data, n, - pwr, pwork, lwork, prwork, info - F77_CHAR_ARG_LEN (1) - F77_CHAR_ARG_LEN (1))); + lwork = static_cast (dummy_work.real ()); + Array work (dim_vector (lwork, 1)); + FloatComplex *pwork = work.fortran_vec (); - if (info < 0) - { - (*current_liboctave_error_handler) ("unrecoverable error in zhegv"); - return info; - } + F77_XFCN (chegv, CHEGV, (1, F77_CONST_CHAR_ARG2 (calc_ev ? "V" : "N", 1), + F77_CONST_CHAR_ARG2 ("U", 1), + n, atmp_data, n, + btmp_data, n, + pwr, pwork, lwork, prwork, info + F77_CHAR_ARG_LEN (1) + F77_CHAR_ARG_LEN (1))); - if (info > 0) - { - (*current_liboctave_error_handler) ("zhegv failed to converge"); - return info; - } + if (info < 0) + (*current_liboctave_error_handler) ("unrecoverable error in zhegv"); - lambda = FloatComplexColumnVector (wr); - v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); - } - else - (*current_liboctave_error_handler) ("zhegv workspace query failed"); + if (info > 0) + (*current_liboctave_error_handler) ("zhegv failed to converge"); + + lambda = FloatComplexColumnVector (wr); + v = calc_ev ? FloatComplexMatrix (atmp) : FloatComplexMatrix (); return info; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatAEPBAL.cc --- a/liboctave/numeric/floatAEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatAEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -57,10 +57,7 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); - return; - } + (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix"); octave_idx_type info; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatCHOL.cc --- a/liboctave/numeric/floatCHOL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatCHOL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -93,10 +93,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("FloatCHOL requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("FloatCHOL requires square matrix"); octave_idx_type n = a_nc; octave_idx_type info; @@ -170,45 +167,43 @@ octave_idx_type r_nr = r.rows (); octave_idx_type r_nc = r.cols (); - if (r_nr == r_nc) - { - octave_idx_type n = r_nc; - octave_idx_type info = 0; + if (r_nr != r_nc) + (*current_liboctave_error_handler) ("chol2inv requires square matrix"); + + octave_idx_type n = r_nc; + octave_idx_type info = 0; + + FloatMatrix tmp = r; + float *v = tmp.fortran_vec (); - FloatMatrix tmp = r; - float *v = tmp.fortran_vec (); + if (info == 0) + { + if (is_upper) + F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); + else + F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, + v, n, info + F77_CHAR_ARG_LEN (1))); - if (info == 0) + // If someone thinks of a more graceful way of doing this (or + // faster for that matter :-)), please let me know! + + if (n > 1) { if (is_upper) - F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (i, j) = tmp.xelem (j, i); else - F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 ("L", 1), n, - v, n, info - F77_CHAR_ARG_LEN (1))); - - // If someone thinks of a more graceful way of doing this (or - // faster for that matter :-)), please let me know! + for (octave_idx_type j = 0; j < r_nc; j++) + for (octave_idx_type i = j+1; i < r_nr; i++) + tmp.xelem (j, i) = tmp.xelem (i, j); + } - if (n > 1) - { - if (is_upper) - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (i, j) = tmp.xelem (j, i); - else - for (octave_idx_type j = 0; j < r_nc; j++) - for (octave_idx_type i = j+1; i < r_nr; i++) - tmp.xelem (j, i) = tmp.xelem (i, j); - } - - retval = tmp; - } + retval = tmp; } - else - (*current_liboctave_error_handler) ("chol2inv requires square matrix"); return retval; } @@ -223,10 +218,10 @@ void FloatCHOL::set (const FloatMatrix& R) { - if (R.is_square ()) - chol_mat = R; - else + if (! R.is_square ()) (*current_liboctave_error_handler) ("FloatCHOL requires square matrix"); + + chol_mat = R; } #ifdef HAVE_QRUPDATE @@ -236,17 +231,15 @@ { octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - FloatColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (float, w, n); + FloatColumnVector utmp = u; - F77_XFCN (sch1up, SCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), w)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (float, w, n); + + F77_XFCN (sch1up, SCH1UP, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), w)); } octave_idx_type @@ -256,17 +249,15 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - FloatColumnVector utmp = u; + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); - OCTAVE_LOCAL_BUFFER (float, w, n); + FloatColumnVector utmp = u; - F77_XFCN (sch1dn, SCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), - utmp.fortran_vec (), w, info)); - } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + OCTAVE_LOCAL_BUFFER (float, w, n); + + F77_XFCN (sch1dn, SCH1DN, (n, chol_mat.fortran_vec (), chol_mat.rows (), + utmp.fortran_vec (), w, info)); return info; } @@ -280,19 +271,17 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); - else - { - FloatColumnVector utmp = u; + + FloatColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, w, n); - - chol_mat.resize (n+1, n+1); + OCTAVE_LOCAL_BUFFER (float, w, n); - F77_XFCN (schinx, SCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, utmp.fortran_vec (), w, info)); - } + chol_mat.resize (n+1, n+1); + + F77_XFCN (schinx, SCHINX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, utmp.fortran_vec (), w, info)); return info; } @@ -304,15 +293,13 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (float, w, n); + + OCTAVE_LOCAL_BUFFER (float, w, n); - F77_XFCN (schdex, SCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - j + 1, w)); + F77_XFCN (schdex, SCHDEX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + j + 1, w)); - chol_mat.resize (n-1, n-1); - } + chol_mat.resize (n-1, n-1); } void @@ -322,13 +309,11 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (float, w, 2*n); + + OCTAVE_LOCAL_BUFFER (float, w, 2*n); - F77_XFCN (schshx, SCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), - i + 1, j + 1, w)); - } + F77_XFCN (schshx, SCHSHX, (n, chol_mat.fortran_vec (), chol_mat.rows (), + i + 1, j + 1, w)); } #else @@ -340,13 +325,11 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) - { - init (chol_mat.transpose () * chol_mat - + FloatMatrix (u) * FloatMatrix (u).transpose (), true, false); - } - else + if (u.numel () != n) (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + init (chol_mat.transpose () * chol_mat + + FloatMatrix (u) * FloatMatrix (u).transpose (), true, false); } static bool @@ -366,20 +349,18 @@ octave_idx_type n = chol_mat.rows (); - if (u.numel () == n) + if (u.numel () != n) + (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); + + if (singular (chol_mat)) + info = 2; + else { - if (singular (chol_mat)) - info = 2; - else - { - info = init (chol_mat.transpose () * chol_mat - - FloatMatrix (u) * FloatMatrix (u).transpose (), true, - false); - if (info) info = 1; - } + info = init (chol_mat.transpose () * chol_mat + - FloatMatrix (u) * FloatMatrix (u).transpose (), true, + false); + if (info) info = 1; } - else - (*current_liboctave_error_handler) ("cholupdate: dimension mismatch"); return info; } @@ -395,29 +376,27 @@ if (u.numel () != n + 1) (*current_liboctave_error_handler) ("cholinsert: dimension mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("cholinsert: index out of range"); + + if (singular (chol_mat)) + info = 2; else { - if (singular (chol_mat)) - info = 2; - else - { - FloatMatrix a = chol_mat.transpose () * chol_mat; - FloatMatrix a1 (n+1, n+1); - for (octave_idx_type k = 0; k < n+1; k++) - for (octave_idx_type l = 0; l < n+1; l++) - { - if (l == j) - a1(k, l) = u(k); - else if (k == j) - a1(k, l) = u(l); - else - a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); - } - info = init (a1, true, false); - if (info) info = 1; - } + FloatMatrix a = chol_mat.transpose () * chol_mat; + FloatMatrix a1 (n+1, n+1); + for (octave_idx_type k = 0; k < n+1; k++) + for (octave_idx_type l = 0; l < n+1; l++) + { + if (l == j) + a1(k, l) = u(k); + else if (k == j) + a1(k, l) = u(l); + else + a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1); + } + info = init (a1, true, false); + if (info) info = 1; } return info; @@ -432,13 +411,11 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("choldelete: index out of range"); - else - { - FloatMatrix a = chol_mat.transpose () * chol_mat; - a.delete_elements (1, idx_vector (j)); - a.delete_elements (0, idx_vector (j)); - init (a, true, false); - } + + FloatMatrix a = chol_mat.transpose () * chol_mat; + a.delete_elements (1, idx_vector (j)); + a.delete_elements (0, idx_vector (j)); + init (a, true, false); } void @@ -450,24 +427,22 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("cholshift: index out of range"); - else + + FloatMatrix a = chol_mat.transpose () * chol_mat; + Array p (dim_vector (n, 1)); + for (octave_idx_type k = 0; k < n; k++) p(k) = k; + if (i < j) { - FloatMatrix a = chol_mat.transpose () * chol_mat; - Array p (dim_vector (n, 1)); - for (octave_idx_type k = 0; k < n; k++) p(k) = k; - if (i < j) - { - for (octave_idx_type k = i; k < j; k++) p(k) = k+1; - p(j) = i; - } - else if (j < i) - { - p(j) = i; - for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; - } + for (octave_idx_type k = i; k < j; k++) p(k) = k+1; + p(j) = i; + } + else if (j < i) + { + p(j) = i; + for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1; + } - init (a.index (idx_vector (p), idx_vector (p)), true, false); - } + init (a.index (idx_vector (p), idx_vector (p)), true, false); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatGEPBAL.cc --- a/liboctave/numeric/floatGEPBAL.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatGEPBAL.cc Sat Jan 23 13:52:03 2016 -0800 @@ -65,11 +65,8 @@ octave_idx_type n = a.cols (); if (a.rows () != n) - { - (*current_liboctave_error_handler) - ("FloatGEPBALANCE requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) + ("FloatGEPBALANCE requires square matrix"); if (a.dims () != b.dims ()) err_nonconformant ("FloatGEPBALANCE", n, n, b.rows(), b.cols()); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatHESS.cc --- a/liboctave/numeric/floatHESS.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatHESS.cc Sat Jan 23 13:52:03 2016 -0800 @@ -67,10 +67,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("FloatHESS requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("FloatHESS requires square matrix"); char job = 'N'; char side = 'R'; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatLU.cc --- a/liboctave/numeric/floatLU.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatLU.cc Sat Jan 23 13:52:03 2016 -0800 @@ -97,16 +97,14 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - FloatColumnVector utmp = u; - FloatColumnVector vtmp = v; - F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + FloatColumnVector utmp = u; + FloatColumnVector vtmp = v; + F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } void FloatLU::update (const FloatMatrix& u, const FloatMatrix& v) @@ -121,19 +119,17 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatColumnVector utmp = u.column (i); - FloatColumnVector vtmp = v.column (i); - F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec ())); - } + FloatColumnVector utmp = u.column (i); + FloatColumnVector vtmp = v.column (i); + F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec ())); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); } void FloatLU::update_piv (const FloatColumnVector& u, @@ -149,20 +145,18 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.numel () == m && v.numel () == n) - { - FloatColumnVector utmp = u; - FloatColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (float, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + FloatColumnVector utmp = u; + FloatColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (float, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } void FloatLU::update_piv (const FloatMatrix& u, const FloatMatrix& v) @@ -177,23 +171,21 @@ octave_idx_type n = r.columns (); octave_idx_type k = l.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (float, w, m); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (float, w, m); - for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatColumnVector utmp = u.column (i); - FloatColumnVector vtmp = v.column (i); - F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), - m, r.fortran_vec (), k, - ipvt.fortran_vec (), - utmp.data (), vtmp.data (), w)); - } - for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement + FloatColumnVector utmp = u.column (i); + FloatColumnVector vtmp = v.column (i); + F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), + m, r.fortran_vec (), k, + ipvt.fortran_vec (), + utmp.data (), vtmp.data (), w)); } - else - (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); + for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement } #else diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatQR.cc --- a/liboctave/numeric/floatQR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatQR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -211,17 +211,15 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.numel () == m && v.numel () == n) - { - FloatColumnVector utmp = u; - FloatColumnVector vtmp = v; - OCTAVE_LOCAL_BUFFER (float, w, 2*k); - F77_XFCN (sqr1up, SQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), w)); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + FloatColumnVector utmp = u; + FloatColumnVector vtmp = v; + OCTAVE_LOCAL_BUFFER (float, w, 2*k); + F77_XFCN (sqr1up, SQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), w)); } void @@ -231,21 +229,19 @@ octave_idx_type n = r.columns (); octave_idx_type k = q.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) + (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + OCTAVE_LOCAL_BUFFER (float, w, 2*k); + for (volatile octave_idx_type i = 0; i < u.cols (); i++) { - OCTAVE_LOCAL_BUFFER (float, w, 2*k); - for (volatile octave_idx_type i = 0; i < u.cols (); i++) - { - FloatColumnVector utmp = u.column (i); - FloatColumnVector vtmp = v.column (i); - F77_XFCN (sqr1up, SQR1UP, (m, n, k, q.fortran_vec (), - m, r.fortran_vec (), k, - utmp.fortran_vec (), vtmp.fortran_vec (), - w)); - } + FloatColumnVector utmp = u.column (i); + FloatColumnVector vtmp = v.column (i); + F77_XFCN (sqr1up, SQR1UP, (m, n, k, q.fortran_vec (), + m, r.fortran_vec (), k, + utmp.fortran_vec (), vtmp.fortran_vec (), + w)); } - else - (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); } void @@ -257,26 +253,24 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); + + if (k < m) + { + q.resize (m, k+1); + r.resize (k+1, n+1); + } else { - if (k < m) - { - q.resize (m, k+1); - r.resize (k+1, n+1); - } - else - { - r.resize (k, n+1); - } + r.resize (k, n+1); + } - FloatColumnVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, w, k); - F77_XFCN (sqrinc, SQRINC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - utmp.data (), w)); - } + FloatColumnVector utmp = u; + OCTAVE_LOCAL_BUFFER (float, w, k); + F77_XFCN (sqrinc, SQRINC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + utmp.data (), w)); } void @@ -295,11 +289,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { octave_idx_type kmax = std::min (k + nj, m); if (k < m) @@ -334,21 +329,19 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); + + OCTAVE_LOCAL_BUFFER (float, w, k); + F77_XFCN (sqrdec, SQRDEC, (m, n, k, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, w)); + + if (k < m) + { + q.resize (m, k-1); + r.resize (k-1, n-1); + } else { - OCTAVE_LOCAL_BUFFER (float, w, k); - F77_XFCN (sqrdec, SQRDEC, (m, n, k, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, w)); - - if (k < m) - { - q.resize (m, k-1); - r.resize (k-1, n-1); - } - else - { - r.resize (k, n-1); - } + r.resize (k, n-1); } } @@ -368,9 +361,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { OCTAVE_LOCAL_BUFFER (float, w, k); for (volatile octave_idx_type i = 0; i < js.numel (); i++) @@ -403,19 +397,17 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - q.resize (m + 1, m + 1); - r.resize (m + 1, n); - FloatRowVector utmp = u; - OCTAVE_LOCAL_BUFFER (float, w, k); - F77_XFCN (sqrinr, SQRINR, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - j + 1, utmp.fortran_vec (), w)); - } + q.resize (m + 1, m + 1); + r.resize (m + 1, n); + FloatRowVector utmp = u; + OCTAVE_LOCAL_BUFFER (float, w, k); + F77_XFCN (sqrinr, SQRINR, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + j + 1, utmp.fortran_vec (), w)); + } void @@ -426,18 +418,16 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (float, w, 2*m); - F77_XFCN (sqrder, SQRDER, (m, n, q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), j + 1, - w)); - q.resize (m - 1, m - 1); - r.resize (m - 1, n); - } + OCTAVE_LOCAL_BUFFER (float, w, 2*m); + F77_XFCN (sqrder, SQRDER, (m, n, q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), j + 1, + w)); + + q.resize (m - 1, m - 1); + r.resize (m - 1, n); } void @@ -449,14 +439,12 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - OCTAVE_LOCAL_BUFFER (float, w, 2*k); - F77_XFCN (sqrshc, SQRSHC, (m, n, k, - q.fortran_vec (), q.rows (), - r.fortran_vec (), r.rows (), - i + 1, j + 1, w)); - } + + OCTAVE_LOCAL_BUFFER (float, w, 2*k); + F77_XFCN (sqrshc, SQRSHC, (m, n, k, + q.fortran_vec (), q.rows (), + r.fortran_vec (), r.rows (), + i + 1, j + 1, w)); } #else @@ -471,12 +459,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.numel () == m && v.numel () == n) - { - init (q*r + FloatMatrix (u) * FloatMatrix (v).transpose (), get_type ()); - } - else + if (u.numel () != m || v.numel () != n) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + FloatMatrix (u) * FloatMatrix (v).transpose (), get_type ()); } void @@ -487,12 +473,10 @@ octave_idx_type m = q.rows (); octave_idx_type n = r.columns (); - if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) - { - init (q*r + u * v.transpose (), get_type ()); - } - else + if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); + + init (q*r + u * v.transpose (), get_type ()); } static @@ -568,12 +552,10 @@ if (u.numel () != m) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > n) + if (j < 0 || j > n) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_col (q*r, j, u), get_type ()); - } + + init (::insert_col (q*r, j, u), get_type ()); } void @@ -593,11 +575,12 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (u.numel () != m || u.columns () != nj) + if (u.numel () != m || u.columns () != nj) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) + if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { FloatMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -615,10 +598,8 @@ if (j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_col (q*r, j), get_type ()); - } + + init (::delete_col (q*r, j), get_type ()); } void @@ -637,9 +618,10 @@ if (dups) (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); - else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) + if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else if (nj > 0) + + if (nj > 0) { FloatMatrix a = q*r; for (octave_idx_type i = 0; i < js.numel (); i++) @@ -658,12 +640,10 @@ if (! q.is_square () || u.numel () != n) (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); - else if (j < 0 || j > m) + if (j < 0 || j > m) (*current_liboctave_error_handler) ("qrinsert: index out of range"); - else - { - init (::insert_row (q*r, j, u), get_type ()); - } + + init (::insert_row (q*r, j, u), get_type ()); } void @@ -675,12 +655,10 @@ if (! q.is_square ()) (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); - else if (j < 0 || j > m-1) + if (j < 0 || j > m-1) (*current_liboctave_error_handler) ("qrdelete: index out of range"); - else - { - init (::delete_row (q*r, j), get_type ()); - } + + init (::delete_row (q*r, j), get_type ()); } void @@ -692,10 +670,8 @@ if (i < 0 || i > n-1 || j < 0 || j > n-1) (*current_liboctave_error_handler) ("qrshift: index out of range"); - else - { - init (::shift_cols (q*r, i, j), get_type ()); - } + + init (::shift_cols (q*r, i, j), get_type ()); } #endif diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatSCHUR.cc --- a/liboctave/numeric/floatSCHUR.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatSCHUR.cc Sat Jan 23 13:52:03 2016 -0800 @@ -68,11 +68,9 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) ("FloatSCHUR requires square matrix"); - return -1; - } - else if (a_nr == 0) + (*current_liboctave_error_handler) ("FloatSCHUR requires square matrix"); + + if (a_nr == 0) { schur_mat.clear (); unitary_mat.clear (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/floatSVD.cc --- a/liboctave/numeric/floatSVD.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/floatSVD.cc Sat Jan 23 13:52:03 2016 -0800 @@ -58,26 +58,20 @@ FloatSVD::left_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("FloatSVD: U not computed because type == SVD::sigma_only"); - return FloatMatrix (); - } - else - return left_sm; + (*current_liboctave_error_handler) + ("FloatSVD: U not computed because type == SVD::sigma_only"); + + return left_sm; } FloatMatrix FloatSVD::right_singular_matrix (void) const { if (type_computed == SVD::sigma_only) - { - (*current_liboctave_error_handler) - ("FloatSVD: V not computed because type == SVD::sigma_only"); - return FloatMatrix (); - } - else - return right_sm; + (*current_liboctave_error_handler) + ("FloatSVD: V not computed because type == SVD::sigma_only"); + + return right_sm; } octave_idx_type diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/lo-specfun.cc --- a/liboctave/numeric/lo-specfun.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/lo-specfun.cc Sat Jan 23 13:52:03 2016 -0800 @@ -1196,23 +1196,21 @@ octave_idx_type alpha_nr = alpha.rows (); octave_idx_type alpha_nc = alpha.cols (); - if (x_nr == alpha_nr && x_nc == alpha_nc) - { - octave_idx_type nr = x_nr; - octave_idx_type nc = x_nc; - - retval.resize (nr, nc); - - ierr.resize (dim_vector (nr, nc)); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - retval(i,j) = f (x(i,j), alpha(i,j), (scaled ? 2 : 1), ierr(i,j)); - } - else + if (x_nr != alpha_nr || x_nc != alpha_nc) (*current_liboctave_error_handler) ("%s: the sizes of alpha and x must conform", fn); + octave_idx_type nr = x_nr; + octave_idx_type nc = x_nc; + + retval.resize (nr, nc); + + ierr.resize (dim_vector (nr, nc)); + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + retval(i,j) = f (x(i,j), alpha(i,j), (scaled ? 2 : 1), ierr(i,j)); + return retval; } @@ -1255,20 +1253,18 @@ dim_vector dv = x.dims (); ComplexNDArray retval; - if (dv == alpha.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - ierr.resize (dv); - - for (octave_idx_type i = 0; i < nel; i++) - retval(i) = f (x(i), alpha(i), (scaled ? 2 : 1), ierr(i)); - } - else + if (dv != alpha.dims ()) (*current_liboctave_error_handler) ("%s: the sizes of alpha and x must conform", fn); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + ierr.resize (dv); + + for (octave_idx_type i = 0; i < nel; i++) + retval(i) = f (x(i), alpha(i), (scaled ? 2 : 1), ierr(i)); + return retval; } @@ -1806,23 +1802,21 @@ octave_idx_type alpha_nr = alpha.rows (); octave_idx_type alpha_nc = alpha.cols (); - if (x_nr == alpha_nr && x_nc == alpha_nc) - { - octave_idx_type nr = x_nr; - octave_idx_type nc = x_nc; - - retval.resize (nr, nc); - - ierr.resize (dim_vector (nr, nc)); - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - retval(i,j) = f (x(i,j), alpha(i,j), (scaled ? 2 : 1), ierr(i,j)); - } - else + if (x_nr != alpha_nr || x_nc != alpha_nc) (*current_liboctave_error_handler) ("%s: the sizes of alpha and x must conform", fn); + octave_idx_type nr = x_nr; + octave_idx_type nc = x_nc; + + retval.resize (nr, nc); + + ierr.resize (dim_vector (nr, nc)); + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + retval(i,j) = f (x(i,j), alpha(i,j), (scaled ? 2 : 1), ierr(i,j)); + return retval; } @@ -1866,20 +1860,18 @@ dim_vector dv = x.dims (); FloatComplexNDArray retval; - if (dv == alpha.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - ierr.resize (dv); - - for (octave_idx_type i = 0; i < nel; i++) - retval(i) = f (x(i), alpha(i), (scaled ? 2 : 1), ierr(i)); - } - else + if (dv != alpha.dims ()) (*current_liboctave_error_handler) ("%s: the sizes of alpha and x must conform", fn); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + ierr.resize (dv); + + for (octave_idx_type i = 0; i < nel; i++) + retval(i) = f (x(i), alpha(i), (scaled ? 2 : 1), ierr(i)); + return retval; } @@ -2578,8 +2570,8 @@ if (a < 0.0 || x < 0.0) (*current_liboctave_error_handler) ("gammainc: A and X must be non-negative"); - else - F77_XFCN (xgammainc, XGAMMAINC, (a, x, retval)); + + F77_XFCN (xgammainc, XGAMMAINC, (a, x, retval)); return retval; } @@ -2601,7 +2593,7 @@ result(i,j) = gammainc (x, a(i,j), err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2628,7 +2620,7 @@ result(i,j) = gammainc (x(i,j), a, err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2650,28 +2642,26 @@ octave_idx_type a_nr = a.rows (); octave_idx_type a_nc = a.cols (); - if (nr == a_nr && nc == a_nc) - { - result.resize (nr, nc); - - bool err; - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - result(i,j) = gammainc (x(i,j), a(i,j), err); - - if (err) - goto done; - } - - retval = result; - } - else + if (nr != a_nr || nc != a_nc) (*current_liboctave_error_handler) ("gammainc: nonconformant arguments (arg 1 is %dx%d, arg 2 is %dx%d)", nr, nc, a_nr, a_nc); + result.resize (nr, nc); + + bool err; + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + { + result(i,j) = gammainc (x(i,j), a(i,j), err); + + if (err) + goto done; // FIXME: why not just use return to exit? + } + + retval = result; + done: return retval; @@ -2693,7 +2683,7 @@ result(i) = gammainc (x, a(i), err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2719,7 +2709,7 @@ result(i) = gammainc (x(i), a, err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2735,26 +2725,7 @@ dim_vector dv = x.dims (); octave_idx_type nel = dv.numel (); - NDArray retval; - NDArray result; - - if (dv == a.dims ()) - { - result.resize (dv); - - bool err; - - for (octave_idx_type i = 0; i < nel; i++) - { - result(i) = gammainc (x(i), a(i), err); - - if (err) - goto done; - } - - retval = result; - } - else + if (dv != a.dims ()) { std::string x_str = dv.str (); std::string a_str = a.dims ().str (); @@ -2764,6 +2735,21 @@ x_str.c_str (), a_str. c_str ()); } + NDArray retval; + NDArray result (dv); + + bool err; + + for (octave_idx_type i = 0; i < nel; i++) + { + result(i) = gammainc (x(i), a(i), err); + + if (err) + goto done; // FIXME: why not just use return to exit? + } + + retval = result; + done: return retval; @@ -2779,8 +2765,8 @@ if (a < 0.0 || x < 0.0) (*current_liboctave_error_handler) ("gammainc: A and X must be non-negative"); - else - F77_XFCN (xsgammainc, XSGAMMAINC, (a, x, retval)); + + F77_XFCN (xsgammainc, XSGAMMAINC, (a, x, retval)); return retval; } @@ -2802,7 +2788,7 @@ result(i,j) = gammainc (x, a(i,j), err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2829,7 +2815,7 @@ result(i,j) = gammainc (x(i,j), a, err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2851,28 +2837,26 @@ octave_idx_type a_nr = a.rows (); octave_idx_type a_nc = a.cols (); - if (nr == a_nr && nc == a_nc) - { - result.resize (nr, nc); - - bool err; - - for (octave_idx_type j = 0; j < nc; j++) - for (octave_idx_type i = 0; i < nr; i++) - { - result(i,j) = gammainc (x(i,j), a(i,j), err); - - if (err) - goto done; - } - - retval = result; - } - else + if (nr != a_nr || nc != a_nc) (*current_liboctave_error_handler) ("gammainc: nonconformant arguments (arg 1 is %dx%d, arg 2 is %dx%d)", nr, nc, a_nr, a_nc); + result.resize (nr, nc); + + bool err; + + for (octave_idx_type j = 0; j < nc; j++) + for (octave_idx_type i = 0; i < nr; i++) + { + result(i,j) = gammainc (x(i,j), a(i,j), err); + + if (err) + goto done; // FIXME: why not just use return to exit? + } + + retval = result; + done: return retval; @@ -2894,7 +2878,7 @@ result(i) = gammainc (x, a(i), err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2920,7 +2904,7 @@ result(i) = gammainc (x(i), a, err); if (err) - goto done; + goto done; // FIXME: why not just use return to exit? } retval = result; @@ -2939,23 +2923,7 @@ FloatNDArray retval; FloatNDArray result; - if (dv == a.dims ()) - { - result.resize (dv); - - bool err; - - for (octave_idx_type i = 0; i < nel; i++) - { - result(i) = gammainc (x(i), a(i), err); - - if (err) - goto done; - } - - retval = result; - } - else + if (dv != a.dims ()) { std::string x_str = dv.str (); std::string a_str = a.dims ().str (); @@ -2965,6 +2933,20 @@ x_str.c_str (), a_str.c_str ()); } + result.resize (dv); + + bool err; + + for (octave_idx_type i = 0; i < nel; i++) + { + result(i) = gammainc (x(i), a(i), err); + + if (err) + goto done; // FIXME: why not just use return to exit? + } + + retval = result; + done: return retval; @@ -3307,21 +3289,12 @@ // Test for admissibility of parameters. if (p <= 0.0 || q <= 0.0) - { - (*current_liboctave_error_handler) - ("betaincinv: wrong parameters"); - } - + (*current_liboctave_error_handler) ("betaincinv: wrong parameters"); if (y < 0.0 || 1.0 < y) - { - (*current_liboctave_error_handler) - ("betaincinv: wrong parameter Y"); - } + (*current_liboctave_error_handler) ("betaincinv: wrong parameter Y"); if (y == 0.0 || y == 1.0) - { - return value; - } + return value; // Change tail if necessary. diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/oct-fftw.cc --- a/liboctave/numeric/oct-fftw.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/oct-fftw.cc Sat Jan 23 13:52:03 2016 -0800 @@ -73,6 +73,7 @@ int init_ret = fftw_init_threads (); if (! init_ret) (*current_liboctave_error_handler) ("Error initializing FFTW threads"); + //Use number of processors available to the current process //This can be later changed with fftw ("threads", nthreads) nthreads = num_processors (NPROC_CURRENT); @@ -114,12 +115,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create octave_fftw_planner object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create octave_fftw_planner object!"); return retval; } @@ -417,6 +414,7 @@ int init_ret = fftwf_init_threads (); if (! init_ret) (*current_liboctave_error_handler) ("Error initializing FFTW3F threads"); + //Use number of processors available to the current process //This can be later changed with fftw ("threads", nthreads) nthreads = num_processors (NPROC_CURRENT); @@ -458,12 +456,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create octave_fftw_planner object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create octave_fftw_planner object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/oct-rand.cc --- a/liboctave/numeric/oct-rand.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/oct-rand.cc Sat Jan 23 13:52:03 2016 -0800 @@ -98,12 +98,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create octave_rand object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create octave_rand object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/oct-spparms.cc --- a/liboctave/numeric/oct-spparms.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/oct-spparms.cc Sat Jan 23 13:52:03 2016 -0800 @@ -47,12 +47,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create octave_sparse_params object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create octave_sparse_params object!"); return retval; } @@ -180,19 +176,13 @@ octave_idx_type len = vals.numel (); if (len > OCTAVE_SPARSE_CONTROLS_SIZE) - { - (*current_liboctave_error_handler) - ("octave_sparse_params::do_set_vals: too many values"); + (*current_liboctave_error_handler) + ("octave_sparse_params::do_set_vals: too many values"); - return false; - } - else - { - for (int i = 0; i < len; i++) - params(i) = vals(i); + for (int i = 0; i < len; i++) + params(i) = vals(i); - return true; - } + return true; } bool diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/sparse-base-chol.cc --- a/liboctave/numeric/sparse-base-chol.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/sparse-base-chol.cc Sat Jan 23 13:52:03 2016 -0800 @@ -89,11 +89,7 @@ octave_idx_type a_nc = a.cols (); if (a_nr != a_nc) - { - (*current_liboctave_error_handler) - ("SparseCHOL requires square matrix"); - return -1; - } + (*current_liboctave_error_handler) ("SparseCHOL requires square matrix"); cholmod_common *cm = &Common; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/numeric/sparse-dmsolve.cc --- a/liboctave/numeric/sparse-dmsolve.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/numeric/sparse-dmsolve.cc Sat Jan 23 13:52:03 2016 -0800 @@ -383,7 +383,8 @@ if (nr < 0 || nc < 0 || nr != b_nr) (*current_liboctave_error_handler) ("matrix dimension mismatch in solution of minimum norm problem"); - else if (nr == 0 || nc == 0 || b_nc == 0) + + if (nr == 0 || nc == 0 || b_nc == 0) retval = RT (nc, b_nc, 0.0); else { diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/system/file-ops.cc --- a/liboctave/system/file-ops.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/system/file-ops.cc Sat Jan 23 13:52:03 2016 -0800 @@ -88,12 +88,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create file_ops object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create file_ops object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/system/lo-sysdep.cc --- a/liboctave/system/lo-sysdep.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/system/lo-sysdep.cc Sat Jan 23 13:52:03 2016 -0800 @@ -56,14 +56,12 @@ char *tmp = gnulib::getcwd (0, 0); - if (tmp) - { - retval = tmp; - free (tmp); - } - else + if (! tmp) (*current_liboctave_error_handler) ("unable to find current directory"); + retval = tmp; + free (tmp); + return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/system/mach-info.cc --- a/liboctave/system/mach-info.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/system/mach-info.cc Sat Jan 23 13:52:03 2016 -0800 @@ -150,12 +150,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create command history object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create command history object!"); return retval; } @@ -195,8 +191,7 @@ else if (s == "unknown") retval = oct_mach_info::flt_fmt_unknown; else - (*current_liboctave_error_handler) - ("invalid architecture type specified"); + (*current_liboctave_error_handler) ("invalid architecture type specified"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/system/oct-env.cc --- a/liboctave/system/oct-env.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/system/oct-env.cc Sat Jan 23 13:52:03 2016 -0800 @@ -90,12 +90,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create current working directory object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create current working directory object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/system/oct-syscalls.cc --- a/liboctave/system/oct-syscalls.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/system/oct-syscalls.cc Sat Jan 23 13:52:03 2016 -0800 @@ -357,7 +357,7 @@ else child_msg = "popen2 (child): file handle duplication failed -- " + child_msg; - (*current_liboctave_error_handler)(child_msg.c_str ()); + (*current_liboctave_error_handler) (child_msg.c_str ()); exit (0); } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/cmd-edit.cc --- a/liboctave/util/cmd-edit.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/cmd-edit.cc Sat Jan 23 13:52:03 2016 -0800 @@ -965,12 +965,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create command history object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create command history object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/cmd-hist.cc --- a/liboctave/util/cmd-hist.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/cmd-hist.cc Sat Jan 23 13:52:03 2016 -0800 @@ -512,12 +512,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create command history object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create command history object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/data-conv.cc --- a/liboctave/util/data-conv.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/data-conv.cc Sat Jan 23 13:52:03 2016 -0800 @@ -390,12 +390,8 @@ s = s.substr (pos+1); } else - { - (*current_liboctave_error_handler) - ("invalid repeat count in '%s'", str.c_str ()); - - return; - } + (*current_liboctave_error_handler) + ("invalid repeat count in '%s'", str.c_str ()); } } @@ -461,12 +457,8 @@ s = s.substr (pos+1); } else - { - (*current_liboctave_error_handler) - ("invalid repeat count in '%s'", str.c_str ()); - - return; - } + (*current_liboctave_error_handler) + ("invalid repeat count in '%s'", str.c_str ()); } output_type = string_to_data_type (s); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/lo-ieee.cc --- a/liboctave/util/lo-ieee.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/lo-ieee.cc Sat Jan 23 13:52:03 2016 -0800 @@ -269,6 +269,7 @@ // experiment with building Octave on a system without IEEE // floating point should be capable of removing this check and // the configure test. + // FIXME: Should this be a warning so that abort is reached? (*current_liboctave_error_handler) ("lo_ieee_init: floating point format is not IEEE! Maybe DLAMCH is miscompiled, or you are using some strange system without IEEE floating point math?"); abort (); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/lo-regexp.cc --- a/liboctave/util/lo-regexp.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/lo-regexp.cc Sat Jan 23 13:52:03 2016 -0800 @@ -95,11 +95,8 @@ size_t tmp_pos = pattern.find_first_of ('>', new_pos); if (tmp_pos == std::string::npos) - { - (*current_liboctave_error_handler) - ("regexp: syntax error in pattern"); - return; - } + (*current_liboctave_error_handler) + ("regexp: syntax error in pattern"); std::string tmp_name = pattern.substr (new_pos+3, tmp_pos-new_pos-3); @@ -235,8 +232,7 @@ if (! data) (*current_liboctave_error_handler) - ("%s: %s at position %d of expression", who.c_str (), - err, erroffset); + ("%s: %s at position %d of expression", who.c_str (), err, erroffset); } regexp::match_data @@ -309,13 +305,11 @@ } if (matches < 0 && matches != PCRE_ERROR_NOMATCH) - { - (*current_liboctave_error_handler) - ("%s: internal error calling pcre_exec; error code from pcre_exec is %i", - who.c_str (), matches); - return retval; - } - else if (matches == PCRE_ERROR_NOMATCH) + (*current_liboctave_error_handler) + ("%s: internal error calling pcre_exec; " + "error code from pcre_exec is %i", who.c_str (), matches); + + if (matches == PCRE_ERROR_NOMATCH) break; else if (ovector[1] <= ovector[0] && ! options.emptymatch ()) { @@ -352,12 +346,9 @@ matches, &listptr); if (status == PCRE_ERROR_NOMEMORY) - { - (*current_liboctave_error_handler) - ("%s: cannot allocate memory in pcre_get_substring_list", - who.c_str ()); - return retval; - } + (*current_liboctave_error_handler) + ("%s: cannot allocate memory in pcre_get_substring_list", + who.c_str ()); string_vector tokens (pos_match); string_vector named_tokens (nnames); diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/oct-base64.cc --- a/liboctave/util/oct-base64.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/oct-base64.cc Sat Jan 23 13:52:03 2016 -0800 @@ -68,25 +68,23 @@ if (! ok) (*current_liboctave_error_handler) ("base64_decode: input was not valid base64"); - else if (! out) + if (! out) (*current_liboctave_error_handler) ("base64_decode: memory allocation error"); + + if ((outlen % (sizeof (double) / sizeof (char))) != 0) + { + ::free (out); + (*current_liboctave_error_handler) + ("base64_decode: incorrect input size"); + } else { - if ((outlen % (sizeof (double) / sizeof (char))) != 0) - { - ::free (out); - (*current_liboctave_error_handler) - ("base64_decode: incorrect input size"); - } - else - { - octave_idx_type len = (outlen * sizeof (char)) / sizeof (double); - retval.resize (dim_vector (1, len)); - double *dout = reinterpret_cast (out); - std::copy (dout, dout + len, retval.fortran_vec ()); - ::free (out); - } + octave_idx_type len = (outlen * sizeof (char)) / sizeof (double); + retval.resize (dim_vector (1, len)); + double *dout = reinterpret_cast (out); + std::copy (dout, dout + len, retval.fortran_vec ()); + ::free (out); } return retval; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/oct-shlib.cc --- a/liboctave/util/oct-shlib.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/oct-shlib.cc Sat Jan 23 13:52:03 2016 -0800 @@ -228,19 +228,17 @@ { void *function = 0; - if (is_open ()) - { - std::string sym_name = name; - - if (mangler) - sym_name = mangler (name); - - function = dlsym (library, sym_name.c_str ()); - } - else + if (! is_open ()) (*current_liboctave_error_handler) ("shared library %s is not open", file.c_str ()); + std::string sym_name = name; + + if (mangler) + sym_name = mangler (name); + + function = dlsym (library, sym_name.c_str ()); + return function; } @@ -280,7 +278,7 @@ if (! library) { - using namespace std; + using namespace std; // FIXME: Why have this line? (*current_liboctave_error_handler) ("%s", gnulib::strerror (errno)); } } @@ -297,20 +295,18 @@ { void *function = 0; - if (is_open ()) - { - std::string sym_name = name; - - if (mangler) - sym_name = mangler (name); - - int status = shl_findsym (&library, sym_name.c_str (), - TYPE_UNDEFINED, &function); - } - else + if (! is_open ()) (*current_liboctave_error_handler) ("shared library %s is not open", file.c_str ()); + std::string sym_name = name; + + if (mangler) + sym_name = mangler (name); + + int status = shl_findsym (&library, sym_name.c_str (), + TYPE_UNDEFINED, &function); + return function; } @@ -391,19 +387,17 @@ { void *function = 0; - if (is_open ()) - { - std::string sym_name = name; - - if (mangler) - sym_name = mangler (name); - - function = octave_w32_library_search (handle, sym_name.c_str ()); - } - else + if (! is_open ()) (*current_liboctave_error_handler) ("shared library %s is not open", file.c_str ()); + std::string sym_name = name; + + if (mangler) + sym_name = mangler (name); + + function = octave_w32_library_search (handle, sym_name.c_str ()); + return function; } @@ -444,34 +438,31 @@ { int returnCode = NSCreateObjectFileImageFromFile (file.c_str (), &img); - if (NSObjectFileImageSuccess == returnCode) - { - handle = NSLinkModule (img, file.c_str (), - (NSLINKMODULE_OPTION_RETURN_ON_ERROR - | NSLINKMODULE_OPTION_PRIVATE)); - if (! handle) - { - NSLinkEditErrors ler; - int lerno; - const char *file2; - const char *errstr = 0; - - NSLinkEditError (&ler, &lerno, &file2, &errstr); - - if (! errstr) - errstr = "unspecified error"; - - (*current_liboctave_error_handler) - ("%s: %s", file.c_str (), errstr); - } - } - else + if (NSObjectFileImageSuccess != returnCode) { (*current_liboctave_error_handler) ("got NSObjectFileImageReturnCode %d", returnCode); // FIXME: should use NSLinkEditError () to get - // more info on what went wrong. + // more info on what went wrong. + } + + handle = NSLinkModule (img, file.c_str (), + (NSLINKMODULE_OPTION_RETURN_ON_ERROR + | NSLINKMODULE_OPTION_PRIVATE)); + if (! handle) + { + NSLinkEditErrors ler; + int lerno; + const char *file2; + const char *errstr = 0; + + NSLinkEditError (&ler, &lerno, &file2, &errstr); + + if (! errstr) + errstr = "unspecified error"; + + (*current_liboctave_error_handler) ("%s: %s", file.c_str (), errstr); } } @@ -489,24 +480,22 @@ { void *function = 0; - if (is_open ()) - { - std::string sym_name = name; - - if (mangler) - sym_name = mangler (name); - - NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ()); - - if (symbol) - { - function = NSAddressOfSymbol (symbol); - } - } - else + if (! is_open ()) (*current_liboctave_error_handler) ("bundle %s is not open", file.c_str ()); + std::string sym_name = name; + + if (mangler) + sym_name = mangler (name); + + NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ()); + + if (symbol) + { + function = NSAddressOfSymbol (symbol); + } + return function; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/pathsearch.cc --- a/liboctave/util/pathsearch.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/pathsearch.cc Sat Jan 23 13:52:03 2016 -0800 @@ -55,12 +55,8 @@ } if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create dir_path::static_members object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create dir_path::static_members object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/singleton-cleanup.cc --- a/liboctave/util/singleton-cleanup.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/singleton-cleanup.cc Sat Jan 23 13:52:03 2016 -0800 @@ -49,12 +49,8 @@ instance = new singleton_cleanup_list (); if (! instance) - { - (*current_liboctave_error_handler) - ("unable to create singleton_cleanup_list object!"); - - retval = false; - } + (*current_liboctave_error_handler) + ("unable to create singleton_cleanup_list object!"); return retval; } diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/sparse-util.cc --- a/liboctave/util/sparse-util.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/sparse-util.cc Sat Jan 23 13:52:03 2016 -0800 @@ -44,7 +44,6 @@ void SparseCholError (int status, const char *file, int line, const char *message) { - // Ignore CHOLMOD_NOT_POSDEF, since we handle that in Fchol as an // error or exit status. if (status != CHOLMOD_NOT_POSDEF) @@ -81,49 +80,35 @@ if (nnz > 0) { if (c[0] != 0) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: cidx[0] must be zero"); - return false; - } + (*current_liboctave_error_handler) + ("invalid sparse matrix: cidx[0] must be zero"); octave_idx_type jold = 0; for (octave_idx_type j = 1; j < ncols+1; j++) { if (c[j] < c[j-1]) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: cidx elements must appear in ascending order"); - return false; - } + (*current_liboctave_error_handler) + ("invalid sparse matrix: cidx elements must appear in ascending order"); if (c[j] > nnz) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: cidx[%d] = %d exceeds number of nonzero elements", - j, c[j]+1); - return false; - } + (*current_liboctave_error_handler) + ("invalid sparse matrix: cidx[%d] = %d " + "exceeds number of nonzero elements", j, c[j]+1); if (c[j] != jold) { for (octave_idx_type i = jold+1; i < c[j]; i++) { if (r[i] < r[i-1]) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: ridx elements must appear in ascending order for each column"); - return false; - } + (*current_liboctave_error_handler) + ("invalid sparse matrix: ridx elements must appear " + "in ascending order for each column"); if (r[i] >= nrows) - { - (*current_liboctave_error_handler) - ("invalid sparse matrix: ridx[%d] = %d out of range", - i, r[i]+1); - return false; - } + (*current_liboctave_error_handler) + ("invalid sparse matrix: ridx[%d] = %d out of range", + i, r[i]+1); } jold = c[j]; diff -r 95da3bc8a281 -r 7cac4e7458f2 liboctave/util/unwind-prot.cc --- a/liboctave/util/unwind-prot.cc Fri Jan 22 13:45:21 2016 -0500 +++ b/liboctave/util/unwind-prot.cc Sat Jan 23 13:52:03 2016 -0800 @@ -33,7 +33,6 @@ { // FIXME: can this throw an exception? // Yes, it can now (1/18/16). Maybe this needs to be re-done? - (*current_liboctave_error_handler) ("internal: unhandled exception in unwind_protect handler"); }