Mercurial > octave-nkf
annotate liboctave/numeric/eigs-base.cc @ 19303:65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
* oct-stream.h: Don't include oct-locbuf.h.
* Sparse-op-decls.h: New file.
* module.mk (OPERATORS_INC): Include it in the list.
* Sparse-op-defs.h: Move decls to Sparse-op-decls.h.
* CSparse.h, boolSparse.h, dSparse.h: Include Sparse-op-decls.h
instead of Sparse-op-defs.h.
* help.cc, oct-map.cc, oct-stream.cc, quadcc.cc, strfind.cc,
sub2ind.cc, utils.cc, xpow.cc, __delaunayn__.cc, __ichol__.cc,
__ilu__.cc, __voronoi__.cc, convhulln.cc, ov-base-mat.cc,
op-dm-scm.cc, op-dm-template.cc, op-fcm-fs.cc, op-fcs-fm.cc,
op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc,
op-pm-template.cc, op-ui16-ui16.cc, op-ui32-ui32.cc,
op-ui64-ui64.cc, op-ui8-ui8.cc, pt-mat.cc, CMatrix.cc, CNDArray.cc,
CSparse.cc, MatrixType.cc, boolMatrix.cc, boolNDArray.cc,
boolSparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fCNDArray.cc,
fMatrix.cc, eigs-base.cc, oct-norm.cc, sparse-base-lu.cc,
* mx-op-defs.h: Update list of include files accordingly.
* sparse-mk-ops.awk: Update emitted list of include files
accordingly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 19 Oct 2014 08:42:58 -0400 |
parents | 49a5a4be04a1 |
children | 95c533ed464b |
rev | line source |
---|---|
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
3 Copyright (C) 2005-2013 David Bateman |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 This file is part of Octave. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 option) any later version. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 for more details. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 #include <config.h> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 #include <cfloat> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 #include <cmath> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 #include <vector> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 #include <iostream> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 #include "f77-fcn.h" |
19303
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
33 #include "oct-locbuf.h" |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 #include "quit.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 #include "SparsedbleLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 #include "SparseCmplxLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 #include "dSparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 #include "CSparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 #include "MatrixType.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 #include "SparsedbleCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 #include "SparseCmplxCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 #include "oct-rand.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 #include "dbleCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 #include "CmplxCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 #include "dbleLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 #include "CmplxLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 |
14144
834df9f10963
remove ARPACK files from sources and restore configure checks for external ARPACK library
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
48 #ifdef HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 typedef ColumnVector (*EigsFunc) (const ColumnVector &x, int &eigs_error); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
50 typedef ComplexColumnVector (*EigsComplexFunc) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 (const ComplexColumnVector &x, int &eigs_error); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 // Arpack and blas fortran functions we call. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 extern "C" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 F77_RET_T |
11518 | 57 F77_FUNC (dsaupd, DSAUPD) (octave_idx_type&, |
58 F77_CONST_CHAR_ARG_DECL, | |
59 const octave_idx_type&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
60 F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
61 const octave_idx_type&, const double&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
62 double*, const octave_idx_type&, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
63 const octave_idx_type&, octave_idx_type*, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
64 octave_idx_type*, double*, double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
65 const octave_idx_type&, octave_idx_type& |
11518 | 66 F77_CHAR_ARG_LEN_DECL |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
67 F77_CHAR_ARG_LEN_DECL); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
68 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 F77_RET_T |
11518 | 70 F77_FUNC (dseupd, DSEUPD) (const octave_idx_type&, |
71 F77_CONST_CHAR_ARG_DECL, | |
72 octave_idx_type*, double*, double*, | |
73 const octave_idx_type&, const double&, | |
74 F77_CONST_CHAR_ARG_DECL, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
75 const octave_idx_type&, |
11518 | 76 F77_CONST_CHAR_ARG_DECL, |
77 const octave_idx_type&, const double&, double*, | |
78 const octave_idx_type&, double*, | |
79 const octave_idx_type&, octave_idx_type*, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
80 octave_idx_type*, double*, double*, |
11518 | 81 const octave_idx_type&, octave_idx_type& |
82 F77_CHAR_ARG_LEN_DECL | |
83 F77_CHAR_ARG_LEN_DECL | |
84 F77_CHAR_ARG_LEN_DECL); | |
85 | |
86 F77_RET_T | |
87 F77_FUNC (dnaupd, DNAUPD) (octave_idx_type&, | |
88 F77_CONST_CHAR_ARG_DECL, | |
89 const octave_idx_type&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
90 F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 octave_idx_type&, const double&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 double*, const octave_idx_type&, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 const octave_idx_type&, octave_idx_type*, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
94 octave_idx_type*, double*, double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 const octave_idx_type&, octave_idx_type& |
11518 | 96 F77_CHAR_ARG_LEN_DECL |
97 F77_CHAR_ARG_LEN_DECL); | |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 F77_RET_T |
11518 | 100 F77_FUNC (dneupd, DNEUPD) (const octave_idx_type&, |
101 F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 octave_idx_type*, double*, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 double*, const octave_idx_type&, const double&, |
11518 | 104 const double&, double*, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
105 F77_CONST_CHAR_ARG_DECL, |
11518 | 106 const octave_idx_type&, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
107 F77_CONST_CHAR_ARG_DECL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
108 octave_idx_type&, const double&, double*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
109 const octave_idx_type&, double*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
110 const octave_idx_type&, octave_idx_type*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
111 octave_idx_type*, double*, double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
112 const octave_idx_type&, octave_idx_type& |
11518 | 113 F77_CHAR_ARG_LEN_DECL |
114 F77_CHAR_ARG_LEN_DECL | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 F77_CHAR_ARG_LEN_DECL); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
116 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
117 F77_RET_T |
11518 | 118 F77_FUNC (znaupd, ZNAUPD) (octave_idx_type&, |
119 F77_CONST_CHAR_ARG_DECL, | |
120 const octave_idx_type&, | |
121 F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
122 const octave_idx_type&, const double&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 Complex*, const octave_idx_type&, Complex*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 const octave_idx_type&, octave_idx_type*, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
125 octave_idx_type*, Complex*, Complex*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
126 const octave_idx_type&, double *, octave_idx_type& |
11518 | 127 F77_CHAR_ARG_LEN_DECL |
128 F77_CHAR_ARG_LEN_DECL); | |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
129 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
130 F77_RET_T |
11518 | 131 F77_FUNC (zneupd, ZNEUPD) (const octave_idx_type&, |
132 F77_CONST_CHAR_ARG_DECL, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
133 octave_idx_type*, Complex*, Complex*, |
11518 | 134 const octave_idx_type&, const Complex&, Complex*, |
135 F77_CONST_CHAR_ARG_DECL, | |
136 const octave_idx_type&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
137 F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
138 const octave_idx_type&, const double&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
139 Complex*, const octave_idx_type&, Complex*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
140 const octave_idx_type&, octave_idx_type*, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
141 octave_idx_type*, Complex*, Complex*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 const octave_idx_type&, double *, octave_idx_type& |
11518 | 143 F77_CHAR_ARG_LEN_DECL |
144 F77_CHAR_ARG_LEN_DECL | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
145 F77_CHAR_ARG_LEN_DECL); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
146 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
147 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
148 F77_FUNC (dgemv, DGEMV) (F77_CONST_CHAR_ARG_DECL, |
11518 | 149 const octave_idx_type&, const octave_idx_type&, |
150 const double&, const double*, | |
151 const octave_idx_type&, const double*, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
152 const octave_idx_type&, const double&, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
153 const octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
154 F77_CHAR_ARG_LEN_DECL); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
155 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
156 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
157 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
158 F77_FUNC (zgemv, ZGEMV) (F77_CONST_CHAR_ARG_DECL, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 const octave_idx_type&, const octave_idx_type&, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 const Complex&, const Complex*, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 const octave_idx_type&, const Complex*, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
162 const octave_idx_type&, const Complex&, Complex*, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
163 const octave_idx_type& |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
164 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
165 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
166 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
167 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
168 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
169 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
170 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
171 lusolve (const SparseMatrix&, const SparseMatrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
172 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
173 static octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
174 lusolve (const SparseComplexMatrix&, const SparseComplexMatrix&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
175 ComplexMatrix&); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
176 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
177 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
178 lusolve (const Matrix&, const Matrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
179 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
180 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
181 lusolve (const ComplexMatrix&, const ComplexMatrix&, ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
182 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
183 static ComplexMatrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
184 ltsolve (const SparseComplexMatrix&, const ColumnVector&, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
185 const ComplexMatrix&); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
186 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
187 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
188 ltsolve (const SparseMatrix&, const ColumnVector&, const Matrix&,); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
189 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
190 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
191 ltsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
192 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
193 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
194 ltsolve (const Matrix&, const ColumnVector&, const Matrix&,); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
195 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
196 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
197 utsolve (const SparseComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
198 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
199 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
200 utsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
201 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
202 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
203 utsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
204 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
205 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
206 utsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
207 |
12202
dc72a664ac7a
eigs-base.cc: fix error in change removing HAVE_ARPACK
John W. Eaton <jwe@octave.org>
parents:
12198
diff
changeset
|
208 #endif |
dc72a664ac7a
eigs-base.cc: fix error in change removing HAVE_ARPACK
John W. Eaton <jwe@octave.org>
parents:
12198
diff
changeset
|
209 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
210 template <class M, class SM> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
211 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
212 lusolve (const SM& L, const SM& U, M& m) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
213 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
214 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
215 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
216 MatrixType utyp (MatrixType::Upper); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
217 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
218 // Sparse L is lower triangular, Dense L is permuted lower triangular!!! |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
219 m = L.solve (m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
220 if (err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
221 return err; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
222 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
223 m = U.solve (utyp, m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
224 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
225 return err; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
226 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
227 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
228 template <class SM, class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
229 static M |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
230 ltsolve (const SM& L, const ColumnVector& Q, const M& m) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
231 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
232 octave_idx_type n = L.cols (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
233 octave_idx_type b_nc = m.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
234 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
235 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
236 MatrixType ltyp (MatrixType::Lower); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
237 M tmp = L.solve (ltyp, m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
238 M retval; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
239 const double* qv = Q.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
240 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
241 if (!err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
242 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
243 retval.resize (n, b_nc); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
244 for (octave_idx_type j = 0; j < b_nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
245 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
246 for (octave_idx_type i = 0; i < n; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
247 retval.elem (static_cast<octave_idx_type>(qv[i]), j) = |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
248 tmp.elem (i,j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
249 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
250 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
251 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
252 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
253 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
254 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
255 template <class SM, class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
256 static M |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
257 utsolve (const SM& U, const ColumnVector& Q, const M& m) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
258 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
259 octave_idx_type n = U.cols (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
260 octave_idx_type b_nc = m.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
261 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
262 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
263 MatrixType utyp (MatrixType::Upper); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
264 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
265 M retval (n, b_nc); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
266 const double* qv = Q.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
267 for (octave_idx_type j = 0; j < b_nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
268 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
269 for (octave_idx_type i = 0; i < n; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
270 retval.elem (i,j) = m.elem (static_cast<octave_idx_type>(qv[i]), j); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
271 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
272 return U.solve (utyp, retval, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
273 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
274 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
275 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
276 vector_product (const SparseMatrix& m, const double* x, double* y) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
277 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
278 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
279 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
280 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
281 y[j] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
282 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
283 for (octave_idx_type j = 0; j < nc; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
284 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
285 y[m.ridx (i)] += m.data (i) * x[j]; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
286 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
287 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
288 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
289 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
290 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
291 vector_product (const Matrix& m, const double *x, double *y) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
292 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
293 octave_idx_type nr = m.rows (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
294 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
295 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
296 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 nr, nc, 1.0, m.data (), nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
298 x, 1, 0.0, y, 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 F77_CHAR_ARG_LEN (1))); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
300 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
301 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
302 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
303 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
304 ("eigs: unrecoverable error in dgemv"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
305 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
306 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
307 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
308 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
309 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
310 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
311 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
312 vector_product (const SparseComplexMatrix& m, const Complex* x, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 Complex* y) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
314 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
315 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
316 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
317 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
318 y[j] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
319 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
320 for (octave_idx_type j = 0; j < nc; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
321 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
322 y[m.ridx (i)] += m.data (i) * x[j]; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
323 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
324 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
325 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
326 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
327 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
328 vector_product (const ComplexMatrix& m, const Complex *x, Complex *y) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
329 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
330 octave_idx_type nr = m.rows (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
331 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
332 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
333 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
334 nr, nc, 1.0, m.data (), nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
335 x, 1, 0.0, y, 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
336 F77_CHAR_ARG_LEN (1))); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
337 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
338 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
339 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
340 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
341 ("eigs: unrecoverable error in zgemv"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
342 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
343 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
344 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
345 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
346 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
347 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
348 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
349 make_cholb (Matrix& b, Matrix& bt, ColumnVector& permB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
350 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
351 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
352 CHOL fact (b, info); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
353 octave_idx_type n = b.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
354 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
355 if (info != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
356 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
357 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
358 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
359 bt = fact.chol_matrix (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
360 b = bt.transpose (); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
361 permB = ColumnVector (n); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
362 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 permB(i) = i; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
364 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
365 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
366 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
367 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
368 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
369 make_cholb (SparseMatrix& b, SparseMatrix& bt, ColumnVector& permB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
370 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
371 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
372 SparseCHOL fact (b, info, false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
373 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
374 if (fact.P () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
375 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
376 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
377 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
378 b = fact.L (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
379 bt = b.transpose (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
380 permB = fact.perm () - 1.0; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
381 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
382 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
383 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
384 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
385 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
386 make_cholb (ComplexMatrix& b, ComplexMatrix& bt, ColumnVector& permB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
387 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
388 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
389 ComplexCHOL fact (b, info); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
390 octave_idx_type n = b.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
391 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
392 if (info != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
393 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
394 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
395 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
396 bt = fact.chol_matrix (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
397 b = bt.hermitian (); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
398 permB = ColumnVector (n); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
399 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
400 permB(i) = i; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
401 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
402 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
403 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
404 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
405 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
406 make_cholb (SparseComplexMatrix& b, SparseComplexMatrix& bt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 ColumnVector& permB) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
408 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
409 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
410 SparseComplexCHOL fact (b, info, false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
411 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
412 if (fact.P () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
413 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
414 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
415 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
416 b = fact.L (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
417 bt = b.hermitian (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
418 permB = fact.perm () - 1.0; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
419 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
420 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
421 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
422 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
423 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
424 LuAminusSigmaB (const SparseMatrix &m, const SparseMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
425 bool cholB, const ColumnVector& permB, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
426 SparseMatrix &L, SparseMatrix &U, octave_idx_type *P, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 octave_idx_type *Q) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
428 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
429 bool have_b = ! b.is_empty (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
430 octave_idx_type n = m.rows (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
431 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
432 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
433 SparseMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
434 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
435 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
436 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
437 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
439 if (permB.length ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 SparseMatrix tmp(n,n,n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
444 tmp.xcidx (i) = i; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
445 tmp.xridx (i) = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
446 static_cast<octave_idx_type>(permB(i)); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
447 tmp.xdata (i) = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
449 tmp.xcidx (n) = n; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
451 AminusSigmaB = AminusSigmaB - sigma * tmp * |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
452 b.transpose () * b * tmp.transpose (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 AminusSigmaB = AminusSigmaB - sigma * |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
456 b.transpose () * b; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
457 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
458 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
459 AminusSigmaB = AminusSigmaB - sigma * b; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
460 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
461 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
462 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
463 SparseMatrix sigmat (n, n, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
464 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
465 // Create sigma * speye (n,n) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
466 sigmat.xcidx (0) = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
467 for (octave_idx_type i = 0; i < n; i++) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
469 sigmat.xdata (i) = sigma; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
470 sigmat.xridx (i) = i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
471 sigmat.xcidx (i+1) = i + 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
473 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
474 AminusSigmaB = AminusSigmaB - sigmat; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
476 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
477 SparseLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
478 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
479 L = fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
480 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
481 const octave_idx_type *P2 = fact.row_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
482 const octave_idx_type *Q2 = fact.col_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
483 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
484 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
485 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
486 P[j] = P2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
487 Q[j] = Q2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
488 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
489 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
490 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
491 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
492 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
493 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
494 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
495 double d = 0.; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
496 if (U.xcidx (j+1) > U.xcidx (j) && |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
497 U.xridx (U.xcidx (j+1)-1) == j) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
498 d = std::abs (U.xdata (U.xcidx (j+1)-1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
499 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
500 if (xisnan (minU) || d < minU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
501 minU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
502 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
503 if (xisnan (maxU) || d > maxU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
504 maxU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
505 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
506 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
507 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
508 volatile double rcond_plus_one = rcond + 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
509 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
510 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
511 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
512 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
513 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
514 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 (" an eigenvalue. Convergence is not guaranteed"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
516 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
517 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
518 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
519 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
520 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
521 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
522 LuAminusSigmaB (const Matrix &m, const Matrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
523 bool cholB, const ColumnVector& permB, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
524 Matrix &L, Matrix &U, octave_idx_type *P, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
525 octave_idx_type *Q) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
526 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
527 bool have_b = ! b.is_empty (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
528 octave_idx_type n = m.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
529 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
530 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
531 Matrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
532 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
533 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
534 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
535 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
536 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
537 Matrix tmp = sigma * b.transpose () * b; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
538 const double *pB = permB.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
539 double *p = AminusSigmaB.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
540 |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
541 if (permB.length ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
542 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
543 for (octave_idx_type j = 0; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
544 j < b.cols (); j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
545 for (octave_idx_type i = 0; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
546 i < b.rows (); i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
547 *p++ -= tmp.xelem (static_cast<octave_idx_type>(pB[i]), |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
548 static_cast<octave_idx_type>(pB[j])); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
549 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
550 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
551 AminusSigmaB = AminusSigmaB - tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
552 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
553 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
554 AminusSigmaB = AminusSigmaB - sigma * b; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
555 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
556 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
557 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
558 double *p = AminusSigmaB.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
559 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
560 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
561 p[i*(n+1)] -= sigma; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
562 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
563 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
564 LU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
565 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
566 L = fact.P ().transpose () * fact.L (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
567 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
568 for (octave_idx_type j = 0; j < n; j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
569 P[j] = Q[j] = j; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
570 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
571 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
572 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
573 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
574 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
575 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
576 double d = std::abs (U.xelem (j,j)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
577 if (xisnan (minU) || d < minU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
578 minU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
579 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
580 if (xisnan (maxU) || d > maxU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
581 maxU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
582 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
583 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
584 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
585 volatile double rcond_plus_one = rcond + 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
586 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
587 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
588 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
589 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
590 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
591 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
592 (" an eigenvalue. Convergence is not guaranteed"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
593 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
594 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
595 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
596 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
597 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
598 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
599 LuAminusSigmaB (const SparseComplexMatrix &m, const SparseComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
600 bool cholB, const ColumnVector& permB, Complex sigma, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
601 SparseComplexMatrix &L, SparseComplexMatrix &U, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
602 octave_idx_type *P, octave_idx_type *Q) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
603 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
604 bool have_b = ! b.is_empty (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
605 octave_idx_type n = m.rows (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
606 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
607 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
608 SparseComplexMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
609 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
610 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
611 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
612 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
613 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
614 if (permB.length ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
615 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
616 SparseMatrix tmp(n,n,n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
617 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
618 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
619 tmp.xcidx (i) = i; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
620 tmp.xridx (i) = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
621 static_cast<octave_idx_type>(permB(i)); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
622 tmp.xdata (i) = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
623 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
624 tmp.xcidx (n) = n; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
625 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
626 AminusSigmaB = AminusSigmaB - tmp * b.hermitian () * b * |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
627 tmp.transpose () * sigma; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
628 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
629 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
630 AminusSigmaB = AminusSigmaB - sigma * b.hermitian () * b; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
631 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
632 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
633 AminusSigmaB = AminusSigmaB - sigma * b; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
634 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
635 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
636 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
637 SparseComplexMatrix sigmat (n, n, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
638 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
639 // Create sigma * speye (n,n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
640 sigmat.xcidx (0) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
641 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
642 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
643 sigmat.xdata (i) = sigma; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
644 sigmat.xridx (i) = i; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
645 sigmat.xcidx (i+1) = i + 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
646 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
647 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
648 AminusSigmaB = AminusSigmaB - sigmat; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
649 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
650 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
651 SparseComplexLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
652 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
653 L = fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
654 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
655 const octave_idx_type *P2 = fact.row_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
656 const octave_idx_type *Q2 = fact.col_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
657 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
658 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
659 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
660 P[j] = P2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
661 Q[j] = Q2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
662 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
663 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
664 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
665 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
666 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
667 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
668 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
669 double d = 0.; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
670 if (U.xcidx (j+1) > U.xcidx (j) && |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
671 U.xridx (U.xcidx (j+1)-1) == j) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
672 d = std::abs (U.xdata (U.xcidx (j+1)-1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
673 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
674 if (xisnan (minU) || d < minU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
675 minU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
676 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
677 if (xisnan (maxU) || d > maxU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
678 maxU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
679 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
680 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
681 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
682 volatile double rcond_plus_one = rcond + 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
683 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
684 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
685 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
686 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
687 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
688 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
689 (" an eigenvalue. Convergence is not guaranteed"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
690 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
691 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
692 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
693 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
694 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
695 static bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
696 LuAminusSigmaB (const ComplexMatrix &m, const ComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
697 bool cholB, const ColumnVector& permB, Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
698 ComplexMatrix &L, ComplexMatrix &U, octave_idx_type *P, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
699 octave_idx_type *Q) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
700 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
701 bool have_b = ! b.is_empty (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
702 octave_idx_type n = m.cols (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
703 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
704 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
705 ComplexMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
706 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
707 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
708 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
709 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
710 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
711 ComplexMatrix tmp = sigma * b.hermitian () * b; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
712 const double *pB = permB.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
713 Complex *p = AminusSigmaB.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
714 |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
715 if (permB.length ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
716 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
717 for (octave_idx_type j = 0; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
718 j < b.cols (); j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
719 for (octave_idx_type i = 0; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
720 i < b.rows (); i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
721 *p++ -= tmp.xelem (static_cast<octave_idx_type>(pB[i]), |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
722 static_cast<octave_idx_type>(pB[j])); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
723 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
724 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
725 AminusSigmaB = AminusSigmaB - tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
726 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
727 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
728 AminusSigmaB = AminusSigmaB - sigma * b; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
729 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
730 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
731 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
732 Complex *p = AminusSigmaB.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
733 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
734 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
735 p[i*(n+1)] -= sigma; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
736 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
737 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
738 ComplexLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
739 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
740 L = fact.P ().transpose () * fact.L (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
741 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
742 for (octave_idx_type j = 0; j < n; j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
743 P[j] = Q[j] = j; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
744 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
745 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
746 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
747 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
748 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
749 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
750 double d = std::abs (U.xelem (j,j)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
751 if (xisnan (minU) || d < minU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
752 minU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
753 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
754 if (xisnan (maxU) || d > maxU) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
755 maxU = d; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
756 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
757 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
758 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
759 volatile double rcond_plus_one = rcond + 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
760 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
761 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
762 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
763 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
764 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
765 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
766 (" an eigenvalue. Convergence is not guaranteed"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
767 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
768 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
769 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
770 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
771 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
772 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
773 octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
774 EigsRealSymmetricMatrix (const M& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
775 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
776 octave_idx_type &info, Matrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
777 ColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
778 ColumnVector &permB, ColumnVector &resid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
779 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
780 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
781 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
782 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
783 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
784 octave_idx_type mode = 1; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
785 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
786 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
787 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
788 double sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
789 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
790 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
791 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
792 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
793 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
794 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
795 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
796 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
797 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
798 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
799 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
800 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
801 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
802 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
803 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
804 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
805 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
806 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
807 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
808 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
809 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
810 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
811 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
812 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
813 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
814 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
815 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
816 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
817 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
818 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
819 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
820 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
821 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
822 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
823 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
824 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
825 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
826 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
827 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
828 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
829 if (k < 1 || k > n - 2) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
830 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
831 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
832 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
833 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
834 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
835 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
836 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
837 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
838 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
839 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
840 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
841 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
842 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
843 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
844 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
845 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
846 // Check the we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
847 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
848 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
849 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
850 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
851 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
852 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
853 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
854 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
855 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
856 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
857 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
858 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
859 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
860 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
861 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
862 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
863 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
864 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
865 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
866 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
867 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
868 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
869 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
870 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
871 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
872 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
873 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
874 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
875 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
876 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
877 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
878 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
879 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
880 if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
881 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
882 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
883 ("eigs: invalid sigma value for real symmetric problem"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
884 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
885 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
886 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
887 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
888 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
889 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
890 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
891 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
892 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
893 bt = b; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
894 b = b.transpose (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
895 if (permB.length () == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
896 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
897 permB = ColumnVector (n); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
898 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
899 permB(i) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
900 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
901 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
902 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
903 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
904 if (! make_cholb (b, bt, permB)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
905 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
906 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
907 ("eigs: The matrix B is not positive definite"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
908 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
909 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
910 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
911 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
912 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
913 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
914 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
915 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
916 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
917 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
918 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
919 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
920 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
921 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
922 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
923 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
924 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
925 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
926 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
927 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
928 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
929 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
930 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
931 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
932 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
933 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
934 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
935 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
936 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
937 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
938 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
939 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
940 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
941 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
942 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
943 F77_FUNC (dsaupd, DSAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
944 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
945 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
946 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
947 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
948 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
949 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
950 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
951 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
952 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
953 ("eigs: unrecoverable exception encountered in dsaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
954 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
955 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
956 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
957 if (disp > 0 && !xisnan (workl[iptr (5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
958 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
959 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
960 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
961 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
962 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
963 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
964 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
965 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
966 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
967 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
968 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
969 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
970 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
971 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
972 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
973 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
974 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
975 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
976 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
977 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
978 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
979 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
980 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
981 Matrix mtmp (n,1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
982 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
983 mtmp(i,0) = workd[i + iptr(0) - 1]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
984 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
985 mtmp = utsolve (bt, permB, m * ltsolve (b, permB, mtmp)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
986 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
987 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
988 workd[i+iptr(1)-1] = mtmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
989 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
990 else if (!vector_product (m, workd + iptr(0) - 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
991 workd + iptr(1) - 1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
992 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
993 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
994 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
995 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
996 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
997 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
998 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
999 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1000 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1001 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1002 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1003 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1004 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1005 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1006 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1007 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1008 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1009 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1010 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1011 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1012 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1013 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1014 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1015 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1016 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
1017 octave_idx_type *sel = s.fortran_vec (); |
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
1018 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1019 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1020 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1021 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1022 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1023 double *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1024 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1025 F77_FUNC (dseupd, DSEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1026 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1027 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1028 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1029 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1030 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1031 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1032 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1033 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1034 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1035 ("eigs: unrecoverable exception encountered in dseupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1036 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1037 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1038 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1039 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1040 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1041 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1042 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1043 if (typ != "SM" && typ != "BE") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1044 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1045 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1046 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1047 double dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1048 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1049 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1050 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1051 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1052 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1053 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1054 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1055 if (typ != "SM" && typ != "BE") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1056 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1057 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1058 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1059 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1060 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1061 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1062 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1063 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1064 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1065 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1066 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1067 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1068 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1069 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1070 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1071 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1072 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1073 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1074 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1075 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1076 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1077 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1078 if (note3) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1079 eig_vec = ltsolve (b, permB, eig_vec); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1080 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1081 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1082 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1083 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1084 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1085 ("eigs: error %d in dseupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1086 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1087 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1088 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1089 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1090 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1091 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1092 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1093 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1094 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1095 EigsRealSymmetricMatrixShift (const M& m, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1096 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1097 octave_idx_type &info, Matrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1098 ColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1099 ColumnVector &permB, ColumnVector &resid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1100 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1101 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1102 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1103 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1104 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1105 octave_idx_type mode = 3; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1106 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1107 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1108 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1109 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1110 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1111 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1112 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1113 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1114 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1115 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1116 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1117 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1118 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1119 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1120 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1121 // FIXME: The "SM" type for mode 1 seems unstable though faster!! |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1122 //if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1123 // return EigsRealSymmetricMatrix (m, "SM", k, p, info, eig_vec, eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1124 // _b, permB, resid, os, tol, rvec, cholB, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1125 // disp, maxit); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1126 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1127 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1128 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1129 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1130 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1131 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1132 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1133 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1134 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1135 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1136 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1137 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1138 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1139 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1140 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1141 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1142 if (k <= 0 || k >= n - 1) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1143 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1144 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1145 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1146 " Use 'eig (full (A))' instead"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1147 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1148 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1149 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1150 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1151 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1152 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1153 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1154 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1155 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1156 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1157 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1158 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1159 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1160 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1161 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1162 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1163 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1164 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1165 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1166 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1167 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1168 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1169 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1170 // Check the we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1171 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1172 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1173 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1174 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1175 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1176 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1177 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1178 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1179 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1180 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1181 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1182 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1183 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1184 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1185 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1186 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1187 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1188 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1189 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1190 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1191 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1192 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1193 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1194 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1195 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1196 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1197 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1198 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1199 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1200 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1201 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1202 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1203 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1204 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1205 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1206 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1207 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1208 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1209 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1210 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1211 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1212 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1213 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1214 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1215 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1216 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1217 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1218 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1219 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1220 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1221 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows () : m.rows ())); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1222 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols () : m.cols ())); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1223 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1224 if (! LuAminusSigmaB (m, b, cholB, permB, sigma, L, U, P, Q)) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1225 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1226 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1227 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1228 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1229 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1230 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1231 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1232 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1233 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1234 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1235 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1236 F77_FUNC (dsaupd, DSAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1237 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1238 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1239 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1240 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1241 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1242 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1243 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1244 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1245 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1246 ("eigs: unrecoverable exception encountered in dsaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1247 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1248 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1249 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1250 if (disp > 0 && !xisnan (workl[iptr (5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1251 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1252 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1253 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1254 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1255 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1256 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1257 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1258 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1259 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1260 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1261 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1262 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1263 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1264 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1265 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1266 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1267 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1268 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1269 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1270 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1271 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1272 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1273 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1274 if (ido == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1275 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1276 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1277 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1278 vector_product (m, workd+iptr(0)-1, dtmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1279 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1280 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1281 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1282 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1283 tmp(i,0) = dtmp[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1284 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1285 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1286 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1287 double *ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1288 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1289 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1290 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1291 else if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1292 vector_product (b, workd+iptr(0)-1, workd+iptr(1)-1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1293 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1294 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1295 double *ip2 = workd+iptr(2)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1296 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1297 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1298 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1299 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1300 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1301 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1302 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1303 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1304 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1305 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1306 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1307 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1308 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1309 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1310 if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1311 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1312 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1313 workd[iptr(0) + i - 1] = workd[iptr(1) + i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1314 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1315 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1316 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1317 double *ip2 = workd+iptr(0)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1318 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1319 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1320 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1321 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1322 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1323 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1324 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1325 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1326 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1327 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1328 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1329 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1330 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1331 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1332 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1333 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1334 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1335 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1336 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1337 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1338 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1339 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1340 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1341 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1342 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1343 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1344 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1345 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1346 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1347 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1348 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1349 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1350 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1351 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1352 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1353 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
1354 octave_idx_type *sel = s.fortran_vec (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1355 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1356 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1357 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1358 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1359 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1360 double *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1361 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1362 F77_FUNC (dseupd, DSEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1363 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1364 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1365 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1366 k, tol, presid, p, v, n, iparam, ipntr, workd, workl, lwork, info2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1367 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1368 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1369 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1370 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1371 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1372 ("eigs: unrecoverable exception encountered in dseupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1373 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1374 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1375 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1376 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1377 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1379 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1380 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1381 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1382 double dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1383 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1384 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1385 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1386 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1387 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1388 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1389 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1390 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1391 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1392 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1393 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1394 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1395 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1396 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1397 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1398 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1399 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1400 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1401 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1402 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1403 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1404 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1405 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1406 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1407 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1408 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1409 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1410 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1411 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1412 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1413 ("eigs: error %d in dseupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1414 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1415 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1416 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1417 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1418 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1419 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1420 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1421 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1422 EigsRealSymmetricFunc (EigsFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1423 const std::string &_typ, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1424 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1425 octave_idx_type &info, Matrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1426 ColumnVector &eig_val, ColumnVector &resid, |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
1427 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1428 bool /* cholB */, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1429 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1430 std::string typ (_typ); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1431 bool have_sigma = (sigma ? true : false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1432 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1433 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1434 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1435 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1436 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1437 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1438 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1439 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1440 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1441 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1442 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1443 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1444 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1445 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1446 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1447 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1448 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1449 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1450 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1451 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1452 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1453 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1454 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1455 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1456 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1457 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1458 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1459 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1460 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1461 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1462 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1463 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1464 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1465 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1466 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1467 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1468 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1469 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1470 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1471 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1472 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1473 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1474 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1475 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1476 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1477 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1478 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1479 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1480 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1481 typ != "SI") |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1482 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1483 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1484 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1485 if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1486 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1487 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1488 ("eigs: invalid sigma value for real symmetric problem"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1489 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1490 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1491 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1492 if (typ == "SM") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1493 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1494 typ = "LM"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1495 sigma = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1496 mode = 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1497 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1498 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1499 else if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1500 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1501 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1502 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1503 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1504 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1505 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1506 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1507 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1508 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1509 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1510 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1511 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1512 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1513 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1514 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1515 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1516 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1517 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1518 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1519 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1520 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1521 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1522 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1523 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1524 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1525 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1526 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1527 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1528 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1529 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1530 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1531 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1532 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1533 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1534 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1535 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1536 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1537 F77_FUNC (dsaupd, DSAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1538 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1539 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1540 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1541 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1542 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1543 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1544 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1545 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1546 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1547 ("eigs: unrecoverable exception encountered in dsaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1548 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1549 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1550 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1551 if (disp > 0 && !xisnan (workl[iptr (5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1552 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1553 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1554 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1555 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1556 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1557 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1558 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1559 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1560 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1561 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1562 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1563 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1564 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1565 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1566 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1567 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1568 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1569 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1570 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1571 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1572 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1573 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1574 double *ip2 = workd + iptr(0) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1575 ColumnVector x(n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1576 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1577 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1578 x(i) = *ip2++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1579 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1580 ColumnVector y = fun (x, err); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1581 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1582 if (err) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1583 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1584 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1585 ip2 = workd + iptr(1) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1586 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1587 *ip2++ = y(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1588 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1589 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1590 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1591 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1592 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1593 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1594 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1595 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1596 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1597 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1598 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1599 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1600 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1601 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1602 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1603 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1604 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1605 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1606 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1607 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1608 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1609 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1610 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1611 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
1612 octave_idx_type *sel = s.fortran_vec (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1613 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1614 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1615 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1616 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1617 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1618 double *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1619 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1620 F77_FUNC (dseupd, DSEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1621 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1622 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1623 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1624 k, tol, presid, p, v, n, iparam, ipntr, workd, workl, lwork, info2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1625 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1626 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1627 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1628 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1629 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1630 ("eigs: unrecoverable exception encountered in dseupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1631 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1632 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1633 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1634 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1635 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1636 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1637 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1638 if (typ != "SM" && typ != "BE") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1639 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1640 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1641 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1642 double dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1643 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1644 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1645 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1646 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1647 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1648 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1649 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1650 if (typ != "SM" && typ != "BE") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1651 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1652 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1653 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1654 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1655 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1656 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1657 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1658 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1659 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1660 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1661 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1662 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1663 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1664 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1665 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1666 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1667 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1668 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1669 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1670 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1671 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1672 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1673 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1674 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1675 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1676 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1677 ("eigs: error %d in dseupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1678 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1679 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1680 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1681 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1682 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1683 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1684 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1685 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1686 octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1687 EigsRealNonSymmetricMatrix (const M& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1688 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1689 octave_idx_type &info, ComplexMatrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1690 ComplexColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1691 ColumnVector &permB, ColumnVector &resid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1692 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1693 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1694 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1695 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1696 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1697 octave_idx_type mode = 1; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1698 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1699 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1700 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1701 double sigmar = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1702 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1703 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1704 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1705 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1706 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1707 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1708 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1709 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1710 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1711 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1712 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1713 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1714 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1715 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1716 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1717 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1718 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1719 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1720 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1721 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1722 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1723 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1724 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1725 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1726 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1727 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1728 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1729 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1730 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1731 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1732 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1733 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1734 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1735 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1736 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1737 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1738 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1739 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1740 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1741 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1742 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1743 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1744 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1745 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1746 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1747 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1748 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1749 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1750 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
1751 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1752 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1753 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1754 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1755 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1756 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1757 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1758 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1759 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1760 // Check the we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1761 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1762 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1763 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1764 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1765 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1766 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1767 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1768 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1769 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1770 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1771 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1772 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1773 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1774 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1775 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1776 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1777 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1778 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1779 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1780 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1781 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1782 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1783 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1784 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1785 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1786 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1787 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1788 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1789 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1790 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1791 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1792 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1793 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1794 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1795 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1796 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1797 ("eigs: invalid sigma value for unsymmetric problem"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1798 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1799 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1800 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1801 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1802 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1803 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1804 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1805 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1806 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1807 bt = b; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1808 b = b.transpose (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1809 if (permB.length () == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1810 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1811 permB = ColumnVector (n); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1812 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1813 permB(i) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1814 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1815 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1816 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1817 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1818 if (! make_cholb (b, bt, permB)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1819 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1820 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1821 ("eigs: The matrix B is not positive definite"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1822 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1823 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1824 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1825 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1826 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1827 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1828 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1829 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1830 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1831 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1832 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1833 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1834 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1835 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1836 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1837 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1838 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1839 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1840 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1841 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1842 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1843 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1844 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1845 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1846 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1847 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1848 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1849 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1850 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1851 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1852 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1853 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1854 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1855 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1856 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1857 F77_FUNC (dnaupd, DNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1858 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
1859 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1860 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1861 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1862 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1863 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1864 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1865 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1866 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1867 ("eigs: unrecoverable exception encountered in dnaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1868 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1869 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1870 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1871 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1872 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1873 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1874 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1875 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1876 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1877 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1878 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1879 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1880 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1881 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1882 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1883 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1884 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1885 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1886 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1887 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1888 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1889 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1890 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1891 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1892 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1893 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1894 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1895 Matrix mtmp (n,1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1896 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1897 mtmp(i,0) = workd[i + iptr(0) - 1]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1898 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1899 mtmp = utsolve (bt, permB, m * ltsolve (b, permB, mtmp)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1900 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1901 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1902 workd[i+iptr(1)-1] = mtmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1903 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1904 else if (!vector_product (m, workd + iptr(0) - 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1905 workd + iptr(1) - 1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1906 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1907 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1908 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1909 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1910 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1911 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1912 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1913 ("eigs: error %d in dnaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1914 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1915 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1916 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1917 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1918 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1919 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1920 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1921 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1922 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1923 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1924 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1925 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1926 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1927 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1928 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1929 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1930 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
1931 octave_idx_type *sel = s.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1932 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1933 // FIXME: initialize eig_vec2 to zero; apparently dneupd can skip |
12198
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1934 // the assignment to elements of Z that represent imaginary parts. |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1935 // Found with valgrind and |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1936 // |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1937 // A = [1,0,0,-1;0,1,0,0;0,0,1,0;0,0,2,1]; |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1938 // [vecs, vals, f] = eigs (A, 1) |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1939 |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
1940 Matrix eig_vec2 (n, k + 1, 0.0); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1941 double *z = eig_vec2.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1942 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1943 OCTAVE_LOCAL_BUFFER (double, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1944 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1945 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1946 for (octave_idx_type i = 0; i < k+1; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1947 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1948 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1949 F77_FUNC (dneupd, DNEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1950 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1951 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1952 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1953 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1954 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1955 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1956 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1957 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1958 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1959 ("eigs: unrecoverable exception encountered in dneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1960 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1961 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1962 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1963 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1964 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1965 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1966 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1967 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1968 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1969 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1970 for (octave_idx_type i = 0; i < k+1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1971 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1972 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1973 jj++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1974 else |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1975 d[i-jj] = Complex (dr[i], di[i]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1976 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1977 if (jj == 0 && !rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1978 for (octave_idx_type i = 0; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1979 d[i] = d[i+1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1980 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1981 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1982 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1983 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1984 Complex dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1985 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1986 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1987 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1988 eig_val.resize (k); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1989 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1990 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1991 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1992 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1993 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1994 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1995 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1996 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1997 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1998 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1999 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2000 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2001 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2002 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2003 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2004 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2005 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2006 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2007 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2008 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2009 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2010 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2011 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2012 eig_vec.resize (n, k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2013 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2014 while (i < k) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2015 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2016 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2017 octave_idx_type off2 = (i+1) * n; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2018 if (std::imag (eig_val(i)) == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2019 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2020 for (octave_idx_type j = 0; j < n; j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2021 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2022 Complex (z[j+off1],0.); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2023 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2024 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2025 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2026 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2027 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2028 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2029 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2030 Complex (z[j+off1],z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2031 if (i < k - 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2032 eig_vec(j,i+1) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2033 Complex (z[j+off1],-z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2034 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2035 i+=2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2036 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2037 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2038 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2039 if (note3) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2040 eig_vec = ltsolve (M(b), permB, eig_vec); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2041 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2042 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2043 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2044 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2045 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2046 ("eigs: error %d in dneupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2047 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2048 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2049 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2050 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2051 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2052 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2053 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2054 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2055 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2056 EigsRealNonSymmetricMatrixShift (const M& m, double sigmar, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2057 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2058 octave_idx_type &info, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2059 ComplexMatrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2060 ComplexColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2061 ColumnVector &permB, ColumnVector &resid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2062 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2063 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2064 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2065 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2066 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2067 octave_idx_type mode = 3; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2068 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2069 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2070 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2071 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2072 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2073 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2074 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2075 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2076 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2077 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2078 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2079 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2080 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2081 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2082 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2083 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2084 // FIXME: The "SM" type for mode 1 seems unstable though faster!! |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2085 //if (! std::abs (sigmar)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2086 // return EigsRealNonSymmetricMatrix (m, "SM", k, p, info, eig_vec, eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2087 // _b, permB, resid, os, tol, rvec, cholB, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2088 // disp, maxit); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2089 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2090 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2091 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2092 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2093 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2094 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2095 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2096 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2097 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2098 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2099 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2100 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2101 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2102 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2103 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2104 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2105 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2106 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2107 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2108 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2109 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2110 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2111 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2112 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2113 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2114 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2115 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2116 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2117 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2118 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2119 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2120 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2121 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2122 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2123 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2124 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2125 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2126 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2127 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2128 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2129 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2130 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2131 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2132 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2133 // Check that we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2134 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2135 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2136 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2137 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2138 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2139 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2140 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2141 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2142 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2143 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2144 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2145 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2146 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2147 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2148 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2149 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2150 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2151 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2152 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2153 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2154 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2155 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2156 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2157 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2158 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2159 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2160 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2161 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2162 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2163 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2164 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2165 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2166 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2167 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2168 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2169 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2170 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2171 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2172 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2173 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2174 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2175 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2176 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2177 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2178 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2179 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2180 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2181 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2182 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2183 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2184 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows () : m.rows ())); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2185 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols () : m.cols ())); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2186 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2187 if (! LuAminusSigmaB (m, b, cholB, permB, sigmar, L, U, P, Q)) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2188 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2189 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2190 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2191 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2192 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2193 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2194 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2195 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2196 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2197 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2198 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2199 F77_FUNC (dnaupd, DNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2200 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2201 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2202 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2203 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2204 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2205 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2206 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2207 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2208 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2209 ("eigs: unrecoverable exception encountered in dsaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2210 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2211 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2212 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2213 if (disp > 0 && !xisnan (workl[iptr (5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2214 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2215 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2216 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2217 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2218 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2219 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2220 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2221 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2222 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2223 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2224 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2225 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2226 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2227 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2228 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2229 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2230 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2231 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2232 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2233 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2234 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2235 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2236 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2237 if (ido == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2238 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2239 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2240 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2241 vector_product (m, workd+iptr(0)-1, dtmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2242 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2243 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2244 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2245 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2246 tmp(i,0) = dtmp[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2247 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2248 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2249 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2250 double *ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2251 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2252 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2253 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2254 else if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2255 vector_product (b, workd+iptr(0)-1, workd+iptr(1)-1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2256 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2257 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2258 double *ip2 = workd+iptr(2)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2259 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2260 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2261 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2262 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2263 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2264 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2265 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2266 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2267 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2268 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2269 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2270 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2271 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2272 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2273 if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2274 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2275 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2276 workd[iptr(0) + i - 1] = workd[iptr(1) + i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2277 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2278 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2279 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2280 double *ip2 = workd+iptr(0)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2281 Matrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2282 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2283 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2284 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2285 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2286 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2287 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2288 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2289 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2290 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2291 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2292 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2293 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2294 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2295 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2296 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2297 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2298 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2299 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2300 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2301 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2302 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2303 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2304 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2305 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2306 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2307 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2308 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2309 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2310 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2311 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2312 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2313 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2314 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2315 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2316 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
2317 octave_idx_type *sel = s.fortran_vec (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2318 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2319 // FIXME: initialize eig_vec2 to zero; apparently dneupd can skip |
12198
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2320 // the assignment to elements of Z that represent imaginary parts. |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2321 // Found with valgrind and |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2322 // |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2323 // A = [1,0,0,-1;0,1,0,0;0,0,1,0;0,0,2,1]; |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2324 // [vecs, vals, f] = eigs (A, 1) |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2325 |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2326 Matrix eig_vec2 (n, k + 1, 0.0); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2327 double *z = eig_vec2.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2328 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2329 OCTAVE_LOCAL_BUFFER (double, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2330 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2331 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2332 for (octave_idx_type i = 0; i < k+1; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2333 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2334 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2335 F77_FUNC (dneupd, DNEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2336 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2337 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2338 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2339 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2340 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2341 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2342 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2343 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2344 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2345 ("eigs: unrecoverable exception encountered in dneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2346 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2347 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2348 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2349 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2350 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2351 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2352 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2353 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2354 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2355 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2356 for (octave_idx_type i = 0; i < k+1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2357 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2358 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2359 jj++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2360 else |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
2361 d[i-jj] = Complex (dr[i], di[i]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2362 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2363 if (jj == 0 && !rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2364 for (octave_idx_type i = 0; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2365 d[i] = d[i+1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2366 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2367 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2368 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2369 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2370 Complex dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2371 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2372 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2373 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2374 eig_val.resize (k); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2375 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2376 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2377 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2378 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2379 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2380 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2381 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2382 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2383 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2384 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2385 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2386 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2387 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2388 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2389 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2390 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2391 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2392 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2393 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2394 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2395 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2396 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2397 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2398 eig_vec.resize (n, k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2399 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2400 while (i < k) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2401 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2402 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2403 octave_idx_type off2 = (i+1) * n; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2404 if (std::imag (eig_val(i)) == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2405 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2406 for (octave_idx_type j = 0; j < n; j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2407 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2408 Complex (z[j+off1],0.); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2409 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2410 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2411 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2412 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2413 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2414 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2415 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2416 Complex (z[j+off1],z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2417 if (i < k - 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2418 eig_vec(j,i+1) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2419 Complex (z[j+off1],-z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2420 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2421 i+=2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2422 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2423 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2424 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2425 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2426 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2427 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2428 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2429 ("eigs: error %d in dneupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2430 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2431 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2432 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2433 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2434 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2435 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2436 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2437 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2438 EigsRealNonSymmetricFunc (EigsFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2439 const std::string &_typ, double sigmar, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2440 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2441 octave_idx_type &info, ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2442 ComplexColumnVector &eig_val, ColumnVector &resid, |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
2443 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2444 bool /* cholB */, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2445 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2446 std::string typ (_typ); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2447 bool have_sigma = (sigmar ? true : false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2448 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2449 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2450 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2451 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2452 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2453 if (resid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2454 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2455 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2456 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2457 resid = ColumnVector (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2458 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2459 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2460 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2461 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2462 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2463 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2464 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2465 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2466 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2467 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2468 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2469 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2470 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2471 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2472 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2473 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2474 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2475 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2476 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2477 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2478 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2479 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2480 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2481 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2482 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2483 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2484 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2485 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2486 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2487 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2488 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2489 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2490 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2491 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2492 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2493 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2494 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2495 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2496 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2497 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2498 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2499 typ != "SI") |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2500 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2501 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2502 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2503 if (typ == "LA" || typ == "SA" || typ == "BE") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2504 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2505 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2506 ("eigs: invalid sigma value for unsymmetric problem"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2507 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2508 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2509 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2510 if (typ == "SM") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2511 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2512 typ = "LM"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2513 sigmar = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2514 mode = 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2515 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2516 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2517 else if (! std::abs (sigmar)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2518 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2519 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2520 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2521 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2522 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2523 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2524 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2525 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2526 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2527 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2528 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2529 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2530 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2531 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2532 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2533 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2534 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2535 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2536 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2537 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2538 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2539 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2540 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2541 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2542 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2543 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2544 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2545 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2546 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2547 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2548 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2549 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2550 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2551 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2552 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2553 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2554 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2555 F77_FUNC (dnaupd, DNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2556 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2557 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2558 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2559 ipntr, workd, workl, lwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2560 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2561 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2562 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2563 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2564 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2565 ("eigs: unrecoverable exception encountered in dnaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2566 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2567 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2568 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2569 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2570 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2571 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2572 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2573 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2574 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2575 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2576 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2577 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2578 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2579 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2580 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2581 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2582 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2583 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2584 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2585 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2586 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2587 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2588 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2589 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2590 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2591 double *ip2 = workd + iptr(0) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2592 ColumnVector x(n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2593 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2594 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2595 x(i) = *ip2++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2596 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2597 ColumnVector y = fun (x, err); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2598 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2599 if (err) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2600 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2601 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2602 ip2 = workd + iptr(1) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2603 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2604 *ip2++ = y(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2605 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2606 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2607 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2608 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2609 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2610 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2611 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2612 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2613 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2614 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2615 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2616 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2617 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2618 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2619 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2620 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2621 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2622 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2623 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2624 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2625 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2626 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2627 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2628 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
2629 octave_idx_type *sel = s.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2630 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2631 // FIXME: initialize eig_vec2 to zero; apparently dneupd can skip |
12198
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2632 // the assignment to elements of Z that represent imaginary parts. |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2633 // Found with valgrind and |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2634 // |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2635 // A = [1,0,0,-1;0,1,0,0;0,0,1,0;0,0,2,1]; |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2636 // [vecs, vals, f] = eigs (A, 1) |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2637 |
30ca5a0b0e2f
don't let uninitialized values escape from DNEUPD
John W. Eaton <jwe@octave.org>
parents:
12195
diff
changeset
|
2638 Matrix eig_vec2 (n, k + 1, 0.0); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2639 double *z = eig_vec2.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2640 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2641 OCTAVE_LOCAL_BUFFER (double, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2642 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2643 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2644 for (octave_idx_type i = 0; i < k+1; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2645 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2646 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2647 F77_FUNC (dneupd, DNEUPD) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2648 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2649 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2650 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2651 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2652 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2653 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2654 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2655 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2656 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2657 ("eigs: unrecoverable exception encountered in dneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2658 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2659 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2660 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2661 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2662 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2663 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2664 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2665 if (info2 == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2666 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2667 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2668 for (octave_idx_type i = 0; i < k+1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2669 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2670 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2671 jj++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2672 else |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
2673 d[i-jj] = Complex (dr[i], di[i]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2674 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2675 if (jj == 0 && !rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2676 for (octave_idx_type i = 0; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2677 d[i] = d[i+1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2678 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2679 octave_idx_type k2 = k / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2680 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2681 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2682 Complex dtmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2683 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2684 d[k - i - 1] = dtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2685 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2686 eig_val.resize (k); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2687 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2688 if (rvec) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2689 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2690 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2691 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2692 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2693 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2694 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2695 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2696 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2697 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2698 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2699 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2700 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2701 dtmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2702 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2703 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2704 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2705 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2706 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2707 z[off2 + j] = dtmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2708 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2709 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2710 eig_vec.resize (n, k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2711 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2712 while (i < k) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2713 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2714 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2715 octave_idx_type off2 = (i+1) * n; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2716 if (std::imag (eig_val(i)) == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2717 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2718 for (octave_idx_type j = 0; j < n; j++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2719 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2720 Complex (z[j+off1],0.); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2721 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2722 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2723 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2724 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2725 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2726 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2727 eig_vec(j,i) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2728 Complex (z[j+off1],z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2729 if (i < k - 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2730 eig_vec(j,i+1) = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2731 Complex (z[j+off1],-z[j+off2]); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2732 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2733 i+=2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2734 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2735 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2736 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2737 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2738 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2739 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2740 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2741 ("eigs: error %d in dneupd", info2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2742 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2743 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2744 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2745 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2746 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2747 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2748 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2749 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2750 octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2751 EigsComplexNonSymmetricMatrix (const M& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2752 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2753 octave_idx_type &info, ComplexMatrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2754 ComplexColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2755 ColumnVector &permB, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2756 ComplexColumnVector &cresid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2757 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2758 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2759 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2760 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2761 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2762 octave_idx_type mode = 1; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2763 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2764 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2765 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2766 Complex sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2767 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2768 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2769 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2770 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2771 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2772 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2773 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2774 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2775 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2776 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2777 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2778 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2779 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2780 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2781 if (cresid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2782 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2783 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2784 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2785 Array<double> rr (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2786 Array<double> ri (octave_rand::vector (n)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2787 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2788 for (octave_idx_type i = 0; i < n; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2789 cresid(i) = Complex (rr(i),ri(i)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2790 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2791 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2792 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2793 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2794 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2795 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2796 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2797 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2798 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2799 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2800 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2801 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2802 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2803 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2804 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2805 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2806 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2807 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2808 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2809 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2810 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2811 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2812 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2813 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2814 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2815 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2816 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2817 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2818 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2819 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2820 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2821 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2822 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2823 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2824 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2825 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2826 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2827 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2828 // Check the we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2829 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2830 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2831 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2832 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2833 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2834 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2835 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2836 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2837 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2838 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2839 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2840 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2841 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2842 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2843 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2844 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2845 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2846 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2847 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2848 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2849 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2850 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2851 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2852 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2853 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2854 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2855 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2856 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2857 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2858 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2859 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2860 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2861 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2862 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2863 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2864 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2865 ("eigs: invalid sigma value for complex problem"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2866 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2867 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2868 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2869 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2870 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2871 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2872 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2873 if (cholB) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2874 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2875 bt = b; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2876 b = b.hermitian (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2877 if (permB.length () == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2878 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2879 permB = ColumnVector (n); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2880 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2881 permB(i) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2882 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2883 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2884 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2885 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2886 if (! make_cholb (b, bt, permB)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2887 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2888 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2889 ("eigs: The matrix B is not positive definite"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2890 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2891 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2892 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2893 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2894 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2895 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2896 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2897 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2898 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2899 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2900 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2901 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2902 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2903 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2904 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2905 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2906 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2907 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2908 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2909 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2910 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2911 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2912 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2913 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2914 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2915 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2916 octave_idx_type lwork = p * (3 * p + 5); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2917 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2918 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2919 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2920 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2921 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2922 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2923 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2924 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2925 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2926 F77_FUNC (znaupd, ZNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2927 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
2928 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2929 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2930 ipntr, workd, workl, lwork, rwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2931 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2932 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2933 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2934 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2935 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2936 ("eigs: unrecoverable exception encountered in znaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2937 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2938 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2939 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2940 if (disp > 0 && !xisnan (workl[iptr (5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2941 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2942 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2943 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2944 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2945 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2946 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2947 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2948 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2949 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2950 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2951 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2952 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2953 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2954 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2955 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2956 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2957 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2958 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2959 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2960 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2961 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2962 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2963 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2964 ComplexMatrix mtmp (n,1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2965 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2966 mtmp(i,0) = workd[i + iptr(0) - 1]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2967 mtmp = utsolve (bt, permB, m * ltsolve (b, permB, mtmp)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2968 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2969 workd[i+iptr(1)-1] = mtmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2970 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2971 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2972 else if (!vector_product (m, workd + iptr(0) - 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2973 workd + iptr(1) - 1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2974 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2975 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2976 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2977 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2978 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2979 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2980 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2981 ("eigs: error %d in znaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2982 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2983 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2984 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2985 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2986 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2987 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2988 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2989 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2990 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2991 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2992 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2993 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2994 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2995 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2996 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2997 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2998 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
2999 octave_idx_type *sel = s.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3000 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3001 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3002 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3003 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3004 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3005 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3006 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3007 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3008 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3009 F77_FUNC (zneupd, ZNEUPD) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3010 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, workev, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3011 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3012 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3013 k, tol, presid, p, v, n, iparam, ipntr, workd, workl, lwork, rwork, info2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3014 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3015 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3016 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3017 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3018 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3019 ("eigs: unrecoverable exception encountered in zneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3020 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3021 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3022 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3023 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3024 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3025 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3026 for (octave_idx_type i = 0; i < k2; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3027 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3028 Complex ctmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3029 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3030 d[k - i - 1] = ctmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3031 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3032 eig_val.resize (k); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3033 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3034 if (rvec) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3035 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3036 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3037 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3038 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3039 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3040 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3041 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3042 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3043 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3044 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3045 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3046 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3047 ctmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3048 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3049 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3050 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3051 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3052 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3053 z[off2 + j] = ctmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3054 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3055 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3056 if (note3) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3057 eig_vec = ltsolve (b, permB, eig_vec); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3058 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3059 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3060 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3061 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3062 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3063 ("eigs: error %d in zneupd", info2); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3064 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3065 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3066 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3067 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3068 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3069 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3070 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3071 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3072 EigsComplexNonSymmetricMatrixShift (const M& m, Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3073 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3074 octave_idx_type &info, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3075 ComplexMatrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3076 ComplexColumnVector &eig_val, const M& _b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3077 ColumnVector &permB, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3078 ComplexColumnVector &cresid, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3079 std::ostream& os, double tol, bool rvec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3080 bool cholB, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3081 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3082 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3083 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3084 octave_idx_type mode = 3; |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3085 bool have_b = ! b.is_empty (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3086 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3087 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3088 if (m.rows () != m.cols ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3089 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3090 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3091 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3092 } |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3093 if (have_b && (m.rows () != b.rows () || m.rows () != b.cols ())) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3094 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3095 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3096 ("eigs: B must be square and the same size as A"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3097 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3098 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3099 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3100 // FIXME: The "SM" type for mode 1 seems unstable though faster!! |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3101 //if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3102 // return EigsComplexNonSymmetricMatrix (m, "SM", k, p, info, eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3103 // eig_val, _b, permB, cresid, os, tol, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3104 // rvec, cholB, disp, maxit); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3105 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3106 if (cresid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3107 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3108 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3109 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3110 Array<double> rr (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3111 Array<double> ri (octave_rand::vector (n)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3112 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3113 for (octave_idx_type i = 0; i < n; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3114 cresid(i) = Complex (rr(i),ri(i)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3115 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3116 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3117 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3118 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3119 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3120 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3121 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3122 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3123 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3124 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3125 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3126 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3127 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3128 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3129 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3130 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3131 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3132 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3133 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3134 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3135 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3136 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3137 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3138 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3139 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3140 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3141 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3142 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3143 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3144 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3145 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3146 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3147 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3148 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3149 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3150 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3151 if (have_b && cholB && permB.length () != 0) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3152 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3153 // Check that we really have a permutation vector |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3154 if (permB.length () != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3155 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3156 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3157 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3158 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3159 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3160 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3161 Array<bool> checked (dim_vector (n, 1), false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3162 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3163 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3164 octave_idx_type bidx = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3165 static_cast<octave_idx_type> (permB(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3166 if (checked(bidx) || bidx < 0 || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3167 bidx >= n || D_NINT (bidx) != bidx) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3168 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3169 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3170 ("eigs: permB vector invalid"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3171 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3172 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3173 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3174 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3175 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3176 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3177 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3178 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3179 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3180 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3181 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3182 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3183 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3184 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3185 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3186 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3187 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3188 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3189 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3190 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3191 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3192 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3193 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3194 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3195 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3196 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3197 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3198 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3199 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3200 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3201 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3202 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3203 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3204 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows () : m.rows ())); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3205 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols () : m.cols ())); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3206 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3207 if (! LuAminusSigmaB (m, b, cholB, permB, sigma, L, U, P, Q)) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3208 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3209 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3210 octave_idx_type lwork = p * (3 * p + 5); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3211 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3212 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3213 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3214 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3215 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3216 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3217 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3218 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3219 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3220 F77_FUNC (znaupd, ZNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3221 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3222 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3223 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3224 ipntr, workd, workl, lwork, rwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3225 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3226 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3227 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3228 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3229 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3230 ("eigs: unrecoverable exception encountered in znaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3231 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3232 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3233 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3234 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3235 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3236 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3237 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3238 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3239 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3240 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3241 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3242 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3243 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3244 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3245 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3246 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3247 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3248 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3249 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3250 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3251 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3252 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3253 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3254 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3255 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3256 if (have_b) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3257 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3258 if (ido == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3259 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3260 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3261 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3262 vector_product (m, workd+iptr(0)-1, ctmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3263 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3264 ComplexMatrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3265 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3266 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3267 tmp(i,0) = ctmp[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3268 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3269 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3270 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3271 Complex *ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3272 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3273 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3274 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3275 else if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3276 vector_product (b, workd + iptr(0) - 1, workd + iptr(1) - 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3277 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3278 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3279 Complex *ip2 = workd+iptr(2)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3280 ComplexMatrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3281 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3282 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3283 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3284 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3285 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3286 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3287 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3288 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3289 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3290 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3291 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3292 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3293 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3294 if (ido == 2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3295 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3296 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3297 workd[iptr(0) + i - 1] = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3298 workd[iptr(1) + i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3299 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3300 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3301 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3302 Complex *ip2 = workd+iptr(0)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3303 ComplexMatrix tmp(n, 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3304 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3305 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3306 tmp(i,0) = ip2[P[i]]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3307 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3308 lusolve (L, U, tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3309 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3310 ip2 = workd+iptr(1)-1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3311 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3312 ip2[Q[i]] = tmp(i,0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3313 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3314 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3315 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3316 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3317 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3318 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3319 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3320 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3321 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3322 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3323 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3324 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3325 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3326 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3327 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3328 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3329 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3330 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3331 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3332 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3333 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3334 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3335 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3336 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3337 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3338 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
3339 octave_idx_type *sel = s.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3340 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3341 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3342 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3343 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3344 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3345 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3346 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3347 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3348 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3349 F77_FUNC (zneupd, ZNEUPD) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3350 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, workev, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3351 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3352 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3353 k, tol, presid, p, v, n, iparam, ipntr, workd, workl, lwork, rwork, info2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3354 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3355 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3356 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3357 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3358 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3359 ("eigs: unrecoverable exception encountered in zneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3360 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3361 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3362 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3363 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3364 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3365 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3366 for (octave_idx_type i = 0; i < k2; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3367 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3368 Complex ctmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3369 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3370 d[k - i - 1] = ctmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3371 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3372 eig_val.resize (k); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3373 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3374 if (rvec) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3375 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3376 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3377 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3378 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3379 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3380 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3381 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3382 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3383 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3384 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3385 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3386 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3387 ctmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3388 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3389 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3390 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3391 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3392 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3393 z[off2 + j] = ctmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3394 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3395 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3396 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3397 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3398 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3399 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3400 ("eigs: error %d in zneupd", info2); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3401 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3402 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3403 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3404 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3405 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3406 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3407 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3408 EigsComplexNonSymmetricFunc (EigsComplexFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3409 const std::string &_typ, Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3410 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3411 octave_idx_type &info, ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3412 ComplexColumnVector &eig_val, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3413 ComplexColumnVector &cresid, std::ostream& os, |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3414 double tol, bool rvec, bool /* cholB */, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3415 int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3416 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3417 std::string typ (_typ); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3418 bool have_sigma = (std::abs (sigma) ? true : false); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3419 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3420 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3421 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3422 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3423 if (cresid.is_empty ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3424 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3425 std::string rand_dist = octave_rand::distribution (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3426 octave_rand::distribution ("uniform"); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3427 Array<double> rr (octave_rand::vector (n)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3428 Array<double> ri (octave_rand::vector (n)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3429 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3430 for (octave_idx_type i = 0; i < n; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3431 cresid(i) = Complex (rr(i),ri(i)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3432 octave_rand::distribution (rand_dist); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3433 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3434 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3435 if (n < 3) |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3436 { |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3437 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3438 ("eigs: n must be at least 3"); |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3439 return -1; |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3440 } |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3441 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3442 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3443 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3444 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3445 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3446 if (p < 20) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3447 p = 20; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3448 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3449 if (p > n - 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3450 p = n - 1 ; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3451 } |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3452 |
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3453 if (k <= 0 || k >= n - 1) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3454 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3455 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3456 ("eigs: Invalid number of eigenvalues to extract (must be 0 < k < n-1).\n" |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3457 " Use 'eig (full (A))' instead"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3458 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3459 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3460 |
9228
ab40ef1e232f
fix tests within eigs-base.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
3461 if (p <= k || p >= n) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3462 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3463 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3464 ("eigs: opts.p must be greater than k and less than n"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3465 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3466 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3467 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3468 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3469 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3470 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3471 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3472 typ != "SI") |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3473 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3474 ("eigs: unrecognized sigma value"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3475 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3476 if (typ == "LA" || typ == "SA" || typ == "BE") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3477 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3478 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3479 ("eigs: invalid sigma value for complex problem"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3480 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3481 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3482 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3483 if (typ == "SM") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3484 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3485 typ = "LM"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3486 sigma = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3487 mode = 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3488 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3489 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3490 else if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3491 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3492 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3493 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3494 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3495 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3496 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3497 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3498 Array<octave_idx_type> ip (dim_vector (11, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3499 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3500 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3501 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3502 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3503 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3504 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3505 ip(4) = 0; // nconv, number of Ritz values that satisfy convergence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3506 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3507 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3508 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3509 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3510 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3511 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3512 // ip(7) to ip(10) return values |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3513 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3514 Array<octave_idx_type> iptr (dim_vector (14, 1)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3515 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3516 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3517 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3518 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3519 octave_idx_type lwork = p * (3 * p + 5); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3520 |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3521 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3522 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3523 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3524 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3525 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3526 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3527 do |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3528 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3529 F77_FUNC (znaupd, ZNAUPD) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3530 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14711
diff
changeset
|
3531 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3532 k, tol, presid, p, v, n, iparam, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3533 ipntr, workd, workl, lwork, rwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3534 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3535 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3536 if (f77_exception_encountered) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3537 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3538 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3539 ("eigs: unrecoverable exception encountered in znaupd"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3540 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3541 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3542 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3543 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3544 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3545 if (iter++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3546 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3547 os << "Iteration " << iter - 1 << |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3548 ": a few Ritz values of the " << p << "-by-" << |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3549 p << " matrix\n"; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3550 for (int i = 0 ; i < k; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3551 os << " " << workl[iptr(5)+i-1] << "\n"; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3552 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3553 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3554 // This is a kludge, as ARPACK doesn't give its |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3555 // iteration pointer. But as workl[iptr(5)-1] is |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3556 // an output value updated at each iteration, setting |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3557 // a value in this array to NaN and testing for it |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3558 // is a way of obtaining the iteration counter. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3559 if (ido != 99) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3560 workl[iptr(5)-1] = octave_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3561 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3562 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3563 if (ido == -1 || ido == 1 || ido == 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3564 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3565 Complex *ip2 = workd + iptr(0) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3566 ComplexColumnVector x(n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3567 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3568 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3569 x(i) = *ip2++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3570 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3571 ComplexColumnVector y = fun (x, err); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3572 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3573 if (err) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3574 return false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3575 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3576 ip2 = workd + iptr(1) - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3577 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3578 *ip2++ = y(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3579 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3580 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3581 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3582 if (info < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3583 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3584 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3585 ("eigs: error %d in dsaupd", info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3586 return -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3587 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3588 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3589 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3590 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3591 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3592 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3593 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3594 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3595 // We have a problem in that the size of the C++ bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3596 // type relative to the fortran logical type. It appears |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3597 // that fortran uses 4- or 8-bytes per logical and C++ 1-byte |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3598 // per bool, though this might be system dependent. As |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3599 // long as the HOWMNY arg is not "S", the logical array |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3600 // is just workspace for ARPACK, so use int type to |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3601 // avoid problems. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3602 Array<octave_idx_type> s (dim_vector (p, 1)); |
9391
333b31ce3434
eigs-base.cc: use octave_idx_type for Fortran LOGICAL values
Alexander Barth <barth.alexander@gmail.com>
parents:
9228
diff
changeset
|
3603 octave_idx_type *sel = s.fortran_vec (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3604 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3605 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3606 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3607 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3608 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3609 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3610 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3611 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3612 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3613 F77_FUNC (zneupd, ZNEUPD) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3614 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, workev, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3615 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3616 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3617 k, tol, presid, p, v, n, iparam, ipntr, workd, workl, lwork, rwork, info2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3618 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3619 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3620 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3621 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3622 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3623 ("eigs: unrecoverable exception encountered in zneupd"); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3624 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3625 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3626 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3627 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3628 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3629 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3630 for (octave_idx_type i = 0; i < k2; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3631 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3632 Complex ctmp = d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3633 d[i] = d[k - i - 1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3634 d[k - i - 1] = ctmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3635 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3636 eig_val.resize (k); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3637 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3638 if (rvec) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3639 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3640 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3641 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3642 for (octave_idx_type i = 0; i < k2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3643 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3644 octave_idx_type off1 = i * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3645 octave_idx_type off2 = (k - i - 1) * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3646 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3647 if (off1 == off2) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3648 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3649 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3650 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3651 ctmp[j] = z[off1 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3652 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3653 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3654 z[off1 + j] = z[off2 + j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3655 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3656 for (octave_idx_type j = 0; j < n; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3657 z[off2 + j] = ctmp[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3658 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3659 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3660 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3661 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3662 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3663 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3664 ("eigs: error %d in zneupd", info2); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3665 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3666 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3667 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3668 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3669 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3670 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3671 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3672 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3673 EigsRealSymmetricMatrix (const Matrix& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3674 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3675 octave_idx_type &info, Matrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3676 ColumnVector &eig_val, const Matrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3677 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3678 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3679 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3680 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3681 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3682 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3683 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3684 EigsRealSymmetricMatrix (const SparseMatrix& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3685 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3686 octave_idx_type &info, Matrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3687 ColumnVector &eig_val, const SparseMatrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3688 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3689 std::ostream& os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3690 double tol = std::numeric_limits<double>::epsilon (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3691 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3692 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3693 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3694 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3695 EigsRealSymmetricMatrixShift (const Matrix& m, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3696 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3697 octave_idx_type &info, Matrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3698 ColumnVector &eig_val, const Matrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3699 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3700 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3701 double tol = std::numeric_limits<double>::epsilon (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3702 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3703 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3704 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3705 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3706 EigsRealSymmetricMatrixShift (const SparseMatrix& m, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3707 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3708 octave_idx_type &info, Matrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3709 ColumnVector &eig_val, const SparseMatrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3710 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3711 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3712 double tol = std::numeric_limits<double>::epsilon (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3713 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3714 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3715 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3716 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3717 EigsRealSymmetricFunc (EigsFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3718 const std::string &typ, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3719 octave_idx_type k, octave_idx_type p, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3720 octave_idx_type &info, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3721 Matrix &eig_vec, ColumnVector &eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3722 ColumnVector &resid, std::ostream &os, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3723 double tol = std::numeric_limits<double>::epsilon (), |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3724 bool rvec = false, bool cholB = 0, int disp = 0, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3725 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3726 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3727 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3728 EigsRealNonSymmetricMatrix (const Matrix& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3729 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3730 octave_idx_type &info, ComplexMatrix &eig_vec, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3731 ComplexColumnVector &eig_val, const Matrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3732 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3733 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3734 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3735 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3736 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3737 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3738 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3739 EigsRealNonSymmetricMatrix (const SparseMatrix& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3740 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3741 octave_idx_type &info, ComplexMatrix &eig_vec, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3742 ComplexColumnVector &eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3743 const SparseMatrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3744 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3745 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3746 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3747 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3748 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3749 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3750 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3751 EigsRealNonSymmetricMatrixShift (const Matrix& m, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3752 octave_idx_type k, octave_idx_type p, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3753 octave_idx_type &info, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3754 ComplexMatrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3755 ComplexColumnVector &eig_val, const Matrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3756 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3757 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3758 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3759 bool rvec = false, bool cholB = 0, |
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3760 int disp = 0, int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3761 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3762 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3763 EigsRealNonSymmetricMatrixShift (const SparseMatrix& m, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3764 octave_idx_type k, octave_idx_type p, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3765 octave_idx_type &info, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3766 ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3767 ComplexColumnVector &eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3768 const SparseMatrix& b, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3769 ColumnVector &permB, ColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3770 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3771 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3772 bool rvec = false, bool cholB = 0, |
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3773 int disp = 0, int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3774 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3775 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3776 EigsRealNonSymmetricFunc (EigsFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3777 const std::string &_typ, double sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3778 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3779 octave_idx_type &info, ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3780 ComplexColumnVector &eig_val, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3781 ColumnVector &resid, std::ostream& os, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3782 double tol = std::numeric_limits<double>::epsilon (), |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3783 bool rvec = false, bool cholB = 0, int disp = 0, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3784 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3785 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3786 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3787 EigsComplexNonSymmetricMatrix (const ComplexMatrix& m, const std::string typ, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3788 octave_idx_type k, octave_idx_type p, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3789 octave_idx_type &info, ComplexMatrix &eig_vec, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3790 ComplexColumnVector &eig_val, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3791 const ComplexMatrix& b, ColumnVector &permB, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3792 ComplexColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3793 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3794 double tol = std::numeric_limits<double>::epsilon (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3795 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3796 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3797 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3798 extern octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3799 EigsComplexNonSymmetricMatrix (const SparseComplexMatrix& m, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3800 const std::string typ, octave_idx_type k, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3801 octave_idx_type p, octave_idx_type &info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3802 ComplexMatrix &eig_vec, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3803 ComplexColumnVector &eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3804 const SparseComplexMatrix& b, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3805 ColumnVector &permB, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3806 ComplexColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3807 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3808 double tol = std::numeric_limits<double>::epsilon (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3809 bool rvec = false, bool cholB = 0, int disp = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3810 int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3811 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3812 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3813 EigsComplexNonSymmetricMatrixShift (const ComplexMatrix& m, Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3814 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3815 octave_idx_type &info, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3816 ComplexMatrix &eig_vec, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3817 ComplexColumnVector &eig_val, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3818 const ComplexMatrix& b, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3819 ColumnVector &permB, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3820 ComplexColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3821 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3822 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3823 bool rvec = false, bool cholB = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3824 int disp = 0, int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3825 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3826 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3827 EigsComplexNonSymmetricMatrixShift (const SparseComplexMatrix& m, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3828 Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3829 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3830 octave_idx_type &info, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3831 ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3832 ComplexColumnVector &eig_val, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3833 const SparseComplexMatrix& b, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3834 ColumnVector &permB, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3835 ComplexColumnVector &resid, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3836 std::ostream &os, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3837 double tol = std::numeric_limits<double>::epsilon (), |
10361
b4f67ca318d8
eigs-base.cc: fix prototypes for arpack functions
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
3838 bool rvec = false, bool cholB = 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3839 int disp = 0, int maxit = 300); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3840 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3841 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3842 EigsComplexNonSymmetricFunc (EigsComplexFunc fun, octave_idx_type n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3843 const std::string &_typ, Complex sigma, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3844 octave_idx_type k, octave_idx_type p, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3845 octave_idx_type &info, ComplexMatrix &eig_vec, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3846 ComplexColumnVector &eig_val, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3847 ComplexColumnVector &resid, std::ostream& os, |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3848 double tol = std::numeric_limits<double>::epsilon (), |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3849 bool rvec = false, bool cholB = 0, |
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15020
diff
changeset
|
3850 int disp = 0, int maxit = 300); |
14144
834df9f10963
remove ARPACK files from sources and restore configure checks for external ARPACK library
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
3851 #endif |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3852 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3853 #ifndef _MSC_VER |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3854 template octave_idx_type |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3855 lusolve (const SparseMatrix&, const SparseMatrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3856 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3857 template octave_idx_type |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3858 lusolve (const SparseComplexMatrix&, const SparseComplexMatrix&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3859 ComplexMatrix&); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3860 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3861 template octave_idx_type |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3862 lusolve (const Matrix&, const Matrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3863 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3864 template octave_idx_type |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3865 lusolve (const ComplexMatrix&, const ComplexMatrix&, ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3866 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3867 template ComplexMatrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3868 ltsolve (const SparseComplexMatrix&, const ColumnVector&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3869 const ComplexMatrix&); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3870 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3871 template Matrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3872 ltsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3873 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3874 template ComplexMatrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3875 ltsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3876 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3877 template Matrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3878 ltsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3879 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3880 template ComplexMatrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3881 utsolve (const SparseComplexMatrix&, const ColumnVector&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3882 const ComplexMatrix&); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3883 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3884 template Matrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3885 utsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3886 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3887 template ComplexMatrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3888 utsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3889 |
14711
f5c3de9502b2
Fix compilation error on newer compilers
Alexander Hansen <alexanderk.hansen@gmail.com>
parents:
14144
diff
changeset
|
3890 template Matrix |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3891 utsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3892 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3893 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3894 #endif |