sparse-base-lu.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 David Bateman
00004 Copyright (C) 1998-2004 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "sparse-base-lu.h"
00029 
00030 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00031 lu_type
00032 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Y (void) const
00033 {
00034   octave_idx_type nr = Lfact.rows ();
00035   octave_idx_type nc = Ufact.rows ();
00036   octave_idx_type rcmin = (nr > nc ? nr : nc);
00037 
00038   lu_type Yout (nr, nc, Lfact.nnz() + Ufact.nnz());
00039   octave_idx_type ii = 0;
00040   Yout.xcidx(0) = 0;
00041 
00042   for (octave_idx_type j = 0; j < nc; j++)
00043     {
00044       for (octave_idx_type i = Ufact.cidx (j); i < Ufact.cidx(j + 1); i++)
00045         {
00046           Yout.xridx (ii) = Ufact.ridx(i);
00047           Yout.xdata (ii++) = Ufact.data(i);
00048         }
00049       if (j < rcmin)
00050         {
00051           // Note the +1 skips the 1.0 on the diagonal
00052           for (octave_idx_type i = Lfact.cidx (j) + 1;
00053                i < Lfact.cidx(j +1); i++)
00054             {
00055               Yout.xridx (ii) = Lfact.ridx(i);
00056               Yout.xdata (ii++) = Lfact.data(i);
00057             }
00058         }
00059       Yout.xcidx(j + 1) = ii;
00060     }
00061 
00062   return Yout;
00063 }
00064 
00065 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00066 p_type
00067 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pr (void) const
00068 {
00069 
00070   octave_idx_type nr = Lfact.rows ();
00071 
00072   p_type Pout (nr, nr, nr);
00073 
00074   for (octave_idx_type i = 0; i < nr; i++)
00075     {
00076       Pout.cidx (i) = i;
00077       Pout.ridx (P (i)) = i;
00078       Pout.data (i) = 1;
00079     }
00080   Pout.cidx (nr) = nr;
00081 
00082   return Pout;
00083 }
00084 
00085 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00086 ColumnVector
00087 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pr_vec (void) const
00088 {
00089 
00090   octave_idx_type nr = Lfact.rows ();
00091 
00092   ColumnVector Pout (nr);
00093 
00094   for (octave_idx_type i = 0; i < nr; i++)
00095     Pout.xelem (i) = static_cast<double> (P(i) + 1);
00096 
00097   return Pout;
00098 }
00099 
00100 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00101 PermMatrix
00102 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pr_mat (void) const
00103 {
00104   return PermMatrix (P, false);
00105 }
00106 
00107 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00108 p_type
00109 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pc (void) const
00110 {
00111   octave_idx_type nc = Ufact.cols ();
00112 
00113   p_type Pout (nc, nc, nc);
00114 
00115   for (octave_idx_type i = 0; i < nc; i++)
00116     {
00117       Pout.cidx (i) = i;
00118       Pout.ridx (i) = Q (i);
00119       Pout.data (i) = 1;
00120     }
00121   Pout.cidx (nc) = nc;
00122 
00123   return Pout;
00124 }
00125 
00126 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00127 ColumnVector
00128 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pc_vec (void) const
00129 {
00130 
00131   octave_idx_type nc = Ufact.cols ();
00132 
00133   ColumnVector Pout (nc);
00134 
00135   for (octave_idx_type i = 0; i < nc; i++)
00136     Pout.xelem (i) = static_cast<double> (Q(i) + 1);
00137 
00138   return Pout;
00139 }
00140 
00141 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
00142 PermMatrix
00143 sparse_base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: Pc_mat (void) const
00144 {
00145   return PermMatrix (Q, true);
00146 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines