GNU Octave  3.8.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
dbleLU.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
4 Copyright (C) 2009 VZLU Prague, a.s.
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 "dbleLU.h"
29 #include "f77-fcn.h"
30 #include "lo-error.h"
31 #include "oct-locbuf.h"
32 #include "dColVector.h"
33 
34 // Instantiate the base LU class for the types we need.
35 
36 #include "base-lu.h"
37 #include "base-lu.cc"
38 
39 template class base_lu <Matrix>;
40 
41 // Define the constructor for this particular derivation.
42 
43 extern "C"
44 {
45  F77_RET_T
46  F77_FUNC (dgetrf, DGETRF) (const octave_idx_type&, const octave_idx_type&,
47  double*, const octave_idx_type&,
48  octave_idx_type*, octave_idx_type&);
49 
50 #ifdef HAVE_QRUPDATE_LUU
51  F77_RET_T
52  F77_FUNC (dlu1up, DLU1UP) (const octave_idx_type&, const octave_idx_type&,
53  double *, const octave_idx_type&,
54  double *, const octave_idx_type&,
55  double *, double *);
56 
57  F77_RET_T
58  F77_FUNC (dlup1up, DLUP1UP) (const octave_idx_type&, const octave_idx_type&,
59  double *, const octave_idx_type&,
60  double *, const octave_idx_type&,
61  octave_idx_type *, const double *,
62  const double *, double *);
63 #endif
64 }
65 
66 LU::LU (const Matrix& a)
67 {
68  octave_idx_type a_nr = a.rows ();
69  octave_idx_type a_nc = a.cols ();
70  octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc);
71 
72  ipvt.resize (dim_vector (mn, 1));
73  octave_idx_type *pipvt = ipvt.fortran_vec ();
74 
75  a_fact = a;
76  double *tmp_data = a_fact.fortran_vec ();
77 
78  octave_idx_type info = 0;
79 
80  F77_XFCN (dgetrf, DGETRF, (a_nr, a_nc, tmp_data, a_nr, pipvt, info));
81 
82  for (octave_idx_type i = 0; i < mn; i++)
83  pipvt[i] -= 1;
84 }
85 
86 #ifdef HAVE_QRUPDATE_LUU
87 
88 void LU::update (const ColumnVector& u, const ColumnVector& v)
89 {
90  if (packed ())
91  unpack ();
92 
93  Matrix& l = l_fact;
94  Matrix& r = a_fact;
95 
96  octave_idx_type m = l.rows ();
97  octave_idx_type n = r.columns ();
98  octave_idx_type k = l.columns ();
99 
100  if (u.length () == m && v.length () == n)
101  {
102  ColumnVector utmp = u, vtmp = v;
103  F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k,
104  utmp.fortran_vec (), vtmp.fortran_vec ()));
105  }
106  else
107  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
108 }
109 
110 void LU::update (const Matrix& u, const Matrix& v)
111 {
112  if (packed ())
113  unpack ();
114 
115  Matrix& l = l_fact;
116  Matrix& r = a_fact;
117 
118  octave_idx_type m = l.rows ();
119  octave_idx_type n = r.columns ();
120  octave_idx_type k = l.columns ();
121 
122  if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
123  {
124  for (volatile octave_idx_type i = 0; i < u.cols (); i++)
125  {
126  ColumnVector utmp = u.column (i), vtmp = v.column (i);
127  F77_XFCN (dlu1up, DLU1UP, (m, n, l.fortran_vec (),
128  m, r.fortran_vec (), k,
129  utmp.fortran_vec (), vtmp.fortran_vec ()));
130  }
131  }
132  else
133  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
134 }
135 
136 void LU::update_piv (const ColumnVector& u, const ColumnVector& v)
137 {
138  if (packed ())
139  unpack ();
140 
141  Matrix& l = l_fact;
142  Matrix& r = a_fact;
143 
144  octave_idx_type m = l.rows ();
145  octave_idx_type n = r.columns ();
146  octave_idx_type k = l.columns ();
147 
148  if (u.length () == m && v.length () == n)
149  {
150  ColumnVector utmp = u, vtmp = v;
151  OCTAVE_LOCAL_BUFFER (double, w, m);
152  for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment
153  F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (),
154  m, r.fortran_vec (), k,
155  ipvt.fortran_vec (),
156  utmp.data (), vtmp.data (), w));
157  for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement
158  }
159  else
160  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
161 }
162 
163 void LU::update_piv (const Matrix& u, const Matrix& v)
164 {
165  if (packed ())
166  unpack ();
167 
168  Matrix& l = l_fact;
169  Matrix& r = a_fact;
170 
171  octave_idx_type m = l.rows ();
172  octave_idx_type n = r.columns ();
173  octave_idx_type k = l.columns ();
174 
175  if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
176  {
177  OCTAVE_LOCAL_BUFFER (double, w, m);
178  for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment
179  for (volatile octave_idx_type i = 0; i < u.cols (); i++)
180  {
181  ColumnVector utmp = u.column (i), vtmp = v.column (i);
182  F77_XFCN (dlup1up, DLUP1UP, (m, n, l.fortran_vec (),
183  m, r.fortran_vec (), k,
184  ipvt.fortran_vec (),
185  utmp.data (), vtmp.data (), w));
186  }
187  for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement
188  }
189  else
190  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
191 }
192 
193 #else
194 
195 void LU::update (const ColumnVector&, const ColumnVector&)
196 {
197  (*current_liboctave_error_handler)
198  ("luupdate: not available in this version");
199 }
200 
201 void LU::update (const Matrix&, const Matrix&)
202 {
203  (*current_liboctave_error_handler)
204  ("luupdate: not available in this version");
205 }
206 
207 void LU::update_piv (const ColumnVector&, const ColumnVector&)
208 {
209  (*current_liboctave_error_handler)
210  ("luupdate: not available in this version");
211 }
212 
213 void LU::update_piv (const Matrix&, const Matrix&)
214 {
215  (*current_liboctave_error_handler)
216  ("luupdate: not available in this version");
217 }
218 
219 #endif