Mercurial > hg > octave-nkf
annotate liboctave/numeric/floatLU.cc @ 20761:b7ac1e94266e
maint: Further clean up of functions in ode/private dir.
* AbsRel_Norm.m, fuzzy_compare.m, integrate_adaptive.m, integrate_const.m,
integrate_n_steps.m, ode_struct_value_check.m, odepkg_event_handle.m,
odepkg_structure_check.m, runge_kutta_45_dorpri.m:
Place latest copyright first in file.
Use two spaces before beginning single-line comment.
Use parentheses around variable to be tested in switch stmt.
Use space between function name and opening parenthesis.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 05 Oct 2015 12:03:16 -0700 |
parents | a9574e3c6e9e |
children |
rev | line source |
---|---|
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 /* |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
3 Copyright (C) 1994-2015 John W. Eaton |
9708 | 4 Copyright (C) 2009 VZLU Prague, a.s. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 This file is part of Octave. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 Octave is free software; you can redistribute it and/or modify it |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 under the terms of the GNU General Public License as published by the |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 Free Software Foundation; either version 3 of the License, or (at your |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 option) any later version. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 for more details. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 */ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 #include <config.h> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 #endif |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 #include "floatLU.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 #include "f77-fcn.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 #include "lo-error.h" |
9708 | 31 #include "oct-locbuf.h" |
32 #include "fColVector.h" | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 // Instantiate the base LU class for the types we need. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 |
15374
b5f28cc401b9
Use double quotes, not angle brackets, for '#include "base-lu.cc"'.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
36 #include "base-lu.h" |
b5f28cc401b9
Use double quotes, not angle brackets, for '#include "base-lu.cc"'.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
37 #include "base-lu.cc" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7810
diff
changeset
|
39 template class base_lu <FloatMatrix>; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 // Define the constructor for this particular derivation. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 extern "C" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 F77_RET_T |
11518 | 46 F77_FUNC (sgetrf, SGETRF) (const octave_idx_type&, const octave_idx_type&, |
47 float*, const octave_idx_type&, octave_idx_type*, | |
48 octave_idx_type&); | |
9708 | 49 |
50 #ifdef HAVE_QRUPDATE_LUU | |
51 F77_RET_T | |
52 F77_FUNC (slu1up, SLU1UP) (const octave_idx_type&, const octave_idx_type&, | |
53 float *, const octave_idx_type&, | |
54 float *, const octave_idx_type&, | |
55 float *, float *); | |
56 | |
57 F77_RET_T | |
58 F77_FUNC (slup1up, SLUP1UP) (const octave_idx_type&, const octave_idx_type&, | |
59 float *, const octave_idx_type&, | |
60 float *, const octave_idx_type&, | |
61 octave_idx_type *, const float *, | |
62 const float *, float *); | |
63 #endif | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
66 FloatLU::FloatLU (const FloatMatrix& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
67 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
68 octave_idx_type a_nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 octave_idx_type a_nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
70 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
71 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
72 ipvt.resize (dim_vector (mn, 1)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
73 octave_idx_type *pipvt = ipvt.fortran_vec (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 a_fact = a; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 float *tmp_data = a_fact.fortran_vec (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
78 octave_idx_type info = 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
79 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 F77_XFCN (sgetrf, SGETRF, (a_nr, a_nc, tmp_data, a_nr, pipvt, info)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
82 for (octave_idx_type i = 0; i < mn; i++) |
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
83 pipvt[i] -= 1; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
85 |
9708 | 86 #ifdef HAVE_QRUPDATE_LUU |
87 | |
88 void FloatLU::update (const FloatColumnVector& u, const FloatColumnVector& v) | |
89 { | |
90 if (packed ()) | |
91 unpack (); | |
92 | |
93 FloatMatrix& l = l_fact; | |
94 FloatMatrix& 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 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
100 if (u.numel () == m && v.numel () == n) |
9708 | 101 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
102 FloatColumnVector utmp = u; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
103 FloatColumnVector vtmp = v; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
104 F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 m, r.fortran_vec (), k, |
9708 | 106 utmp.fortran_vec (), vtmp.fortran_vec ())); |
107 } | |
108 else | |
109 (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); | |
110 } | |
111 | |
112 void FloatLU::update (const FloatMatrix& u, const FloatMatrix& v) | |
113 { | |
114 if (packed ()) | |
115 unpack (); | |
116 | |
117 FloatMatrix& l = l_fact; | |
118 FloatMatrix& r = a_fact; | |
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 { | |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
128 FloatColumnVector utmp = u.column (i); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
129 FloatColumnVector vtmp = v.column (i); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
130 F77_XFCN (slu1up, SLU1UP, (m, n, l.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
131 m, r.fortran_vec (), k, |
9708 | 132 utmp.fortran_vec (), vtmp.fortran_vec ())); |
133 } | |
134 } | |
135 else | |
136 (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); | |
137 } | |
138 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 void FloatLU::update_piv (const FloatColumnVector& u, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
140 const FloatColumnVector& v) |
9708 | 141 { |
142 if (packed ()) | |
143 unpack (); | |
144 | |
145 FloatMatrix& l = l_fact; | |
146 FloatMatrix& r = a_fact; | |
147 | |
148 octave_idx_type m = l.rows (); | |
149 octave_idx_type n = r.columns (); | |
150 octave_idx_type k = l.columns (); | |
151 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
152 if (u.numel () == m && v.numel () == n) |
9708 | 153 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
154 FloatColumnVector utmp = u; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
155 FloatColumnVector vtmp = v; |
9708 | 156 OCTAVE_LOCAL_BUFFER (float, w, m); |
157 for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
158 F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 m, r.fortran_vec (), k, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 ipvt.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 utmp.data (), vtmp.data (), w)); |
9708 | 162 for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement |
163 } | |
164 else | |
165 (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); | |
166 } | |
167 | |
168 void FloatLU::update_piv (const FloatMatrix& u, const FloatMatrix& v) | |
169 { | |
170 if (packed ()) | |
171 unpack (); | |
172 | |
173 FloatMatrix& l = l_fact; | |
174 FloatMatrix& r = a_fact; | |
175 | |
176 octave_idx_type m = l.rows (); | |
177 octave_idx_type n = r.columns (); | |
178 octave_idx_type k = l.columns (); | |
179 | |
180 if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) | |
181 { | |
182 OCTAVE_LOCAL_BUFFER (float, w, m); | |
183 for (octave_idx_type i = 0; i < m; i++) ipvt(i) += 1; // increment | |
184 for (volatile octave_idx_type i = 0; i < u.cols (); i++) | |
185 { | |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
186 FloatColumnVector utmp = u.column (i); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
187 FloatColumnVector vtmp = v.column (i); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
188 F77_XFCN (slup1up, SLUP1UP, (m, n, l.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
189 m, r.fortran_vec (), k, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
190 ipvt.fortran_vec (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 utmp.data (), vtmp.data (), w)); |
9708 | 192 } |
193 for (octave_idx_type i = 0; i < m; i++) ipvt(i) -= 1; // decrement | |
194 } | |
195 else | |
196 (*current_liboctave_error_handler) ("luupdate: dimensions mismatch"); | |
197 } | |
198 | |
199 #else | |
200 | |
201 void FloatLU::update (const FloatColumnVector&, const FloatColumnVector&) | |
202 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
203 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
204 ("luupdate: not available in this version"); |
9708 | 205 } |
206 | |
207 void FloatLU::update (const FloatMatrix&, const FloatMatrix&) | |
208 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
209 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 ("luupdate: not available in this version"); |
9708 | 211 } |
212 | |
213 void FloatLU::update_piv (const FloatColumnVector&, const FloatColumnVector&) | |
214 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
216 ("luupdate: not available in this version"); |
9708 | 217 } |
218 | |
219 void FloatLU::update_piv (const FloatMatrix&, const FloatMatrix&) | |
220 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
222 ("luupdate: not available in this version"); |
9708 | 223 } |
224 | |
225 #endif |