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
fCmplxLU.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 "fCmplxLU.h"
29 #include "f77-fcn.h"
30 #include "lo-error.h"
31 #include "oct-locbuf.h"
32 #include "fCColVector.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 <FloatComplexMatrix>;
40 
41 // Define the constructor for this particular derivation.
42 
43 extern "C"
44 {
45  F77_RET_T
46  F77_FUNC (cgetrf, CGETRF) (const octave_idx_type&, const octave_idx_type&,
47  FloatComplex*, const octave_idx_type&,
48  octave_idx_type*, octave_idx_type&);
49 
50 #ifdef HAVE_QRUPDATE_LUU
51  F77_RET_T
52  F77_FUNC (clu1up, CLU1UP) (const octave_idx_type&, const octave_idx_type&,
53  FloatComplex *, const octave_idx_type&,
54  FloatComplex *, const octave_idx_type&,
55  FloatComplex *, FloatComplex *);
56 
57  F77_RET_T
58  F77_FUNC (clup1up, CLUP1UP) (const octave_idx_type&, const octave_idx_type&,
59  FloatComplex *, const octave_idx_type&,
60  FloatComplex *, const octave_idx_type&,
61  octave_idx_type *, const FloatComplex *,
62  const FloatComplex *, FloatComplex *);
63 #endif
64 }
65 
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  FloatComplex *tmp_data = a_fact.fortran_vec ();
77 
78  octave_idx_type info = 0;
79 
80  F77_XFCN (cgetrf, CGETRF, (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 
89  const FloatComplexColumnVector& v)
90 {
91  if (packed ())
92  unpack ();
93 
96 
97  octave_idx_type m = l.rows ();
98  octave_idx_type n = r.columns ();
99  octave_idx_type k = l.columns ();
100 
101  if (u.length () == m && v.length () == n)
102  {
103  FloatComplexColumnVector utmp = u, vtmp = v;
104  F77_XFCN (clu1up, CLU1UP, (m, n, l.fortran_vec (), m, r.fortran_vec (), k,
105  utmp.fortran_vec (), vtmp.fortran_vec ()));
106  }
107  else
108  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
109 }
110 
112  const FloatComplexMatrix& v)
113 {
114  if (packed ())
115  unpack ();
116 
119 
120  octave_idx_type m = l.rows ();
121  octave_idx_type n = r.columns ();
122  octave_idx_type k = l.columns ();
123 
124  if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
125  {
126  for (volatile octave_idx_type i = 0; i < u.cols (); i++)
127  {
128  FloatComplexColumnVector utmp = u.column (i), vtmp = v.column (i);
129  F77_XFCN (clu1up, CLU1UP, (m, n, l.fortran_vec (),
130  m, r.fortran_vec (), k,
131  utmp.fortran_vec (), vtmp.fortran_vec ()));
132  }
133  }
134  else
135  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
136 }
137 
139  const FloatComplexColumnVector& v)
140 {
141  if (packed ())
142  unpack ();
143 
146 
147  octave_idx_type m = l.rows ();
148  octave_idx_type n = r.columns ();
149  octave_idx_type k = l.columns ();
150 
151  if (u.length () == m && v.length () == n)
152  {
153  FloatComplexColumnVector utmp = u, vtmp = v;
155  for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment
156  F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (),
157  m, r.fortran_vec (), k,
158  ipvt.fortran_vec (),
159  utmp.data (), vtmp.data (), w));
160  for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement
161  }
162  else
163  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
164 }
165 
167  const FloatComplexMatrix& v)
168 {
169  if (packed ())
170  unpack ();
171 
174 
175  octave_idx_type m = l.rows ();
176  octave_idx_type n = r.columns ();
177  octave_idx_type k = l.columns ();
178 
179  if (u.rows () == m && v.rows () == n && u.cols () == v.cols ())
180  {
182  for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment
183  for (volatile octave_idx_type i = 0; i < u.cols (); i++)
184  {
185  FloatComplexColumnVector utmp = u.column (i), vtmp = v.column (i);
186  F77_XFCN (clup1up, CLUP1UP, (m, n, l.fortran_vec (),
187  m, r.fortran_vec (), k,
188  ipvt.fortran_vec (),
189  utmp.data (), vtmp.data (), w));
190  }
191  for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement
192  }
193  else
194  (*current_liboctave_error_handler) ("luupdate: dimensions mismatch");
195 }
196 
197 #else
198 
201 {
202  (*current_liboctave_error_handler)
203  ("luupdate: not available in this version");
204 }
205 
207  const FloatComplexMatrix&)
208 {
209  (*current_liboctave_error_handler)
210  ("luupdate: not available in this version");
211 }
212 
215 {
216  (*current_liboctave_error_handler)
217  ("luupdate: not available in this version");
218 }
219 
221  const FloatComplexMatrix&)
222 {
223  (*current_liboctave_error_handler)
224  ("luupdate: not available in this version");
225 }
226 
227 #endif