Mercurial > hg > octave-nkf
annotate liboctave/eigs-base.cc @ 8677:095ae5e0a831
eliminte some compiler warnings
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 05 Feb 2009 02:42:58 -0500 |
parents | 654bcfb937bf |
children | eb63fbe60fab |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 Copyright (C) 2005 David Bateman |
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" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 #include "quit.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 #include "SparsedbleLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 #include "SparseCmplxLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 #include "dSparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 #include "CSparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 #include "MatrixType.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 #include "SparsedbleCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 #include "SparseCmplxCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 #include "oct-rand.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 #include "dbleCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 #include "CmplxCHOL.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 #include "dbleLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 #include "CmplxLU.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 #ifdef HAVE_ARPACK |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 typedef ColumnVector (*EigsFunc) (const ColumnVector &x, int &eigs_error); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 typedef ComplexColumnVector (*EigsComplexFunc) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 (const ComplexColumnVector &x, int &eigs_error); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 // Arpack and blas fortran functions we call. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 extern "C" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 F77_FUNC (dsaupd, DSAUPD) (octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 const octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
59 double*, const octave_idx_type&, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
60 const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
61 octave_idx_type*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 const octave_idx_type&, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
66 F77_FUNC (dseupd, DSEUPD) (const int&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
67 int*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
68 const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
70 F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
71 const double&, double*, const octave_idx_type&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
72 double*, const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
73 octave_idx_type*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 const octave_idx_type&, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
78 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
79 F77_FUNC (dnaupd, DNAUPD) (octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 const octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 double*, const octave_idx_type&, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 octave_idx_type*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
85 const octave_idx_type&, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
86 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
88 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
89 F77_FUNC (dneupd, DNEUPD) (const int&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 int*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 double*, const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 const double&, double*, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
93 const octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 octave_idx_type&, const double&, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 const octave_idx_type&, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 octave_idx_type*, double*, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 const octave_idx_type&, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
100 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
101 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 F77_FUNC (znaupd, ZNAUPD) (octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
104 const octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
105 const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
106 Complex*, const octave_idx_type&, Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
107 const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
108 octave_idx_type*, Complex*, Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
109 const octave_idx_type&, double *, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
110 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
111 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
112 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
113 F77_FUNC (zneupd, ZNEUPD) (const int&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 int*, Complex*, Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
115 const octave_idx_type&, const Complex&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
116 Complex*, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
117 const octave_idx_type&, F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
118 const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
119 Complex*, const octave_idx_type&, Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
120 const octave_idx_type&, octave_idx_type*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
121 octave_idx_type*, Complex*, Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
122 const octave_idx_type&, double *, octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
123 F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
124 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
125 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
126 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
127 F77_FUNC (dgemv, DGEMV) (F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
128 const octave_idx_type&, const octave_idx_type&, const double&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
129 const double*, const octave_idx_type&, const double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
130 const octave_idx_type&, const double&, double*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
131 const octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
132 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
133 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
134 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
135 F77_RET_T |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
136 F77_FUNC (zgemv, ZGEMV) (F77_CONST_CHAR_ARG_DECL, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
137 const octave_idx_type&, const octave_idx_type&, const Complex&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
138 const Complex*, const octave_idx_type&, const Complex*, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
139 const octave_idx_type&, const Complex&, Complex*, const octave_idx_type& |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
140 F77_CHAR_ARG_LEN_DECL); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
141 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
142 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
143 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
144 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
145 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
146 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
147 lusolve (const SparseMatrix&, const SparseMatrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
148 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
149 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
150 lusolve (const SparseComplexMatrix&, const SparseComplexMatrix&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
151 ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
152 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
153 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
154 lusolve (const Matrix&, const Matrix&, Matrix&); |
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 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
157 lusolve (const ComplexMatrix&, const ComplexMatrix&, ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
158 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
159 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
160 ltsolve (const SparseComplexMatrix&, const ColumnVector&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
161 const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
162 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
163 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
164 ltsolve (const SparseMatrix&, const ColumnVector&, const Matrix&,); |
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 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
167 ltsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
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 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
170 ltsolve (const Matrix&, const ColumnVector&, const Matrix&,); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
171 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
172 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
173 utsolve (const SparseComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
174 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
175 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
176 utsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
177 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
178 static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
179 utsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
180 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
181 static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
182 utsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
183 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
184 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
185 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
186 template <class M, class SM> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
187 static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
188 lusolve (const SM& L, const SM& U, M& m) |
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 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
191 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
192 MatrixType utyp (MatrixType::Upper); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
193 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
194 // 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
|
195 m = L.solve (m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
196 if (err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
197 return err; |
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 m = U.solve (utyp, m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
200 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
201 return err; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
202 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
203 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
204 template <class SM, class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
205 static M |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
206 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
|
207 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
208 octave_idx_type n = L.cols(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
209 octave_idx_type b_nc = m.cols(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
210 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
211 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
212 MatrixType ltyp (MatrixType::Lower); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
213 M tmp = L.solve (ltyp, m, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
214 M retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
215 const double* qv = Q.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
216 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
217 if (!err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
218 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
219 retval.resize (n, b_nc); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
220 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
|
221 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
222 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
223 retval.elem(static_cast<octave_idx_type>(qv[i]), j) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
224 tmp.elem(i,j); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
225 } |
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 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
229 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
230 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
231 template <class SM, class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
232 static M |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
233 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
|
234 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
235 octave_idx_type n = U.cols(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
236 octave_idx_type b_nc = m.cols(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
237 octave_idx_type err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
238 double rcond; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
239 MatrixType utyp (MatrixType::Upper); |
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 M retval (n, b_nc); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
242 const double* qv = Q.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
243 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
|
244 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
245 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
246 retval.elem(i,j) = m.elem(static_cast<octave_idx_type>(qv[i]), j); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
247 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
248 return U.solve (utyp, retval, err, rcond, 0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
249 } |
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 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
252 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
|
253 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
254 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
255 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
256 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
257 y[j] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
258 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
259 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
260 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
261 y[m.ridx(i)] += m.data(i) * x[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
262 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
263 return true; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
266 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
267 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
|
268 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
269 octave_idx_type nr = m.rows (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
270 octave_idx_type nc = m.cols (); |
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 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
273 nr, nc, 1.0, m.data (), nr, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
274 x, 1, 0.0, y, 1 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
275 F77_CHAR_ARG_LEN (1))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
276 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
277 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
278 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
279 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
280 ("eigs: unrecoverable error in dgemv"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
281 return false; |
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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
284 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
285 } |
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 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
288 vector_product (const SparseComplexMatrix& m, const Complex* x, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
289 Complex* y) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
290 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
291 octave_idx_type nc = m.cols (); |
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 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
294 y[j] = 0.; |
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 for (octave_idx_type j = 0; j < nc; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
297 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
298 y[m.ridx(i)] += m.data(i) * x[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
299 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
300 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
301 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
302 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
303 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
304 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
|
305 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
306 octave_idx_type nr = m.rows (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
307 octave_idx_type nc = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
308 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
309 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 ("N", 1), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
310 nr, nc, 1.0, m.data (), nr, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
311 x, 1, 0.0, y, 1 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
312 F77_CHAR_ARG_LEN (1))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
313 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
314 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
315 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
316 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
317 ("eigs: unrecoverable error in zgemv"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
318 return false; |
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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
321 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
322 } |
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 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
325 make_cholb (Matrix& b, Matrix& bt, ColumnVector& permB) |
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 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
328 CHOL fact (b, info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
329 octave_idx_type n = b.cols(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
330 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
331 if (info != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
332 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
333 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
334 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
335 bt = fact.chol_matrix (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
336 b = bt.transpose(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
337 permB = ColumnVector(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
338 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
339 permB(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
340 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
341 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
342 } |
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 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
345 make_cholb (SparseMatrix& b, SparseMatrix& bt, ColumnVector& permB) |
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 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
348 SparseCHOL fact (b, info, false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
349 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
350 if (fact.P() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
351 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
352 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
353 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
354 b = fact.L(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
355 bt = b.transpose(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
356 permB = fact.perm() - 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
357 return true; |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
360 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
361 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
362 make_cholb (ComplexMatrix& b, ComplexMatrix& bt, ColumnVector& permB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
363 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
364 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
365 ComplexCHOL fact (b, info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
366 octave_idx_type n = b.cols(); |
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 if (info != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
369 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
370 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
371 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
372 bt = fact.chol_matrix (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
373 b = bt.hermitian(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
374 permB = ColumnVector(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
375 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
376 permB(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
377 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
378 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
379 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
380 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
381 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
382 make_cholb (SparseComplexMatrix& b, SparseComplexMatrix& bt, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
383 ColumnVector& permB) |
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 octave_idx_type info; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
386 SparseComplexCHOL fact (b, info, false); |
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 if (fact.P() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
389 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
390 else |
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 b = fact.L(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
393 bt = b.hermitian(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
394 permB = fact.perm() - 1.0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
395 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
396 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
397 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
398 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
399 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
400 LuAminusSigmaB (const SparseMatrix &m, const SparseMatrix &b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
401 bool cholB, const ColumnVector& permB, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
402 SparseMatrix &L, SparseMatrix &U, octave_idx_type *P, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
403 octave_idx_type *Q) |
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 bool have_b = ! b.is_empty (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
406 octave_idx_type n = m.rows(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
407 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
408 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
409 SparseMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
410 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
411 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
412 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
413 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
414 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
415 if (permB.length()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
416 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
417 SparseMatrix tmp(n,n,n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
418 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
419 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
420 tmp.xcidx(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
421 tmp.xridx(i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
422 static_cast<octave_idx_type>(permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
423 tmp.xdata(i) = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
424 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
425 tmp.xcidx(n) = n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
426 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
427 AminusSigmaB = AminusSigmaB - sigma * tmp * |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
428 b.transpose() * b * tmp.transpose(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
429 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
430 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
431 AminusSigmaB = AminusSigmaB - sigma * |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
432 b.transpose() * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
433 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
434 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
435 AminusSigmaB = AminusSigmaB - sigma * 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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
438 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
439 SparseMatrix sigmat (n, n, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
440 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
441 // Create sigma * speye(n,n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
442 sigmat.xcidx (0) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
443 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
444 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
445 sigmat.xdata(i) = sigma; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
446 sigmat.xridx(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
447 sigmat.xcidx(i+1) = i + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
448 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
449 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
450 AminusSigmaB = AminusSigmaB - sigmat; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
451 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
452 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
453 SparseLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
454 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
455 L = fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
456 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
457 const octave_idx_type *P2 = fact.row_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
458 const octave_idx_type *Q2 = fact.col_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
459 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
460 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
461 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
462 P[j] = P2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
463 Q[j] = Q2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
464 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
465 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
466 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
467 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
468 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
469 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
470 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
471 double d = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
472 if (U.xcidx(j+1) > U.xcidx(j) && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
473 U.xridx (U.xcidx(j+1)-1) == j) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
474 d = std::abs (U.xdata (U.xcidx(j+1)-1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
475 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
476 if (xisnan (minU) || d < minU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
477 minU = d; |
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 if (xisnan (maxU) || d > maxU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
480 maxU = d; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
481 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
482 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
483 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
484 volatile double rcond_plus_one = rcond + 1.0; |
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 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
487 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
488 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
489 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
490 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
491 (" an eigenvalue. Convergence is not guaranteed"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
492 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
493 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
494 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
495 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
496 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
497 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
498 LuAminusSigmaB (const Matrix &m, const Matrix &b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
499 bool cholB, const ColumnVector& permB, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
500 Matrix &L, Matrix &U, octave_idx_type *P, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
501 octave_idx_type *Q) |
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 bool have_b = ! b.is_empty (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
504 octave_idx_type n = m.cols(); |
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 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
507 Matrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
508 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
509 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
510 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
511 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
512 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
513 Matrix tmp = sigma * b.transpose() * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
514 const double *pB = permB.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
515 double *p = AminusSigmaB.fortran_vec(); |
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 if (permB.length()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
518 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
519 for (octave_idx_type j = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
520 j < b.cols(); j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
521 for (octave_idx_type i = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
522 i < b.rows(); i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
523 *p++ -= tmp.xelem (static_cast<octave_idx_type>(pB[i]), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
524 static_cast<octave_idx_type>(pB[j])); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
525 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
526 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
527 AminusSigmaB = AminusSigmaB - tmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
528 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
529 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
530 AminusSigmaB = AminusSigmaB - sigma * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
531 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
532 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
533 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
534 double *p = AminusSigmaB.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
535 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
536 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
537 p[i*(n+1)] -= sigma; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
538 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
539 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
540 LU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
541 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
542 L = fact.P().transpose() * fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
543 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
544 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
545 P[j] = Q[j] = j; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
546 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
547 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
548 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
549 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
550 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
551 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
552 double d = std::abs (U.xelem(j,j)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
553 if (xisnan (minU) || d < minU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
554 minU = d; |
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 if (xisnan (maxU) || d > maxU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
557 maxU = d; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
558 } |
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 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
561 volatile double rcond_plus_one = rcond + 1.0; |
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 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
564 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
565 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
566 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
567 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
568 (" an eigenvalue. Convergence is not guaranteed"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
569 } |
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 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
572 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
573 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
574 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
575 LuAminusSigmaB (const SparseComplexMatrix &m, const SparseComplexMatrix &b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
576 bool cholB, const ColumnVector& permB, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
577 SparseComplexMatrix &L, SparseComplexMatrix &U, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
578 octave_idx_type *P, octave_idx_type *Q) |
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 bool have_b = ! b.is_empty (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
581 octave_idx_type n = m.rows(); |
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 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
584 SparseComplexMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
585 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
586 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
587 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
588 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
589 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
590 if (permB.length()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
591 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
592 SparseMatrix tmp(n,n,n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
593 for (octave_idx_type i = 0; i < n; i++) |
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 tmp.xcidx(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
596 tmp.xridx(i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
597 static_cast<octave_idx_type>(permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
598 tmp.xdata(i) = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
599 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
600 tmp.xcidx(n) = n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
601 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
602 AminusSigmaB = AminusSigmaB - tmp * b.hermitian() * b * |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
603 tmp.transpose() * sigma; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
604 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
605 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
606 AminusSigmaB = AminusSigmaB - sigma * b.hermitian() * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
607 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
608 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
609 AminusSigmaB = AminusSigmaB - sigma * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
610 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
611 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
612 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
613 SparseComplexMatrix sigmat (n, n, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
614 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
615 // Create sigma * speye(n,n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
616 sigmat.xcidx (0) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
617 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
618 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
619 sigmat.xdata(i) = sigma; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
620 sigmat.xridx(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
621 sigmat.xcidx(i+1) = i + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
622 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
623 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
624 AminusSigmaB = AminusSigmaB - sigmat; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
625 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
626 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
627 SparseComplexLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
628 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
629 L = fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
630 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
631 const octave_idx_type *P2 = fact.row_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
632 const octave_idx_type *Q2 = fact.col_perm (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
633 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
634 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
635 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
636 P[j] = P2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
637 Q[j] = Q2[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
638 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
639 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
640 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
641 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
642 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
643 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
644 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
645 double d = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
646 if (U.xcidx(j+1) > U.xcidx(j) && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
647 U.xridx (U.xcidx(j+1)-1) == j) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
648 d = std::abs (U.xdata (U.xcidx(j+1)-1)); |
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 if (xisnan (minU) || d < minU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
651 minU = d; |
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 if (xisnan (maxU) || d > maxU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
654 maxU = d; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
655 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
656 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
657 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
658 volatile double rcond_plus_one = rcond + 1.0; |
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 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
661 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
662 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
663 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
664 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
665 (" an eigenvalue. Convergence is not guaranteed"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
666 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
667 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
668 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
669 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
670 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
671 static bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
672 LuAminusSigmaB (const ComplexMatrix &m, const ComplexMatrix &b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
673 bool cholB, const ColumnVector& permB, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
674 ComplexMatrix &L, ComplexMatrix &U, octave_idx_type *P, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
675 octave_idx_type *Q) |
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 bool have_b = ! b.is_empty (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
678 octave_idx_type n = m.cols(); |
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 // Caclulate LU decomposition of 'A - sigma * B' |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
681 ComplexMatrix AminusSigmaB (m); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
682 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
683 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
684 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
685 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
686 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
687 ComplexMatrix tmp = sigma * b.hermitian() * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
688 const double *pB = permB.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
689 Complex *p = AminusSigmaB.fortran_vec(); |
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 if (permB.length()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
692 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
693 for (octave_idx_type j = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
694 j < b.cols(); j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
695 for (octave_idx_type i = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
696 i < b.rows(); i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
697 *p++ -= tmp.xelem (static_cast<octave_idx_type>(pB[i]), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
698 static_cast<octave_idx_type>(pB[j])); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
699 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
700 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
701 AminusSigmaB = AminusSigmaB - tmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
702 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
703 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
704 AminusSigmaB = AminusSigmaB - sigma * b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
705 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
706 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
707 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
708 Complex *p = AminusSigmaB.fortran_vec(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
709 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
710 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
711 p[i*(n+1)] -= sigma; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
712 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
713 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
714 ComplexLU fact (AminusSigmaB); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
715 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
716 L = fact.P().transpose() * fact.L (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
717 U = fact.U (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
718 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
719 P[j] = Q[j] = j; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
720 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
721 // Test condition number of LU decomposition |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
722 double minU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
723 double maxU = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
724 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
725 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
726 double d = std::abs (U.xelem(j,j)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
727 if (xisnan (minU) || d < minU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
728 minU = d; |
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 if (xisnan (maxU) || d > maxU) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
731 maxU = d; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
732 } |
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 double rcond = (minU / maxU); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
735 volatile double rcond_plus_one = rcond + 1.0; |
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 if (rcond_plus_one == 1.0 || xisnan (rcond)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
738 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
739 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
740 ("eigs: 'A - sigma*B' is singular, indicating sigma is exactly"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
741 (*current_liboctave_warning_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
742 (" an eigenvalue. Convergence is not guaranteed"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
743 } |
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 return true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
746 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
747 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
748 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
749 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
750 EigsRealSymmetricMatrix (const M& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
751 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
752 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
753 ColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
754 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
755 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
756 bool cholB, int disp, int maxit) |
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 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
759 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
760 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
761 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
762 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
763 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
764 double sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
765 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
766 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
767 if (m.rows() != m.cols()) |
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 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
770 return -1; |
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 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
773 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
774 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
775 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
776 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
777 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
778 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
779 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
780 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
781 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
782 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
783 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
784 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
785 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
786 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
787 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
788 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
789 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
790 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
791 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
792 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
793 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
794 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
795 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
796 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
797 else if (p <= k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
798 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
799 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
800 ("eigs: opts.p must be between k and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
801 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
802 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
803 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
804 if (k > n ) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
805 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
806 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
807 ("eigs: Too many eigenvalues to extract (k >= n).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
808 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
809 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
810 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
811 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
812 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
813 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
814 // Check the we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
815 if (permB.length() != n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
816 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
817 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
818 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
819 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
820 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
821 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
822 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
823 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
824 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
825 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
826 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
827 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
828 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
829 bidx >= n || D_NINT (bidx) != bidx) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
830 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
831 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
832 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
833 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
834 } |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
837 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
838 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
839 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
840 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
841 typ != "SI") |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
844 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
845 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
846 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
847 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
848 if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
849 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
850 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
851 ("eigs: invalid sigma value for real symmetric problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
852 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
853 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
854 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
855 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
856 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
857 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
858 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
859 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
860 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
861 bt = b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
862 b = b.transpose(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
863 if (permB.length() == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
864 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
865 permB = ColumnVector(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
866 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
867 permB(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
868 } |
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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
871 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
872 if (! make_cholb(b, bt, permB)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
873 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
874 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
875 ("eigs: The matrix B is not positive definite"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
876 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
877 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
878 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
879 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
880 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
881 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
882 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
883 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
884 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
885 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
886 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
887 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
888 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
|
889 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
890 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
891 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
892 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
893 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
894 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
895 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
896 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
897 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
898 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
899 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
900 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
901 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
902 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
903 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
904 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
905 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
906 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
907 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
908 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
909 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
910 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
911 F77_FUNC (dsaupd, DSAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
912 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
913 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
914 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
915 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
916 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
|
917 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
918 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
919 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
920 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
921 ("eigs: unrecoverable exception encountered in dsaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
922 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
923 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
924 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
925 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
926 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
927 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
928 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
929 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
930 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
931 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
932 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
933 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
934 } |
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 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
937 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
938 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
939 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
940 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
941 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
942 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
943 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
944 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
945 if (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
946 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
947 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
948 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
949 Matrix mtmp (n,1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
950 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
951 mtmp(i,0) = workd[i + iptr(0) - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
952 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
953 mtmp = utsolve(bt, permB, m * ltsolve(b, permB, mtmp)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
954 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
955 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
956 workd[i+iptr(1)-1] = mtmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
957 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
958 else if (!vector_product (m, workd + iptr(0) - 1, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
959 workd + iptr(1) - 1)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
960 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
961 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
962 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
963 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
964 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
965 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
966 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
967 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
968 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
969 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
970 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
971 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
972 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
973 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
974 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
975 octave_idx_type info2; |
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 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
978 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
979 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
980 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
981 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
982 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
983 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
984 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
985 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
986 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
987 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
988 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
989 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
990 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
991 double *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
992 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
993 F77_FUNC (dseupd, DSEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
994 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
995 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
996 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
997 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
998 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
999 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1000 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1001 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1002 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1003 ("eigs: unrecoverable exception encountered in dseupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1004 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1005 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1006 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1007 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1008 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1009 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1010 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1011 if (typ != "SM" && typ != "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1012 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1013 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1014 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1015 double dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1016 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1017 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1018 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1019 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1020 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1021 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1022 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1023 if (typ != "SM" && typ != "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1024 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1025 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1026 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1027 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1028 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1029 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1030 octave_idx_type off2 = (k - i - 1) * n; |
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 (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1033 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1034 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1035 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1036 dtmp[j] = z[off1 + j]; |
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 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1039 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1040 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1041 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1042 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1043 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1044 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1045 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1046 if (note3) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1047 eig_vec = ltsolve(b, permB, eig_vec); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1048 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1049 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1050 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1051 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1052 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1053 ("eigs: error %d in dseupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1054 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1055 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1056 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1057 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1058 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1059 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1060 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1061 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1062 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1063 EigsRealSymmetricMatrixShift (const M& m, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1064 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1065 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1066 ColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1067 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1068 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1069 bool cholB, int disp, int maxit) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1070 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1071 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1072 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1073 octave_idx_type mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1074 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1075 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1076 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1077 if (m.rows() != m.cols()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1078 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1079 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1080 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1081 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1082 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1083 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1084 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1085 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1086 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1087 } |
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 // 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
|
1090 //if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1091 // return EigsRealSymmetricMatrix (m, "SM", k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1092 // _b, permB, resid, os, tol, rvec, cholB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1093 // disp, maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1094 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1095 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1096 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1097 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1098 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1099 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1100 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1101 } |
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 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1104 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1105 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1106 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1107 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1108 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1109 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1110 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1111 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1112 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1113 else if (p <= k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1114 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1115 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1116 ("eigs: opts.p must be between k and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1117 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1118 } |
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 if (k > n ) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1121 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1122 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1123 ("eigs: Too many eigenvalues to extract (k >= n).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1124 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1125 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1126 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1127 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1128 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1129 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1130 // Check the we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1131 if (permB.length() != n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1132 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1133 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1134 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1135 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1136 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1137 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1138 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1139 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1140 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1141 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1142 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1143 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1144 bidx >= n || D_NINT (bidx) != bidx) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1145 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1146 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1147 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1148 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1149 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1150 } |
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 } |
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 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1155 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1156 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1157 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1158 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1159 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1160 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1161 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1162 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1163 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1164 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1165 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
|
1166 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1167 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1168 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1169 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1170 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1171 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1172 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1173 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1174 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1175 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1176 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1177 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1178 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1179 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1180 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1181 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows() : m.rows())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1182 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols() : m.cols())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1183 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1184 if (! LuAminusSigmaB(m, b, cholB, permB, sigma, L, U, P, Q)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1185 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1186 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1187 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1188 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1189 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1190 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1191 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1192 double *presid = resid.fortran_vec (); |
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 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1195 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1196 F77_FUNC (dsaupd, DSAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1197 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1198 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1199 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1200 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1201 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
|
1202 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1203 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1204 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1205 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1206 ("eigs: unrecoverable exception encountered in dsaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1207 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1208 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1209 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1210 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1211 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1212 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1213 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1214 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1215 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1216 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1217 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1218 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1219 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1220 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1221 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1222 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1223 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1224 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1225 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1226 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1227 workl[iptr(5)-1] = octave_NaN; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1230 if (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1231 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1232 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1233 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1234 if (ido == -1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1235 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1236 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1237 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1238 vector_product (m, workd+iptr(0)-1, dtmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1239 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1240 Matrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1241 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1242 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1243 tmp(i,0) = dtmp[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1244 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1245 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1246 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1247 double *ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1248 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1249 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1250 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1251 else if (ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1252 vector_product (b, workd+iptr(0)-1, workd+iptr(1)-1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1253 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1254 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1255 double *ip2 = workd+iptr(2)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1256 Matrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1257 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1258 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1259 tmp(i,0) = ip2[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1260 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1261 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1262 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1263 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1264 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1265 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1266 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1267 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1268 else |
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 == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1271 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1272 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1273 workd[iptr(0) + i - 1] = workd[iptr(1) + i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1274 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1275 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1276 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1277 double *ip2 = workd+iptr(0)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1278 Matrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1279 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1280 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1281 tmp(i,0) = ip2[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1282 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1283 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1284 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1285 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1286 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1287 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1288 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1289 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1290 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1291 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1292 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1293 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1294 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1295 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1296 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1297 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1298 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1299 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1300 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1301 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1302 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1303 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1304 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1305 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1306 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1307 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1308 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1309 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1310 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1311 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1312 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1313 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1314 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1315 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1316 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1317 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1318 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1319 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1320 double *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1321 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1322 F77_FUNC (dseupd, DSEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1323 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1324 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1325 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1326 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
|
1327 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
|
1328 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1329 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1330 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1331 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1332 ("eigs: unrecoverable exception encountered in dseupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1333 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1334 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1335 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1336 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1337 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1338 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1339 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1340 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1341 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1342 double dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1343 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1344 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1345 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1346 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1347 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1348 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1349 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1350 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1351 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1352 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1353 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1354 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1355 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1356 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1357 continue; |
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 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1360 dtmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1361 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1362 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1363 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1364 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1365 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1366 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1367 } |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1370 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1371 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1372 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1373 ("eigs: error %d in dseupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1374 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1375 } |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1378 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1379 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1380 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1381 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1382 EigsRealSymmetricFunc (EigsFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1383 const std::string &_typ, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1384 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1385 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1386 ColumnVector &eig_val, ColumnVector &resid, |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1387 std::ostream& os, double tol, int rvec, |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1388 bool /* cholB */, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1389 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1390 std::string typ (_typ); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1391 bool have_sigma = (sigma ? true : false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1392 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1393 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1394 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1395 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1396 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1397 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1398 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1399 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1400 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1401 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1402 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1403 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1404 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1405 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1406 p = k * 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1407 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1408 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1409 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1410 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1411 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1412 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1413 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1414 else if (p <= k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1415 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1416 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1417 ("eigs: opts.p must be between k and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1418 return -1; |
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 if (k > n ) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1422 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1423 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1424 ("eigs: Too many eigenvalues to extract (k >= n).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1425 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1426 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1427 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1428 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1429 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1430 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1431 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1432 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1433 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1434 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1435 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1436 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1437 if (typ == "LI" || typ == "SI" || typ == "LR" || typ == "SR") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1438 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1439 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1440 ("eigs: invalid sigma value for real symmetric problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1441 return -1; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1444 if (typ == "SM") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1445 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1446 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1447 sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1448 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1449 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1450 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1451 else if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1452 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1453 else |
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 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1456 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1457 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1458 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1459 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1460 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1461 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1462 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1463 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1464 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1465 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1466 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
|
1467 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1468 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1469 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1470 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1471 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1472 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1473 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1474 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1475 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1476 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1477 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1478 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1479 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1480 octave_idx_type lwork = p * (p + 8); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1481 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1482 OCTAVE_LOCAL_BUFFER (double, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1483 OCTAVE_LOCAL_BUFFER (double, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1484 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1485 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1486 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1487 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1488 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1489 F77_FUNC (dsaupd, DSAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1490 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1491 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1492 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1493 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1494 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
|
1495 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1496 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1497 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1498 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1499 ("eigs: unrecoverable exception encountered in dsaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1500 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1501 } |
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 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1504 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1505 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1506 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1507 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1508 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1509 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1510 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1511 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1512 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1513 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1514 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1515 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1516 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1517 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1518 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1519 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1520 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1521 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1522 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1523 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1524 if (ido == -1 || ido == 1 || ido == 2) |
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 double *ip2 = workd + iptr(0) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1527 ColumnVector x(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1528 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1529 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1530 x(i) = *ip2++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1531 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1532 ColumnVector y = fun (x, err); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1533 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1534 if (err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1535 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1536 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1537 ip2 = workd + iptr(1) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1538 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1539 *ip2++ = y(i); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1540 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1541 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1542 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1543 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1544 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1545 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1546 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1547 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1548 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1549 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1550 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1551 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1552 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1553 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1554 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1555 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1556 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1557 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1558 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1559 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1560 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1561 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1562 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1563 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1564 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1565 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1566 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1567 double *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1568 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1569 eig_val.resize (k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1570 double *d = eig_val.fortran_vec (); |
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 F77_FUNC (dseupd, DSEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1573 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, d, z, n, sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1574 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1575 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1576 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
|
1577 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
|
1578 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1579 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1580 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1581 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1582 ("eigs: unrecoverable exception encountered in dseupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1583 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1584 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1585 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1586 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1587 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1588 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1589 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1590 if (typ != "SM" && typ != "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1591 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1592 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1593 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1594 double dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1595 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1596 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1597 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1598 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1599 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1600 if (rvec) |
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 if (typ != "SM" && typ != "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1603 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1604 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1605 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1606 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1607 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1608 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1609 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1610 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1611 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1612 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1613 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1614 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1615 dtmp[j] = z[off1 + j]; |
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 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1618 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1619 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1620 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1621 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1622 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1623 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1624 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1625 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1626 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1627 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1628 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1629 ("eigs: error %d in dseupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1630 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1631 } |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1634 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1635 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1636 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1637 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1638 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1639 EigsRealNonSymmetricMatrix (const M& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1640 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1641 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1642 ComplexColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1643 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1644 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1645 bool cholB, int disp, int maxit) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1646 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1647 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1648 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1649 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1650 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1651 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1652 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1653 double sigmar = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1654 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1655 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1656 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1657 if (m.rows() != m.cols()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1658 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1659 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1660 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1661 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1662 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1663 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1664 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1665 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1666 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1667 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1668 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1669 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1670 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1671 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1672 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1673 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1674 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1675 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1676 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1677 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1678 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1679 p = k * 2 + 1; |
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 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1682 p = 20; |
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 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1685 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1686 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1687 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1688 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1689 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1690 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1691 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1692 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1693 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1694 if (k > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1695 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1696 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1697 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1698 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1699 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1700 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1701 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1702 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1703 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1704 // Check the we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1705 if (permB.length() != n) |
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) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1708 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1709 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1710 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1711 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1712 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1713 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1714 for (octave_idx_type i = 0; i < n; i++) |
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 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1717 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1718 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1719 bidx >= n || D_NINT (bidx) != bidx) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1720 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1721 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1722 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1723 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1724 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1725 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1726 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1727 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1728 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1729 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1730 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1731 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1732 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1733 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1734 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1735 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1736 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1737 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1738 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1739 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1740 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1741 ("eigs: invalid sigma value for unsymmetric problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1742 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1743 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1744 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1745 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1746 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1747 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1748 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1749 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1750 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1751 bt = b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1752 b = b.transpose(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1753 if (permB.length() == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1754 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1755 permB = ColumnVector(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1756 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1757 permB(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1758 } |
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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1761 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1762 if (! make_cholb(b, bt, permB)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1763 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1764 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1765 ("eigs: The matrix B is not positive definite"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1766 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1767 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1768 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1769 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1770 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1771 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1772 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1773 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1774 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1775 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1776 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1777 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1778 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
|
1779 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1780 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1781 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1782 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1783 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1784 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1785 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1786 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1787 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1788 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1789 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1790 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1791 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1792 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1793 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1794 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1795 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1796 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1797 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1798 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1799 do |
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 F77_FUNC (dnaupd, DNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1802 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1803 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1804 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1805 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1806 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
|
1807 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1808 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1809 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1810 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1811 ("eigs: unrecoverable exception encountered in dnaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1812 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1813 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1814 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1815 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1816 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1817 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1818 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1819 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1820 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1821 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1822 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1823 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1824 } |
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 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1827 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1828 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1829 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1830 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1831 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1832 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1833 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1834 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1835 if (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1836 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1837 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1838 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1839 Matrix mtmp (n,1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1840 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1841 mtmp(i,0) = workd[i + iptr(0) - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1842 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1843 mtmp = utsolve(bt, permB, m * ltsolve(b, permB, mtmp)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1844 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1845 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1846 workd[i+iptr(1)-1] = mtmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1847 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1848 else if (!vector_product (m, workd + iptr(0) - 1, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1849 workd + iptr(1) - 1)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1850 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1851 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1852 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1853 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1854 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1855 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1856 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1857 ("eigs: error %d in dnaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1858 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1859 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1860 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1861 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1862 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1863 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1864 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1865 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1866 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1867 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1868 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1869 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1870 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1871 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1872 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1873 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1874 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1875 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1876 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1877 Matrix eig_vec2 (n, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1878 double *z = eig_vec2.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1879 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1880 OCTAVE_LOCAL_BUFFER (double, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1881 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1882 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1883 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
|
1884 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1885 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1886 F77_FUNC (dneupd, DNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1887 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1888 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1889 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1890 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1891 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1892 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1893 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1894 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1895 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1896 ("eigs: unrecoverable exception encountered in dneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1897 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1898 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1899 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1900 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1901 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1902 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1903 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1904 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1905 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1906 octave_idx_type jj = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1907 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
|
1908 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1909 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1910 jj++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1911 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1912 d [i-jj] = Complex (dr[i], di[i]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1913 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1914 if (jj == 0 && !rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1915 for (octave_idx_type i = 0; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1916 d[i] = d[i+1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1917 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1918 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1919 for (octave_idx_type i = 0; i < k2; i++) |
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 Complex dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1922 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1923 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1924 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1925 eig_val.resize(k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1926 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1927 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1928 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1929 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1930 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1931 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1932 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1933 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1934 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1935 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1936 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1937 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1938 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1939 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1940 dtmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1941 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1942 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1943 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1944 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1945 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1946 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1947 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1948 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1949 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1950 octave_idx_type i = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1951 while (i < k) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1952 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1953 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1954 octave_idx_type off2 = (i+1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1955 if (std::imag(eig_val(i)) == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1956 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1957 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1958 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1959 Complex(z[j+off1],0.); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1960 i++; |
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 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1965 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1966 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1967 Complex(z[j+off1],z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1968 if (i < k - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1969 eig_vec(j,i+1) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1970 Complex(z[j+off1],-z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1971 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1972 i+=2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1973 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1974 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1975 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1976 if (note3) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1977 eig_vec = ltsolve(M (b), permB, eig_vec); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1978 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1979 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1980 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1981 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1982 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1983 ("eigs: error %d in dneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1984 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1985 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1986 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1987 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1988 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1989 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1990 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1991 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1992 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1993 EigsRealNonSymmetricMatrixShift (const M& m, double sigmar, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1994 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1995 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1996 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1997 ComplexColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1998 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1999 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2000 bool cholB, int disp, int maxit) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2001 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2002 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2003 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2004 octave_idx_type mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2005 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2006 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2007 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2008 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2009 if (m.rows() != m.cols()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2010 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2011 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2012 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2013 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2014 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2015 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2016 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2017 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2018 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2019 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2020 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2021 // 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
|
2022 //if (! std::abs (sigmar)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2023 // return EigsRealNonSymmetricMatrix (m, "SM", k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2024 // _b, permB, resid, os, tol, rvec, cholB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2025 // disp, maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2026 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2027 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2028 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2029 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2030 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2031 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2032 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2033 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2034 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2035 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2036 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2037 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2038 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2039 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2040 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2041 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2042 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2043 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2044 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2045 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2046 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2047 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2048 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2049 return -1; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2052 if (k > n - 1) |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2055 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2056 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2057 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2058 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2059 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2060 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2061 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2062 // Check that we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2063 if (permB.length() != n) |
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 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2066 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2067 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2068 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2069 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2070 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2071 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2072 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2073 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2074 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2075 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2076 bidx >= n || D_NINT (bidx) != bidx) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2077 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2078 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2079 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2080 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2081 } |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2085 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2086 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2087 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2088 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2089 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2090 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2091 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2092 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2093 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2094 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2095 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2096 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2097 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
|
2098 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2099 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2100 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2101 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2102 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2103 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2104 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2105 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2106 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2107 octave_idx_type *ipntr = iptr.fortran_vec (); |
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 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2110 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2111 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2112 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2113 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows() : m.rows())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2114 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols() : m.cols())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2115 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2116 if (! LuAminusSigmaB(m, b, cholB, permB, sigmar, L, U, P, Q)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2117 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2118 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2119 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2120 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2121 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2122 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2123 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2124 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2125 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2126 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2127 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2128 F77_FUNC (dnaupd, DNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2129 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2130 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2131 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2132 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2133 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
|
2134 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2135 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2136 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2137 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2138 ("eigs: unrecoverable exception encountered in dsaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2139 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2140 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2141 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2142 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2143 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2144 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2145 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2146 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2147 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2148 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2149 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2150 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2151 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2152 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2153 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2154 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2155 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2156 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2157 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2158 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2159 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2160 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2161 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2162 if (ido == -1 || ido == 1 || ido == 2) |
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 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2165 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2166 if (ido == -1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2167 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2168 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2169 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2170 vector_product (m, workd+iptr(0)-1, dtmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2171 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2172 Matrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2173 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2174 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2175 tmp(i,0) = dtmp[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2176 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2177 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2178 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2179 double *ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2180 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2181 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2182 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2183 else if (ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2184 vector_product (b, workd+iptr(0)-1, workd+iptr(1)-1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2185 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2186 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2187 double *ip2 = workd+iptr(2)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2188 Matrix tmp(n, 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 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2191 tmp(i,0) = ip2[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2192 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2193 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2194 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2195 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2196 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2197 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2198 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2199 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2200 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2201 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2202 if (ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2203 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2204 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2205 workd[iptr(0) + i - 1] = workd[iptr(1) + i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2206 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2207 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2208 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2209 double *ip2 = workd+iptr(0)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2210 Matrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2211 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2212 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2213 tmp(i,0) = ip2[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2214 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2215 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2216 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2217 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2218 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2219 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2220 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2221 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2222 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2223 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2224 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2225 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2226 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2227 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2228 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2229 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2230 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2231 break; |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2234 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2235 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2236 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2237 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2238 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2239 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2240 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2241 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2242 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2243 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2244 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2245 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2246 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2247 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2248 Matrix eig_vec2 (n, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2249 double *z = eig_vec2.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2250 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2251 OCTAVE_LOCAL_BUFFER (double, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2252 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2253 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2254 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
|
2255 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2256 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2257 F77_FUNC (dneupd, DNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2258 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2259 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2260 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2261 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2262 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2263 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2264 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2265 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2266 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2267 ("eigs: unrecoverable exception encountered in dneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2268 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2269 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2270 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2271 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2272 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2273 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2274 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2275 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2276 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2277 octave_idx_type jj = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2278 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
|
2279 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2280 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2281 jj++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2282 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2283 d [i-jj] = Complex (dr[i], di[i]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2284 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2285 if (jj == 0 && !rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2286 for (octave_idx_type i = 0; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2287 d[i] = d[i+1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2288 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2289 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2290 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2291 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2292 Complex dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2293 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2294 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2295 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2296 eig_val.resize(k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2297 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2298 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2299 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2300 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2301 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2302 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2303 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2304 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2305 octave_idx_type off2 = (k - i - 1) * n; |
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 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2308 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2309 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2310 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2311 dtmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2312 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2313 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2314 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2315 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2316 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2317 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2318 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2319 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2320 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2321 octave_idx_type i = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2322 while (i < k) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2323 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2324 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2325 octave_idx_type off2 = (i+1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2326 if (std::imag(eig_val(i)) == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2327 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2328 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2329 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2330 Complex(z[j+off1],0.); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2331 i++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2332 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2333 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2334 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2335 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2336 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2337 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2338 Complex(z[j+off1],z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2339 if (i < k - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2340 eig_vec(j,i+1) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2341 Complex(z[j+off1],-z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2342 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2343 i+=2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2344 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2345 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2346 } |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2351 ("eigs: error %d in dneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2352 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2353 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2354 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2355 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2356 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2357 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2358 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2359 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2360 EigsRealNonSymmetricFunc (EigsFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2361 const std::string &_typ, double sigmar, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2362 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2363 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2364 ComplexColumnVector &eig_val, ColumnVector &resid, |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
2365 std::ostream& os, double tol, int rvec, |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
2366 bool /* cholB */, int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2367 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2368 std::string typ (_typ); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2369 bool have_sigma = (sigmar ? true : false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2370 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2371 double sigmai = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2372 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2373 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2374 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2375 if (resid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2376 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2377 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2378 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2379 resid = ColumnVector (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2380 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2381 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2382 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2383 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2384 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2385 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2386 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2387 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2388 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2389 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2390 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2391 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2392 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2393 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2394 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2395 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2396 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2397 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2398 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2399 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2400 if (k > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2401 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2402 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2403 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2404 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2405 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2406 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2407 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2408 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2409 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2410 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2411 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2412 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2413 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2414 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2415 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2416 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2417 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2418 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2419 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2420 ("eigs: invalid sigma value for unsymmetric problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2421 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2422 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2423 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2424 if (typ == "SM") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2425 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2426 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2427 sigmar = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2428 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2429 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2430 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2431 else if (! std::abs (sigmar)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2432 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2433 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2434 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2435 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2436 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2437 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2438 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2439 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2440 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2441 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2442 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2443 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2444 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2445 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2446 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
|
2447 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2448 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2449 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2450 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2451 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2452 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2453 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2454 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2455 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2456 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2457 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2458 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2459 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2460 octave_idx_type lwork = 3 * p * (p + 2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2461 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2462 OCTAVE_LOCAL_BUFFER (double, v, n * (p + 1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2463 OCTAVE_LOCAL_BUFFER (double, workl, lwork + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2464 OCTAVE_LOCAL_BUFFER (double, workd, 3 * n + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2465 double *presid = resid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2466 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2467 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2468 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2469 F77_FUNC (dnaupd, DNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2470 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2471 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2472 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2473 ipntr, workd, workl, lwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2474 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
|
2475 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2476 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2477 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2478 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2479 ("eigs: unrecoverable exception encountered in dnaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2480 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2481 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2482 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2483 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2484 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2485 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2486 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2487 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2488 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2489 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2490 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2491 os << " " << workl[iptr(5)+i-1] << "\n"; |
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 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2495 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2496 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2497 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2498 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2499 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2500 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2501 } |
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 (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2504 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2505 double *ip2 = workd + iptr(0) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2506 ColumnVector x(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2507 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2508 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2509 x(i) = *ip2++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2510 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2511 ColumnVector y = fun (x, err); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2512 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2513 if (err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2514 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2515 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2516 ip2 = workd + iptr(1) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2517 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2518 *ip2++ = y(i); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2519 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2520 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2521 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2522 if (info < 0) |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2525 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2526 return -1; |
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 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2529 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2530 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2531 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2532 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2533 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2534 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2535 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2536 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2537 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2538 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2539 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2540 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2541 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2542 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2543 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2544 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2545 Matrix eig_vec2 (n, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2546 double *z = eig_vec2.fortran_vec (); |
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, dr, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2549 OCTAVE_LOCAL_BUFFER (double, di, k + 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2550 OCTAVE_LOCAL_BUFFER (double, workev, 3 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2551 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
|
2552 dr[i] = di[i] = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2553 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2554 F77_FUNC (dneupd, DNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2555 (rvec, F77_CONST_CHAR_ARG2 ("A", 1), sel, dr, di, z, n, sigmar, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2556 sigmai, workev, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2557 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2558 ipntr, workd, workl, lwork, info2 F77_CHAR_ARG_LEN(1) F77_CHAR_ARG_LEN(1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2559 F77_CHAR_ARG_LEN(2)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2560 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2561 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2562 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2563 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2564 ("eigs: unrecoverable exception encountered in dneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2565 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2566 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2567 else |
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 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2570 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2571 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2572 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2573 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2574 octave_idx_type jj = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2575 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
|
2576 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2577 if (dr[i] == 0.0 && di[i] == 0.0 && jj == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2578 jj++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2579 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2580 d [i-jj] = Complex (dr[i], di[i]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2581 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2582 if (jj == 0 && !rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2583 for (octave_idx_type i = 0; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2584 d[i] = d[i+1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2585 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2586 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2587 for (octave_idx_type i = 0; i < k2; i++) |
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 Complex dtmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2590 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2591 d[k - i - 1] = dtmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2592 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2593 eig_val.resize(k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2594 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2595 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2596 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2597 OCTAVE_LOCAL_BUFFER (double, dtmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2598 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2599 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2600 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2601 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2602 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2603 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2604 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2605 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2606 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2607 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2608 dtmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2609 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2610 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2611 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2612 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2613 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2614 z[off2 + j] = dtmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2615 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2616 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2617 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2618 octave_idx_type i = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2619 while (i < k) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2620 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2621 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2622 octave_idx_type off2 = (i+1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2623 if (std::imag(eig_val(i)) == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2624 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2625 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2626 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2627 Complex(z[j+off1],0.); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2628 i++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2629 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2630 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2631 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2632 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2633 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2634 eig_vec(j,i) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2635 Complex(z[j+off1],z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2636 if (i < k - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2637 eig_vec(j,i+1) = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2638 Complex(z[j+off1],-z[j+off2]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2639 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2640 i+=2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2641 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2642 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2643 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2644 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2645 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2646 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2647 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2648 ("eigs: error %d in dneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2649 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2650 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2651 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2652 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2653 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2654 } |
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 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2657 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2658 EigsComplexNonSymmetricMatrix (const M& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2659 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2660 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2661 ComplexColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2662 ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2663 ComplexColumnVector &cresid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2664 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2665 bool cholB, int disp, int maxit) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2666 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2667 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2668 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2669 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2670 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2671 bool note3 = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2672 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2673 Complex sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2674 M bt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2675 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2676 if (m.rows() != m.cols()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2677 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2678 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2679 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2680 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2681 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2682 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2683 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2684 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2685 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2686 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2687 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2688 if (cresid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2689 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2690 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2691 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2692 Array<double> rr (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2693 Array<double> ri (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2694 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2695 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2696 cresid(i) = Complex(rr(i),ri(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2697 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2698 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2699 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2700 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2701 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2702 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2703 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2704 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2705 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2706 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2707 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2708 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2709 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2710 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2711 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2712 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2713 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2714 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2715 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2716 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2717 if (k > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2718 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2719 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2720 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2721 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2722 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2723 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2724 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2725 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2726 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2727 // Check the we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2728 if (permB.length() != n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2729 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2730 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2731 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2732 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2733 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2734 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2735 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2736 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2737 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2738 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2739 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2740 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2741 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2742 bidx >= n || D_NINT (bidx) != bidx) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2743 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2744 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2745 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2746 return -1; |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2750 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2751 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2752 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2753 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2754 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2755 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2756 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2757 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2758 return -1; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2761 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2762 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2763 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2764 ("eigs: invalid sigma value for complex problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2765 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2766 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2767 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2768 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2769 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2770 // See Note 3 dsaupd |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2771 note3 = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2772 if (cholB) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2773 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2774 bt = b; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2775 b = b.hermitian(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2776 if (permB.length() == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2777 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2778 permB = ColumnVector(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2779 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2780 permB(i) = i; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2781 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2782 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2783 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2784 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2785 if (! make_cholb(b, bt, permB)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2786 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2787 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2788 ("eigs: The matrix B is not positive definite"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2789 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2790 } |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2793 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2794 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2795 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2796 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2797 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2798 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2799 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2800 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2801 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
|
2802 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2803 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2804 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2805 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2806 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2807 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2808 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2809 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2810 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2811 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2812 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2813 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2814 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2815 octave_idx_type lwork = p * (3 * p + 5); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2816 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2817 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2818 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2819 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2820 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2821 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2822 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2823 do |
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 F77_FUNC (znaupd, ZNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2826 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2827 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2828 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2829 ipntr, workd, workl, lwork, rwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2830 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
|
2831 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2832 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2833 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2834 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2835 ("eigs: unrecoverable exception encountered in znaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2836 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2837 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2838 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2839 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2840 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2841 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2842 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2843 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2844 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2845 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2846 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2847 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2848 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2849 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2850 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2851 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2852 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2853 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2854 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2855 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2856 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2857 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2858 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2859 if (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2860 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2861 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2862 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2863 ComplexMatrix mtmp (n,1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2864 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2865 mtmp(i,0) = workd[i + iptr(0) - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2866 mtmp = utsolve(bt, permB, m * ltsolve(b, permB, mtmp)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2867 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2868 workd[i+iptr(1)-1] = mtmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2869 |
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 else if (!vector_product (m, workd + iptr(0) - 1, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2872 workd + iptr(1) - 1)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2873 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2874 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2875 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2876 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2877 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2878 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2879 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2880 ("eigs: error %d in znaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2881 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2882 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2883 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2884 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2885 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2886 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2887 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2888 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2889 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2890 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2891 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2892 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2893 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2894 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2895 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2896 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2897 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2898 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2899 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2900 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2901 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2902 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2903 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2904 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2905 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2906 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2907 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2908 F77_FUNC (zneupd, ZNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2909 (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
|
2910 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2911 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2912 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
|
2913 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
|
2914 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2915 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2916 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2917 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2918 ("eigs: unrecoverable exception encountered in zneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2919 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2920 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2921 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2922 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2923 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2924 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2925 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2926 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2927 Complex ctmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2928 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2929 d[k - i - 1] = ctmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2930 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2931 eig_val.resize(k); |
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 (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2934 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2935 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2936 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2937 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2938 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2939 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2940 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2941 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2942 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2943 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2944 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2945 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2946 ctmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2947 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2948 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2949 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2950 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2951 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2952 z[off2 + j] = ctmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2953 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2954 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2955 if (note3) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2956 eig_vec = ltsolve(b, permB, eig_vec); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2957 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2958 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2959 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2960 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2961 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2962 ("eigs: error %d in zneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2963 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2964 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2965 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2966 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2967 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2968 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2969 template <class M> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2970 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2971 EigsComplexNonSymmetricMatrixShift (const M& m, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2972 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2973 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2974 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2975 ComplexColumnVector &eig_val, const M& _b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2976 ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2977 ComplexColumnVector &cresid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2978 std::ostream& os, double tol, int rvec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2979 bool cholB, int disp, int maxit) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2980 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2981 M b(_b); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2982 octave_idx_type n = m.cols (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2983 octave_idx_type mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2984 bool have_b = ! b.is_empty(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2985 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2986 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2987 if (m.rows() != m.cols()) |
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 (*current_liboctave_error_handler) ("eigs: A must be square"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2990 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2991 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2992 if (have_b && (m.rows() != b.rows() || m.rows() != b.cols())) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2993 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2994 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2995 ("eigs: B must be square and the same size as A"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2996 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2997 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2998 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2999 // 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
|
3000 //if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3001 // return EigsComplexNonSymmetricMatrix (m, "SM", k, p, info, eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3002 // eig_val, _b, permB, cresid, os, tol, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3003 // rvec, cholB, disp, maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3004 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3005 if (cresid.is_empty()) |
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 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3008 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3009 Array<double> rr (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3010 Array<double> ri (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3011 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3012 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3013 cresid(i) = Complex(rr(i),ri(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3014 octave_rand::distribution(rand_dist); |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3017 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3018 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3019 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3020 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3021 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3022 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3023 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3024 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3025 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3026 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3027 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3028 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3029 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3030 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3031 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3032 } |
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 (k > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3035 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3036 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3037 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3038 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3039 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3040 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3041 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3042 if (have_b && cholB && permB.length() != 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3043 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3044 // Check that we really have a permutation vector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3045 if (permB.length() != n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3046 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3047 (*current_liboctave_error_handler) ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3048 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3049 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3050 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3051 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3052 Array<bool> checked(n,false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3053 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3054 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3055 octave_idx_type bidx = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3056 static_cast<octave_idx_type> (permB(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3057 if (checked(bidx) || bidx < 0 || |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3058 bidx >= n || D_NINT (bidx) != bidx) |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3061 ("eigs: permB vector invalid"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3062 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3063 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3064 } |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3068 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3069 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3070 bmat = 'G'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3071 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3072 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3073 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3074 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3075 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3076 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3077 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3078 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3079 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
|
3080 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3081 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3082 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3083 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3084 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3085 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3086 // ip(7) to ip(10) return values |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3087 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3088 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3089 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3090 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3091 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3092 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3093 M L, U; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3094 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3095 OCTAVE_LOCAL_BUFFER (octave_idx_type, P, (have_b ? b.rows() : m.rows())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3096 OCTAVE_LOCAL_BUFFER (octave_idx_type, Q, (have_b ? b.cols() : m.cols())); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3097 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3098 if (! LuAminusSigmaB(m, b, cholB, permB, sigma, L, U, P, Q)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3099 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3100 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3101 octave_idx_type lwork = p * (3 * p + 5); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3102 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3103 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3104 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3105 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3106 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3107 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3108 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3109 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3110 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3111 F77_FUNC (znaupd, ZNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3112 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3113 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3114 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3115 ipntr, workd, workl, lwork, rwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3116 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
|
3117 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3118 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3119 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3120 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3121 ("eigs: unrecoverable exception encountered in znaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3122 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3123 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3124 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3125 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
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 if (iter++) |
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 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3130 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3131 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3132 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3133 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3134 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3135 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3136 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3137 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3138 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3139 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3140 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3141 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3142 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3143 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3144 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3145 if (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3146 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3147 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3148 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3149 if (ido == -1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3150 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3151 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
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 vector_product (m, workd+iptr(0)-1, ctmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3154 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3155 ComplexMatrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3156 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3157 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3158 tmp(i,0) = ctmp[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3159 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3160 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3161 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3162 Complex *ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3163 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3164 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3165 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3166 else if (ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3167 vector_product (b, workd + iptr(0) - 1, workd + iptr(1) - 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3168 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3169 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3170 Complex *ip2 = workd+iptr(2)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3171 ComplexMatrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3172 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3173 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3174 tmp(i,0) = ip2[P[i]]; |
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 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3177 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3178 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3179 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3180 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3181 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3182 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3183 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3184 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3185 if (ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3186 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3187 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3188 workd[iptr(0) + i - 1] = |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3189 workd[iptr(1) + i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3190 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3191 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3192 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3193 Complex *ip2 = workd+iptr(0)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3194 ComplexMatrix tmp(n, 1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3195 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3196 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3197 tmp(i,0) = ip2[P[i]]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3198 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3199 lusolve (L, U, tmp); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3200 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3201 ip2 = workd+iptr(1)-1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3202 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3203 ip2[Q[i]] = tmp(i,0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3204 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3205 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3206 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3207 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3208 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3209 if (info < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3210 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3211 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3212 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3213 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3214 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3215 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3216 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3217 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3218 while (1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3219 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3220 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3221 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3222 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3223 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3224 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3225 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3226 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3227 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3228 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3229 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3230 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3231 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3232 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3233 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3234 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3235 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3236 Complex *d = eig_val.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3237 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3238 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3239 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3240 F77_FUNC (zneupd, ZNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3241 (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
|
3242 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3243 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3244 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
|
3245 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
|
3246 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3247 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3248 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3249 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3250 ("eigs: unrecoverable exception encountered in zneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3251 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3252 } |
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 (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3255 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3256 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3257 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3258 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3259 Complex ctmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3260 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3261 d[k - i - 1] = ctmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3262 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3263 eig_val.resize(k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3264 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3265 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3266 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3267 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3268 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3269 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3270 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3271 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3272 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3273 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3274 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3275 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3276 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3277 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3278 ctmp[j] = z[off1 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3279 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3280 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3281 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3282 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3283 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3284 z[off2 + j] = ctmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3285 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3286 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3287 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3288 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3289 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3290 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3291 ("eigs: error %d in zneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3292 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3293 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3294 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3295 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3296 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3297 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3298 octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3299 EigsComplexNonSymmetricFunc (EigsComplexFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3300 const std::string &_typ, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3301 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3302 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3303 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3304 ComplexColumnVector &cresid, std::ostream& os, |
8677
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
3305 double tol, int rvec, bool /* cholB */, |
095ae5e0a831
eliminte some compiler warnings
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
3306 int disp, int maxit) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3307 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3308 std::string typ (_typ); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3309 bool have_sigma = (std::abs(sigma) ? true : false); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3310 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3311 octave_idx_type mode = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3312 int err = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3313 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3314 if (cresid.is_empty()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3315 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3316 std::string rand_dist = octave_rand::distribution(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3317 octave_rand::distribution("uniform"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3318 Array<double> rr (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3319 Array<double> ri (octave_rand::vector(n)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3320 cresid = ComplexColumnVector (n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3321 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3322 cresid(i) = Complex(rr(i),ri(i)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3323 octave_rand::distribution(rand_dist); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3324 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3325 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3326 if (p < 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3327 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3328 p = k * 2 + 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3329 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3330 if (p < 20) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3331 p = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3332 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3333 if (p > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3334 p = n - 1 ; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3335 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3336 else if (p < k || p > n) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3337 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3338 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3339 ("eigs: opts.p must be between k+1 and n"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3340 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3341 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3342 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3343 if (k > n - 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3344 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3345 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3346 ("eigs: Too many eigenvalues to extract (k >= n-1).\n" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3347 " Use 'eig(full(A))' instead"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3348 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3349 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3350 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3351 if (! have_sigma) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3352 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3353 if (typ != "LM" && typ != "SM" && typ != "LA" && typ != "SA" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3354 typ != "BE" && typ != "LR" && typ != "SR" && typ != "LI" && |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3355 typ != "SI") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3356 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3357 ("eigs: unrecognized sigma value"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3358 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3359 if (typ == "LA" || typ == "SA" || typ == "BE") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3360 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3361 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3362 ("eigs: invalid sigma value for complex problem"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3363 return -1; |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3366 if (typ == "SM") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3367 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3368 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3369 sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3370 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3371 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3372 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3373 else if (! std::abs (sigma)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3374 typ = "SM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3375 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3376 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3377 typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3378 mode = 3; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3379 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3380 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3381 Array<octave_idx_type> ip (11); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3382 octave_idx_type *iparam = ip.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3383 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3384 ip(0) = 1; //ishift |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3385 ip(1) = 0; // ip(1) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3386 ip(2) = maxit; // mxiter, maximum number of iterations |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3387 ip(3) = 1; // NB blocksize in recurrence |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3388 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
|
3389 ip(5) = 0; //ip(5) not referenced |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3390 ip(6) = mode; // mode |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3391 ip(7) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3392 ip(8) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3393 ip(9) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3394 ip(10) = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3395 // ip(7) to ip(10) return values |
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 Array<octave_idx_type> iptr (14); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3398 octave_idx_type *ipntr = iptr.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3399 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3400 octave_idx_type ido = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3401 int iter = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3402 octave_idx_type lwork = p * (3 * p + 5); |
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 OCTAVE_LOCAL_BUFFER (Complex, v, n * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3405 OCTAVE_LOCAL_BUFFER (Complex, workl, lwork); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3406 OCTAVE_LOCAL_BUFFER (Complex, workd, 3 * n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3407 OCTAVE_LOCAL_BUFFER (double, rwork, p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3408 Complex *presid = cresid.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3409 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3410 do |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3411 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3412 F77_FUNC (znaupd, ZNAUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3413 (ido, F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3414 F77_CONST_CHAR_ARG2 ((typ.c_str()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3415 k, tol, presid, p, v, n, iparam, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3416 ipntr, workd, workl, lwork, rwork, info |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3417 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
|
3418 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3419 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3420 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3421 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3422 ("eigs: unrecoverable exception encountered in znaupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3423 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3424 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3425 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3426 if (disp > 0 && !xisnan(workl[iptr(5)-1])) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3427 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3428 if (iter++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3429 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3430 os << "Iteration " << iter - 1 << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3431 ": a few Ritz values of the " << p << "-by-" << |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3432 p << " matrix\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3433 for (int i = 0 ; i < k; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3434 os << " " << workl[iptr(5)+i-1] << "\n"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3435 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3436 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3437 // This is a kludge, as ARPACK doesn't give its |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3438 // iteration pointer. But as workl[iptr(5)-1] is |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3439 // an output value updated at each iteration, setting |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3440 // a value in this array to NaN and testing for it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3441 // is a way of obtaining the iteration counter. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3442 if (ido != 99) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3443 workl[iptr(5)-1] = octave_NaN; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3444 } |
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 (ido == -1 || ido == 1 || ido == 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3447 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3448 Complex *ip2 = workd + iptr(0) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3449 ComplexColumnVector x(n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3450 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3451 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3452 x(i) = *ip2++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3453 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3454 ComplexColumnVector y = fun (x, err); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3455 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3456 if (err) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3457 return false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3458 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3459 ip2 = workd + iptr(1) - 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3460 for (octave_idx_type i = 0; i < n; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3461 *ip2++ = y(i); |
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 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3464 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3465 if (info < 0) |
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 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3468 ("eigs: error %d in dsaupd", info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3469 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3470 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3471 break; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3472 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3473 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3474 while (1); |
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 octave_idx_type info2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3477 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3478 // We have a problem in that the size of the C++ bool |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3479 // type relative to the fortran logical type. It appears |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3480 // that fortran uses 4-bytes per logical and C++ 1-byte |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3481 // per bool, though this might be system dependent. As |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3482 // long as the HOWMNY arg is not "S", the logical array |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3483 // is just workspace for ARPACK, so use int type to |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3484 // avoid problems. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3485 Array<int> s (p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3486 int *sel = s.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3487 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3488 eig_vec.resize (n, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3489 Complex *z = eig_vec.fortran_vec (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3490 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3491 eig_val.resize (k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3492 Complex *d = eig_val.fortran_vec (); |
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 OCTAVE_LOCAL_BUFFER (Complex, workev, 2 * p); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3495 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3496 F77_FUNC (zneupd, ZNEUPD) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3497 (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
|
3498 F77_CONST_CHAR_ARG2 (&bmat, 1), n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3499 F77_CONST_CHAR_ARG2 ((typ.c_str ()), 2), |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3500 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
|
3501 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
|
3502 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3503 if (f77_exception_encountered) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3504 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3505 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3506 ("eigs: unrecoverable exception encountered in zneupd"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3507 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3508 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3509 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3510 if (info2 == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3511 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3512 octave_idx_type k2 = k / 2; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3513 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3514 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3515 Complex ctmp = d[i]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3516 d[i] = d[k - i - 1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3517 d[k - i - 1] = ctmp; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3518 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3519 eig_val.resize(k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3520 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3521 if (rvec) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3522 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3523 OCTAVE_LOCAL_BUFFER (Complex, ctmp, n); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3524 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3525 for (octave_idx_type i = 0; i < k2; i++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3526 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3527 octave_idx_type off1 = i * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3528 octave_idx_type off2 = (k - i - 1) * n; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3529 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3530 if (off1 == off2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3531 continue; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3532 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3533 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3534 ctmp[j] = z[off1 + j]; |
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 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3537 z[off1 + j] = z[off2 + j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3538 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3539 for (octave_idx_type j = 0; j < n; j++) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3540 z[off2 + j] = ctmp[j]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3541 } |
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 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3544 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3545 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3546 (*current_liboctave_error_handler) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3547 ("eigs: error %d in zneupd", info2); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3548 return -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3549 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3550 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3551 return ip(4); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3552 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3553 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3554 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3555 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3556 EigsRealSymmetricMatrix (const Matrix& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3557 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3558 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3559 ColumnVector &eig_val, const Matrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3560 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3561 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3562 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3563 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3564 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3565 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3566 EigsRealSymmetricMatrix (const SparseMatrix& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3567 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3568 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3569 ColumnVector &eig_val, const SparseMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3570 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3571 std::ostream& os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3572 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3573 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3574 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3575 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3576 EigsRealSymmetricMatrixShift (const Matrix& m, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3577 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3578 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3579 ColumnVector &eig_val, const Matrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3580 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3581 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3582 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3583 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3584 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3585 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3586 EigsRealSymmetricMatrixShift (const SparseMatrix& m, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3587 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3588 octave_idx_type &info, Matrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3589 ColumnVector &eig_val, const SparseMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3590 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3591 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3592 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3593 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3594 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3595 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3596 EigsRealSymmetricFunc (EigsFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3597 const std::string &typ, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3598 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3599 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3600 Matrix &eig_vec, ColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3601 ColumnVector &resid, std::ostream &os, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3602 double tol = DBL_EPSILON, int rvec = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3603 bool cholB = 0, int disp = 0, int maxit = 300); |
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 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3606 EigsRealNonSymmetricMatrix (const Matrix& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3607 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3608 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3609 ComplexColumnVector &eig_val, const Matrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3610 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3611 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3612 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3613 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3614 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3615 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3616 EigsRealNonSymmetricMatrix (const SparseMatrix& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3617 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3618 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3619 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3620 const SparseMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3621 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3622 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3623 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3624 int maxit = 300); |
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 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3627 EigsRealNonSymmetricMatrixShift (const Matrix& m, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3628 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3629 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3630 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3631 ComplexColumnVector &eig_val, const Matrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3632 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3633 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3634 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3635 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3636 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3637 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3638 EigsRealNonSymmetricMatrixShift (const SparseMatrix& m, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3639 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3640 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3641 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3642 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3643 const SparseMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3644 ColumnVector &permB, ColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3645 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3646 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3647 int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3648 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3649 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3650 EigsRealNonSymmetricFunc (EigsFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3651 const std::string &_typ, double sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3652 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3653 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3654 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3655 ColumnVector &resid, std::ostream& os, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3656 double tol = DBL_EPSILON, int rvec = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3657 bool cholB = 0, int disp = 0, int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3658 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3659 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3660 EigsComplexNonSymmetricMatrix (const ComplexMatrix& m, const std::string typ, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3661 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3662 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3663 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3664 const ComplexMatrix& b, ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3665 ComplexColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3666 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3667 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3668 int maxit = 300); |
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 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3671 EigsComplexNonSymmetricMatrix (const SparseComplexMatrix& m, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3672 const std::string typ, octave_idx_type k, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3673 octave_idx_type p, octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3674 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3675 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3676 const SparseComplexMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3677 ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3678 ComplexColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3679 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3680 int rvec = 0, bool cholB = 0, int disp = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3681 int maxit = 300); |
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 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3684 EigsComplexNonSymmetricMatrixShift (const ComplexMatrix& m, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3685 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3686 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3687 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3688 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3689 const ComplexMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3690 ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3691 ComplexColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3692 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3693 int rvec = 0, bool cholB = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3694 int disp = 0, int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3695 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3696 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3697 EigsComplexNonSymmetricMatrixShift (const SparseComplexMatrix& m, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3698 Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3699 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3700 octave_idx_type &info, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3701 ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3702 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3703 const SparseComplexMatrix& b, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3704 ColumnVector &permB, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3705 ComplexColumnVector &resid, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3706 std::ostream &os, double tol = DBL_EPSILON, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3707 int rvec = 0, bool cholB = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3708 int disp = 0, int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3709 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3710 extern octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3711 EigsComplexNonSymmetricFunc (EigsComplexFunc fun, octave_idx_type n, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3712 const std::string &_typ, Complex sigma, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3713 octave_idx_type k, octave_idx_type p, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3714 octave_idx_type &info, ComplexMatrix &eig_vec, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3715 ComplexColumnVector &eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3716 ComplexColumnVector &resid, std::ostream& os, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3717 double tol = DBL_EPSILON, int rvec = 0, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3718 bool cholB = 0, int disp = 0, int maxit = 300); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3719 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3720 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3721 #ifndef _MSC_VER |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3722 template static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3723 lusolve (const SparseMatrix&, const SparseMatrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3724 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3725 template static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3726 lusolve (const SparseComplexMatrix&, const SparseComplexMatrix&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3727 ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3728 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3729 template static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3730 lusolve (const Matrix&, const Matrix&, Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3731 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3732 template static octave_idx_type |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3733 lusolve (const ComplexMatrix&, const ComplexMatrix&, ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3734 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3735 template static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3736 ltsolve (const SparseComplexMatrix&, const ColumnVector&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3737 const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3738 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3739 template static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3740 ltsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3741 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3742 template static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3743 ltsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3744 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3745 template static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3746 ltsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3747 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3748 template static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3749 utsolve (const SparseComplexMatrix&, const ColumnVector&, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3750 const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3751 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3752 template static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3753 utsolve (const SparseMatrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3754 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3755 template static ComplexMatrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3756 utsolve (const ComplexMatrix&, const ColumnVector&, const ComplexMatrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3757 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3758 template static Matrix |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3759 utsolve (const Matrix&, const ColumnVector&, const Matrix&); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3760 #endif |
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 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3763 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3764 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3765 ;;; Local Variables: *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3766 ;;; mode: C++ *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3767 ;;; End: *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3768 */ |