Mercurial > octave
annotate liboctave/array/dMatrix.cc @ 24195:d3dc76efb38b
Return correct value for pinv of zero vectors and scalars (bug #51246).
CMatrix.cc, dMatrix.cc (pseudo_inverse): Change any computed tolerance of 0 to
std::numeric_limits<double>::min() so that zero values are later dropped from
calculation.
fCMatrix.cc, fMatrix.cc (pseudo_inverse): Change calculation of default tolerance
to us the <float> version of std::numeric_limits::epsilon () rather than the
double version. Change any computed tolerance of 0 to
std::numeric_limits<float>::min() so that zero values are later dropped from
calculation.
* pinv.cc (Fpinv): Add BIST tests.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 03 Nov 2017 10:03:36 -0700 |
parents | bc0aa7e18c96 |
children | 2b769c242188 |
rev | line source |
---|---|
458 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1994-2017 John W. Eaton |
7803 | 4 Copyright (C) 2008 Jaroslav Hajek |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague, a.s. |
458 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
10 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
11 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
12 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
13 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
14 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
15 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22598
diff
changeset
|
17 GNU General Public License for more details. |
458 | 18 |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
458 | 22 |
23 */ | |
24 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21273
diff
changeset
|
26 # include "config.h" |
458 | 27 #endif |
28 | |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
29 #include <algorithm> |
3503 | 30 #include <iostream> |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
31 #include <limits> |
1367 | 32 |
4669 | 33 #include "Array-util.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
34 #include "CColVector.h" |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
35 #include "CMatrix.h" |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
36 #include "DET.h" |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
37 #include "PermMatrix.h" |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
38 #include "boolMatrix.h" |
2317 | 39 #include "byte-swap.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
40 #include "chMatrix.h" |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21266
diff
changeset
|
41 #include "chol.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
42 #include "dColVector.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
43 #include "dDiagMatrix.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
44 #include "dMatrix.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
45 #include "dRowVector.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7488
diff
changeset
|
46 #include "functor.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
47 #include "lo-blas-proto.h" |
458 | 48 #include "lo-error.h" |
2354 | 49 #include "lo-ieee.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
50 #include "lo-lapack-proto.h" |
2354 | 51 #include "lo-mappers.h" |
1968 | 52 #include "lo-utils.h" |
3176 | 53 #include "mx-dm-m.h" |
1367 | 54 #include "mx-inlines.cc" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
55 #include "mx-m-dm.h" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
56 #include "mx-op-defs.h" |
1650 | 57 #include "oct-cmplx.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
58 #include "oct-fftw.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
59 #include "oct-locbuf.h" |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
60 #include "oct-norm.h" |
4153 | 61 #include "quit.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
62 #include "schur.h" |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
63 #include "svd.h" |
458 | 64 |
1360 | 65 // Matrix class. |
458 | 66 |
2349 | 67 Matrix::Matrix (const RowVector& rv) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
68 : NDArray (rv) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
69 { } |
2349 | 70 |
71 Matrix::Matrix (const ColumnVector& cv) | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
72 : NDArray (cv) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
73 { } |
2349 | 74 |
458 | 75 Matrix::Matrix (const DiagMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
76 : NDArray (a.dims (), 0.0) |
458 | 77 { |
5275 | 78 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 79 elem (i, i) = a.elem (i, i); |
80 } | |
81 | |
19391
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
82 Matrix::Matrix (const MDiagArray2<double>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
83 : NDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
84 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
85 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
86 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
87 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
88 |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
89 Matrix::Matrix (const DiagArray2<double>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
90 : NDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
91 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
92 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
93 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
94 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19321
diff
changeset
|
95 |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
96 Matrix::Matrix (const PermMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
97 : NDArray (a.dims (), 0.0) |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
98 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18632
diff
changeset
|
99 const Array<octave_idx_type> ia (a.col_perm_vec ()); |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
100 octave_idx_type len = a.rows (); |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18632
diff
changeset
|
101 for (octave_idx_type i = 0; i < len; i++) |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18632
diff
changeset
|
102 elem (ia(i), i) = 1.0; |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
103 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
104 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 // FIXME: could we use a templated mixed-type copy function here? |
1574 | 106 |
2828 | 107 Matrix::Matrix (const boolMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
108 : NDArray (a) |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
109 { } |
2828 | 110 |
1574 | 111 Matrix::Matrix (const charMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
112 : NDArray (a.dims ()) |
1574 | 113 { |
5275 | 114 for (octave_idx_type i = 0; i < a.rows (); i++) |
115 for (octave_idx_type j = 0; j < a.cols (); j++) | |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
116 elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); |
1574 | 117 } |
118 | |
2385 | 119 bool |
458 | 120 Matrix::operator == (const Matrix& a) const |
121 { | |
122 if (rows () != a.rows () || cols () != a.cols ()) | |
2385 | 123 return false; |
458 | 124 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
125 return mx_inline_equal (numel (), data (), a.data ()); |
458 | 126 } |
127 | |
2385 | 128 bool |
458 | 129 Matrix::operator != (const Matrix& a) const |
130 { | |
131 return !(*this == a); | |
132 } | |
133 | |
3354 | 134 bool |
23596
b63c3a09aee7
maint: Deprecate is_symmetric and replace with issymmetric.
Rik <rik@octave.org>
parents:
23594
diff
changeset
|
135 Matrix::issymmetric (void) const |
3354 | 136 { |
23593
a8361bc2361a
maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents:
23461
diff
changeset
|
137 if (issquare () && rows () > 0) |
3354 | 138 { |
5275 | 139 for (octave_idx_type i = 0; i < rows (); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
140 for (octave_idx_type j = i+1; j < cols (); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
141 if (elem (i, j) != elem (j, i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
142 return false; |
3354 | 143 |
144 return true; | |
145 } | |
146 | |
147 return false; | |
148 } | |
149 | |
458 | 150 Matrix& |
5275 | 151 Matrix::insert (const Matrix& a, octave_idx_type r, octave_idx_type c) |
458 | 152 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
153 Array<double>::insert (a, r, c); |
458 | 154 return *this; |
155 } | |
156 | |
157 Matrix& | |
5275 | 158 Matrix::insert (const RowVector& a, octave_idx_type r, octave_idx_type c) |
458 | 159 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
160 octave_idx_type a_len = a.numel (); |
4316 | 161 |
1698 | 162 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
163 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 164 |
4316 | 165 if (a_len > 0) |
166 { | |
167 make_unique (); | |
168 | |
5275 | 169 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
170 xelem (r, c+i) = a.elem (i); |
4316 | 171 } |
458 | 172 |
173 return *this; | |
174 } | |
175 | |
176 Matrix& | |
5275 | 177 Matrix::insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c) |
458 | 178 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
179 octave_idx_type a_len = a.numel (); |
4316 | 180 |
1698 | 181 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
182 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 183 |
4316 | 184 if (a_len > 0) |
185 { | |
186 make_unique (); | |
187 | |
5275 | 188 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
189 xelem (r+i, c) = a.elem (i); |
4316 | 190 } |
458 | 191 |
192 return *this; | |
193 } | |
194 | |
195 Matrix& | |
5275 | 196 Matrix::insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c) |
458 | 197 { |
5275 | 198 octave_idx_type a_nr = a.rows (); |
199 octave_idx_type a_nc = a.cols (); | |
1697 | 200 |
1698 | 201 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
202 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 203 |
1697 | 204 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
205 | |
5275 | 206 octave_idx_type a_len = a.length (); |
4316 | 207 |
208 if (a_len > 0) | |
209 { | |
210 make_unique (); | |
211 | |
5275 | 212 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
213 xelem (r+i, c+i) = a.elem (i, i); |
4316 | 214 } |
458 | 215 |
216 return *this; | |
217 } | |
218 | |
219 Matrix& | |
220 Matrix::fill (double val) | |
221 { | |
5275 | 222 octave_idx_type nr = rows (); |
223 octave_idx_type nc = cols (); | |
4316 | 224 |
458 | 225 if (nr > 0 && nc > 0) |
4316 | 226 { |
227 make_unique (); | |
228 | |
5275 | 229 for (octave_idx_type j = 0; j < nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
230 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
231 xelem (i, j) = val; |
4316 | 232 } |
458 | 233 |
234 return *this; | |
235 } | |
236 | |
237 Matrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
238 Matrix::fill (double val, octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
239 octave_idx_type r2, octave_idx_type c2) |
458 | 240 { |
5275 | 241 octave_idx_type nr = rows (); |
242 octave_idx_type nc = cols (); | |
4316 | 243 |
458 | 244 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
245 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
246 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 247 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
248 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
249 if (c1 > c2) { std::swap (c1, c2); } |
458 | 250 |
4316 | 251 if (r2 >= r1 && c2 >= c1) |
252 { | |
253 make_unique (); | |
254 | |
5275 | 255 for (octave_idx_type j = c1; j <= c2; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
256 for (octave_idx_type i = r1; i <= r2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
257 xelem (i, j) = val; |
4316 | 258 } |
458 | 259 |
260 return *this; | |
261 } | |
262 | |
263 Matrix | |
264 Matrix::append (const Matrix& a) const | |
265 { | |
5275 | 266 octave_idx_type nr = rows (); |
267 octave_idx_type nc = cols (); | |
458 | 268 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
269 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 270 |
5275 | 271 octave_idx_type nc_insert = nc; |
458 | 272 Matrix retval (nr, nc + a.cols ()); |
273 retval.insert (*this, 0, 0); | |
274 retval.insert (a, 0, nc_insert); | |
275 return retval; | |
276 } | |
277 | |
278 Matrix | |
279 Matrix::append (const RowVector& a) const | |
280 { | |
5275 | 281 octave_idx_type nr = rows (); |
282 octave_idx_type nc = cols (); | |
458 | 283 if (nr != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
284 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 285 |
5275 | 286 octave_idx_type nc_insert = nc; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
287 Matrix retval (nr, nc + a.numel ()); |
458 | 288 retval.insert (*this, 0, 0); |
289 retval.insert (a, 0, nc_insert); | |
290 return retval; | |
291 } | |
292 | |
293 Matrix | |
294 Matrix::append (const ColumnVector& a) const | |
295 { | |
5275 | 296 octave_idx_type nr = rows (); |
297 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
298 if (nr != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
299 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 300 |
5275 | 301 octave_idx_type nc_insert = nc; |
458 | 302 Matrix retval (nr, nc + 1); |
303 retval.insert (*this, 0, 0); | |
304 retval.insert (a, 0, nc_insert); | |
305 return retval; | |
306 } | |
307 | |
308 Matrix | |
309 Matrix::append (const DiagMatrix& a) const | |
310 { | |
5275 | 311 octave_idx_type nr = rows (); |
312 octave_idx_type nc = cols (); | |
458 | 313 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
314 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 315 |
5275 | 316 octave_idx_type nc_insert = nc; |
458 | 317 Matrix retval (nr, nc + a.cols ()); |
318 retval.insert (*this, 0, 0); | |
319 retval.insert (a, 0, nc_insert); | |
320 return retval; | |
321 } | |
322 | |
323 Matrix | |
324 Matrix::stack (const Matrix& a) const | |
325 { | |
5275 | 326 octave_idx_type nr = rows (); |
327 octave_idx_type nc = cols (); | |
458 | 328 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
329 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 330 |
5275 | 331 octave_idx_type nr_insert = nr; |
458 | 332 Matrix retval (nr + a.rows (), nc); |
333 retval.insert (*this, 0, 0); | |
334 retval.insert (a, nr_insert, 0); | |
335 return retval; | |
336 } | |
337 | |
338 Matrix | |
339 Matrix::stack (const RowVector& a) const | |
340 { | |
5275 | 341 octave_idx_type nr = rows (); |
342 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
343 if (nc != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
344 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 345 |
5275 | 346 octave_idx_type nr_insert = nr; |
458 | 347 Matrix retval (nr + 1, nc); |
348 retval.insert (*this, 0, 0); | |
349 retval.insert (a, nr_insert, 0); | |
350 return retval; | |
351 } | |
352 | |
353 Matrix | |
354 Matrix::stack (const ColumnVector& a) const | |
355 { | |
5275 | 356 octave_idx_type nr = rows (); |
357 octave_idx_type nc = cols (); | |
458 | 358 if (nc != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
359 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 360 |
5275 | 361 octave_idx_type nr_insert = nr; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
362 Matrix retval (nr + a.numel (), nc); |
458 | 363 retval.insert (*this, 0, 0); |
364 retval.insert (a, nr_insert, 0); | |
365 return retval; | |
366 } | |
367 | |
368 Matrix | |
369 Matrix::stack (const DiagMatrix& a) const | |
370 { | |
5275 | 371 octave_idx_type nr = rows (); |
372 octave_idx_type nc = cols (); | |
458 | 373 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
374 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 375 |
5275 | 376 octave_idx_type nr_insert = nr; |
458 | 377 Matrix retval (nr + a.rows (), nc); |
378 retval.insert (*this, 0, 0); | |
379 retval.insert (a, nr_insert, 0); | |
380 return retval; | |
381 } | |
382 | |
383 Matrix | |
1205 | 384 real (const ComplexMatrix& a) |
385 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
386 return do_mx_unary_op<double, Complex> (a, mx_inline_real); |
1205 | 387 } |
388 | |
389 Matrix | |
390 imag (const ComplexMatrix& a) | |
391 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
392 return do_mx_unary_op<double, Complex> (a, mx_inline_imag); |
1205 | 393 } |
394 | |
395 Matrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
396 Matrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
397 octave_idx_type r2, octave_idx_type c2) const |
458 | 398 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
399 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
400 if (c1 > c2) { std::swap (c1, c2); } |
5275 | 401 |
10805
8c858a1a2079
simplify Matrix::extract
Jaroslav Hajek <highegg@gmail.com>
parents:
10630
diff
changeset
|
402 return index (idx_vector (r1, r2+1), idx_vector (c1, c2+1)); |
4316 | 403 } |
404 | |
405 Matrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 Matrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
407 octave_idx_type nc) const |
4316 | 408 { |
10806
7c542263a92a
omissions from last two patches
Jaroslav Hajek <highegg@gmail.com>
parents:
10805
diff
changeset
|
409 return index (idx_vector (r1, r1 + nr), idx_vector (c1, c1 + nc)); |
458 | 410 } |
411 | |
412 // extract row or column i. | |
413 | |
414 RowVector | |
5275 | 415 Matrix::row (octave_idx_type i) const |
458 | 416 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
417 return index (idx_vector (i), idx_vector::colon); |
458 | 418 } |
419 | |
420 ColumnVector | |
5275 | 421 Matrix::column (octave_idx_type i) const |
458 | 422 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
423 return index (idx_vector::colon, idx_vector (i)); |
458 | 424 } |
425 | |
426 Matrix | |
427 Matrix::inverse (void) const | |
428 { | |
5275 | 429 octave_idx_type info; |
7788 | 430 double rcon; |
6207 | 431 MatrixType mattype (*this); |
7788 | 432 return inverse (mattype, info, rcon, 0, 0); |
6207 | 433 } |
434 | |
435 Matrix | |
6479 | 436 Matrix::inverse (octave_idx_type& info) const |
437 { | |
7788 | 438 double rcon; |
6479 | 439 MatrixType mattype (*this); |
7788 | 440 return inverse (mattype, info, rcon, 0, 0); |
6479 | 441 } |
442 | |
443 Matrix | |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
444 Matrix::inverse (octave_idx_type& info, double& rcon, bool force, |
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
445 bool calc_cond) const |
6479 | 446 { |
447 MatrixType mattype (*this); | |
7788 | 448 return inverse (mattype, info, rcon, force, calc_cond); |
6479 | 449 } |
450 | |
451 Matrix | |
6207 | 452 Matrix::inverse (MatrixType& mattype) const |
453 { | |
454 octave_idx_type info; | |
7788 | 455 double rcon; |
456 return inverse (mattype, info, rcon, 0, 0); | |
6207 | 457 } |
458 | |
459 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
460 Matrix::inverse (MatrixType& mattype, octave_idx_type& info) const |
6207 | 461 { |
7788 | 462 double rcon; |
463 return inverse (mattype, info, rcon, 0, 0); | |
458 | 464 } |
465 | |
466 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
467 Matrix::tinverse (MatrixType& mattype, octave_idx_type& info, double& rcon, |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
468 bool force, bool calc_cond) const |
458 | 469 { |
6207 | 470 Matrix retval; |
471 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
472 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
473 F77_INT nc = octave::to_f77_int (cols ()); |
6207 | 474 |
475 if (nr != nc || nr == 0 || nc == 0) | |
476 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
477 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
478 int typ = mattype.type (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
479 char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
480 char udiag = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
481 retval = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
482 double *tmp_data = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
483 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
484 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
485 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
486 F77_XFCN (dtrtri, DTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
487 F77_CONST_CHAR_ARG2 (&udiag, 1), |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
488 nr, tmp_data, nr, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
489 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
490 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
491 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
492 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
493 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
494 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
495 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
496 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
497 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
498 else if (calc_cond) |
6207 | 499 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
500 F77_INT dtrcon_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
501 char job = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
502 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
503 OCTAVE_LOCAL_BUFFER (double, work, 3 * nr); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
504 OCTAVE_LOCAL_BUFFER (F77_INT, iwork, nr); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
505 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
506 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
507 F77_CONST_CHAR_ARG2 (&uplo, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
508 F77_CONST_CHAR_ARG2 (&udiag, 1), |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
509 nr, tmp_data, nr, rcon, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
510 work, iwork, dtrcon_info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
511 F77_CHAR_ARG_LEN (1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
512 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
513 F77_CHAR_ARG_LEN (1))); |
6207 | 514 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
515 if (dtrcon_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
516 info = -1; |
6207 | 517 } |
518 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
519 if (info == -1 && ! force) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
520 retval = *this; // Restore matrix contents. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
521 |
6207 | 522 return retval; |
458 | 523 } |
524 | |
525 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
526 Matrix::finverse (MatrixType& mattype, octave_idx_type& info, double& rcon, |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
527 bool force, bool calc_cond) const |
458 | 528 { |
1948 | 529 Matrix retval; |
530 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
531 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
532 F77_INT nc = octave::to_f77_int (cols ()); |
1948 | 533 |
458 | 534 if (nr != nc || nr == 0 || nc == 0) |
1948 | 535 (*current_liboctave_error_handler) ("inverse requires square matrix"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
536 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
537 Array<F77_INT> ipvt (dim_vector (nr, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
538 F77_INT *pipvt = ipvt.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
539 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
540 retval = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
541 double *tmp_data = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
542 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
543 Array<double> z (dim_vector (1, 1)); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
544 F77_INT lwork = -1; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
545 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
546 F77_INT tmp_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
547 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
548 // Query the optimum work array size. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
549 F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
550 z.fortran_vec (), lwork, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
551 |
24035
bc0aa7e18c96
fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
552 info = tmp_info; |
bc0aa7e18c96
fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
553 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
554 lwork = static_cast<F77_INT> (z(0)); |
24035
bc0aa7e18c96
fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents:
23807
diff
changeset
|
555 lwork = (lwork < 4 * nc ? 4 * nc : lwork); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
556 z.resize (dim_vector (lwork, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
557 double *pz = z.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
558 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
559 info = 0; |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
560 tmp_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
561 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
562 // Calculate the norm of the matrix, for later use. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
563 double anorm = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
564 if (calc_cond) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
565 anorm = retval.abs ().sum ().row (static_cast<octave_idx_type>(0)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
566 .max (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
567 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
568 F77_XFCN (dgetrf, DGETRF, (nc, nc, tmp_data, nr, pipvt, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
569 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
570 info = tmp_info; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
571 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
572 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
573 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
574 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
575 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
576 else if (calc_cond) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
577 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
578 F77_INT dgecon_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
579 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
580 // Now calculate the condition number for non-singular matrix. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
581 char job = '1'; |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
582 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
583 F77_INT *piz = iz.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
584 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
585 nc, tmp_data, nr, anorm, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
586 rcon, pz, piz, dgecon_info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
587 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
588 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
589 if (dgecon_info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
590 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
591 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
592 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
593 if (info == -1 && ! force) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
594 retval = *this; // Restore matrix contents. |
458 | 595 else |
596 { | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
597 F77_INT dgetri_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
598 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
599 F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
600 pz, lwork, dgetri_info)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
601 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
602 if (dgetri_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
603 info = -1; |
458 | 604 } |
605 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
606 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
607 mattype.mark_as_rectangular (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
608 |
1948 | 609 return retval; |
458 | 610 } |
611 | |
740 | 612 Matrix |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
613 Matrix::inverse (MatrixType& mattype, octave_idx_type& info, double& rcon, |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
614 bool force, bool calc_cond) const |
6207 | 615 { |
616 int typ = mattype.type (false); | |
617 Matrix ret; | |
618 | |
619 if (typ == MatrixType::Unknown) | |
620 typ = mattype.type (*this); | |
621 | |
622 if (typ == MatrixType::Upper || typ == MatrixType::Lower) | |
7788 | 623 ret = tinverse (mattype, info, rcon, force, calc_cond); |
6840 | 624 else |
6207 | 625 { |
23594
af5b813503cb
maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents:
23593
diff
changeset
|
626 if (mattype.ishermitian ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
627 { |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
628 octave::math::chol<Matrix> chol (*this, info, true, calc_cond); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
629 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
630 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
631 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
632 rcon = chol.rcond (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
633 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
634 rcon = 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
635 ret = chol.inverse (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
636 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
637 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
638 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
639 } |
6207 | 640 |
23594
af5b813503cb
maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents:
23593
diff
changeset
|
641 if (! mattype.ishermitian ()) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
642 ret = finverse (mattype, info, rcon, force, calc_cond); |
7788 | 643 |
23594
af5b813503cb
maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents:
23593
diff
changeset
|
644 if ((calc_cond || mattype.ishermitian ()) && rcon == 0. |
22849
1d242ae72240
Return 0 for special case of scalar Inf input to inverse (bug #49690).
Rik <rik@octave.org>
parents:
22848
diff
changeset
|
645 && ! (numel () == 1)) |
1d242ae72240
Return 0 for special case of scalar Inf input to inverse (bug #49690).
Rik <rik@octave.org>
parents:
22848
diff
changeset
|
646 ret = Matrix (rows (), columns (), |
1d242ae72240
Return 0 for special case of scalar Inf input to inverse (bug #49690).
Rik <rik@octave.org>
parents:
22848
diff
changeset
|
647 octave::numeric_limits<double>::Inf ()); |
6207 | 648 } |
649 | |
650 return ret; | |
651 } | |
652 | |
653 Matrix | |
4384 | 654 Matrix::pseudo_inverse (double tol) const |
740 | 655 { |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
656 octave::math::svd<Matrix> result (*this, |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
657 octave::math::svd<Matrix>::Type::economy); |
740 | 658 |
659 DiagMatrix S = result.singular_values (); | |
660 Matrix U = result.left_singular_matrix (); | |
661 Matrix V = result.right_singular_matrix (); | |
662 | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15383
diff
changeset
|
663 ColumnVector sigma = S.extract_diag (); |
740 | 664 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
665 octave_idx_type r = sigma.numel () - 1; |
5275 | 666 octave_idx_type nr = rows (); |
667 octave_idx_type nc = cols (); | |
740 | 668 |
669 if (tol <= 0.0) | |
670 { | |
671 if (nr > nc) | |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
672 tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); |
740 | 673 else |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
674 tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); |
24195
d3dc76efb38b
Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents:
24035
diff
changeset
|
675 |
d3dc76efb38b
Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents:
24035
diff
changeset
|
676 if (tol == 0) |
d3dc76efb38b
Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents:
24035
diff
changeset
|
677 tol = std::numeric_limits<double>::min (); |
740 | 678 } |
679 | |
680 while (r >= 0 && sigma.elem (r) < tol) | |
681 r--; | |
682 | |
683 if (r < 0) | |
684 return Matrix (nc, nr, 0.0); | |
685 else | |
686 { | |
687 Matrix Ur = U.extract (0, 0, nr-1, r); | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
688 DiagMatrix D = DiagMatrix (sigma.extract (0, r)).inverse (); |
740 | 689 Matrix Vr = V.extract (0, 0, nc-1, r); |
690 return Vr * D * Ur.transpose (); | |
691 } | |
692 } | |
693 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
694 #if defined (HAVE_FFTW) |
3827 | 695 |
696 ComplexMatrix | |
697 Matrix::fourier (void) const | |
698 { | |
699 size_t nr = rows (); | |
700 size_t nc = cols (); | |
701 | |
702 ComplexMatrix retval (nr, nc); | |
703 | |
704 size_t npts, nsamples; | |
705 | |
706 if (nr == 1 || nc == 1) | |
707 { | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
708 npts = (nr > nc ? nr : nc); |
3827 | 709 nsamples = 1; |
710 } | |
711 else | |
712 { | |
713 npts = nr; | |
714 nsamples = nc; | |
715 } | |
716 | |
4773 | 717 const double *in (fortran_vec ()); |
3827 | 718 Complex *out (retval.fortran_vec ()); |
719 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22988
diff
changeset
|
720 octave::fftw::fft (in, out, npts, nsamples); |
3827 | 721 |
722 return retval; | |
723 } | |
724 | |
725 ComplexMatrix | |
726 Matrix::ifourier (void) const | |
727 { | |
728 size_t nr = rows (); | |
729 size_t nc = cols (); | |
730 | |
731 ComplexMatrix retval (nr, nc); | |
732 | |
733 size_t npts, nsamples; | |
734 | |
735 if (nr == 1 || nc == 1) | |
736 { | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
737 npts = (nr > nc ? nr : nc); |
3827 | 738 nsamples = 1; |
739 } | |
740 else | |
741 { | |
742 npts = nr; | |
743 nsamples = nc; | |
744 } | |
745 | |
746 ComplexMatrix tmp (*this); | |
747 Complex *in (tmp.fortran_vec ()); | |
748 Complex *out (retval.fortran_vec ()); | |
749 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22988
diff
changeset
|
750 octave::fftw::ifft (in, out, npts, nsamples); |
3827 | 751 |
752 return retval; | |
753 } | |
754 | |
755 ComplexMatrix | |
756 Matrix::fourier2d (void) const | |
757 { | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
758 dim_vector dv (rows (), cols ()); |
4773 | 759 |
760 const double *in = fortran_vec (); | |
761 ComplexMatrix retval (rows (), cols ()); | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22988
diff
changeset
|
762 octave::fftw::fftNd (in, retval.fortran_vec (), 2, dv); |
3827 | 763 |
764 return retval; | |
765 } | |
766 | |
767 ComplexMatrix | |
768 Matrix::ifourier2d (void) const | |
769 { | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
770 dim_vector dv (rows (), cols ()); |
3827 | 771 |
772 ComplexMatrix retval (*this); | |
4773 | 773 Complex *out (retval.fortran_vec ()); |
774 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22988
diff
changeset
|
775 octave::fftw::ifftNd (out, out, 2, dv); |
3827 | 776 |
777 return retval; | |
778 } | |
779 | |
780 #else | |
781 | |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
782 #include "lo-fftpack-proto.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
783 |
458 | 784 ComplexMatrix |
785 Matrix::fourier (void) const | |
786 { | |
1948 | 787 ComplexMatrix retval; |
788 | |
5275 | 789 octave_idx_type nr = rows (); |
790 octave_idx_type nc = cols (); | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
791 octave_idx_type nsamples; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
792 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
793 F77_INT npts; |
1948 | 794 |
458 | 795 if (nr == 1 || nc == 1) |
796 { | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
797 npts = octave::to_f77_int (nr > nc ? nr : nc); |
458 | 798 nsamples = 1; |
799 } | |
800 else | |
801 { | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
802 npts = octave::to_f77_int (nr); |
458 | 803 nsamples = nc; |
804 } | |
805 | |
5275 | 806 octave_idx_type nn = 4*npts+15; |
1948 | 807 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
808 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 809 Complex *pwsave = wsave.fortran_vec (); |
810 | |
3585 | 811 retval = ComplexMatrix (*this); |
1948 | 812 Complex *tmp_data = retval.fortran_vec (); |
813 | |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
814 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
458 | 815 |
5275 | 816 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 817 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
818 octave_quit (); |
4153 | 819 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
820 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (&tmp_data[npts*j]), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
821 F77_DBLE_CMPLX_ARG (pwsave)); |
4153 | 822 } |
1948 | 823 |
824 return retval; | |
458 | 825 } |
826 | |
827 ComplexMatrix | |
828 Matrix::ifourier (void) const | |
829 { | |
1948 | 830 ComplexMatrix retval; |
831 | |
5275 | 832 octave_idx_type nr = rows (); |
833 octave_idx_type nc = cols (); | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
834 octave_idx_type nsamples; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
835 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
836 F77_INT npts; |
1948 | 837 |
458 | 838 if (nr == 1 || nc == 1) |
839 { | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
840 npts = octave::to_f77_int (nr > nc ? nr : nc); |
458 | 841 nsamples = 1; |
842 } | |
843 else | |
844 { | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
845 npts = octave::to_f77_int (nr); |
458 | 846 nsamples = nc; |
847 } | |
848 | |
5275 | 849 octave_idx_type nn = 4*npts+15; |
1948 | 850 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
851 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 852 Complex *pwsave = wsave.fortran_vec (); |
853 | |
3585 | 854 retval = ComplexMatrix (*this); |
1948 | 855 Complex *tmp_data = retval.fortran_vec (); |
856 | |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
857 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
458 | 858 |
5275 | 859 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 860 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
861 octave_quit (); |
4153 | 862 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
863 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (&tmp_data[npts*j]), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
864 F77_DBLE_CMPLX_ARG (pwsave)); |
4153 | 865 } |
458 | 866 |
5275 | 867 for (octave_idx_type j = 0; j < npts*nsamples; j++) |
3572 | 868 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
458 | 869 |
1948 | 870 return retval; |
458 | 871 } |
872 | |
677 | 873 ComplexMatrix |
874 Matrix::fourier2d (void) const | |
875 { | |
1948 | 876 ComplexMatrix retval; |
877 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
878 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
879 F77_INT nc = octave::to_f77_int (cols ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
880 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
881 F77_INT npts, nsamples; |
1948 | 882 |
677 | 883 if (nr == 1 || nc == 1) |
884 { | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
885 npts = (nr > nc ? nr : nc); |
677 | 886 nsamples = 1; |
887 } | |
888 else | |
889 { | |
890 npts = nr; | |
891 nsamples = nc; | |
892 } | |
893 | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
894 F77_INT nn = 4*npts+15; |
1948 | 895 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
896 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 897 Complex *pwsave = wsave.fortran_vec (); |
898 | |
3585 | 899 retval = ComplexMatrix (*this); |
1948 | 900 Complex *tmp_data = retval.fortran_vec (); |
901 | |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
902 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 903 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
904 for (F77_INT j = 0; j < nsamples; j++) |
4153 | 905 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
906 octave_quit (); |
4153 | 907 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
908 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (&tmp_data[npts*j]), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
909 F77_DBLE_CMPLX_ARG (pwsave)); |
4153 | 910 } |
677 | 911 |
912 npts = nc; | |
913 nsamples = nr; | |
914 nn = 4*npts+15; | |
1948 | 915 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
916 wsave.resize (dim_vector (nn, 1)); |
1948 | 917 pwsave = wsave.fortran_vec (); |
918 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
919 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 920 Complex *prow = tmp.fortran_vec (); |
1948 | 921 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
922 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 923 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
924 for (F77_INT j = 0; j < nsamples; j++) |
677 | 925 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
926 octave_quit (); |
4153 | 927 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
928 for (F77_INT i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
929 prow[i] = tmp_data[i*nr + j]; |
1948 | 930 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
931 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
932 F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 933 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
934 for (F77_INT i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
935 tmp_data[i*nr + j] = prow[i]; |
677 | 936 } |
937 | |
1948 | 938 return retval; |
677 | 939 } |
940 | |
941 ComplexMatrix | |
942 Matrix::ifourier2d (void) const | |
943 { | |
1948 | 944 ComplexMatrix retval; |
945 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
946 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
947 F77_INT nc = octave::to_f77_int (cols ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
948 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
949 F77_INT npts, nsamples; |
1948 | 950 |
677 | 951 if (nr == 1 || nc == 1) |
952 { | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
953 npts = (nr > nc ? nr : nc); |
677 | 954 nsamples = 1; |
955 } | |
956 else | |
957 { | |
958 npts = nr; | |
959 nsamples = nc; | |
960 } | |
961 | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
962 F77_INT nn = 4*npts+15; |
1948 | 963 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
964 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 965 Complex *pwsave = wsave.fortran_vec (); |
966 | |
3585 | 967 retval = ComplexMatrix (*this); |
1948 | 968 Complex *tmp_data = retval.fortran_vec (); |
969 | |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
970 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 971 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
972 for (F77_INT j = 0; j < nsamples; j++) |
4153 | 973 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
974 octave_quit (); |
4153 | 975 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
976 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (&tmp_data[npts*j]), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
977 F77_DBLE_CMPLX_ARG (pwsave)); |
4153 | 978 } |
677 | 979 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
980 for (F77_INT j = 0; j < npts*nsamples; j++) |
3572 | 981 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
677 | 982 |
983 npts = nc; | |
984 nsamples = nr; | |
985 nn = 4*npts+15; | |
1948 | 986 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
987 wsave.resize (dim_vector (nn, 1)); |
1948 | 988 pwsave = wsave.fortran_vec (); |
989 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
990 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 991 Complex *prow = tmp.fortran_vec (); |
1948 | 992 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22204
diff
changeset
|
993 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 994 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
995 for (F77_INT j = 0; j < nsamples; j++) |
677 | 996 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
997 octave_quit (); |
4153 | 998 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
999 for (F77_INT i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1000 prow[i] = tmp_data[i*nr + j]; |
1948 | 1001 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1002 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
1003 F77_DBLE_CMPLX_ARG (pwsave)); |
677 | 1004 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1005 for (F77_INT i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1006 tmp_data[i*nr + j] = prow[i] / static_cast<double> (npts); |
677 | 1007 } |
1008 | |
1948 | 1009 return retval; |
677 | 1010 } |
1011 | |
3827 | 1012 #endif |
1013 | |
458 | 1014 DET |
1015 Matrix::determinant (void) const | |
1016 { | |
5275 | 1017 octave_idx_type info; |
7788 | 1018 double rcon; |
1019 return determinant (info, rcon, 0); | |
458 | 1020 } |
1021 | |
1022 DET | |
5275 | 1023 Matrix::determinant (octave_idx_type& info) const |
458 | 1024 { |
7788 | 1025 double rcon; |
1026 return determinant (info, rcon, 0); | |
458 | 1027 } |
1028 | |
1029 DET | |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1030 Matrix::determinant (octave_idx_type& info, double& rcon, bool calc_cond) const |
458 | 1031 { |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1032 MatrixType mattype (*this); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1033 return determinant (mattype, info, rcon, calc_cond); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1034 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1035 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1036 DET |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1037 Matrix::determinant (MatrixType& mattype, |
21719
ff054947d132
use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1038 octave_idx_type& info, double& rcon, bool calc_cond) const |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1039 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1040 DET retval (1.0); |
458 | 1041 |
13828
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13756
diff
changeset
|
1042 info = 0; |
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13756
diff
changeset
|
1043 rcon = 0.0; |
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13756
diff
changeset
|
1044 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1045 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1046 F77_INT nc = octave::to_f77_int (cols ()); |
458 | 1047 |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1048 if (nr != nc) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1049 (*current_liboctave_error_handler) ("matrix must be square"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1050 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1051 volatile int typ = mattype.type (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1052 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1053 // Even though the matrix is marked as singular (Rectangular), we may |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1054 // still get a useful number from the LU factorization, because it always |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1055 // completes. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1056 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1057 if (typ == MatrixType::Unknown) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1058 typ = mattype.type (*this); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1059 else if (typ == MatrixType::Rectangular) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1060 typ = MatrixType::Full; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1061 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1062 if (typ == MatrixType::Lower || typ == MatrixType::Upper) |
458 | 1063 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1064 for (F77_INT i = 0; i < nc; i++) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1065 retval *= elem (i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1066 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1067 else if (typ == MatrixType::Hermitian) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1068 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1069 Matrix atmp = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1070 double *tmp_data = atmp.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1071 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1072 double anorm = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1073 if (calc_cond) anorm = xnorm (*this, 1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1074 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1075 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1076 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1077 char job = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1078 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1079 tmp_data, nr, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1080 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1081 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1082 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1083 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1084 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1085 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1086 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1087 mattype.mark_as_unsymmetric (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1088 typ = MatrixType::Full; |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1089 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1090 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1091 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1092 Array<double> z (dim_vector (3 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1093 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1094 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1095 F77_INT *piz = iz.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1096 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1097 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1098 nr, tmp_data, nr, anorm, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1099 rcon, pz, piz, tmp_info |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1100 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1101 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1102 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1103 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1104 if (info != 0) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1105 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1106 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1107 for (F77_INT i = 0; i < nc; i++) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1108 retval *= atmp (i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1109 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1110 retval = retval.square (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1111 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1112 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1113 else if (typ != MatrixType::Full) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1114 (*current_liboctave_error_handler) ("det: invalid dense matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1115 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1116 if (typ == MatrixType::Full) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1117 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1118 Array<F77_INT> ipvt (dim_vector (nr, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1119 F77_INT *pipvt = ipvt.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1120 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1121 Matrix atmp = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1122 double *tmp_data = atmp.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1123 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1124 info = 0; |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1125 F77_INT tmp_info = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1126 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1127 // Calculate the norm of the matrix, for later use. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1128 double anorm = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1129 if (calc_cond) anorm = xnorm (*this, 1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1130 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1131 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1132 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1133 info = tmp_info; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1134 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1135 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1136 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1137 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1138 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1139 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1140 retval = DET (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1141 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1142 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1143 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1144 if (calc_cond) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1145 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1146 // Now calc the condition number for non-singular matrix. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1147 char job = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1148 Array<double> z (dim_vector (4 * nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1149 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1150 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1151 F77_INT *piz = iz.fortran_vec (); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1152 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1153 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1154 nc, tmp_data, nr, anorm, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1155 rcon, pz, piz, tmp_info |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1156 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1157 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1158 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1159 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1160 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1161 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1162 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1163 info = -1; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1164 retval = DET (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1165 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1166 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1167 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1168 for (F77_INT i = 0; i < nc; i++) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1169 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1170 double c = atmp(i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1171 retval *= (ipvt(i) != (i+1)) ? -c : c; |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1172 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1173 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1174 } |
458 | 1175 } |
1176 | |
1177 return retval; | |
1178 } | |
1179 | |
7788 | 1180 double |
1181 Matrix::rcond (void) const | |
1182 { | |
1183 MatrixType mattype (*this); | |
1184 return rcond (mattype); | |
1185 } | |
1186 | |
1187 double | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1188 Matrix::rcond (MatrixType& mattype) const |
7788 | 1189 { |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
1190 double rcon = octave::numeric_limits<double>::NaN (); |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1191 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1192 F77_INT nc = octave::to_f77_int (cols ()); |
7788 | 1193 |
1194 if (nr != nc) | |
1195 (*current_liboctave_error_handler) ("matrix must be square"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1196 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1197 if (nr == 0 || nc == 0) |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
1198 rcon = octave::numeric_limits<double>::Inf (); |
7788 | 1199 else |
1200 { | |
16300
23c5f90f92cd
eliminate some variable might be clobbered by 'longjmp' or 'vfork' warnings
John W. Eaton <jwe@octave.org>
parents:
15448
diff
changeset
|
1201 volatile int typ = mattype.type (); |
7788 | 1202 |
1203 if (typ == MatrixType::Unknown) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1204 typ = mattype.type (*this); |
7788 | 1205 |
1206 // Only calculate the condition number for LU/Cholesky | |
1207 if (typ == MatrixType::Upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1208 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1209 const double *tmp_data = fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1210 F77_INT info = 0; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1211 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1212 char uplo = 'U'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1213 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1214 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1215 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1216 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1217 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1218 F77_INT *piz = iz.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1219 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1220 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1221 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1222 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1223 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1224 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1225 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1226 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1227 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1228 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1229 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1230 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1231 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1232 else if (typ == MatrixType::Permuted_Upper) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1233 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1234 ("permuted triangular matrix not implemented"); |
7788 | 1235 else if (typ == MatrixType::Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1236 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1237 const double *tmp_data = fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1238 F77_INT info = 0; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1239 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1240 char uplo = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1241 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1242 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1243 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1244 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1245 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1246 F77_INT *piz = iz.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1247 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1248 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1249 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1250 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1251 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1252 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1253 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1254 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1255 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1256 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1257 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1258 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1259 } |
7788 | 1260 else if (typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1261 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1262 ("permuted triangular matrix not implemented"); |
7788 | 1263 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1264 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1265 double anorm = -1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1266 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1267 if (typ == MatrixType::Hermitian) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1268 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1269 F77_INT info = 0; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1270 char job = 'L'; |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1271 |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1272 Matrix atmp = *this; |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1273 double *tmp_data = atmp.fortran_vec (); |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1274 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1275 anorm = atmp.abs().sum(). |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1276 row(static_cast<octave_idx_type>(0)).max(); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1277 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1278 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1279 tmp_data, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1280 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1281 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1282 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1283 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1284 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1285 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1286 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1287 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1288 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1289 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1290 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1291 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1292 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1293 F77_INT *piz = iz.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1294 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1295 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1296 nr, tmp_data, nr, anorm, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1297 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1298 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1299 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1300 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1301 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1302 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1303 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1304 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1305 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1306 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1307 F77_INT info = 0; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1308 |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1309 Matrix atmp = *this; |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1310 double *tmp_data = atmp.fortran_vec (); |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1311 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1312 Array<F77_INT> ipvt (dim_vector (nr, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1313 F77_INT *pipvt = ipvt.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1314 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1315 if (anorm < 0.) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
1316 anorm = atmp.abs ().sum (). |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1317 row(static_cast<octave_idx_type>(0)).max (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1318 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1319 Array<double> z (dim_vector (4 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1320 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1321 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1322 F77_INT *piz = iz.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1323 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1324 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1325 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1326 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1327 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1328 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1329 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1330 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1331 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1332 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1333 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1334 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1335 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1336 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1337 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1338 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1339 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1340 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1341 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1342 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1343 } |
7788 | 1344 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1345 rcon = 0.0; |
7788 | 1346 } |
1347 | |
1348 return rcon; | |
1349 } | |
1350 | |
458 | 1351 Matrix |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1352 Matrix::utsolve (MatrixType& mattype, const Matrix& b, octave_idx_type& info, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1353 double& rcon, solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1354 bool calc_cond, blas_trans_type transt) const |
5785 | 1355 { |
1356 Matrix retval; | |
1357 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1358 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1359 F77_INT nc = octave::to_f77_int (cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1360 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1361 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1362 F77_INT b_nc = octave::to_f77_int (b.cols ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1363 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1364 if (nr != b_nr) |
5785 | 1365 (*current_liboctave_error_handler) |
1366 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1367 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1368 if (nr == 0 || nc == 0 || b_nc == 0) |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1369 retval = Matrix (nc, b_nc, 0.0); |
5785 | 1370 else |
1371 { | |
1372 volatile int typ = mattype.type (); | |
1373 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1374 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1375 (*current_liboctave_error_handler) ("incorrect matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1376 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1377 rcon = 1.; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1378 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1379 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1380 if (typ == MatrixType::Permuted_Upper) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1381 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1382 ("permuted triangular matrix not implemented"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1383 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1384 const double *tmp_data = fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1385 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1386 retval = b; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1387 double *result = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1388 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1389 char uplo = 'U'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1390 char trans = get_blas_char (transt); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1391 char dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1392 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1393 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1394 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1395 F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1396 F77_CONST_CHAR_ARG2 (&trans, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1397 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1398 nr, b_nc, tmp_data, nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1399 result, nr, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1400 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1401 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1402 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1403 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1404 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1405 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1406 if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1407 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1408 char norm = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1409 uplo = 'U'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1410 dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1411 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1412 Array<double> z (dim_vector (3 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1413 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1414 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1415 F77_INT *piz = iz.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1416 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1417 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1418 F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1419 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1420 nr, tmp_data, nr, rcon, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1421 pz, piz, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1422 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1423 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1424 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1425 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1426 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1427 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1428 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1429 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1430 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1431 volatile double rcond_plus_one = rcon + 1.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1432 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1433 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1434 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1435 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1436 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1437 if (sing_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1438 sing_handler (rcon); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1439 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1440 octave::warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1441 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1442 } |
5785 | 1443 } |
1444 | |
1445 return retval; | |
1446 } | |
1447 | |
1448 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1449 Matrix::ltsolve (MatrixType& mattype, const Matrix& b, octave_idx_type& info, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1450 double& rcon, solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1451 bool calc_cond, blas_trans_type transt) const |
5785 | 1452 { |
1453 Matrix retval; | |
1454 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1455 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1456 F77_INT nc = octave::to_f77_int (cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1457 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1458 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1459 F77_INT b_nc = octave::to_f77_int (b.cols ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1460 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1461 if (nr != b_nr) |
5785 | 1462 (*current_liboctave_error_handler) |
1463 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1464 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1465 if (nr == 0 || nc == 0 || b_nc == 0) |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1466 retval = Matrix (nc, b_nc, 0.0); |
5785 | 1467 else |
1468 { | |
1469 volatile int typ = mattype.type (); | |
1470 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1471 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1472 (*current_liboctave_error_handler) ("incorrect matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1473 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1474 rcon = 1.; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1475 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1476 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1477 if (typ == MatrixType::Permuted_Lower) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1478 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1479 ("permuted triangular matrix not implemented"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1480 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1481 const double *tmp_data = fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1482 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1483 retval = b; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1484 double *result = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1485 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1486 char uplo = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1487 char trans = get_blas_char (transt); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1488 char dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1489 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1490 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1491 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1492 F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1493 F77_CONST_CHAR_ARG2 (&trans, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1494 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1495 nr, b_nc, tmp_data, nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1496 result, nr, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1497 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1498 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1499 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1500 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1501 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1502 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1503 if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1504 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1505 char norm = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1506 uplo = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1507 dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1508 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1509 Array<double> z (dim_vector (3 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1510 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1511 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1512 F77_INT *piz = iz.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1513 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1514 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1515 F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1516 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1517 nr, tmp_data, nr, rcon, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1518 pz, piz, tmp_info |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1519 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1520 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1521 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1522 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1523 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1524 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1525 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1526 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1527 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1528 volatile double rcond_plus_one = rcon + 1.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1529 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1530 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1531 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1532 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1533 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1534 if (sing_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1535 sing_handler (rcon); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1536 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1537 octave::warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1538 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1539 } |
5785 | 1540 } |
1541 | |
1542 return retval; | |
1543 } | |
1544 | |
1545 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1546 Matrix::fsolve (MatrixType& mattype, const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1547 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1548 bool calc_cond) const |
5785 | 1549 { |
1550 Matrix retval; | |
1551 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1552 F77_INT nr = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1553 F77_INT nc = octave::to_f77_int (cols ()); |
5785 | 1554 |
6924 | 1555 if (nr != nc || nr != b.rows ()) |
5785 | 1556 (*current_liboctave_error_handler) |
1557 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1558 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1559 if (nr == 0 || b.cols () == 0) |
6924 | 1560 retval = Matrix (nc, b.cols (), 0.0); |
5785 | 1561 else |
1562 { | |
1563 volatile int typ = mattype.type (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1564 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1565 // Calculate the norm of the matrix, for later use. |
5785 | 1566 double anorm = -1.; |
1567 | |
1568 if (typ == MatrixType::Hermitian) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1569 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1570 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1571 char job = 'L'; |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1572 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1573 Matrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1574 double *tmp_data = atmp.fortran_vec (); |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1575 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1576 anorm = atmp.abs().sum().row(static_cast<octave_idx_type>(0)).max(); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1577 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1578 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1579 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1580 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1581 tmp_data, nr, tmp_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1582 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1583 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1584 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1585 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1586 // Throw-away extra info LAPACK gives so as to not change output. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1587 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1588 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1589 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1590 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1591 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1592 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1593 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1594 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1595 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1596 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1597 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1598 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1599 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1600 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1601 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1602 F77_INT *piz = iz.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1603 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1604 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1605 nr, tmp_data, nr, anorm, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1606 rcon, pz, piz, tmp_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1607 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1608 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1609 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1610 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1611 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1612 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1613 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1614 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1615 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1616 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1617 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1618 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1619 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1620 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1621 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1622 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1623 octave::warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1624 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1625 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1626 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1627 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1628 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1629 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1630 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1631 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1632 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1633 F77_INT b_nc = octave::to_f77_int (b.cols ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1634 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1635 F77_XFCN (dpotrs, DPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1636 nr, b_nc, tmp_data, nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1637 result, b_nr, tmp_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1638 F77_CHAR_ARG_LEN (1))); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1639 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1640 info = tmp_info; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1641 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1642 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1643 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1644 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1645 typ = MatrixType::Full; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1646 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1647 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1648 } |
5785 | 1649 |
1650 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1651 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1652 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1653 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1654 Array<F77_INT> ipvt (dim_vector (nr, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1655 F77_INT *pipvt = ipvt.fortran_vec (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1656 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1657 Matrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1658 double *tmp_data = atmp.fortran_vec (); |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1659 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1660 if (anorm < 0.) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1661 anorm = atmp.abs().sum().row(static_cast<octave_idx_type>(0)).max(); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1662 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1663 Array<double> z (dim_vector (4 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1664 double *pz = z.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1665 Array<F77_INT> iz (dim_vector (nc, 1)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1666 F77_INT *piz = iz.fortran_vec (); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1667 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1668 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1669 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1670 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1671 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1672 info = tmp_info; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1673 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1674 // Throw-away extra info LAPACK gives so as to not change output. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1675 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1676 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1677 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1678 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1679 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1680 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1681 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1682 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1683 octave::warn_singular_matrix (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1684 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1685 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1686 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1687 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1688 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1689 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1690 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1691 // Now calculate the condition number for |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1692 // non-singular matrix. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1693 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1694 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1695 nc, tmp_data, nr, anorm, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1696 rcon, pz, piz, tmp_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1697 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1698 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1699 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1700 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1701 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1702 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1703 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1704 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1705 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1706 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1707 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1708 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1709 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1710 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1711 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1712 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1713 octave::warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1714 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1715 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1716 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1717 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1718 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1719 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1720 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1721 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1722 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
1723 F77_INT b_nc = octave::to_f77_int (b.cols ()); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1724 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1725 char job = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1726 F77_XFCN (dgetrs, DGETRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1727 nr, b_nc, tmp_data, nr, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1728 pipvt, result, b_nr, tmp_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1729 F77_CHAR_ARG_LEN (1))); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1730 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
1731 info = tmp_info; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1732 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1733 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1734 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1735 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1736 } |
5785 | 1737 else if (typ != MatrixType::Hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1738 (*current_liboctave_error_handler) ("incorrect matrix type"); |
5785 | 1739 } |
1740 | |
1741 return retval; | |
1742 } | |
1743 | |
1744 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1745 Matrix::solve (MatrixType& mattype, const Matrix& b) const |
5785 | 1746 { |
1747 octave_idx_type info; | |
7788 | 1748 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1749 return solve (mattype, b, info, rcon, nullptr); |
5785 | 1750 } |
1751 | |
1752 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1753 Matrix::solve (MatrixType& mattype, const Matrix& b, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1754 octave_idx_type& info) const |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1755 { |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1756 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1757 return solve (mattype, b, info, rcon, nullptr); |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1758 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1759 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1760 Matrix |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1761 Matrix::solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1762 double& rcon) const |
5785 | 1763 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1764 return solve (mattype, b, info, rcon, nullptr); |
5785 | 1765 } |
1766 | |
1767 Matrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1768 Matrix::solve (MatrixType& mattype, const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1769 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1770 bool singular_fallback, blas_trans_type transt) const |
5785 | 1771 { |
1772 Matrix retval; | |
1773 int typ = mattype.type (); | |
1774 | |
1775 if (typ == MatrixType::Unknown) | |
1776 typ = mattype.type (*this); | |
1777 | |
1778 // Only calculate the condition number for LU/Cholesky | |
1779 if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
19434
aee5fea8a03e
compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents:
19408
diff
changeset
|
1780 retval = utsolve (mattype, b, info, rcon, sing_handler, true, transt); |
5785 | 1781 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
19434
aee5fea8a03e
compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents:
19408
diff
changeset
|
1782 retval = ltsolve (mattype, b, info, rcon, sing_handler, true, transt); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1783 else if (transt == blas_trans || transt == blas_conj_trans) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1784 return transpose ().solve (mattype, b, info, rcon, sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1785 singular_fallback); |
5785 | 1786 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
7788 | 1787 retval = fsolve (mattype, b, info, rcon, sing_handler, true); |
5785 | 1788 else if (typ != MatrixType::Rectangular) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1789 (*current_liboctave_error_handler) ("unknown matrix type"); |
5785 | 1790 |
1791 // Rectangular or one of the above solvers flags a singular matrix | |
1792 if (singular_fallback && mattype.type () == MatrixType::Rectangular) | |
1793 { | |
1794 octave_idx_type rank; | |
7788 | 1795 retval = lssolve (b, info, rank, rcon); |
5785 | 1796 } |
1797 | |
1798 return retval; | |
1799 } | |
1800 | |
1801 ComplexMatrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1802 Matrix::solve (MatrixType& mattype, const ComplexMatrix& b) const |
5785 | 1803 { |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1804 octave_idx_type info; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1805 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1806 return solve (mattype, b, info, rcon, nullptr); |
5785 | 1807 } |
1808 | |
1809 ComplexMatrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1810 Matrix::solve (MatrixType& mattype, const ComplexMatrix& b, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1811 octave_idx_type& info) const |
5785 | 1812 { |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1813 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1814 return solve (mattype, b, info, rcon, nullptr); |
5785 | 1815 } |
1816 | |
1817 ComplexMatrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1818 Matrix::solve (MatrixType& mattype, const ComplexMatrix& b, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1819 octave_idx_type& info, double& rcon) const |
5785 | 1820 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1821 return solve (mattype, b, info, rcon, nullptr); |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1822 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1823 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1824 static Matrix |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1825 stack_complex_matrix (const ComplexMatrix& cm) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1826 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1827 octave_idx_type m = cm.rows (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1828 octave_idx_type n = cm.cols (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1829 octave_idx_type nel = m*n; |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1830 Matrix retval (m, 2*n); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1831 const Complex *cmd = cm.data (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1832 double *rd = retval.fortran_vec (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1833 for (octave_idx_type i = 0; i < nel; i++) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1834 { |
23708
750e42a35adc
Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents:
23596
diff
changeset
|
1835 rd[i] = std::real (cmd[i]); |
750e42a35adc
Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents:
23596
diff
changeset
|
1836 rd[nel+i] = std::imag (cmd[i]); |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1837 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1838 return retval; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1839 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1840 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1841 static ComplexMatrix |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1842 unstack_complex_matrix (const Matrix& sm) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1843 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1844 octave_idx_type m = sm.rows (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1845 octave_idx_type n = sm.cols () / 2; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1846 octave_idx_type nel = m*n; |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1847 ComplexMatrix retval (m, n); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1848 const double *smd = sm.data (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1849 Complex *rd = retval.fortran_vec (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1850 for (octave_idx_type i = 0; i < nel; i++) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1851 rd[i] = Complex (smd[i], smd[nel+i]); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1852 return retval; |
5785 | 1853 } |
1854 | |
1855 ComplexMatrix | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1856 Matrix::solve (MatrixType& mattype, const ComplexMatrix& b, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1857 octave_idx_type& info, double& rcon, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1858 solve_singularity_handler sing_handler, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1859 bool singular_fallback, blas_trans_type transt) const |
5785 | 1860 { |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1861 Matrix tmp = stack_complex_matrix (b); |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1862 tmp = solve (mattype, tmp, info, rcon, sing_handler, singular_fallback, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1863 transt); |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1864 return unstack_complex_matrix (tmp); |
5785 | 1865 } |
1866 | |
1867 ColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1868 Matrix::solve (MatrixType& mattype, const ColumnVector& b) const |
5785 | 1869 { |
7788 | 1870 octave_idx_type info; double rcon; |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1871 return solve (mattype, b, info, rcon); |
5785 | 1872 } |
1873 | |
1874 ColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1875 Matrix::solve (MatrixType& mattype, const ColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1876 octave_idx_type& info) const |
5785 | 1877 { |
7788 | 1878 double rcon; |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1879 return solve (mattype, b, info, rcon); |
5785 | 1880 } |
1881 | |
1882 ColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1883 Matrix::solve (MatrixType& mattype, const ColumnVector& b, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1884 octave_idx_type& info, double& rcon) const |
5785 | 1885 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1886 return solve (mattype, b, info, rcon, nullptr); |
5785 | 1887 } |
1888 | |
1889 ColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1890 Matrix::solve (MatrixType& mattype, const ColumnVector& b, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1891 octave_idx_type& info, double& rcon, |
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1892 solve_singularity_handler sing_handler, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1893 blas_trans_type transt) const |
5785 | 1894 { |
1895 Matrix tmp (b); | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1896 tmp = solve (mattype, tmp, info, rcon, sing_handler, true, transt); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1897 return tmp.column (static_cast<octave_idx_type> (0)); |
5785 | 1898 } |
1899 | |
1900 ComplexColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1901 Matrix::solve (MatrixType& mattype, const ComplexColumnVector& b) const |
5785 | 1902 { |
1903 ComplexMatrix tmp (*this); | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1904 return tmp.solve (mattype, b); |
5785 | 1905 } |
1906 | |
1907 ComplexColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1908 Matrix::solve (MatrixType& mattype, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1909 octave_idx_type& info) const |
5785 | 1910 { |
1911 ComplexMatrix tmp (*this); | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1912 return tmp.solve (mattype, b, info); |
5785 | 1913 } |
1914 | |
1915 ComplexColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1916 Matrix::solve (MatrixType& mattype, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1917 octave_idx_type& info, double& rcon) const |
5785 | 1918 { |
1919 ComplexMatrix tmp (*this); | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1920 return tmp.solve (mattype, b, info, rcon); |
5785 | 1921 } |
1922 | |
1923 ComplexColumnVector | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1924 Matrix::solve (MatrixType& mattype, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1925 octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1926 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1927 blas_trans_type transt) const |
5785 | 1928 { |
1929 ComplexMatrix tmp (*this); | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1930 return tmp.solve (mattype, b, info, rcon, sing_handler, transt); |
5785 | 1931 } |
1932 | |
1933 Matrix | |
458 | 1934 Matrix::solve (const Matrix& b) const |
1935 { | |
5275 | 1936 octave_idx_type info; |
7788 | 1937 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1938 return solve (b, info, rcon, nullptr); |
458 | 1939 } |
1940 | |
1941 Matrix | |
5275 | 1942 Matrix::solve (const Matrix& b, octave_idx_type& info) const |
458 | 1943 { |
7788 | 1944 double rcon; |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1945 return solve (b, info, rcon, nullptr); |
458 | 1946 } |
1947 | |
1948 Matrix | |
7788 | 1949 Matrix::solve (const Matrix& b, octave_idx_type& info, double& rcon) const |
458 | 1950 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
1951 return solve (b, info, rcon, nullptr); |
3480 | 1952 } |
1953 | |
1954 Matrix | |
5785 | 1955 Matrix::solve (const Matrix& b, octave_idx_type& info, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1956 double& rcon, solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1957 blas_trans_type transt) const |
3480 | 1958 { |
5785 | 1959 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1960 return solve (mattype, b, info, rcon, sing_handler, true, transt); |
458 | 1961 } |
1962 | |
1963 ComplexMatrix | |
1964 Matrix::solve (const ComplexMatrix& b) const | |
1965 { | |
1966 ComplexMatrix tmp (*this); | |
1967 return tmp.solve (b); | |
1968 } | |
1969 | |
1970 ComplexMatrix | |
5275 | 1971 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 1972 { |
1973 ComplexMatrix tmp (*this); | |
1974 return tmp.solve (b, info); | |
1975 } | |
1976 | |
1977 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1978 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1979 double& rcon) const |
458 | 1980 { |
1981 ComplexMatrix tmp (*this); | |
7788 | 1982 return tmp.solve (b, info, rcon); |
458 | 1983 } |
1984 | |
3480 | 1985 ComplexMatrix |
7788 | 1986 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1987 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1988 blas_trans_type transt) const |
3480 | 1989 { |
1990 ComplexMatrix tmp (*this); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1991 return tmp.solve (b, info, rcon, sing_handler, transt); |
3480 | 1992 } |
1993 | |
458 | 1994 ColumnVector |
1995 Matrix::solve (const ColumnVector& b) const | |
1996 { | |
7788 | 1997 octave_idx_type info; double rcon; |
1998 return solve (b, info, rcon); | |
458 | 1999 } |
2000 | |
2001 ColumnVector | |
5275 | 2002 Matrix::solve (const ColumnVector& b, octave_idx_type& info) const |
458 | 2003 { |
7788 | 2004 double rcon; |
2005 return solve (b, info, rcon); | |
458 | 2006 } |
2007 | |
2008 ColumnVector | |
7788 | 2009 Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const |
458 | 2010 { |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23708
diff
changeset
|
2011 return solve (b, info, rcon, nullptr); |
3480 | 2012 } |
2013 | |
2014 ColumnVector | |
7788 | 2015 Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2016 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2017 blas_trans_type transt) const |
3480 | 2018 { |
5785 | 2019 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2020 return solve (mattype, b, info, rcon, sing_handler, transt); |
458 | 2021 } |
2022 | |
2023 ComplexColumnVector | |
2024 Matrix::solve (const ComplexColumnVector& b) const | |
2025 { | |
2026 ComplexMatrix tmp (*this); | |
2027 return tmp.solve (b); | |
2028 } | |
2029 | |
2030 ComplexColumnVector | |
5275 | 2031 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info) const |
458 | 2032 { |
2033 ComplexMatrix tmp (*this); | |
2034 return tmp.solve (b, info); | |
2035 } | |
2036 | |
2037 ComplexColumnVector | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2038 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2039 double& rcon) const |
458 | 2040 { |
2041 ComplexMatrix tmp (*this); | |
7788 | 2042 return tmp.solve (b, info, rcon); |
458 | 2043 } |
2044 | |
3480 | 2045 ComplexColumnVector |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2046 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2047 double& rcon, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2048 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2049 blas_trans_type transt) const |
3480 | 2050 { |
2051 ComplexMatrix tmp (*this); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2052 return tmp.solve (b, info, rcon, sing_handler, transt); |
3480 | 2053 } |
2054 | |
458 | 2055 Matrix |
2056 Matrix::lssolve (const Matrix& b) const | |
2057 { | |
5275 | 2058 octave_idx_type info; |
2059 octave_idx_type rank; | |
7788 | 2060 double rcon; |
2061 return lssolve (b, info, rank, rcon); | |
458 | 2062 } |
2063 | |
2064 Matrix | |
5275 | 2065 Matrix::lssolve (const Matrix& b, octave_idx_type& info) const |
458 | 2066 { |
5275 | 2067 octave_idx_type rank; |
7788 | 2068 double rcon; |
2069 return lssolve (b, info, rank, rcon); | |
458 | 2070 } |
2071 | |
2072 Matrix | |
7072 | 2073 Matrix::lssolve (const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2074 octave_idx_type& rank) const |
458 | 2075 { |
7788 | 2076 double rcon; |
2077 return lssolve (b, info, rank, rcon); | |
7076 | 2078 } |
2079 | |
2080 Matrix | |
2081 Matrix::lssolve (const Matrix& b, octave_idx_type& info, | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2082 octave_idx_type& rank, double& rcon) const |
7076 | 2083 { |
1948 | 2084 Matrix retval; |
2085 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2086 F77_INT nrhs = octave::to_f77_int (b.cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2087 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2088 F77_INT m = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2089 F77_INT n = octave::to_f77_int (cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2090 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2091 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2092 F77_INT b_nc = octave::to_f77_int (b.cols ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2093 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2094 if (m != b_nr) |
1948 | 2095 (*current_liboctave_error_handler) |
6924 | 2096 ("matrix dimension mismatch solution of linear equations"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2097 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2098 if (m == 0 || n == 0 || b_nc == 0) |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2099 retval = Matrix (n, b_nc, 0.0); |
1948 | 2100 else |
458 | 2101 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2102 volatile F77_INT minmn = (m < n ? m : n); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2103 F77_INT maxmn = (m > n ? m : n); |
7788 | 2104 rcon = -1.0; |
7072 | 2105 if (m != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2106 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2107 retval = Matrix (maxmn, nrhs, 0.0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2108 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2109 for (F77_INT j = 0; j < nrhs; j++) |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2110 for (F77_INT i = 0; i < m; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2111 retval.elem (i, j) = b.elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2112 } |
7072 | 2113 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2114 retval = b; |
7072 | 2115 |
1948 | 2116 Matrix atmp = *this; |
2117 double *tmp_data = atmp.fortran_vec (); | |
2118 | |
7072 | 2119 double *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2120 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2121 double *ps = s.fortran_vec (); |
1948 | 2122 |
7072 | 2123 // Ask DGELSD what the dimension of WORK should be. |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2124 F77_INT lwork = -1; |
3752 | 2125 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2126 Array<double> work (dim_vector (1, 1)); |
1948 | 2127 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2128 F77_INT smlsiz; |
7477 | 2129 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2130 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2131 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2132 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2133 F77_CHAR_ARG_LEN (1)); |
7079 | 2134 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2135 F77_INT mnthr; |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2136 F77_FUNC (xilaenv, XILAENV) (6, F77_CONST_CHAR_ARG2 ("DGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2137 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2138 m, n, nrhs, -1, mnthr |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2139 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2140 F77_CHAR_ARG_LEN (1)); |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2141 |
7079 | 2142 // We compute the size of iwork because DGELSD in older versions |
2143 // of LAPACK does not return it on a query call. | |
7124 | 2144 double dminmn = static_cast<double> (minmn); |
2145 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2146 double tmp = octave::math::log2 (dminmn / dsmlsizp1); |
22598
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2147 double anorm = 0.0; |
18847
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2148 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2149 F77_INT nlvl = static_cast<F77_INT> (tmp) + 1; |
7079 | 2150 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2151 nlvl = 0; |
7079 | 2152 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2153 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn; |
7079 | 2154 if (liwork < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2155 liwork = 1; |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2156 Array<F77_INT> iwork (dim_vector (liwork, 1)); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
2157 F77_INT *piwork = iwork.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2158 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2159 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2160 F77_INT tmp_rank = 0; |
7072 | 2161 |
2162 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2163 ps, rcon, tmp_rank, work.fortran_vec (), |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2164 lwork, piwork, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2165 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2166 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2167 rank = tmp_rank; |
1948 | 2168 |
7476 | 2169 // The workspace query is broken in at least LAPACK 3.0.0 |
7488
6470f946a425
another small xGELSD workspace fix
John W. Eaton <jwe@octave.org>
parents:
7486
diff
changeset
|
2170 // through 3.1.1 when n >= mnthr. The obtuse formula below |
7476 | 2171 // should provide sufficient workspace for DGELSD to operate |
2172 // efficiently. | |
10813
2c2d4a2f1047
fix workspace bug workaround for xGELSD (since 7486:6a6d2abe51ff)
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
2173 if (n > m && n >= mnthr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2174 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2175 const F77_INT wlalsd |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2176 = 9*m + 2*m*smlsiz + 8*m*nlvl + m*nrhs + (smlsiz+1)*(smlsiz+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2177 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2178 F77_INT addend = m; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2179 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2180 if (2*m-4 > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2181 addend = 2*m-4; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2182 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2183 if (nrhs > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2184 addend = nrhs; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2185 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2186 if (n-3*m > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2187 addend = n-3*m; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2188 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2189 if (wlalsd > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2190 addend = wlalsd; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2191 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2192 const F77_INT lworkaround = 4*m + m*m + addend; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2193 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2194 if (work(0) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2195 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2196 } |
7532
493bb0de3199
avoid another xGELSD workspace query bug
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
2197 else if (m >= n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2198 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2199 F77_INT lworkaround |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2200 = 12*n + 2*n*smlsiz + 8*n*nlvl + n*nrhs + (smlsiz+1)*(smlsiz+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2201 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2202 if (work(0) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2203 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2204 } |
7476 | 2205 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2206 lwork = static_cast<F77_INT> (work(0)); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2207 work.resize (dim_vector (lwork, 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2208 |
22598
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2209 anorm = xnorm (*this, 1); |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2210 |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2211 if (octave::math::isinf (anorm) || octave::math::isnan (anorm)) |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2212 { |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2213 rcon = 0.0; |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2214 octave::warn_singular_matrix (); |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2215 retval = Matrix (n, m, 0.0); |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2216 } |
1948 | 2217 else |
22598
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2218 { |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2219 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2220 maxmn, ps, rcon, tmp_rank, |
22598
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2221 work.fortran_vec (), lwork, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2222 piwork, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2223 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2224 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2225 rank = tmp_rank; |
22598
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2226 |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2227 if (s.elem (0) == 0.0) |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2228 rcon = 0.0; |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2229 else |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2230 rcon = s.elem (minmn - 1) / s.elem (0); |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2231 |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2232 retval.resize (n, nrhs); |
5aa8f199e328
avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents:
22417
diff
changeset
|
2233 } |
458 | 2234 } |
2235 | |
2236 return retval; | |
2237 } | |
2238 | |
2239 ComplexMatrix | |
2240 Matrix::lssolve (const ComplexMatrix& b) const | |
2241 { | |
2242 ComplexMatrix tmp (*this); | |
5275 | 2243 octave_idx_type info; |
2244 octave_idx_type rank; | |
7788 | 2245 double rcon; |
2246 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2247 } |
2248 | |
2249 ComplexMatrix | |
5275 | 2250 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 2251 { |
2252 ComplexMatrix tmp (*this); | |
5275 | 2253 octave_idx_type rank; |
7788 | 2254 double rcon; |
2255 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2256 } |
2257 | |
2258 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2259 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2260 octave_idx_type& rank) const |
458 | 2261 { |
2262 ComplexMatrix tmp (*this); | |
7788 | 2263 double rcon; |
2264 return tmp.lssolve (b, info, rank, rcon); | |
7076 | 2265 } |
2266 | |
2267 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2268 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2269 octave_idx_type& rank, double& rcon) const |
7076 | 2270 { |
2271 ComplexMatrix tmp (*this); | |
7788 | 2272 return tmp.lssolve (b, info, rank, rcon); |
458 | 2273 } |
2274 | |
2275 ColumnVector | |
2276 Matrix::lssolve (const ColumnVector& b) const | |
2277 { | |
5275 | 2278 octave_idx_type info; |
2279 octave_idx_type rank; | |
7788 | 2280 double rcon; |
2281 return lssolve (b, info, rank, rcon); | |
458 | 2282 } |
2283 | |
2284 ColumnVector | |
5275 | 2285 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info) const |
458 | 2286 { |
5275 | 2287 octave_idx_type rank; |
7788 | 2288 double rcon; |
2289 return lssolve (b, info, rank, rcon); | |
458 | 2290 } |
2291 | |
2292 ColumnVector | |
7072 | 2293 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2294 octave_idx_type& rank) const |
458 | 2295 { |
7788 | 2296 double rcon; |
2297 return lssolve (b, info, rank, rcon); | |
7076 | 2298 } |
2299 | |
2300 ColumnVector | |
2301 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info, | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2302 octave_idx_type& rank, double& rcon) const |
7076 | 2303 { |
1948 | 2304 ColumnVector retval; |
2305 | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2306 F77_INT nrhs = 1; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2307 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2308 F77_INT m = octave::to_f77_int (rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2309 F77_INT n = octave::to_f77_int (cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2310 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2311 F77_INT b_nel = octave::to_f77_int (b.numel ()); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2312 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2313 if (m != b_nel) |
1948 | 2314 (*current_liboctave_error_handler) |
6924 | 2315 ("matrix dimension mismatch solution of linear equations"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2316 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2317 if (m == 0 || n == 0) |
6924 | 2318 retval = ColumnVector (n, 0.0); |
1948 | 2319 else |
458 | 2320 { |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2321 volatile F77_INT minmn = (m < n ? m : n); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2322 F77_INT maxmn = (m > n ? m : n); |
7788 | 2323 rcon = -1.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2324 |
7072 | 2325 if (m != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2326 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2327 retval = ColumnVector (maxmn, 0.0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2328 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2329 for (F77_INT i = 0; i < m; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2330 retval.elem (i) = b.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2331 } |
7072 | 2332 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2333 retval = b; |
7072 | 2334 |
1948 | 2335 Matrix atmp = *this; |
2336 double *tmp_data = atmp.fortran_vec (); | |
2337 | |
7072 | 2338 double *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2339 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2340 double *ps = s.fortran_vec (); |
1948 | 2341 |
7072 | 2342 // Ask DGELSD what the dimension of WORK should be. |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2343 F77_INT lwork = -1; |
3752 | 2344 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2345 Array<double> work (dim_vector (1, 1)); |
3752 | 2346 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2347 F77_INT smlsiz; |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2348 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2349 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2350 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2351 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2352 F77_CHAR_ARG_LEN (1)); |
7079 | 2353 |
2354 // We compute the size of iwork because DGELSD in older versions | |
2355 // of LAPACK does not return it on a query call. | |
7124 | 2356 double dminmn = static_cast<double> (minmn); |
2357 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2358 double tmp = octave::math::log2 (dminmn / dsmlsizp1); |
18847
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2359 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2360 F77_INT nlvl = static_cast<F77_INT> (tmp) + 1; |
7079 | 2361 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2362 nlvl = 0; |
7079 | 2363 |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2364 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn; |
7079 | 2365 if (liwork < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2366 liwork = 1; |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2367 Array<F77_INT> iwork (dim_vector (liwork, 1)); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
2368 F77_INT *piwork = iwork.fortran_vec (); |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2369 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2370 F77_INT tmp_info = 0; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2371 F77_INT tmp_rank = 0; |
7072 | 2372 |
2373 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2374 ps, rcon, tmp_rank, work.fortran_vec (), |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2375 lwork, piwork, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2376 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2377 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2378 rank = tmp_rank; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2379 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2380 lwork = static_cast<F77_INT> (work(0)); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2381 work.resize (dim_vector (lwork, 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2382 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2383 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2384 maxmn, ps, rcon, tmp_rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2385 work.fortran_vec (), lwork, |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2386 piwork, tmp_info)); |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2387 |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2388 info = tmp_info; |
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2389 rank = tmp_rank; |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2390 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2391 if (rank < minmn) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2392 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2393 if (s.elem (0) == 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2394 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2395 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2396 rcon = s.elem (minmn - 1) / s.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2397 } |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2398 |
22848
a3bd04422a87
don't pass two dimensions to column vector resize method
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
2399 retval.resize (n); |
458 | 2400 } |
2401 | |
2402 return retval; | |
2403 } | |
2404 | |
2405 ComplexColumnVector | |
2406 Matrix::lssolve (const ComplexColumnVector& b) const | |
2407 { | |
2408 ComplexMatrix tmp (*this); | |
7076 | 2409 octave_idx_type info; |
2410 octave_idx_type rank; | |
7788 | 2411 double rcon; |
2412 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2413 } |
2414 | |
2415 ComplexColumnVector | |
5275 | 2416 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info) const |
458 | 2417 { |
2418 ComplexMatrix tmp (*this); | |
7076 | 2419 octave_idx_type rank; |
7788 | 2420 double rcon; |
2421 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2422 } |
2423 | |
2424 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2425 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2426 octave_idx_type& rank) const |
458 | 2427 { |
2428 ComplexMatrix tmp (*this); | |
7788 | 2429 double rcon; |
2430 return tmp.lssolve (b, info, rank, rcon); | |
7076 | 2431 } |
2432 | |
2433 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2434 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2435 octave_idx_type& rank, double& rcon) const |
7076 | 2436 { |
2437 ComplexMatrix tmp (*this); | |
7788 | 2438 return tmp.lssolve (b, info, rank, rcon); |
458 | 2439 } |
2440 | |
2441 Matrix& | |
2442 Matrix::operator += (const DiagMatrix& a) | |
2443 { | |
5275 | 2444 octave_idx_type nr = rows (); |
2445 octave_idx_type nc = cols (); | |
2446 | |
2447 octave_idx_type a_nr = a.rows (); | |
2448 octave_idx_type a_nc = a.cols (); | |
2385 | 2449 |
2450 if (nr != a_nr || nc != a_nc) | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2451 octave::err_nonconformant ("operator +=", nr, nc, a_nr, a_nc); |
458 | 2452 |
5275 | 2453 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2454 elem (i, i) += a.elem (i, i); |
2455 | |
2456 return *this; | |
2457 } | |
2458 | |
2459 Matrix& | |
2460 Matrix::operator -= (const DiagMatrix& a) | |
2461 { | |
5275 | 2462 octave_idx_type nr = rows (); |
2463 octave_idx_type nc = cols (); | |
2464 | |
2465 octave_idx_type a_nr = a.rows (); | |
2466 octave_idx_type a_nc = a.cols (); | |
2385 | 2467 |
2468 if (nr != a_nr || nc != a_nc) | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2469 octave::err_nonconformant ("operator -=", nr, nc, a_nr, a_nc); |
458 | 2470 |
5275 | 2471 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2472 elem (i, i) -= a.elem (i, i); |
2473 | |
2474 return *this; | |
2475 } | |
2476 | |
2477 // unary operations | |
2478 | |
1205 | 2479 // column vector by row vector -> matrix operations |
458 | 2480 |
1205 | 2481 Matrix |
2482 operator * (const ColumnVector& v, const RowVector& a) | |
458 | 2483 { |
1948 | 2484 Matrix retval; |
2485 | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2486 F77_INT len = octave::to_f77_int (v.numel ()); |
3233 | 2487 |
2488 if (len != 0) | |
1205 | 2489 { |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2490 F77_INT a_len = octave::to_f77_int (a.numel ()); |
3233 | 2491 |
9359
be6867ba8104
avoid useless zero initialization when doing matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
2492 retval = Matrix (len, a_len); |
3233 | 2493 double *c = retval.fortran_vec (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2494 |
4552 | 2495 F77_XFCN (dgemm, DGEMM, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2496 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2497 len, a_len, 1, 1.0, v.data (), len, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2498 a.data (), 1, 0.0, c, len |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2499 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2500 F77_CHAR_ARG_LEN (1))); |
1205 | 2501 } |
458 | 2502 |
1948 | 2503 return retval; |
458 | 2504 } |
2505 | |
2506 // other operations. | |
2507 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2508 // FIXME: Do these really belong here? Maybe they should be in a base class? |
458 | 2509 |
2832 | 2510 boolMatrix |
4015 | 2511 Matrix::all (int dim) const |
458 | 2512 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2513 return NDArray::all (dim); |
458 | 2514 } |
2515 | |
2832 | 2516 boolMatrix |
4015 | 2517 Matrix::any (int dim) const |
458 | 2518 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2519 return NDArray::any (dim); |
458 | 2520 } |
2521 | |
2522 Matrix | |
3723 | 2523 Matrix::cumprod (int dim) const |
458 | 2524 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2525 return NDArray::cumprod (dim); |
458 | 2526 } |
2527 | |
2528 Matrix | |
3723 | 2529 Matrix::cumsum (int dim) const |
458 | 2530 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2531 return NDArray::cumsum (dim); |
458 | 2532 } |
2533 | |
2534 Matrix | |
3723 | 2535 Matrix::prod (int dim) const |
458 | 2536 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2537 return NDArray::prod (dim); |
458 | 2538 } |
2539 | |
2540 Matrix | |
3723 | 2541 Matrix::sum (int dim) const |
458 | 2542 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2543 return NDArray::sum (dim); |
458 | 2544 } |
2545 | |
2546 Matrix | |
3723 | 2547 Matrix::sumsq (int dim) const |
458 | 2548 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2549 return NDArray::sumsq (dim); |
458 | 2550 } |
2551 | |
2385 | 2552 Matrix |
2553 Matrix::abs (void) const | |
2554 { | |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
2555 return NDArray::abs (); |
2385 | 2556 } |
2557 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7544
diff
changeset
|
2558 Matrix |
5275 | 2559 Matrix::diag (octave_idx_type k) const |
458 | 2560 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
2561 return NDArray::diag (k); |
458 | 2562 } |
2563 | |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2564 DiagMatrix |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2565 Matrix::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2566 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2567 DiagMatrix retval; |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2568 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2569 octave_idx_type nr = rows (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2570 octave_idx_type nc = cols (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2571 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2572 if (nr == 1 || nc == 1) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2573 retval = DiagMatrix (*this, m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2574 else |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2575 (*current_liboctave_error_handler) ("diag: expecting vector argument"); |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2576 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2577 return retval; |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2578 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
2579 |
458 | 2580 ColumnVector |
2581 Matrix::row_min (void) const | |
2582 { | |
5275 | 2583 Array<octave_idx_type> dummy_idx; |
4587 | 2584 return row_min (dummy_idx); |
458 | 2585 } |
2586 | |
2587 ColumnVector | |
5275 | 2588 Matrix::row_min (Array<octave_idx_type>& idx_arg) const |
458 | 2589 { |
2590 ColumnVector result; | |
2591 | |
5275 | 2592 octave_idx_type nr = rows (); |
2593 octave_idx_type nc = cols (); | |
458 | 2594 |
2595 if (nr > 0 && nc > 0) | |
2596 { | |
2597 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2598 idx_arg.resize (dim_vector (nr, 1)); |
458 | 2599 |
5275 | 2600 for (octave_idx_type i = 0; i < nr; i++) |
458 | 2601 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2602 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2603 |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2604 double tmp_min = octave::numeric_limits<double>::NaN (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2605 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2606 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2607 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2608 tmp_min = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2609 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2610 if (! octave::math::isnan (tmp_min)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2611 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2612 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2613 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2614 for (octave_idx_type j = idx_j+1; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2615 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2616 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2617 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2618 if (octave::math::isnan (tmp)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2619 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2620 else if (tmp < tmp_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2621 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2622 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2623 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2624 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2625 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2626 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2627 result.elem (i) = tmp_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2628 idx_arg.elem (i) = (octave::math::isnan (tmp_min) ? 0 : idx_j); |
458 | 2629 } |
2630 } | |
2631 | |
2632 return result; | |
2633 } | |
2634 | |
2635 ColumnVector | |
2636 Matrix::row_max (void) const | |
2637 { | |
5275 | 2638 Array<octave_idx_type> dummy_idx; |
4587 | 2639 return row_max (dummy_idx); |
458 | 2640 } |
2641 | |
2642 ColumnVector | |
5275 | 2643 Matrix::row_max (Array<octave_idx_type>& idx_arg) const |
458 | 2644 { |
2645 ColumnVector result; | |
2646 | |
5275 | 2647 octave_idx_type nr = rows (); |
2648 octave_idx_type nc = cols (); | |
458 | 2649 |
2650 if (nr > 0 && nc > 0) | |
2651 { | |
2652 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2653 idx_arg.resize (dim_vector (nr, 1)); |
458 | 2654 |
5275 | 2655 for (octave_idx_type i = 0; i < nr; i++) |
458 | 2656 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2657 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2658 |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2659 double tmp_max = octave::numeric_limits<double>::NaN (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2660 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2661 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2662 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2663 tmp_max = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2664 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2665 if (! octave::math::isnan (tmp_max)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2666 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2667 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2668 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2669 for (octave_idx_type j = idx_j+1; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2670 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2671 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2672 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2673 if (octave::math::isnan (tmp)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2674 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2675 else if (tmp > tmp_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2676 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2677 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2678 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2679 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2680 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2681 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2682 result.elem (i) = tmp_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2683 idx_arg.elem (i) = (octave::math::isnan (tmp_max) ? 0 : idx_j); |
458 | 2684 } |
2685 } | |
2686 | |
2687 return result; | |
2688 } | |
2689 | |
2690 RowVector | |
2691 Matrix::column_min (void) const | |
2692 { | |
5275 | 2693 Array<octave_idx_type> dummy_idx; |
4587 | 2694 return column_min (dummy_idx); |
458 | 2695 } |
2354 | 2696 |
458 | 2697 RowVector |
5275 | 2698 Matrix::column_min (Array<octave_idx_type>& idx_arg) const |
458 | 2699 { |
2700 RowVector result; | |
2701 | |
5275 | 2702 octave_idx_type nr = rows (); |
2703 octave_idx_type nc = cols (); | |
458 | 2704 |
2705 if (nr > 0 && nc > 0) | |
2706 { | |
2707 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2708 idx_arg.resize (dim_vector (1, nc)); |
458 | 2709 |
5275 | 2710 for (octave_idx_type j = 0; j < nc; j++) |
458 | 2711 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2712 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2713 |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2714 double tmp_min = octave::numeric_limits<double>::NaN (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2715 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2716 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2717 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2718 tmp_min = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2719 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2720 if (! octave::math::isnan (tmp_min)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2721 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2722 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2723 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2724 for (octave_idx_type i = idx_i+1; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2725 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2726 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2727 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2728 if (octave::math::isnan (tmp)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2729 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2730 else if (tmp < tmp_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2731 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2732 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2733 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2734 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2735 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2736 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2737 result.elem (j) = tmp_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2738 idx_arg.elem (j) = (octave::math::isnan (tmp_min) ? 0 : idx_i); |
458 | 2739 } |
2740 } | |
2741 | |
2742 return result; | |
2743 } | |
2744 | |
2354 | 2745 RowVector |
2746 Matrix::column_max (void) const | |
2747 { | |
5275 | 2748 Array<octave_idx_type> dummy_idx; |
4587 | 2749 return column_max (dummy_idx); |
2354 | 2750 } |
458 | 2751 |
2752 RowVector | |
5275 | 2753 Matrix::column_max (Array<octave_idx_type>& idx_arg) const |
458 | 2754 { |
2755 RowVector result; | |
2756 | |
5275 | 2757 octave_idx_type nr = rows (); |
2758 octave_idx_type nc = cols (); | |
458 | 2759 |
2760 if (nr > 0 && nc > 0) | |
2761 { | |
2762 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2763 idx_arg.resize (dim_vector (1, nc)); |
458 | 2764 |
5275 | 2765 for (octave_idx_type j = 0; j < nc; j++) |
458 | 2766 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2767 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2768 |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
2769 double tmp_max = octave::numeric_limits<double>::NaN (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2770 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2771 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2772 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2773 tmp_max = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2774 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2775 if (! octave::math::isnan (tmp_max)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2776 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2777 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2778 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2779 for (octave_idx_type i = idx_i+1; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2780 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2781 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2782 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2783 if (octave::math::isnan (tmp)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2784 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2785 else if (tmp > tmp_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2786 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2787 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2788 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2789 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2790 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2791 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2792 result.elem (j) = tmp_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2793 idx_arg.elem (j) = (octave::math::isnan (tmp_max) ? 0 : idx_i); |
458 | 2794 } |
2795 } | |
2796 | |
2797 return result; | |
2798 } | |
2799 | |
3504 | 2800 std::ostream& |
2801 operator << (std::ostream& os, const Matrix& a) | |
458 | 2802 { |
5275 | 2803 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 2804 { |
5275 | 2805 for (octave_idx_type j = 0; j < a.cols (); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2806 { |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
2807 os << ' '; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2808 octave_write_double (os, a.elem (i, j)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2809 } |
458 | 2810 os << "\n"; |
2811 } | |
2812 return os; | |
2813 } | |
2814 | |
3504 | 2815 std::istream& |
2816 operator >> (std::istream& is, Matrix& a) | |
458 | 2817 { |
5275 | 2818 octave_idx_type nr = a.rows (); |
2819 octave_idx_type nc = a.cols (); | |
458 | 2820 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
2821 if (nr > 0 && nc > 0) |
458 | 2822 { |
2823 double tmp; | |
5275 | 2824 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2825 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2826 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2827 tmp = octave_read_value<double> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2828 if (is) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2829 a.elem (i, j) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2830 else |
21169
40051830f89b
maint: Replace more instances of goto in liboctave with other constructs.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
2831 return is; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2832 } |
458 | 2833 } |
2834 | |
2835 return is; | |
2836 } | |
2837 | |
1819 | 2838 Matrix |
2839 Givens (double x, double y) | |
2840 { | |
2841 double cc, s, temp_r; | |
2842 | |
3887 | 2843 F77_FUNC (dlartg, DLARTG) (x, y, cc, s, temp_r); |
1819 | 2844 |
2845 Matrix g (2, 2); | |
2846 | |
2847 g.elem (0, 0) = cc; | |
2848 g.elem (1, 1) = cc; | |
2849 g.elem (0, 1) = s; | |
2850 g.elem (1, 0) = -s; | |
2851 | |
2852 return g; | |
2853 } | |
2854 | |
2855 Matrix | |
2856 Sylvester (const Matrix& a, const Matrix& b, const Matrix& c) | |
2857 { | |
2858 Matrix retval; | |
2859 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2860 // FIXME: need to check that a, b, and c are all the same size. |
1819 | 2861 |
2862 // Compute Schur decompositions. | |
2863 | |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
2864 octave::math::schur<Matrix> as (a, "U"); |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
2865 octave::math::schur<Matrix> bs (b, "U"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2866 |
1819 | 2867 // Transform c to new coordinates. |
2868 | |
2869 Matrix ua = as.unitary_matrix (); | |
2870 Matrix sch_a = as.schur_matrix (); | |
2871 | |
2872 Matrix ub = bs.unitary_matrix (); | |
2873 Matrix sch_b = bs.schur_matrix (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2874 |
1819 | 2875 Matrix cx = ua.transpose () * c * ub; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2876 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2877 // Solve the sylvester equation, back-transform, and return the solution. |
1819 | 2878 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2879 F77_INT a_nr = octave::to_f77_int (a.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2880 F77_INT b_nr = octave::to_f77_int (b.rows ()); |
1819 | 2881 |
2882 double scale; | |
22971
d244af1d0bc7
use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents:
22849
diff
changeset
|
2883 F77_INT info; |
1819 | 2884 |
1950 | 2885 double *pa = sch_a.fortran_vec (); |
2886 double *pb = sch_b.fortran_vec (); | |
2887 double *px = cx.fortran_vec (); | |
2888 | |
4552 | 2889 F77_XFCN (dtrsyl, DTRSYL, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2890 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2891 1, a_nr, b_nr, pa, a_nr, pb, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2892 b_nr, px, a_nr, scale, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2893 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2894 F77_CHAR_ARG_LEN (1))); |
1950 | 2895 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2896 // FIXME: check info? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2897 |
19065
d20c81d3cd21
Deprecate syl, add new function sylvester.
Rik <rik@octave.org>
parents:
18850
diff
changeset
|
2898 retval = ua*cx*ub.transpose (); |
1819 | 2899 |
2900 return retval; | |
2901 } | |
2902 | |
2828 | 2903 // matrix by matrix -> matrix operations |
2904 | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2905 /* |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2906 |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2907 ## Simple Dot Product, Matrix-Vector and Matrix-Matrix Unit tests |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2908 %!assert ([1 2 3] * [ 4 ; 5 ; 6], 32, 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2909 %!assert ([1 2 ; 3 4 ] * [5 ; 6], [17 ; 39 ], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2910 %!assert ([1 2 ; 3 4 ] * [5 6 ; 7 8], [19 22; 43 50], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2911 |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2912 ## Test some simple identities |
12992
0413227e407b
dMatrix.cc: Fix tests introduced by changeset f217edac2c71. Declare variables
Marco atzeri <marco.atzeri@gmail.com>
parents:
12986
diff
changeset
|
2913 %!shared M, cv, rv, Mt, rvt |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2914 %! M = randn (10,10) + 100*eye (10,10); |
12986
f217edac2c71
fix dimension check for A'\B (bug #33997)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2915 %! Mt = M'; |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2916 %! cv = randn (10,1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2917 %! rv = randn (1,10); |
12986
f217edac2c71
fix dimension check for A'\B (bug #33997)
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
2918 %! rvt = rv'; |
22152
19d54df7d719
test: increase tolerance on Matrix tests
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
2919 %!assert ([M*cv,M*cv], M*[cv,cv], 2e-13) |
19d54df7d719
test: increase tolerance on Matrix tests
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
2920 %!assert ([M'*cv,M'*cv], M'*[cv,cv], 2e-13) |
19d54df7d719
test: increase tolerance on Matrix tests
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
2921 %!assert ([rv*M;rv*M], [rv;rv]*M, 2e-13) |
19d54df7d719
test: increase tolerance on Matrix tests
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
2922 %!assert ([rv*M';rv*M'], [rv;rv]*M', 2e-13) |
19d54df7d719
test: increase tolerance on Matrix tests
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
2923 %!assert (2*rv*cv, [rv,rv]*[cv;cv], 2e-13) |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2924 %!assert (M'\cv, Mt\cv, 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2925 %!assert (M'\rv', Mt\rvt, 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2926 |
6162 | 2927 */ |
2928 | |
11516 | 2929 static inline char |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2930 get_blas_trans_arg (bool trans) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2931 { |
11516 | 2932 return trans ? 'T' : 'N'; |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2933 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2934 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2935 // the general GEMM operation |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2936 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2937 Matrix |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2938 xgemm (const Matrix& a, const Matrix& b, |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
2939 blas_trans_type transa, blas_trans_type transb) |
2828 | 2940 { |
2941 Matrix retval; | |
2942 | |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2943 bool tra = transa != blas_no_trans; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2944 bool trb = transb != blas_no_trans; |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
2945 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2946 F77_INT a_nr = octave::to_f77_int (tra ? a.cols () : a.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2947 F77_INT a_nc = octave::to_f77_int (tra ? a.rows () : a.cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2948 |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2949 F77_INT b_nr = octave::to_f77_int (trb ? b.cols () : b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2950 F77_INT b_nc = octave::to_f77_int (trb ? b.rows () : b.cols ()); |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2951 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2952 if (a_nc != b_nr) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2953 octave::err_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2954 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2955 if (a_nr == 0 || a_nc == 0 || b_nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2956 retval = Matrix (a_nr, b_nc, 0.0); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2957 else if (a.data () == b.data () && a_nr == b_nc && tra != trb) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2958 { |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2959 F77_INT lda = octave::to_f77_int (a.rows ()); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2960 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2961 retval = Matrix (a_nr, b_nc); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2962 double *c = retval.fortran_vec (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2963 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2964 const char ctra = get_blas_trans_arg (tra); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2965 F77_XFCN (dsyrk, DSYRK, (F77_CONST_CHAR_ARG2 ("U", 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2966 F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2967 a_nr, a_nc, 1.0, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2968 a.data (), lda, 0.0, c, a_nr |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2969 F77_CHAR_ARG_LEN (1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2970 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2971 for (int j = 0; j < a_nr; j++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2972 for (int i = 0; i < j; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2973 retval.xelem (j,i) = retval.xelem (i,j); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2974 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2975 } |
2828 | 2976 else |
2977 { | |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2978 F77_INT lda = octave::to_f77_int (a.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2979 F77_INT tda = octave::to_f77_int (a.cols ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2980 F77_INT ldb = octave::to_f77_int (b.rows ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22971
diff
changeset
|
2981 F77_INT tdb = octave::to_f77_int (b.cols ()); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2982 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2983 retval = Matrix (a_nr, b_nc); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2984 double *c = retval.fortran_vec (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2985 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2986 if (b_nc == 1) |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
2987 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2988 if (a_nr == 1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2989 F77_FUNC (xddot, XDDOT) (a_nc, a.data (), 1, b.data (), 1, *c); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2990 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2991 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2992 const char ctra = get_blas_trans_arg (tra); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2993 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2994 lda, tda, 1.0, a.data (), lda, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2995 b.data (), 1, 0.0, c, 1 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2996 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2997 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2998 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
2999 else if (a_nr == 1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3000 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3001 const char crevtrb = get_blas_trans_arg (! trb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3002 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3003 ldb, tdb, 1.0, b.data (), ldb, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3004 a.data (), 1, 0.0, c, 1 |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3005 F77_CHAR_ARG_LEN (1))); |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3006 } |
2828 | 3007 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3008 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3009 const char ctra = get_blas_trans_arg (tra); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3010 const char ctrb = get_blas_trans_arg (trb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3011 F77_XFCN (dgemm, DGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3012 F77_CONST_CHAR_ARG2 (&ctrb, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3013 a_nr, b_nc, a_nc, 1.0, a.data (), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3014 lda, b.data (), ldb, 0.0, c, a_nr |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3015 F77_CHAR_ARG_LEN (1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3016 F77_CHAR_ARG_LEN (1))); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3017 } |
2828 | 3018 } |
3019 | |
3020 return retval; | |
3021 } | |
3022 | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3023 Matrix |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3024 operator * (const Matrix& a, const Matrix& b) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3025 { |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3026 return xgemm (a, b); |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3027 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3028 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3029 // FIXME: it would be nice to share code among the min/max functions below. |
4309 | 3030 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22152
diff
changeset
|
3031 #define EMPTY_RETURN_CHECK(T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22152
diff
changeset
|
3032 if (nr == 0 || nc == 0) \ |
4309 | 3033 return T (nr, nc); |
3034 | |
3035 Matrix | |
3036 min (double d, const Matrix& m) | |
3037 { | |
5275 | 3038 octave_idx_type nr = m.rows (); |
3039 octave_idx_type nc = m.columns (); | |
4309 | 3040 |
3041 EMPTY_RETURN_CHECK (Matrix); | |
3042 | |
3043 Matrix result (nr, nc); | |
3044 | |
5275 | 3045 for (octave_idx_type j = 0; j < nc; j++) |
3046 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3047 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3048 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3049 result(i, j) = octave::math::min (d, m(i, j)); |
4309 | 3050 } |
3051 | |
3052 return result; | |
3053 } | |
3054 | |
3055 Matrix | |
3056 min (const Matrix& m, double d) | |
3057 { | |
5275 | 3058 octave_idx_type nr = m.rows (); |
3059 octave_idx_type nc = m.columns (); | |
4309 | 3060 |
3061 EMPTY_RETURN_CHECK (Matrix); | |
3062 | |
3063 Matrix result (nr, nc); | |
3064 | |
5275 | 3065 for (octave_idx_type j = 0; j < nc; j++) |
3066 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3067 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3068 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3069 result(i, j) = octave::math::min (m(i, j), d); |
4309 | 3070 } |
3071 | |
3072 return result; | |
3073 } | |
3074 | |
3075 Matrix | |
3076 min (const Matrix& a, const Matrix& b) | |
3077 { | |
5275 | 3078 octave_idx_type nr = a.rows (); |
3079 octave_idx_type nc = a.columns (); | |
4309 | 3080 |
3081 if (nr != b.rows () || nc != b.columns ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3082 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3083 ("two-arg min requires same size arguments"); |
4309 | 3084 |
3085 EMPTY_RETURN_CHECK (Matrix); | |
3086 | |
3087 Matrix result (nr, nc); | |
3088 | |
5275 | 3089 for (octave_idx_type j = 0; j < nc; j++) |
3090 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3091 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3092 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3093 result(i, j) = octave::math::min (a(i, j), b(i, j)); |
4309 | 3094 } |
3095 | |
3096 return result; | |
3097 } | |
3098 | |
3099 Matrix | |
3100 max (double d, const Matrix& m) | |
3101 { | |
5275 | 3102 octave_idx_type nr = m.rows (); |
3103 octave_idx_type nc = m.columns (); | |
4309 | 3104 |
3105 EMPTY_RETURN_CHECK (Matrix); | |
3106 | |
3107 Matrix result (nr, nc); | |
3108 | |
5275 | 3109 for (octave_idx_type j = 0; j < nc; j++) |
3110 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3111 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3112 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3113 result(i, j) = octave::math::max (d, m(i, j)); |
4309 | 3114 } |
3115 | |
3116 return result; | |
3117 } | |
3118 | |
3119 Matrix | |
3120 max (const Matrix& m, double d) | |
3121 { | |
5275 | 3122 octave_idx_type nr = m.rows (); |
3123 octave_idx_type nc = m.columns (); | |
4309 | 3124 |
3125 EMPTY_RETURN_CHECK (Matrix); | |
3126 | |
3127 Matrix result (nr, nc); | |
3128 | |
5275 | 3129 for (octave_idx_type j = 0; j < nc; j++) |
3130 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3131 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3132 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3133 result(i, j) = octave::math::max (m(i, j), d); |
4309 | 3134 } |
3135 | |
3136 return result; | |
3137 } | |
3138 | |
3139 Matrix | |
3140 max (const Matrix& a, const Matrix& b) | |
3141 { | |
5275 | 3142 octave_idx_type nr = a.rows (); |
3143 octave_idx_type nc = a.columns (); | |
4309 | 3144 |
3145 if (nr != b.rows () || nc != b.columns ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3146 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3147 ("two-arg max requires same size arguments"); |
4309 | 3148 |
3149 EMPTY_RETURN_CHECK (Matrix); | |
3150 | |
3151 Matrix result (nr, nc); | |
3152 | |
5275 | 3153 for (octave_idx_type j = 0; j < nc; j++) |
3154 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3155 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3156 octave_quit (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
3157 result(i, j) = octave::math::max (a(i, j), b(i, j)); |
4309 | 3158 } |
3159 | |
3160 return result; | |
3161 } | |
3162 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3163 Matrix linspace (const ColumnVector& x1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3164 const ColumnVector& x2, |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3165 octave_idx_type n) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3166 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3167 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3168 octave_idx_type m = x1.numel (); |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3169 |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3170 if (x2.numel () != m) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3171 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3172 ("linspace: vectors must be of equal length"); |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3173 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3174 NoAlias<Matrix> retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3175 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3176 if (n < 1) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3177 { |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3178 retval.clear (m, 0); |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3179 return retval; |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3180 } |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3181 |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3182 retval.clear (m, n); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3183 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3184 retval(i, 0) = x1(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3185 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3186 // The last column is unused so temporarily store delta there |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3187 double *delta = &retval(0, n-1); |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3188 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3189 delta[i] = (x2(i) - x1(i)) / (n - 1); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3190 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3191 for (octave_idx_type j = 1; j < n-1; j++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3192 for (octave_idx_type i = 0; i < m; i++) |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9653
diff
changeset
|
3193 retval(i, j) = x1(i) + j*delta[i]; |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3194 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3195 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3196 retval(i, n-1) = x2(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3197 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3198 return retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3199 } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3200 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3201 MS_CMP_OPS (Matrix, double) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3202 MS_BOOL_OPS (Matrix, double) |
2870 | 3203 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3204 SM_CMP_OPS (double, Matrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3205 SM_BOOL_OPS (double, Matrix) |
2870 | 3206 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3207 MM_CMP_OPS (Matrix, Matrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3208 MM_BOOL_OPS (Matrix, Matrix) |