CmplxQR.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 Copyright (C) 2008-2009 Jaroslav Hajek
00005 Copyright (C) 2009 VZLU Prague
00006 
00007 This file is part of Octave.
00008 
00009 Octave is free software; you can redistribute it and/or modify it
00010 under the terms of the GNU General Public License as published by the
00011 Free Software Foundation; either version 3 of the License, or (at your
00012 option) any later version.
00013 
00014 Octave is distributed in the hope that it will be useful, but WITHOUT
00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00017 for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with Octave; see the file COPYING.  If not, see
00021 <http://www.gnu.org/licenses/>.
00022 
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028 
00029 #include "CmplxQR.h"
00030 #include "f77-fcn.h"
00031 #include "lo-error.h"
00032 #include "Range.h"
00033 #include "idx-vector.h"
00034 #include "oct-locbuf.h"
00035 
00036 #include "base-qr.cc"
00037 
00038 template class base_qr<ComplexMatrix>;
00039 
00040 extern "C"
00041 {
00042   F77_RET_T
00043   F77_FUNC (zgeqrf, ZGEQRF) (const octave_idx_type&, const octave_idx_type&,
00044                              Complex*, const octave_idx_type&, Complex*,
00045                              Complex*, const octave_idx_type&,
00046                              octave_idx_type&);
00047 
00048   F77_RET_T
00049   F77_FUNC (zungqr, ZUNGQR) (const octave_idx_type&, const octave_idx_type&,
00050                              const octave_idx_type&, Complex*,
00051                              const octave_idx_type&, Complex*, Complex*,
00052                              const octave_idx_type&, octave_idx_type&);
00053 
00054 #ifdef HAVE_QRUPDATE
00055 
00056   F77_RET_T
00057   F77_FUNC (zqr1up, ZQR1UP) (const octave_idx_type&, const octave_idx_type&,
00058                              const octave_idx_type&, Complex*,
00059                              const octave_idx_type&, Complex*,
00060                              const octave_idx_type&, Complex*,
00061                              Complex*, Complex*, double*);
00062 
00063   F77_RET_T
00064   F77_FUNC (zqrinc, ZQRINC) (const octave_idx_type&, const octave_idx_type&,
00065                              const octave_idx_type&, Complex*,
00066                              const octave_idx_type&, Complex*,
00067                              const octave_idx_type&, const octave_idx_type&,
00068                              const Complex*, double*);
00069 
00070   F77_RET_T
00071   F77_FUNC (zqrdec, ZQRDEC) (const octave_idx_type&, const octave_idx_type&,
00072                              const octave_idx_type&, Complex*,
00073                              const octave_idx_type&, Complex*,
00074                              const octave_idx_type&, const octave_idx_type&,
00075                              double*);
00076 
00077   F77_RET_T
00078   F77_FUNC (zqrinr, ZQRINR) (const octave_idx_type&, const octave_idx_type&,
00079                              Complex*, const octave_idx_type&, Complex*,
00080                              const octave_idx_type&, const octave_idx_type&,
00081                              const Complex*, double*);
00082 
00083   F77_RET_T
00084   F77_FUNC (zqrder, ZQRDER) (const octave_idx_type&, const octave_idx_type&,
00085                              Complex*, const octave_idx_type&, Complex*,
00086                              const octave_idx_type&, const octave_idx_type&,
00087                              Complex*, double*);
00088 
00089   F77_RET_T
00090   F77_FUNC (zqrshc, ZQRSHC) (const octave_idx_type&, const octave_idx_type&,
00091                              const octave_idx_type&, Complex*,
00092                              const octave_idx_type&, Complex*,
00093                              const octave_idx_type&, const octave_idx_type&,
00094                              const octave_idx_type&, Complex*, double*);
00095 
00096 #endif
00097 }
00098 
00099 ComplexQR::ComplexQR (const ComplexMatrix& a, qr_type_t qr_type)
00100 {
00101   init (a, qr_type);
00102 }
00103 
00104 void
00105 ComplexQR::init (const ComplexMatrix& a, qr_type_t qr_type)
00106 {
00107   octave_idx_type m = a.rows ();
00108   octave_idx_type n = a.cols ();
00109 
00110   octave_idx_type min_mn = m < n ? m : n;
00111   OCTAVE_LOCAL_BUFFER (Complex, tau, min_mn);
00112 
00113   octave_idx_type info = 0;
00114 
00115   ComplexMatrix afact = a;
00116   if (m > n && qr_type == qr_type_std)
00117     afact.resize (m, m);
00118 
00119   if (m > 0)
00120     {
00121       // workspace query.
00122       Complex clwork;
00123       F77_XFCN (zgeqrf, ZGEQRF, (m, n, afact.fortran_vec (), m, tau, &clwork, -1, info));
00124 
00125       // allocate buffer and do the job.
00126       octave_idx_type lwork = clwork.real ();
00127       lwork = std::max (lwork, static_cast<octave_idx_type> (1));
00128       OCTAVE_LOCAL_BUFFER (Complex, work, lwork);
00129       F77_XFCN (zgeqrf, ZGEQRF, (m, n, afact.fortran_vec (), m, tau, work, lwork, info));
00130     }
00131 
00132   form (n, afact, tau, qr_type);
00133 }
00134 
00135 void ComplexQR::form (octave_idx_type n, ComplexMatrix& afact,
00136                       Complex *tau, qr_type_t qr_type)
00137 {
00138   octave_idx_type m = afact.rows (), min_mn = std::min (m, n);
00139   octave_idx_type info;
00140 
00141   if (qr_type == qr_type_raw)
00142     {
00143       for (octave_idx_type j = 0; j < min_mn; j++)
00144         {
00145           octave_idx_type limit = j < min_mn - 1 ? j : min_mn - 1;
00146           for (octave_idx_type i = limit + 1; i < m; i++)
00147             afact.elem (i, j) *= tau[j];
00148         }
00149 
00150       r = afact;
00151     }
00152   else
00153     {
00154       // Attempt to minimize copying.
00155       if (m >= n)
00156         {
00157           // afact will become q.
00158           q = afact;
00159           octave_idx_type k = qr_type == qr_type_economy ? n : m;
00160           r = ComplexMatrix (k, n);
00161           for (octave_idx_type j = 0; j < n; j++)
00162             {
00163               octave_idx_type i = 0;
00164               for (; i <= j; i++)
00165                 r.xelem (i, j) = afact.xelem (i, j);
00166               for (;i < k; i++)
00167                 r.xelem (i, j) = 0;
00168             }
00169           afact = ComplexMatrix (); // optimize memory
00170         }
00171       else
00172         {
00173           // afact will become r.
00174           q = ComplexMatrix (m, m);
00175           for (octave_idx_type j = 0; j < m; j++)
00176             for (octave_idx_type i = j + 1; i < m; i++)
00177               {
00178                 q.xelem (i, j) = afact.xelem (i, j);
00179                 afact.xelem (i, j) = 0;
00180               }
00181           r = afact;
00182         }
00183 
00184 
00185       if (m > 0)
00186         {
00187           octave_idx_type k = q.columns ();
00188           // workspace query.
00189           Complex clwork;
00190           F77_XFCN (zungqr, ZUNGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
00191                                      &clwork, -1, info));
00192 
00193           // allocate buffer and do the job.
00194           octave_idx_type lwork = clwork.real ();
00195           lwork = std::max (lwork, static_cast<octave_idx_type> (1));
00196           OCTAVE_LOCAL_BUFFER (Complex, work, lwork);
00197           F77_XFCN (zungqr, ZUNGQR, (m, k, min_mn, q.fortran_vec (), m, tau,
00198                                      work, lwork, info));
00199         }
00200     }
00201 }
00202 
00203 #ifdef HAVE_QRUPDATE
00204 
00205 void
00206 ComplexQR::update (const ComplexColumnVector& u, const ComplexColumnVector& v)
00207 {
00208   octave_idx_type m = q.rows ();
00209   octave_idx_type n = r.columns ();
00210   octave_idx_type k = q.columns ();
00211 
00212   if (u.length () == m && v.length () == n)
00213     {
00214       ComplexColumnVector utmp = u, vtmp = v;
00215       OCTAVE_LOCAL_BUFFER (Complex, w, k);
00216       OCTAVE_LOCAL_BUFFER (double, rw, k);
00217       F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), m, r.fortran_vec (), k,
00218                                  utmp.fortran_vec (), vtmp.fortran_vec (), w, rw));
00219     }
00220   else
00221     (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch");
00222 }
00223 
00224 void
00225 ComplexQR::update (const ComplexMatrix& u, const ComplexMatrix& v)
00226 {
00227   octave_idx_type m = q.rows ();
00228   octave_idx_type n = r.columns ();
00229   octave_idx_type k = q.columns ();
00230 
00231   if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
00232     {
00233       OCTAVE_LOCAL_BUFFER (Complex, w, k);
00234       OCTAVE_LOCAL_BUFFER (double, rw, k);
00235       for (volatile octave_idx_type i = 0; i < u.cols (); i++)
00236         {
00237           ComplexColumnVector utmp = u.column (i), vtmp = v.column (i);
00238           F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), m, r.fortran_vec (), k,
00239                                      utmp.fortran_vec (), vtmp.fortran_vec (), w, rw));
00240         }
00241     }
00242   else
00243     (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch");
00244 }
00245 
00246 void
00247 ComplexQR::insert_col (const ComplexColumnVector& u, octave_idx_type j)
00248 {
00249   octave_idx_type m = q.rows ();
00250   octave_idx_type n = r.columns ();
00251   octave_idx_type k = q.columns ();
00252 
00253   if (u.length () != m)
00254     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00255   else if (j < 0 || j > n)
00256     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00257   else
00258     {
00259       if (k < m)
00260         {
00261           q.resize (m, k+1);
00262           r.resize (k+1, n+1);
00263         }
00264       else
00265         {
00266           r.resize (k, n+1);
00267         }
00268 
00269       ComplexColumnVector utmp = u;
00270       OCTAVE_LOCAL_BUFFER (double, rw, k);
00271       F77_XFCN (zqrinc, ZQRINC, (m, n, k, q.fortran_vec (), q.rows (),
00272                                  r.fortran_vec (), r.rows (), j + 1,
00273                                  utmp.data (), rw));
00274     }
00275 }
00276 
00277 void
00278 ComplexQR::insert_col (const ComplexMatrix& u, const Array<octave_idx_type>& j)
00279 {
00280   octave_idx_type m = q.rows ();
00281   octave_idx_type n = r.columns ();
00282   octave_idx_type k = q.columns ();
00283 
00284   Array<octave_idx_type> jsi;
00285   Array<octave_idx_type> js = j.sort (jsi, 0, ASCENDING);
00286   octave_idx_type nj = js.length ();
00287   bool dups = false;
00288   for (octave_idx_type i = 0; i < nj - 1; i++)
00289     dups = dups && js(i) == js(i+1);
00290 
00291   if (dups)
00292     (*current_liboctave_error_handler) ("qrinsert: duplicate index detected");
00293   else if (u.length () != m || u.columns () != nj)
00294     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00295   else if (nj > 0 && (js(0) < 0 || js(nj-1) > n))
00296     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00297   else if (nj > 0)
00298     {
00299       octave_idx_type kmax = std::min (k + nj, m);
00300       if (k < m)
00301         {
00302           q.resize (m, kmax);
00303           r.resize (kmax, n + nj);
00304         }
00305       else
00306         {
00307           r.resize (k, n + nj);
00308         }
00309 
00310       OCTAVE_LOCAL_BUFFER (double, rw, kmax);
00311       for (volatile octave_idx_type i = 0; i < js.length (); i++)
00312         {
00313           octave_idx_type ii = i;
00314           ComplexColumnVector utmp = u.column (jsi(i));
00315           F77_XFCN (zqrinc, ZQRINC, (m, n + ii, std::min (kmax, k + ii),
00316                                      q.fortran_vec (), q.rows (),
00317                                      r.fortran_vec (), r.rows (), js(ii) + 1,
00318                                      utmp.data (), rw));
00319         }
00320     }
00321 }
00322 
00323 void
00324 ComplexQR::delete_col (octave_idx_type j)
00325 {
00326   octave_idx_type m = q.rows ();
00327   octave_idx_type k = r.rows ();
00328   octave_idx_type n = r.columns ();
00329 
00330   if (j < 0 || j > n-1)
00331     (*current_liboctave_error_handler) ("qrdelete: index out of range");
00332   else
00333     {
00334       OCTAVE_LOCAL_BUFFER (double, rw, k);
00335       F77_XFCN (zqrdec, ZQRDEC, (m, n, k, q.fortran_vec (), q.rows (),
00336                                  r.fortran_vec (), r.rows (), j + 1, rw));
00337 
00338       if (k < m)
00339         {
00340           q.resize (m, k-1);
00341           r.resize (k-1, n-1);
00342         }
00343       else
00344         {
00345           r.resize (k, n-1);
00346         }
00347     }
00348 }
00349 
00350 void
00351 ComplexQR::delete_col (const Array<octave_idx_type>& j)
00352 {
00353   octave_idx_type m = q.rows ();
00354   octave_idx_type n = r.columns ();
00355   octave_idx_type k = q.columns ();
00356 
00357   Array<octave_idx_type> jsi;
00358   Array<octave_idx_type> js = j.sort (jsi, 0, DESCENDING);
00359   octave_idx_type nj = js.length ();
00360   bool dups = false;
00361   for (octave_idx_type i = 0; i < nj - 1; i++)
00362     dups = dups && js(i) == js(i+1);
00363 
00364   if (dups)
00365     (*current_liboctave_error_handler) ("qrinsert: duplicate index detected");
00366   else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0))
00367     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00368   else if (nj > 0)
00369     {
00370       OCTAVE_LOCAL_BUFFER (double, rw, k);
00371       for (volatile octave_idx_type i = 0; i < js.length (); i++)
00372         {
00373           octave_idx_type ii = i;
00374           F77_XFCN (zqrdec, ZQRDEC, (m, n - ii, k == m ? k : k - ii,
00375                                      q.fortran_vec (), q.rows (),
00376                                      r.fortran_vec (), r.rows (), js(ii) + 1, rw));
00377         }
00378       if (k < m)
00379         {
00380           q.resize (m, k - nj);
00381           r.resize (k - nj, n - nj);
00382         }
00383       else
00384         {
00385           r.resize (k, n - nj);
00386         }
00387 
00388     }
00389 }
00390 
00391 void
00392 ComplexQR::insert_row (const ComplexRowVector& u, octave_idx_type j)
00393 {
00394   octave_idx_type m = r.rows ();
00395   octave_idx_type n = r.columns ();
00396   octave_idx_type k = std::min (m, n);
00397 
00398   if (! q.is_square () || u.length () != n)
00399     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00400   else if (j < 0 || j > m)
00401     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00402   else
00403     {
00404       q.resize (m + 1, m + 1);
00405       r.resize (m + 1, n);
00406       ComplexRowVector utmp = u;
00407       OCTAVE_LOCAL_BUFFER (double, rw, k);
00408       F77_XFCN (zqrinr, ZQRINR, (m, n, q.fortran_vec (), q.rows (),
00409                                  r.fortran_vec (), r.rows (),
00410                                  j + 1, utmp.fortran_vec (), rw));
00411 
00412     }
00413 }
00414 
00415 void
00416 ComplexQR::delete_row (octave_idx_type j)
00417 {
00418   octave_idx_type m = r.rows ();
00419   octave_idx_type n = r.columns ();
00420 
00421   if (! q.is_square ())
00422     (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch");
00423   else if (j < 0 || j > m-1)
00424     (*current_liboctave_error_handler) ("qrdelete: index out of range");
00425   else
00426     {
00427       OCTAVE_LOCAL_BUFFER (Complex, w, m);
00428       OCTAVE_LOCAL_BUFFER (double, rw, m);
00429       F77_XFCN (zqrder, ZQRDER, (m, n, q.fortran_vec (), q.rows (),
00430                                  r.fortran_vec (), r.rows (), j + 1,
00431                                  w, rw));
00432 
00433       q.resize (m - 1, m - 1);
00434       r.resize (m - 1, n);
00435     }
00436 }
00437 
00438 void
00439 ComplexQR::shift_cols (octave_idx_type i, octave_idx_type j)
00440 {
00441   octave_idx_type m = q.rows ();
00442   octave_idx_type k = r.rows ();
00443   octave_idx_type n = r.columns ();
00444 
00445   if (i < 0 || i > n-1 || j < 0 || j > n-1)
00446     (*current_liboctave_error_handler) ("qrshift: index out of range");
00447   else
00448     {
00449       OCTAVE_LOCAL_BUFFER (Complex, w, k);
00450       OCTAVE_LOCAL_BUFFER (double, rw, k);
00451       F77_XFCN (zqrshc, ZQRSHC, (m, n, k,
00452                                  q.fortran_vec (), q.rows (),
00453                                  r.fortran_vec (), r.rows (),
00454                                  i + 1, j + 1, w, rw));
00455     }
00456 }
00457 
00458 #else
00459 
00460 // Replacement update methods.
00461 
00462 void
00463 ComplexQR::update (const ComplexColumnVector& u, const ComplexColumnVector& v)
00464 {
00465   warn_qrupdate_once ();
00466 
00467   octave_idx_type m = q.rows ();
00468   octave_idx_type n = r.columns ();
00469 
00470   if (u.length () == m && v.length () == n)
00471     {
00472       init(q*r + ComplexMatrix (u) * ComplexMatrix (v).hermitian (), get_type ());
00473     }
00474   else
00475     (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch");
00476 }
00477 
00478 void
00479 ComplexQR::update (const ComplexMatrix& u, const ComplexMatrix& v)
00480 {
00481   warn_qrupdate_once ();
00482 
00483   octave_idx_type m = q.rows ();
00484   octave_idx_type n = r.columns ();
00485 
00486   if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
00487     {
00488       init(q*r + u * v.hermitian (), get_type ());
00489     }
00490   else
00491     (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch");
00492 }
00493 
00494 static
00495 ComplexMatrix insert_col (const ComplexMatrix& a, octave_idx_type i,
00496                           const ComplexColumnVector& x)
00497 {
00498   ComplexMatrix retval (a.rows (), a.columns () + 1);
00499   retval.assign (idx_vector::colon, idx_vector (0, i),
00500                  a.index (idx_vector::colon, idx_vector (0, i)));
00501   retval.assign (idx_vector::colon, idx_vector (i), x);
00502   retval.assign (idx_vector::colon, idx_vector (i+1, retval.columns ()),
00503                  a.index (idx_vector::colon, idx_vector (i, a.columns ())));
00504   return retval;
00505 }
00506 
00507 static
00508 ComplexMatrix insert_row (const ComplexMatrix& a, octave_idx_type i,
00509                           const ComplexRowVector& x)
00510 {
00511   ComplexMatrix retval (a.rows () + 1, a.columns ());
00512   retval.assign (idx_vector (0, i), idx_vector::colon,
00513                  a.index (idx_vector (0, i), idx_vector::colon));
00514   retval.assign (idx_vector (i), idx_vector::colon, x);
00515   retval.assign (idx_vector (i+1, retval.rows ()), idx_vector::colon,
00516                  a.index (idx_vector (i, a.rows ()), idx_vector::colon));
00517   return retval;
00518 }
00519 
00520 static
00521 ComplexMatrix delete_col (const ComplexMatrix& a, octave_idx_type i)
00522 {
00523   ComplexMatrix retval = a;
00524   retval.delete_elements (1, idx_vector (i));
00525   return retval;
00526 }
00527 
00528 static
00529 ComplexMatrix delete_row (const ComplexMatrix& a, octave_idx_type i)
00530 {
00531   ComplexMatrix retval = a;
00532   retval.delete_elements (0, idx_vector (i));
00533   return retval;
00534 }
00535 
00536 static
00537 ComplexMatrix shift_cols (const ComplexMatrix& a,
00538                           octave_idx_type i, octave_idx_type j)
00539 {
00540   octave_idx_type n = a.columns ();
00541   Array<octave_idx_type> p (n);
00542   for (octave_idx_type k = 0; k < n; k++) p(k) = k;
00543   if (i < j)
00544     {
00545       for (octave_idx_type k = i; k < j; k++) p(k) = k+1;
00546       p(j) = i;
00547     }
00548   else if (j < i)
00549     {
00550       p(j) = i;
00551       for (octave_idx_type k = j+1; k < i+1; k++) p(k) = k-1;
00552     }
00553 
00554   return a.index (idx_vector::colon, idx_vector (p));
00555 }
00556 
00557 void
00558 ComplexQR::insert_col (const ComplexColumnVector& u, octave_idx_type j)
00559 {
00560   warn_qrupdate_once ();
00561 
00562   octave_idx_type m = q.rows ();
00563   octave_idx_type n = r.columns ();
00564 
00565   if (u.length () != m)
00566     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00567   else if (j < 0 || j > n)
00568     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00569   else
00570     {
00571       init (::insert_col (q*r, j, u), get_type ());
00572     }
00573 }
00574 
00575 void
00576 ComplexQR::insert_col (const ComplexMatrix& u, const Array<octave_idx_type>& j)
00577 {
00578   warn_qrupdate_once ();
00579 
00580   octave_idx_type m = q.rows ();
00581   octave_idx_type n = r.columns ();
00582 
00583   Array<octave_idx_type> jsi;
00584   Array<octave_idx_type> js = j.sort (jsi, 0, ASCENDING);
00585   octave_idx_type nj = js.length ();
00586   bool dups = false;
00587   for (octave_idx_type i = 0; i < nj - 1; i++)
00588     dups = dups && js(i) == js(i+1);
00589 
00590   if (dups)
00591     (*current_liboctave_error_handler) ("qrinsert: duplicate index detected");
00592   else if (u.length () != m || u.columns () != nj)
00593     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00594   else if (nj > 0 && (js(0) < 0 || js(nj-1) > n))
00595     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00596   else if (nj > 0)
00597     {
00598       ComplexMatrix a = q*r;
00599       for (octave_idx_type i = 0; i < js.length (); i++)
00600         a = ::insert_col (a, js(i), u.column (i));
00601       init (a, get_type ());
00602     }
00603 }
00604 
00605 void
00606 ComplexQR::delete_col (octave_idx_type j)
00607 {
00608   warn_qrupdate_once ();
00609 
00610   octave_idx_type m = q.rows ();
00611   octave_idx_type n = r.columns ();
00612 
00613   if (j < 0 || j > n-1)
00614     (*current_liboctave_error_handler) ("qrdelete: index out of range");
00615   else
00616     {
00617       init (::delete_col (q*r, j), get_type ());
00618     }
00619 }
00620 
00621 void
00622 ComplexQR::delete_col (const Array<octave_idx_type>& j)
00623 {
00624   warn_qrupdate_once ();
00625 
00626   octave_idx_type m = q.rows ();
00627   octave_idx_type n = r.columns ();
00628 
00629   Array<octave_idx_type> jsi;
00630   Array<octave_idx_type> js = j.sort (jsi, 0, DESCENDING);
00631   octave_idx_type nj = js.length ();
00632   bool dups = false;
00633   for (octave_idx_type i = 0; i < nj - 1; i++)
00634     dups = dups && js(i) == js(i+1);
00635 
00636   if (dups)
00637     (*current_liboctave_error_handler) ("qrinsert: duplicate index detected");
00638   else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0))
00639     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00640   else if (nj > 0)
00641     {
00642       ComplexMatrix a = q*r;
00643       for (octave_idx_type i = 0; i < js.length (); i++)
00644         a = ::delete_col (a, js(i));
00645       init (a, get_type ());
00646     }
00647 }
00648 
00649 void
00650 ComplexQR::insert_row (const ComplexRowVector& u, octave_idx_type j)
00651 {
00652   warn_qrupdate_once ();
00653 
00654   octave_idx_type m = r.rows ();
00655   octave_idx_type n = r.columns ();
00656 
00657   if (! q.is_square () || u.length () != n)
00658     (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch");
00659   else if (j < 0 || j > m)
00660     (*current_liboctave_error_handler) ("qrinsert: index out of range");
00661   else
00662     {
00663       init (::insert_row (q*r, j, u), get_type ());
00664     }
00665 }
00666 
00667 void
00668 ComplexQR::delete_row (octave_idx_type j)
00669 {
00670   warn_qrupdate_once ();
00671 
00672   octave_idx_type m = r.rows ();
00673   octave_idx_type n = r.columns ();
00674 
00675   if (! q.is_square ())
00676     (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch");
00677   else if (j < 0 || j > m-1)
00678     (*current_liboctave_error_handler) ("qrdelete: index out of range");
00679   else
00680     {
00681       init (::delete_row (q*r, j), get_type ());
00682     }
00683 }
00684 
00685 void
00686 ComplexQR::shift_cols (octave_idx_type i, octave_idx_type j)
00687 {
00688   warn_qrupdate_once ();
00689 
00690   octave_idx_type m = q.rows ();
00691   octave_idx_type n = r.columns ();
00692 
00693   if (i < 0 || i > n-1 || j < 0 || j > n-1)
00694     (*current_liboctave_error_handler) ("qrshift: index out of range");
00695   else
00696     {
00697       init (::shift_cols (q*r, i, j), get_type ());
00698     }
00699 }
00700 
00701 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines