GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sparse-base-lu.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2015 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "sparse-base-lu.h"
29 
30 #include "PermMatrix.h"
31 
32 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
33 lu_type
35 {
36  octave_idx_type nr = Lfact.rows ();
37  octave_idx_type nz = Lfact.cols ();
38  octave_idx_type nc = Ufact.cols ();
39 
40  lu_type Yout (nr, nc, Lfact.nnz () + Ufact.nnz () - (nr<nz?nr:nz));
41  octave_idx_type ii = 0;
42  Yout.xcidx (0) = 0;
43 
44  for (octave_idx_type j = 0; j < nc; j++)
45  {
46  for (octave_idx_type i = Ufact.cidx (j); i < Ufact.cidx (j + 1); i++)
47  {
48  Yout.xridx (ii) = Ufact.ridx (i);
49  Yout.xdata (ii++) = Ufact.data (i);
50  }
51  if (j < nz)
52  {
53  // Note the +1 skips the 1.0 on the diagonal
54  for (octave_idx_type i = Lfact.cidx (j) + 1;
55  i < Lfact.cidx (j +1); i++)
56  {
57  Yout.xridx (ii) = Lfact.ridx (i);
58  Yout.xdata (ii++) = Lfact.data (i);
59  }
60  }
61  Yout.xcidx (j + 1) = ii;
62  }
63 
64  return Yout;
65 }
66 
67 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
68 p_type
70 {
71 
72  octave_idx_type nr = Lfact.rows ();
73 
74  p_type Pout (nr, nr, nr);
75 
76  for (octave_idx_type i = 0; i < nr; i++)
77  {
78  Pout.cidx (i) = i;
79  Pout.ridx (P (i)) = i;
80  Pout.data (i) = 1;
81  }
82  Pout.cidx (nr) = nr;
83 
84  return Pout;
85 }
86 
87 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
90 {
91 
92  octave_idx_type nr = Lfact.rows ();
93 
94  ColumnVector Pout (nr);
95 
96  for (octave_idx_type i = 0; i < nr; i++)
97  Pout.xelem (i) = static_cast<double> (P(i) + 1);
98 
99  return Pout;
100 }
101 
102 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
105 {
106  return PermMatrix (P, false);
107 }
108 
109 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
110 p_type
112 {
113  octave_idx_type nc = Ufact.cols ();
114 
115  p_type Pout (nc, nc, nc);
116 
117  for (octave_idx_type i = 0; i < nc; i++)
118  {
119  Pout.cidx (i) = i;
120  Pout.ridx (i) = Q (i);
121  Pout.data (i) = 1;
122  }
123  Pout.cidx (nc) = nc;
124 
125  return Pout;
126 }
127 
128 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
131 {
132 
133  octave_idx_type nc = Ufact.cols ();
134 
135  ColumnVector Pout (nc);
136 
137  for (octave_idx_type i = 0; i < nc; i++)
138  Pout.xelem (i) = static_cast<double> (Q(i) + 1);
139 
140  return Pout;
141 }
142 
143 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type>
146 {
147  return PermMatrix (Q, true);
148 }
T & xelem(octave_idx_type n)
Definition: Array.h:353
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type double const octave_idx_type double const octave_idx_type double * Q
Definition: qz.cc:114