メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

dbleQRP.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00024 #pragma implementation
00025 #endif
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030 
00031 #include <cassert>
00032 
00033 #include "dbleQRP.h"
00034 #include "f77-fcn.h"
00035 #include "lo-error.h"
00036 
00037 extern "C"
00038 {
00039   F77_RET_T
00040   F77_FUNC (dgeqpf, DGEQPF) (const int&, const int&, double*,
00041                              const int&, int*, double*, double*, int&);
00042 
00043   F77_RET_T
00044   F77_FUNC (dorgqr, DORGQR) (const int&, const int&, const int&,
00045                              double*, const int&, double*, double*,
00046                              const int&, int&);
00047 }
00048 
00049 // It would be best to share some of this code with QR class...
00050 
00051 QRP::QRP (const Matrix& a, QR::type qr_type)
00052   : QR (), p ()
00053 {
00054   init (a, qr_type);
00055 }
00056 
00057 void
00058 QRP::init (const Matrix& a, QR::type qr_type)
00059 {
00060   assert (qr_type != QR::raw);
00061 
00062   int m = a.rows ();
00063   int n = a.cols ();
00064 
00065   if (m == 0 || n == 0)
00066     {
00067       (*current_liboctave_error_handler) ("QR must have non-empty matrix");
00068       return;
00069     }
00070 
00071   int min_mn = m < n ? m : n;
00072   Array<double> tau (min_mn);
00073   double *ptau = tau.fortran_vec ();
00074 
00075   int lwork = 3*n > 32*m ? 3*n : 32*m;
00076   Array<double> work (lwork);
00077   double *pwork = work.fortran_vec ();
00078 
00079   int info = 0;
00080 
00081   Matrix A_fact = a;
00082   if (m > n && qr_type != QR::economy)
00083     A_fact.resize (m, m, 0.0);
00084 
00085   double *tmp_data = A_fact.fortran_vec ();
00086 
00087   Array<int> jpvt (n, 0);
00088   int *pjpvt = jpvt.fortran_vec ();
00089 
00090   // Code to enforce a certain permutation could go here...
00091 
00092   F77_XFCN (dgeqpf, DGEQPF, (m, n, tmp_data, m, pjpvt, ptau, pwork, info));
00093 
00094   if (f77_exception_encountered)
00095     (*current_liboctave_error_handler) ("unrecoverable error in dgeqpf");
00096   else
00097     {
00098       // Form Permutation matrix (if economy is requested, return the
00099       // indices only!)
00100 
00101       if (qr_type == QR::economy)
00102         {
00103           p.resize (1, n, 0.0);
00104           for (int j = 0; j < n; j++)
00105             p.elem (0, j) = jpvt.elem (j);
00106         }
00107       else
00108         {
00109           p.resize (n, n, 0.0);
00110           for (int j = 0; j < n; j++)
00111             p.elem (jpvt.elem (j) - 1, j) = 1.0;
00112         }
00113 
00114       int n2 = (qr_type == QR::economy) ? min_mn : m;
00115 
00116       if (qr_type == QR::economy && m > n)
00117         r.resize (n, n, 0.0);
00118       else
00119         r.resize (m, n, 0.0);
00120 
00121       for (int j = 0; j < n; j++)
00122         {
00123           int limit = j < min_mn-1 ? j : min_mn-1;
00124           for (int i = 0; i <= limit; i++)
00125             r.elem (i, j) = A_fact.elem (i, j);
00126         }
00127 
00128       F77_XFCN (dorgqr, DORGQR, (m, n2, min_mn, tmp_data, m, ptau,
00129                                  pwork, lwork, info));
00130 
00131       if (f77_exception_encountered)
00132         (*current_liboctave_error_handler) ("unrecoverable error in dorgqr");
00133       else
00134         {
00135           q = A_fact;
00136           q.resize (m, n2);
00137         }
00138     }
00139 }
00140 
00141 /*
00142 ;;; Local Variables: ***
00143 ;;; mode: C++ ***
00144 ;;; End: ***
00145 */

Wed Dec 29 11:51:11 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送