| 1 |
do('./Config'); |
| 2 |
|
| 3 |
{ # required because PAUSE will reject undefined $VERSION |
| 4 |
require ExtUtils::MM; |
| 5 |
my $MM = bless { NAME => 'Fake' }, 'MM'; |
| 6 |
my $global_version = $MM->parse_version('lib/PDL/LinearAlgebra.pm'); |
| 7 |
pp_setversion($global_version); |
| 8 |
} |
| 9 |
|
| 10 |
{ no warnings 'once'; # pass info back to Makefile.PL |
| 11 |
$PDL::Core::Dev::EXTRAS{$::PDLMOD}{OBJECT} .= join '', map " $::PDLBASE-$_\$(OBJ_EXT)", qw(selectfunc); |
| 12 |
} |
| 13 |
|
| 14 |
sub generate_code($){ |
| 15 |
if ($config{WITHOUT_THREAD}){ |
| 16 |
return ' |
| 17 |
#if 0 |
| 18 |
broadcastloop%{ |
| 19 |
%} |
| 20 |
#endif'.$_[0]; |
| 21 |
} |
| 22 |
else{ |
| 23 |
return $_[0]; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
if ($config{CBLAS}){ |
| 28 |
pp_addhdr('#include <cblas.h>'); |
| 29 |
} |
| 30 |
|
| 31 |
if ($^O =~ /MSWin/) { |
| 32 |
pp_addhdr(' |
| 33 |
#include <float.h> |
| 34 |
'); |
| 35 |
} |
| 36 |
|
| 37 |
pp_addhdr(' |
| 38 |
#include <math.h> |
| 39 |
|
| 40 |
#define CONCAT_(A, B) A ## B |
| 41 |
#define CONCAT(A, B) CONCAT_(A, B) |
| 42 |
#define FORTRAN(name) CONCAT(name, F77_USCORE) |
| 43 |
|
| 44 |
/* avoid annoying warnings */ |
| 45 |
typedef PDL_Long logical; |
| 46 |
typedef PDL_Long integer; |
| 47 |
typedef PDL_Long ftnlen; |
| 48 |
|
| 49 |
#define DEF_SEL_FUNC(letter, letter2, args) \ |
| 50 |
void letter ## letter2 ## select_func_set(SV* func); \ |
| 51 |
logical letter ## letter2 ## select_wrapper args; \ |
| 52 |
typedef logical (*L_ ## letter ## letter2 ## p) args; |
| 53 |
DEF_SEL_FUNC(f, , (float *wr, float *wi)) |
| 54 |
DEF_SEL_FUNC(d, , (double *wr, double *wi)) |
| 55 |
DEF_SEL_FUNC(f, g, (float *zr, float *zi, float *d)) |
| 56 |
DEF_SEL_FUNC(d, g, (double *zr, double *zi, double *d)) |
| 57 |
|
| 58 |
static integer c_zero = 0; |
| 59 |
static integer c_nine = 9; |
| 60 |
extern integer FORTRAN(ilaenv)(integer *ispec, char *name__, char *opts, integer *n1, |
| 61 |
integer *n2, integer *n3, integer *n4, ftnlen name_len, ftnlen |
| 62 |
opts_len); |
| 63 |
|
| 64 |
#define PDL_MAYBE_SIZE(flagpdltype, flagval, flagcond, outpdl, outdim, indim) \ |
| 65 |
{ \ |
| 66 |
flagpdltype tmp = flagval; \ |
| 67 |
outdim = (flagcond) ? indim : 1; \ |
| 68 |
} |
| 69 |
'); |
| 70 |
|
| 71 |
pp_addpm({At=>'Top'},<<'EOD'); |
| 72 |
use strict; |
| 73 |
|
| 74 |
|
| 75 |
{ |
| 76 |
package # hide from CPAN |
| 77 |
PDL; |
| 78 |
my $warningFlag; |
| 79 |
BEGIN{ |
| 80 |
$warningFlag = $^W; |
| 81 |
$^W = 0; |
| 82 |
} |
| 83 |
|
| 84 |
sub overload_mmult { |
| 85 |
!(grep ref($_) && !$_->type->real, @_[0,1]) |
| 86 |
? PDL::mmult($_[0], $_[1]) |
| 87 |
: PDL::cmmult($_[0], $_[1]) |
| 88 |
} |
| 89 |
use overload |
| 90 |
'x' => \&overload_mmult; |
| 91 |
|
| 92 |
BEGIN{ $^W = $warningFlag;} |
| 93 |
} |
| 94 |
|
| 95 |
=encoding utf8 |
| 96 |
|
| 97 |
=head1 NAME |
| 98 |
|
| 99 |
PDL::LinearAlgebra::Real - PDL interface to the real lapack linear algebra programming library |
| 100 |
|
| 101 |
=head1 SYNOPSIS |
| 102 |
|
| 103 |
use PDL::LinearAlgebra::Real; |
| 104 |
|
| 105 |
$a = random (100,100); |
| 106 |
$s = zeroes(100); |
| 107 |
$u = zeroes(100,100); |
| 108 |
$v = zeroes(100,100); |
| 109 |
$info = 0; |
| 110 |
$job = 0; |
| 111 |
gesdd($a, $job, $info, $s , $u, $v); |
| 112 |
|
| 113 |
=head1 DESCRIPTION |
| 114 |
|
| 115 |
This module provides an interface to parts of the real lapack library. |
| 116 |
These routines accept either float or double ndarrays. |
| 117 |
|
| 118 |
=cut |
| 119 |
EOD |
| 120 |
|
| 121 |
pp_def("gtsv", |
| 122 |
HandleBad => 0, |
| 123 |
Pars => '[io]DL(n); [io]D(n); [io]DU(n); [io]B(n,nrhs); int [o]info()', |
| 124 |
GenericTypes => [F,D], |
| 125 |
Code => generate_code ' |
| 126 |
extern int FORTRAN($TFD(s,d)gtsv)(integer *n, integer *nrhs, |
| 127 |
$GENERIC() *dl, $GENERIC() *d, $GENERIC() *du, $GENERIC() *b, |
| 128 |
integer *ldb, integer *info); |
| 129 |
FORTRAN($TFD(s,d)gtsv)( |
| 130 |
&(integer){$SIZE(n)}, |
| 131 |
&(integer){$SIZE(nrhs)}, |
| 132 |
$P(DL), |
| 133 |
$P(D), |
| 134 |
$P(DU), |
| 135 |
$P(B), |
| 136 |
&(integer){$SIZE(n)}, |
| 137 |
$P(info)); |
| 138 |
', |
| 139 |
Doc => ' |
| 140 |
|
| 141 |
=for ref |
| 142 |
|
| 143 |
Solves the equation |
| 144 |
|
| 145 |
A * X = B |
| 146 |
|
| 147 |
where A is an C<n> by C<n> tridiagonal matrix, by Gaussian elimination with |
| 148 |
partial pivoting, and B is an C<n> by C<nrhs> matrix. |
| 149 |
|
| 150 |
Note that the equation C<A**T*X = B> may be solved by interchanging the |
| 151 |
order of the arguments DU and DL. |
| 152 |
|
| 153 |
B<NB> This differs from the LINPACK function C<dgtsl> in that C<DL> |
| 154 |
starts from its first element, while the LINPACK equivalent starts from |
| 155 |
its second element. |
| 156 |
|
| 157 |
Arguments |
| 158 |
========= |
| 159 |
|
| 160 |
DL: On entry, DL must contain the (n-1) sub-diagonal elements of A. |
| 161 |
|
| 162 |
On exit, DL is overwritten by the (n-2) elements of the |
| 163 |
second super-diagonal of the upper triangular matrix U from |
| 164 |
the LU factorization of A, in DL(1), ..., DL(n-2). |
| 165 |
|
| 166 |
D: On entry, D must contain the diagonal elements of A. |
| 167 |
|
| 168 |
On exit, D is overwritten by the n diagonal elements of U. |
| 169 |
|
| 170 |
DU: On entry, DU must contain the (n-1) super-diagonal elements of A. |
| 171 |
|
| 172 |
On exit, DU is overwritten by the (n-1) elements of the |
| 173 |
first super-diagonal of the U. |
| 174 |
|
| 175 |
B: On entry, the n by nrhs matrix of right hand side matrix B. |
| 176 |
On exit, if info = 0, the n by nrhs solution matrix X. |
| 177 |
|
| 178 |
info: = 0: successful exit |
| 179 |
< 0: if info = -i, the i-th argument had an illegal value |
| 180 |
> 0: if info = i, U(i,i) is exactly zero, and the solution |
| 181 |
has not been computed. The factorization has not been |
| 182 |
completed unless i = n. |
| 183 |
|
| 184 |
=for example |
| 185 |
|
| 186 |
$dl = random(float, 9); |
| 187 |
$d = random(float, 10); |
| 188 |
$du = random(float, 9); |
| 189 |
$b = random(10,5); |
| 190 |
gtsv($dl, $d, $du, $b, ($info=null)); |
| 191 |
print "X is:\n$b" unless $info; |
| 192 |
|
| 193 |
'); |
| 194 |
|
| 195 |
pp_def("gesvd", |
| 196 |
HandleBad => 0, |
| 197 |
Pars => '[io]A(m,n); [o]s(minmn=CALC(PDLMIN($SIZE(m),$SIZE(n)))); [o]U(p,p); [o]VT(s,s); int [o]info()', |
| 198 |
OtherPars => 'int jobu; int jobvt', |
| 199 |
ArgOrder => [qw(A jobu jobvt s U VT info)], |
| 200 |
RedoDimsCode => ' |
| 201 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobu), tmp==1 || tmp==2, $PDL(U), $SIZE(p), $SIZE(m)) |
| 202 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvt), tmp==1 || tmp==2, $PDL(VT), $SIZE(s), $SIZE(n)) |
| 203 |
', |
| 204 |
GenericTypes => [F,D], |
| 205 |
Code => generate_code ' |
| 206 |
extern int FORTRAN($TFD(s,d)gesvd)(char *jobu, char *jobvt, integer *m, integer *n, $GENERIC() *a, |
| 207 |
integer *lda, $GENERIC() *s, $GENERIC() *u, int *ldu, |
| 208 |
$GENERIC() *vt, integer *ldvt, $GENERIC() *work, integer *lwork, |
| 209 |
integer *info); |
| 210 |
|
| 211 |
$GENERIC() tmp_work; |
| 212 |
integer lwork = -1; |
| 213 |
char trau, travt; |
| 214 |
|
| 215 |
switch ($COMP(jobu)) |
| 216 |
{ |
| 217 |
case 1: trau = \'A\'; |
| 218 |
break; |
| 219 |
case 2: trau = \'S\'; |
| 220 |
break; |
| 221 |
case 3: trau = \'O\'; |
| 222 |
break; |
| 223 |
default: trau = \'N\'; |
| 224 |
} |
| 225 |
switch ($COMP(jobvt)) |
| 226 |
{ |
| 227 |
case 1: travt = \'A\'; |
| 228 |
break; |
| 229 |
case 2: travt = \'S\'; |
| 230 |
break; |
| 231 |
case 3: travt = \'O\'; |
| 232 |
break; |
| 233 |
default: travt = \'N\'; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
FORTRAN($TFD(s,d)gesvd)( |
| 239 |
&trau, |
| 240 |
&travt, |
| 241 |
&(integer){$SIZE(m)}, |
| 242 |
&(integer){$SIZE(n)}, |
| 243 |
$P(A), |
| 244 |
&(integer){$SIZE(m)}, |
| 245 |
$P(s), |
| 246 |
$P(U), |
| 247 |
&(integer){$SIZE(p)}, |
| 248 |
$P(VT), |
| 249 |
&(integer){$SIZE(s)}, |
| 250 |
&tmp_work, |
| 251 |
&lwork, |
| 252 |
$P(info)); |
| 253 |
|
| 254 |
lwork = (integer )tmp_work; |
| 255 |
{ |
| 256 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 257 |
FORTRAN($TFD(s,d)gesvd)( |
| 258 |
&trau, |
| 259 |
&travt, |
| 260 |
&(integer){$SIZE(m)}, |
| 261 |
&(integer){$SIZE(n)}, |
| 262 |
$P(A), |
| 263 |
&(integer){$SIZE(m)}, |
| 264 |
$P(s), |
| 265 |
$P(U), |
| 266 |
&(integer){$SIZE(p)}, |
| 267 |
$P(VT), |
| 268 |
&(integer){$SIZE(s)}, |
| 269 |
work, |
| 270 |
&lwork, |
| 271 |
$P(info)); |
| 272 |
free(work); |
| 273 |
} |
| 274 |
', |
| 275 |
Doc => ' |
| 276 |
|
| 277 |
=for ref |
| 278 |
|
| 279 |
Computes the singular value decomposition (SVD) of a real |
| 280 |
M-by-N matrix A. |
| 281 |
|
| 282 |
The SVD is written |
| 283 |
|
| 284 |
A = U * SIGMA * V\' |
| 285 |
|
| 286 |
where SIGMA is an M-by-N matrix which is zero except for its |
| 287 |
min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and |
| 288 |
V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA |
| 289 |
are the singular values of A; they are real and non-negative, and |
| 290 |
are returned in descending order. The first min(m,n) columns of |
| 291 |
U and V are the left and right singular vectors of A. |
| 292 |
|
| 293 |
Note that the routine returns VT = V\', not V. |
| 294 |
|
| 295 |
jobu: Specifies options for computing all or part of the matrix U: |
| 296 |
= 0: no columns of U (no left singular vectors) are |
| 297 |
computed. |
| 298 |
= 1: all M columns of U are returned in array U: |
| 299 |
= 2: the first min(m,n) columns of U (the left singular |
| 300 |
vectors) are returned in the array U; |
| 301 |
= 3: the first min(m,n) columns of U (the left singular |
| 302 |
vectors) are overwritten on the array A; |
| 303 |
|
| 304 |
|
| 305 |
jobvt: Specifies options for computing all or part of the matrix |
| 306 |
V\': |
| 307 |
= 0: no rows of V\' (no right singular vectors) are |
| 308 |
computed. |
| 309 |
= 1: all N rows of V\' are returned in the array VT; |
| 310 |
= 2: the first min(m,n) rows of V\' (the right singular |
| 311 |
vectors) are returned in the array VT; |
| 312 |
= 3: the first min(m,n) rows of V\' (the right singular |
| 313 |
vectors) are overwritten on the array A; |
| 314 |
|
| 315 |
jobvt and jobu cannot both be 3. |
| 316 |
|
| 317 |
A: On entry, the M-by-N matrix A. |
| 318 |
On exit, |
| 319 |
if jobu = 3, A is overwritten with the first min(m,n) |
| 320 |
columns of U (the left singular vectors, |
| 321 |
stored columnwise); |
| 322 |
if jobvt = 3, A is overwritten with the first min(m,n) |
| 323 |
rows of V\' (the right singular vectors, |
| 324 |
stored rowwise); |
| 325 |
if jobu != 3 and jobvt != 3, the contents of A |
| 326 |
are destroyed. |
| 327 |
|
| 328 |
s: The singular values of A, sorted so that s(i) >= s(i+1). |
| 329 |
|
| 330 |
U: If jobu = 1, U contains the M-by-M orthogonal matrix U; |
| 331 |
if jobu = 3, U contains the first min(m,n) columns of U |
| 332 |
(the left singular vectors, stored columnwise); |
| 333 |
if jobu = 0 or 3, U is not referenced. |
| 334 |
Min size = [1,1]. |
| 335 |
|
| 336 |
VT: If jobvt = 1, VT contains the N-by-N orthogonal matrix |
| 337 |
V\'; |
| 338 |
if jobvt = 2, VT contains the first min(m,n) rows of |
| 339 |
V\' (the right singular vectors, stored rowwise); |
| 340 |
if jobvt = 0 or 3, VT is not referenced. |
| 341 |
Min size = [1,1]. |
| 342 |
|
| 343 |
info: = 0: successful exit. |
| 344 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 345 |
> 0: if bdsqr did not converge, info specifies how many |
| 346 |
superdiagonals of an intermediate bidiagonal form B |
| 347 |
did not converge to zero. |
| 348 |
|
| 349 |
=for example |
| 350 |
|
| 351 |
$a = random (float, 100,100); |
| 352 |
$s = zeroes(float, 100); |
| 353 |
$u = zeroes(float, 100,100); |
| 354 |
$vt = zeroes(float, 100,100); |
| 355 |
$info = pdl(long, 0); |
| 356 |
gesvd($a, 2, 2, $s , $u, $vt, $info); |
| 357 |
'); |
| 358 |
|
| 359 |
pp_def("gesdd", |
| 360 |
HandleBad => 0, |
| 361 |
Pars => '[io]A(m,n); [o]s(minmn=CALC(PDLMIN($SIZE(m),$SIZE(n)))); [o]U(p,p); [o]VT(s,s); int [o]info(); int [t]iwork(iworkn);', |
| 362 |
OtherPars => 'int jobz', |
| 363 |
ArgOrder => [qw(A jobz s U VT info)], |
| 364 |
RedoDimsCode => ' |
| 365 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobz), tmp==1 || (tmp==2) || (tmp==3 && $SIZE(m)<$SIZE(n)), $PDL(U), $SIZE(p), $SIZE(m)) |
| 366 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobz), tmp==1 || (tmp==2) || (tmp==3 && $SIZE(m)>=$SIZE(n)), $PDL(VT), $SIZE(s), $SIZE(n)) |
| 367 |
$SIZE(iworkn) = 8*$SIZE(minmn); |
| 368 |
', |
| 369 |
GenericTypes => [F,D], |
| 370 |
Code => generate_code <<'EOF', |
| 371 |
integer smlsiz; |
| 372 |
char tra; |
| 373 |
extern int FORTRAN($TFD(s,d)gesdd)(char *jobz, integer *m, integer *n, $GENERIC() * |
| 374 |
a, integer *lda, $GENERIC() *s, $GENERIC() *u, int *ldu, |
| 375 |
$GENERIC() *vt, integer *ldvt, $GENERIC() *work, integer *lwork, |
| 376 |
integer *iwork, integer *info); |
| 377 |
|
| 378 |
$GENERIC() tmp_work; |
| 379 |
|
| 380 |
integer lwork = -1; |
| 381 |
|
| 382 |
switch ($COMP(jobz)) { |
| 383 |
case 1: tra = 'A'; |
| 384 |
break; |
| 385 |
case 2: tra = 'S'; |
| 386 |
break; |
| 387 |
case 3: tra = 'O'; |
| 388 |
break; |
| 389 |
default: tra = 'N'; |
| 390 |
break; |
| 391 |
} |
| 392 |
|
| 393 |
FORTRAN($TFD(s,d)gesdd)( |
| 394 |
&tra, |
| 395 |
&(integer){$SIZE(m)}, |
| 396 |
&(integer){$SIZE(n)}, |
| 397 |
$P(A), |
| 398 |
&(integer){$SIZE(m)}, |
| 399 |
$P(s), |
| 400 |
$P(U), |
| 401 |
&(integer){$SIZE(p)}, |
| 402 |
$P(VT), |
| 403 |
&(integer){$SIZE(s)}, |
| 404 |
&tmp_work, |
| 405 |
&lwork, |
| 406 |
$P(iwork), |
| 407 |
$P(info)); |
| 408 |
|
| 409 |
lwork = (integer )tmp_work; |
| 410 |
{ |
| 411 |
$GENERIC() *work; |
| 412 |
if (tra == 'N'){ |
| 413 |
smlsiz = FORTRAN(ilaenv)(&c_nine, "SGESDD", " ", &c_zero, &c_zero, &c_zero, &c_zero, (ftnlen)6, (ftnlen)1); |
| 414 |
lwork = PDLMAX(14*PDLMIN($SIZE(m),$SIZE(n))+4, 10*PDLMIN($SIZE(m), |
| 415 |
$SIZE(n))+2+ smlsiz*(smlsiz+8)) + PDLMAX($SIZE(m),$SIZE(n)); |
| 416 |
} |
| 417 |
work = ($GENERIC() *) malloc(lwork * sizeof($GENERIC())); |
| 418 |
FORTRAN($TFD(s,d)gesdd)( |
| 419 |
&tra, |
| 420 |
&(integer){$SIZE(m)}, |
| 421 |
&(integer){$SIZE(n)}, |
| 422 |
$P(A), |
| 423 |
&(integer){$SIZE(m)}, |
| 424 |
$P(s), |
| 425 |
$P(U), |
| 426 |
&(integer){$SIZE(p)}, |
| 427 |
$P(VT), |
| 428 |
&(integer){$SIZE(s)}, |
| 429 |
work, |
| 430 |
&lwork, |
| 431 |
$P(iwork), |
| 432 |
$P(info)); |
| 433 |
free(work); |
| 434 |
} |
| 435 |
EOF |
| 436 |
Doc => <<'EOF', |
| 437 |
=for ref |
| 438 |
|
| 439 |
Computes the singular value decomposition (SVD) of a real |
| 440 |
M-by-N matrix A. |
| 441 |
|
| 442 |
This routine use the Cuppen's divide and conquer algorithm. |
| 443 |
It is much faster than the simple driver for large matrices, but uses more workspace. |
| 444 |
|
| 445 |
jobz: Specifies options for computing all or part of matrix: |
| 446 |
|
| 447 |
= 0: no columns of U or rows of V' are computed; |
| 448 |
= 1: all M columns of U and all N rows of V' are |
| 449 |
returned in the arrays U and VT; |
| 450 |
= 2: the first min(M,N) columns of U and the first |
| 451 |
min(M,N) rows of V' are returned in the arrays U |
| 452 |
and VT; |
| 453 |
= 3: If M >= N, the first N columns of U are overwritten |
| 454 |
on the array A and all rows of V' are returned in |
| 455 |
the array VT; |
| 456 |
otherwise, all columns of U are returned in the |
| 457 |
array U and the first M rows of V' are overwritten |
| 458 |
on the array A. |
| 459 |
|
| 460 |
A: On entry, the M-by-N matrix A. |
| 461 |
On exit, |
| 462 |
if jobz = 3, A is overwritten with the first N columns |
| 463 |
of U (the left singular vectors, stored |
| 464 |
columnwise) if M >= N; |
| 465 |
A is overwritten with the first M rows |
| 466 |
of V' (the right singular vectors, stored |
| 467 |
rowwise) otherwise. |
| 468 |
if jobz != 3, the contents of A are destroyed. |
| 469 |
|
| 470 |
s: The singular values of A, sorted so that s(i) >= s(i+1). |
| 471 |
|
| 472 |
U: If jobz = 1 or jobz = 3 and M < N, U contains the M-by-M |
| 473 |
orthogonal matrix U; |
| 474 |
if jobz = 2, U contains the first min(M,N) columns of U |
| 475 |
(the left singular vectors, stored columnwise); |
| 476 |
if jobz = 3 and M >= N, or jobz = 0, U is not referenced. |
| 477 |
Min size = [1,1]. |
| 478 |
|
| 479 |
VT: If jobz = 1 or jobz = 3 and M >= N, VT contains the |
| 480 |
N-by-N orthogonal matrix V'; |
| 481 |
if jobz = 2, VT contains the first min(M,N) rows of |
| 482 |
V' (the right singular vectors, stored rowwise); |
| 483 |
if jobz = 3 and M < N, or jobz = 0, VT is not referenced. |
| 484 |
Min size = [1,1]. |
| 485 |
|
| 486 |
info: = 0: successful exit. |
| 487 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 488 |
> 0: bdsdc did not converge, updating process failed. |
| 489 |
|
| 490 |
=for example |
| 491 |
|
| 492 |
$lines = 50; |
| 493 |
$columns = 100; |
| 494 |
$a = random (float, $lines, $columns); |
| 495 |
$min = $lines < $columns ? $lines : $columns; |
| 496 |
$s = zeroes(float, $min); |
| 497 |
$u = zeroes(float, $lines, $lines); |
| 498 |
$vt = zeroes(float, $columns, $columns); |
| 499 |
$info = long (0); |
| 500 |
gesdd($a, 1, $s , $u, $vt, $info); |
| 501 |
EOF |
| 502 |
); |
| 503 |
|
| 504 |
pp_def("ggsvd", |
| 505 |
HandleBad => 0, |
| 506 |
Pars => '[io]A(m,n); [io]B(p,n); int [o]k(); int [o]l();[o]alpha(n);[o]beta(n); [o]U(q,q); [o]V(r,r); [o]Q(s,s); int [o]iwork(n); int [o]info()', |
| 507 |
OtherPars => 'int jobu; int jobv; int jobq', |
| 508 |
ArgOrder => [qw(A jobu jobv jobq B k l alpha beta U V Q iwork info)], |
| 509 |
RedoDimsCode => ' |
| 510 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobu), tmp, $PDL(U), $SIZE(q), $SIZE(m)) |
| 511 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobv), tmp, $PDL(V), $SIZE(r), $SIZE(p)) |
| 512 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobq), tmp, $PDL(Q), $SIZE(s), $SIZE(n)) |
| 513 |
', |
| 514 |
GenericTypes => [F,D], |
| 515 |
Code => generate_code ' |
| 516 |
char pjobu = \'N\'; |
| 517 |
char pjobv = \'N\'; |
| 518 |
char pjobq = \'N\'; |
| 519 |
|
| 520 |
extern int FORTRAN($TFD(s,d)ggsvd3)(char *jobu, char *jobv, char *jobq, integer *m, |
| 521 |
integer *n, integer *p, integer *k, integer *l, $GENERIC() *a, |
| 522 |
integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *alpha, |
| 523 |
$GENERIC() *beta, $GENERIC() *u, integer *ldu, $GENERIC() *v, integer |
| 524 |
*ldv, $GENERIC() *q, integer *ldq, $GENERIC() *work, integer *lwork, integer *iwork, |
| 525 |
integer *info); |
| 526 |
|
| 527 |
$GENERIC() *work, twork[1]; |
| 528 |
integer lwork = -1; // = ($SIZE (m) < $SIZE (n)) ? $SIZE (n): $SIZE (m); |
| 529 |
|
| 530 |
//if ($SIZE (p) > lwork) |
| 531 |
// lwork = $SIZE (p); |
| 532 |
|
| 533 |
if ($COMP(jobu)) |
| 534 |
pjobu = \'U\'; |
| 535 |
if ($COMP(jobv)) |
| 536 |
pjobv = \'V\'; |
| 537 |
if ($COMP(jobq)) |
| 538 |
pjobq = \'Q\'; |
| 539 |
|
| 540 |
FORTRAN($TFD(s,d)ggsvd3)( |
| 541 |
&pjobu, |
| 542 |
&pjobv, |
| 543 |
&pjobq, |
| 544 |
&(integer){$SIZE(m)}, |
| 545 |
&(integer){$SIZE(n)}, |
| 546 |
&(integer){$SIZE(p)}, |
| 547 |
$P(k), |
| 548 |
$P(l), |
| 549 |
$P(A), |
| 550 |
&(integer){$SIZE(m)}, |
| 551 |
$P(B), |
| 552 |
&(integer){$SIZE(p)}, |
| 553 |
$P(alpha), |
| 554 |
$P(beta), |
| 555 |
$P(U), |
| 556 |
&(integer){$SIZE(q)}, |
| 557 |
$P(V), |
| 558 |
&(integer){$SIZE(r)}, |
| 559 |
$P(Q), |
| 560 |
&(integer){$SIZE(s)}, |
| 561 |
&twork[0], |
| 562 |
&lwork, |
| 563 |
$P(iwork), |
| 564 |
$P(info)); |
| 565 |
|
| 566 |
lwork = (integer) twork[0]; |
| 567 |
|
| 568 |
work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 569 |
|
| 570 |
FORTRAN($TFD(s,d)ggsvd3)( |
| 571 |
&pjobu, |
| 572 |
&pjobv, |
| 573 |
&pjobq, |
| 574 |
&(integer){$SIZE(m)}, |
| 575 |
&(integer){$SIZE(n)}, |
| 576 |
&(integer){$SIZE(p)}, |
| 577 |
$P(k), |
| 578 |
$P(l), |
| 579 |
$P(A), |
| 580 |
&(integer){$SIZE(m)}, |
| 581 |
$P(B), |
| 582 |
&(integer){$SIZE(p)}, |
| 583 |
$P(alpha), |
| 584 |
$P(beta), |
| 585 |
$P(U), |
| 586 |
&(integer){$SIZE(q)}, |
| 587 |
$P(V), |
| 588 |
&(integer){$SIZE(r)}, |
| 589 |
$P(Q), |
| 590 |
&(integer){$SIZE(s)}, |
| 591 |
work, |
| 592 |
&lwork, |
| 593 |
$P(iwork), |
| 594 |
$P(info)); |
| 595 |
free(work); |
| 596 |
', |
| 597 |
Doc => ' |
| 598 |
|
| 599 |
=for ref |
| 600 |
|
| 601 |
Computes the generalized singular value decomposition (GSVD) |
| 602 |
of an M-by-N real matrix A and P-by-N real matrix B: |
| 603 |
|
| 604 |
U\'*A*Q = D1*( 0 R ), V\'*B*Q = D2*( 0 R ) |
| 605 |
|
| 606 |
where U, V and Q are orthogonal matrices, and Z\' is the transpose |
| 607 |
of Z. |
| 608 |
|
| 609 |
Let K+L = the effective numerical rank of the matrix (A\',B\')\', |
| 610 |
then R is a K+L-by-K+L nonsingular upper triangular matrix, D1 and |
| 611 |
D2 are M-by-(K+L) and P-by-(K+L) "diagonal" matrices and of the |
| 612 |
following structures, respectively: |
| 613 |
|
| 614 |
If M-K-L >= 0, |
| 615 |
|
| 616 |
K L |
| 617 |
D1 = K ( I 0 ) |
| 618 |
L ( 0 C ) |
| 619 |
M-K-L ( 0 0 ) |
| 620 |
|
| 621 |
K L |
| 622 |
D2 = L ( 0 S ) |
| 623 |
P-L ( 0 0 ) |
| 624 |
|
| 625 |
N-K-L K L |
| 626 |
( 0 R ) = K ( 0 R11 R12 ) |
| 627 |
L ( 0 0 R22 ) |
| 628 |
|
| 629 |
where |
| 630 |
|
| 631 |
C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), |
| 632 |
S = diag( BETA(K+1), ... , BETA(K+L) ), |
| 633 |
C**2 + S**2 = I. |
| 634 |
|
| 635 |
R is stored in A(1:K+L,N-K-L+1:N) on exit. |
| 636 |
|
| 637 |
If M-K-L < 0, |
| 638 |
|
| 639 |
K M-K K+L-M |
| 640 |
D1 = K ( I 0 0 ) |
| 641 |
M-K ( 0 C 0 ) |
| 642 |
|
| 643 |
K M-K K+L-M |
| 644 |
D2 = M-K ( 0 S 0 ) |
| 645 |
K+L-M ( 0 0 I ) |
| 646 |
P-L ( 0 0 0 ) |
| 647 |
|
| 648 |
N-K-L K M-K K+L-M |
| 649 |
( 0 R ) = K ( 0 R11 R12 R13 ) |
| 650 |
M-K ( 0 0 R22 R23 ) |
| 651 |
K+L-M ( 0 0 0 R33 ) |
| 652 |
|
| 653 |
where |
| 654 |
|
| 655 |
C = diag( ALPHA(K+1), ... , ALPHA(M) ), |
| 656 |
S = diag( BETA(K+1), ... , BETA(M) ), |
| 657 |
C**2 + S**2 = I. |
| 658 |
|
| 659 |
(R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored |
| 660 |
( 0 R22 R23 ) |
| 661 |
in B(M-K+1:L,N+M-K-L+1:N) on exit. |
| 662 |
|
| 663 |
The routine computes C, S, R, and optionally the orthogonal |
| 664 |
transformation matrices U, V and Q. |
| 665 |
|
| 666 |
In particular, if B is an N-by-N nonsingular matrix, then the GSVD of |
| 667 |
A and B implicitly gives the SVD of A*inv(B): |
| 668 |
|
| 669 |
A*inv(B) = U*(D1*inv(D2))*V\'. |
| 670 |
|
| 671 |
If ( A\',B\')\' has orthonormal columns, then the GSVD of A and B is |
| 672 |
also equal to the CS decomposition of A and B. Furthermore, the GSVD |
| 673 |
can be used to derive the solution of the eigenvalue problem: |
| 674 |
|
| 675 |
A\'*A x = lambda* B\'*B x. |
| 676 |
|
| 677 |
In some literature, the GSVD of A and B is presented in the form |
| 678 |
|
| 679 |
U\'*A*X = ( 0 D1 ), V\'*B*X = ( 0 D2 ) |
| 680 |
where U and V are orthogonal and X is nonsingular, D1 and D2 are "diagonal". |
| 681 |
|
| 682 |
The former GSVD form can be converted to the latter |
| 683 |
form by taking the nonsingular matrix X as |
| 684 |
|
| 685 |
X = Q*( I 0 ) |
| 686 |
( 0 inv(R) ). |
| 687 |
|
| 688 |
Arguments |
| 689 |
========= |
| 690 |
|
| 691 |
jobu: = 0: U is not computed. |
| 692 |
= 1: Orthogonal matrix U is computed; |
| 693 |
|
| 694 |
jobv: = 0: V is not computed. |
| 695 |
= 1: Orthogonal matrix V is computed; |
| 696 |
|
| 697 |
jobq: = 0: Q is not computed. |
| 698 |
= 1: Orthogonal matrix Q is computed; |
| 699 |
|
| 700 |
k: |
| 701 |
l: On exit, k and l specify the dimension of the subblocks |
| 702 |
described in the Purpose section. |
| 703 |
k + l = effective numerical rank of (A\',B\')\'. |
| 704 |
|
| 705 |
A: On entry, the M-by-N matrix A. |
| 706 |
On exit, A contains the triangular matrix R, or part of R. |
| 707 |
|
| 708 |
B: On entry, the P-by-N matrix B. |
| 709 |
On exit, B contains the triangular matrix R if M-k-l < 0. |
| 710 |
|
| 711 |
alpha: |
| 712 |
beta: On exit, alpha and beta contain the generalized singular |
| 713 |
value pairs of A and B; |
| 714 |
alpha(1:k) = 1, |
| 715 |
beta(1:k) = 0, |
| 716 |
and if M-k-l >= 0, |
| 717 |
alpha(k+1:k+l) = C, |
| 718 |
beta(k+1:k+l) = S, |
| 719 |
or if M-k-l < 0, |
| 720 |
alpha(k+1:M)=C, alpha(M+1:k+l)=0 |
| 721 |
beta(k+1:M) =S, beta(M+1:k+l) =1 |
| 722 |
and |
| 723 |
alpha(k+l+1:N) = 0 |
| 724 |
beta(k+l+1:N) = 0 |
| 725 |
|
| 726 |
U: If jobu = 1, U contains the M-by-M orthogonal matrix U. |
| 727 |
If jobu = 0, U is not referenced. |
| 728 |
Need a minimum array of (1,1) if jobu = 0; |
| 729 |
|
| 730 |
V: If jobv = 1, V contains the P-by-P orthogonal matrix V. |
| 731 |
If jobv = 0, V is not referenced. |
| 732 |
Need a minimum array of (1,1) if jobv = 0; |
| 733 |
|
| 734 |
Q: If jobq = 1, Q contains the N-by-N orthogonal matrix Q. |
| 735 |
If jobq = 0, Q is not referenced. |
| 736 |
Need a minimum array of (1,1) if jobq = 0; |
| 737 |
|
| 738 |
iwork: On exit, iwork stores the sorting information. More |
| 739 |
precisely, the following loop will sort alpha |
| 740 |
for I = k+1, min(M,k+l) |
| 741 |
swap alpha(I) and alpha(iwork(I)) |
| 742 |
endfor |
| 743 |
such that alpha(1) >= alpha(2) >= ... >= alpha(N). |
| 744 |
|
| 745 |
info: = 0: successful exit |
| 746 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 747 |
> 0: if info = 1, the Jacobi-type procedure failed to |
| 748 |
converge. For further details, see subroutine tgsja. |
| 749 |
|
| 750 |
=for example |
| 751 |
|
| 752 |
$k = null; |
| 753 |
$l = null; |
| 754 |
$A = random(5,6); |
| 755 |
$B = random(7,6); |
| 756 |
$alpha = zeroes(6); |
| 757 |
$beta = zeroes(6); |
| 758 |
$U = zeroes(5,5); |
| 759 |
$V = zeroes(7,7); |
| 760 |
$Q = zeroes(6,6); |
| 761 |
$iwork = zeroes(long, 6); |
| 762 |
$info = null; |
| 763 |
ggsvd($A,1,1,1,$B,$k,$l,$alpha, $beta,$U, $V, $Q, $iwork,$info); |
| 764 |
|
| 765 |
'); |
| 766 |
|
| 767 |
pp_def("geev", |
| 768 |
HandleBad => 0, |
| 769 |
Pars => '[io]A(n,n); [o]wr(n); [o]wi(n); [o]vl(m,m); [o]vr(p,p); int [o]info()', |
| 770 |
OtherPars => 'int jobvl; int jobvr', |
| 771 |
ArgOrder => [qw(A jobvl jobvr wr wi vl vr info)], |
| 772 |
RedoDimsCode => ' |
| 773 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvl), tmp, $PDL(vl), $SIZE(m), $SIZE(n)) |
| 774 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvr), tmp, $PDL(vr), $SIZE(p), $SIZE(n)) |
| 775 |
', |
| 776 |
GenericTypes => [F,D], |
| 777 |
Code => generate_code ' |
| 778 |
char jvl = \'N\'; |
| 779 |
char jvr = \'N\'; |
| 780 |
extern int FORTRAN($TFD(s,d)geev)(char *jobvl, char *jobvr, integer *n, $GENERIC() *a, |
| 781 |
integer *lda, $GENERIC() *wr, $GENERIC() *wi, $GENERIC() *vl, integer *ldvl, $GENERIC() *vr, |
| 782 |
integer *ldvr, $GENERIC() *work, integer *lwork, integer *info); |
| 783 |
|
| 784 |
$GENERIC() tmp_work; |
| 785 |
integer lwork = -1; |
| 786 |
|
| 787 |
if ($COMP(jobvl)) |
| 788 |
jvl = \'V\'; |
| 789 |
if ($COMP(jobvr)) |
| 790 |
jvr = \'V\'; |
| 791 |
|
| 792 |
FORTRAN($TFD(s,d)geev)( |
| 793 |
&jvl, |
| 794 |
&jvr, |
| 795 |
&(integer){$SIZE(n)}, |
| 796 |
$P(A), |
| 797 |
&(integer){$SIZE(n)}, |
| 798 |
$P(wr), |
| 799 |
$P(wi), |
| 800 |
$P(vl), |
| 801 |
&(integer){$SIZE(m)}, |
| 802 |
$P(vr), |
| 803 |
&(integer){$SIZE(p)}, |
| 804 |
&tmp_work, |
| 805 |
&lwork, |
| 806 |
$P(info)); |
| 807 |
|
| 808 |
lwork = (integer )tmp_work; |
| 809 |
{ |
| 810 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 811 |
FORTRAN($TFD(s,d)geev)( |
| 812 |
&jvl, |
| 813 |
&jvr, |
| 814 |
&(integer){$SIZE(n)}, |
| 815 |
$P(A), |
| 816 |
&(integer){$SIZE(n)}, |
| 817 |
$P(wr), |
| 818 |
$P(wi), |
| 819 |
$P(vl), |
| 820 |
&(integer){$SIZE(m)}, |
| 821 |
$P(vr), |
| 822 |
&(integer){$SIZE(p)}, |
| 823 |
work, |
| 824 |
&lwork, |
| 825 |
$P(info)); |
| 826 |
free(work); |
| 827 |
} |
| 828 |
', |
| 829 |
Doc => ' |
| 830 |
|
| 831 |
=for ref |
| 832 |
|
| 833 |
Computes for an N-by-N real nonsymmetric matrix A, the |
| 834 |
eigenvalues and, optionally, the left and/or right eigenvectors. |
| 835 |
|
| 836 |
The right eigenvector v(j) of A satisfies: |
| 837 |
A * v(j) = lambda(j) * v(j) |
| 838 |
where lambda(j) is its eigenvalue. |
| 839 |
|
| 840 |
The left eigenvector u(j) of A satisfies: |
| 841 |
u(j)**H * A = lambda(j) * u(j)**H |
| 842 |
where u(j)**H denotes the conjugate transpose of u(j). |
| 843 |
|
| 844 |
The computed eigenvectors are normalized to have Euclidean norm |
| 845 |
equal to 1 and largest component real. |
| 846 |
|
| 847 |
Arguments |
| 848 |
========= |
| 849 |
|
| 850 |
jobvl: = 0: left eigenvectors of A are not computed; |
| 851 |
= 1: left eigenvectors of A are computed. |
| 852 |
|
| 853 |
jobvr: = 0: right eigenvectors of A are not computed; |
| 854 |
= 1: right eigenvectors of A are computed. |
| 855 |
|
| 856 |
A: A is overwritten. |
| 857 |
|
| 858 |
wr: |
| 859 |
wi: wr and wi contain the real and imaginary parts, |
| 860 |
respectively, of the computed eigenvalues. Complex |
| 861 |
conjugate pairs of eigenvalues appear consecutively |
| 862 |
with the eigenvalue having the positive imaginary part |
| 863 |
first. |
| 864 |
|
| 865 |
vl: If jobvl = 1, the left eigenvectors u(j) are stored one |
| 866 |
after another in the columns of vl, in the same order |
| 867 |
as their eigenvalues else vl is not referenced. |
| 868 |
If the j-th eigenvalue is real, then u(j) = vl(:,j), |
| 869 |
the j-th column of vl. |
| 870 |
If the j-th and (j+1)-st eigenvalues form a complex |
| 871 |
conjugate pair, then u(j) = vl(:,j) + i*vl(:,j+1) and |
| 872 |
u(j+1) = vl(:,j) - i*vl(:,j+1). |
| 873 |
Min size = [1]. |
| 874 |
|
| 875 |
vr: If jobvr = 1, the right eigenvectors v(j) are stored one |
| 876 |
after another in the columns of vr, in the same order |
| 877 |
as their eigenvalues else vr is not referenced. |
| 878 |
If the j-th eigenvalue is real, then v(j) = vr(:,j), |
| 879 |
the j-th column of vr. |
| 880 |
If the j-th and (j+1)-st eigenvalues form a complex |
| 881 |
conjugate pair, then v(j) = vr(:,j) + i*vr(:,j+1) and |
| 882 |
v(j+1) = vr(:,j) - i*vr(:,j+1). |
| 883 |
Min size = [1]. |
| 884 |
|
| 885 |
info: = 0: successful exit |
| 886 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 887 |
> 0: if info = i, the QR algorithm failed to compute all the |
| 888 |
eigenvalues, and no eigenvectors have been computed; |
| 889 |
elements i+1:N of wr and wi contain eigenvalues which |
| 890 |
have converged. |
| 891 |
|
| 892 |
|
| 893 |
=for example |
| 894 |
|
| 895 |
$a = random (5, 5); |
| 896 |
$wr = zeroes(5); |
| 897 |
$wi = zeroes($wr); |
| 898 |
$vl = zeroes($a); |
| 899 |
$vr = zeroes($a); |
| 900 |
$info = null; |
| 901 |
geev($a, 1, 1, $wr, $wi, $vl, $vr, $info); |
| 902 |
|
| 903 |
'); |
| 904 |
|
| 905 |
pp_def("geevx", |
| 906 |
HandleBad => 0, |
| 907 |
Pars => '[io]A(n,n); [o]wr(n); [o]wi(n); [o]vl(m,m); [o]vr(p,p); int [o]ilo(); int [o]ihi(); [o]scale(n); [o]abnrm(); [o]rconde(q); [o]rcondv(r); int [o]info(); int [t]iwork(iworkn);', |
| 908 |
OtherPars => 'int jobvl; int jobvr; int balance; int sense', |
| 909 |
ArgOrder => [qw(A jobvl jobvr balance sense wr wi vl vr ilo ihi scale abnrm rconde rcondv info)], |
| 910 |
RedoDimsCode => ' |
| 911 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvl), tmp, $PDL(vl), $SIZE(m), $SIZE(n)) |
| 912 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvr), tmp, $PDL(vr), $SIZE(p), $SIZE(n)) |
| 913 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp == 1 || tmp == 3, $PDL(rconde), $SIZE(q), $SIZE(n)) |
| 914 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp == 2 || tmp == 3, $PDL(rcondv), $SIZE(r), $SIZE(n)) |
| 915 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp == 2 || tmp == 3, $PDL(iwork), $SIZE(iworkn), 2*$SIZE(n)-2) |
| 916 |
', |
| 917 |
GenericTypes => [F,D], |
| 918 |
Code => generate_code ' |
| 919 |
char jvl = \'N\'; |
| 920 |
char jvr = \'N\'; |
| 921 |
char balanc, sens; |
| 922 |
integer lwork = -1; |
| 923 |
extern int FORTRAN($TFD(s,d)geevx)(char *balanc, char *jobvl, char *jobvr, char * |
| 924 |
sense, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *wr, |
| 925 |
$GENERIC() *wi, $GENERIC() *vl, integer *ldvl, $GENERIC() *vr, |
| 926 |
integer *ldvr, integer *ilo, integer *ihi, $GENERIC() *scale, |
| 927 |
$GENERIC() *abnrm, $GENERIC() *rconde, $GENERIC() *rcondv, $GENERIC() |
| 928 |
*work, integer *lwork, integer *iwork, integer *info); |
| 929 |
|
| 930 |
$GENERIC() tmp_work; |
| 931 |
|
| 932 |
if ($COMP(jobvl)) |
| 933 |
jvl = \'V\'; |
| 934 |
if ($COMP(jobvr)) |
| 935 |
jvr = \'V\'; |
| 936 |
|
| 937 |
switch ($COMP(balance)) |
| 938 |
{ |
| 939 |
case 1: balanc = \'P\'; |
| 940 |
break; |
| 941 |
case 2: balanc = \'S\'; |
| 942 |
break; |
| 943 |
case 3: balanc = \'B\'; |
| 944 |
break; |
| 945 |
default: balanc = \'N\'; |
| 946 |
} |
| 947 |
switch ($COMP(sense)) |
| 948 |
{ |
| 949 |
case 1: sens = \'E\'; |
| 950 |
break; |
| 951 |
case 2: sens = \'V\'; |
| 952 |
break; |
| 953 |
case 3: sens = \'B\'; |
| 954 |
break; |
| 955 |
default: sens = \'N\'; |
| 956 |
} |
| 957 |
|
| 958 |
FORTRAN($TFD(s,d)geevx)( |
| 959 |
&balanc, |
| 960 |
&jvl, |
| 961 |
&jvr, |
| 962 |
&sens, |
| 963 |
&(integer){$SIZE(n)}, |
| 964 |
$P(A), |
| 965 |
&(integer){$SIZE(n)}, |
| 966 |
$P(wr), |
| 967 |
$P(wi), |
| 968 |
$P(vl), |
| 969 |
&(integer){$SIZE(m)}, |
| 970 |
$P(vr), |
| 971 |
&(integer){$SIZE(p)}, |
| 972 |
$P(ilo), |
| 973 |
$P(ihi), |
| 974 |
$P(scale), |
| 975 |
$P(abnrm), |
| 976 |
$P(rconde), |
| 977 |
$P(rcondv), |
| 978 |
&tmp_work, |
| 979 |
&lwork, |
| 980 |
$P(iwork), |
| 981 |
$P(info)); |
| 982 |
|
| 983 |
lwork = (integer )tmp_work; |
| 984 |
{ |
| 985 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 986 |
FORTRAN($TFD(s,d)geevx)( |
| 987 |
&balanc, |
| 988 |
&jvl, |
| 989 |
&jvr, |
| 990 |
&sens, |
| 991 |
&(integer){$SIZE(n)}, |
| 992 |
$P(A), |
| 993 |
&(integer){$SIZE(n)}, |
| 994 |
$P(wr), |
| 995 |
$P(wi), |
| 996 |
$P(vl), |
| 997 |
&(integer){$SIZE(m)}, |
| 998 |
$P(vr), |
| 999 |
&(integer){$SIZE(p)}, |
| 1000 |
$P(ilo), |
| 1001 |
$P(ihi), |
| 1002 |
$P(scale), |
| 1003 |
$P(abnrm), |
| 1004 |
$P(rconde), |
| 1005 |
$P(rcondv), |
| 1006 |
work, |
| 1007 |
&lwork, |
| 1008 |
$P(iwork), |
| 1009 |
$P(info)); |
| 1010 |
free(work); |
| 1011 |
} |
| 1012 |
', |
| 1013 |
Doc => ' |
| 1014 |
|
| 1015 |
=for ref |
| 1016 |
|
| 1017 |
Computes for an N-by-N real nonsymmetric matrix A, the |
| 1018 |
eigenvalues and, optionally, the left and/or right eigenvectors. |
| 1019 |
|
| 1020 |
Optionally also, it computes a balancing transformation to improve |
| 1021 |
the conditioning of the eigenvalues and eigenvectors (ilo, ihi, |
| 1022 |
scale, and abnrm), reciprocal condition numbers for the eigenvalues |
| 1023 |
(rconde), and reciprocal condition numbers for the right |
| 1024 |
eigenvectors (rcondv). |
| 1025 |
|
| 1026 |
The right eigenvector v(j) of A satisfies: |
| 1027 |
|
| 1028 |
A * v(j) = lambda(j) * v(j) |
| 1029 |
where lambda(j) is its eigenvalue. |
| 1030 |
|
| 1031 |
The left eigenvector u(j) of A satisfies: |
| 1032 |
|
| 1033 |
u(j)**H * A = lambda(j) * u(j)**H |
| 1034 |
where u(j)**H denotes the conjugate transpose of u(j). |
| 1035 |
|
| 1036 |
The computed eigenvectors are normalized to have Euclidean norm |
| 1037 |
equal to 1 and largest component real. |
| 1038 |
|
| 1039 |
Balancing a matrix means permuting the rows and columns to make it |
| 1040 |
more nearly upper triangular, and applying a diagonal similarity |
| 1041 |
transformation D * A * D**(-1), where D is a diagonal matrix, to |
| 1042 |
make its rows and columns closer in norm and the condition numbers |
| 1043 |
of its eigenvalues and eigenvectors smaller. The computed |
| 1044 |
reciprocal condition numbers correspond to the balanced matrix. |
| 1045 |
Permuting rows and columns will not change the condition numbers |
| 1046 |
(in exact arithmetic) but diagonal scaling will. For further |
| 1047 |
explanation of balancing, see section 4.10.2 of the LAPACK |
| 1048 |
Users\' Guide. |
| 1049 |
|
| 1050 |
Arguments |
| 1051 |
========= |
| 1052 |
|
| 1053 |
balance: |
| 1054 |
Indicates how the input matrix should be diagonally scaled |
| 1055 |
and/or permuted to improve the conditioning of its |
| 1056 |
eigenvalues. |
| 1057 |
= 0: Do not diagonally scale or permute; |
| 1058 |
= 1: Perform permutations to make the matrix more nearly |
| 1059 |
upper triangular. Do not diagonally scale; |
| 1060 |
= 2: Diagonally scale the matrix, i.e. replace A by |
| 1061 |
D*A*D**(-1), where D is a diagonal matrix chosen |
| 1062 |
to make the rows and columns of A more equal in |
| 1063 |
norm. Do not permute; |
| 1064 |
= 3: Both diagonally scale and permute A. |
| 1065 |
|
| 1066 |
Computed reciprocal condition numbers will be for the matrix |
| 1067 |
after balancing and/or permuting. Permuting does not change |
| 1068 |
condition numbers (in exact arithmetic), but balancing does. |
| 1069 |
|
| 1070 |
jobvl: = 0: left eigenvectors of A are not computed; |
| 1071 |
= 1: left eigenvectors of A are computed. |
| 1072 |
If sense = 1 or 3, jobvl must = 1. |
| 1073 |
|
| 1074 |
jobvr; = 0: right eigenvectors of A are not computed; |
| 1075 |
= 1: right eigenvectors of A are computed. |
| 1076 |
If sense = 1 or 3, jobvr must = 1. |
| 1077 |
|
| 1078 |
sense: Determines which reciprocal condition numbers are computed. |
| 1079 |
= 0: None are computed; |
| 1080 |
= 1: Computed for eigenvalues only; |
| 1081 |
= 2: Computed for right eigenvectors only; |
| 1082 |
= 3: Computed for eigenvalues and right eigenvectors. |
| 1083 |
|
| 1084 |
If sense = 1 or 3, both left and right eigenvectors |
| 1085 |
must also be computed (jobvl = 1 and jobvr = 1). |
| 1086 |
|
| 1087 |
A: The N-by-N matrix. |
| 1088 |
It is overwritten. If jobvl = 1 or |
| 1089 |
jobvr = 1, A contains the real Schur form of the balanced |
| 1090 |
version of the input matrix A. |
| 1091 |
|
| 1092 |
wr |
| 1093 |
wi: wr and wi contain the real and imaginary parts, |
| 1094 |
respectively, of the computed eigenvalues. Complex |
| 1095 |
conjugate pairs of eigenvalues will appear consecutively |
| 1096 |
with the eigenvalue having the positive imaginary part |
| 1097 |
first. |
| 1098 |
|
| 1099 |
vl: If jobvl = 1, the left eigenvectors u(j) are stored one |
| 1100 |
after another in the columns of vl, in the same order |
| 1101 |
as their eigenvalues else vl is not referenced. |
| 1102 |
If the j-th eigenvalue is real, then u(j) = vl(:,j), |
| 1103 |
the j-th column of vl. |
| 1104 |
If the j-th and (j+1)-st eigenvalues form a complex |
| 1105 |
conjugate pair, then u(j) = vl(:,j) + i*vl(:,j+1) and |
| 1106 |
u(j+1) = vl(:,j) - i*vl(:,j+1). |
| 1107 |
Min size = [1]. |
| 1108 |
|
| 1109 |
vr: If jobvr = 1, the right eigenvectors v(j) are stored one |
| 1110 |
after another in the columns of vr, in the same order |
| 1111 |
as their eigenvalues else vr is not referenced. |
| 1112 |
If the j-th eigenvalue is real, then v(j) = vr(:,j), |
| 1113 |
the j-th column of vr. |
| 1114 |
If the j-th and (j+1)-st eigenvalues form a complex |
| 1115 |
conjugate pair, then v(j) = vr(:,j) + i*vr(:,j+1) and |
| 1116 |
v(j+1) = vr(:,j) - i*vr(:,j+1). |
| 1117 |
Min size = [1]. |
| 1118 |
|
| 1119 |
ilo,ihi:Integer values determined when A was |
| 1120 |
balanced. The balanced A(i,j) = 0 if I > J and |
| 1121 |
J = 1,...,ilo-1 or I = ihi+1,...,N. |
| 1122 |
|
| 1123 |
scale: Details of the permutations and scaling factors applied |
| 1124 |
when balancing A. If P(j) is the index of the row and column |
| 1125 |
interchanged with row and column j, and D(j) is the scaling |
| 1126 |
factor applied to row and column j, then |
| 1127 |
scale(J) = P(J), for J = 1,...,ilo-1 |
| 1128 |
= D(J), for J = ilo,...,ihi |
| 1129 |
= P(J) for J = ihi+1,...,N. |
| 1130 |
The order in which the interchanges are made is N to ihi+1, |
| 1131 |
then 1 to ilo-1. |
| 1132 |
|
| 1133 |
abnrm: The one-norm of the balanced matrix (the maximum |
| 1134 |
of the sum of absolute values of elements of any column). |
| 1135 |
|
| 1136 |
rconde: rconde(j) is the reciprocal condition number of the j-th |
| 1137 |
eigenvalue. |
| 1138 |
|
| 1139 |
rcondv: rcondv(j) is the reciprocal condition number of the j-th |
| 1140 |
right eigenvector. |
| 1141 |
|
| 1142 |
info: = 0: successful exit |
| 1143 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 1144 |
> 0: if info = i, the QR algorithm failed to compute all the |
| 1145 |
eigenvalues, and no eigenvectors or condition numbers |
| 1146 |
have been computed; elements 1:ilo-1 and i+1:N of wr |
| 1147 |
and wi contain eigenvalues which have converged. |
| 1148 |
|
| 1149 |
=for example |
| 1150 |
|
| 1151 |
$a = random (5,5); |
| 1152 |
$wr = zeroes(5); |
| 1153 |
$wi = zeroes(5); |
| 1154 |
$vl = zeroes(5,5); |
| 1155 |
$vr = zeroes(5,5); |
| 1156 |
$ilo = null; |
| 1157 |
$ihi = null; |
| 1158 |
$scale = zeroes(5); |
| 1159 |
$abnrm = null; |
| 1160 |
$rconde = zeroes(5); |
| 1161 |
$rcondv = zeroes(5); |
| 1162 |
$info = null; |
| 1163 |
geevx($a, 1,1,3,3,$wr, $wi, $vl, $vr, $ilo, $ihi, $scale, $abnrm,$rconde, $rcondv, $info); |
| 1164 |
|
| 1165 |
'); |
| 1166 |
|
| 1167 |
|
| 1168 |
pp_def("ggev", |
| 1169 |
HandleBad => 0, |
| 1170 |
Pars => '[io]A(n,n);[io]B(n,n);[o]alphar(n);[o]alphai(n);[o]beta(n);[o]VL(m,m);[o]VR(p,p);int [o]info()', |
| 1171 |
OtherPars => 'int jobvl; int jobvr', |
| 1172 |
ArgOrder => [qw{A jobvl jobvr B alphar alphai beta VL VR info}], |
| 1173 |
GenericTypes => [F,D], |
| 1174 |
RedoDimsCode => ' |
| 1175 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvl), tmp, $PDL(VL), $SIZE(m), $SIZE(n)) |
| 1176 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvr), tmp, $PDL(VR), $SIZE(p), $SIZE(n)) |
| 1177 |
', |
| 1178 |
Code => generate_code ' |
| 1179 |
integer lwork = -1; |
| 1180 |
char pjobvl = \'N\', pjobvr = \'N\'; |
| 1181 |
|
| 1182 |
extern int FORTRAN($TFD(s,d)ggev)(char *jobvl, char *jobvr, integer *n, $GENERIC() * |
| 1183 |
a, integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *alphar, |
| 1184 |
$GENERIC() *alphai, $GENERIC() *beta, $GENERIC() *vl, integer *ldvl, |
| 1185 |
$GENERIC() *vr, integer *ldvr, $GENERIC() *work, integer *lwork, |
| 1186 |
integer *info); |
| 1187 |
$GENERIC() tmp_work; |
| 1188 |
if ($COMP(jobvl)) |
| 1189 |
pjobvl = \'V\'; |
| 1190 |
if ($COMP(jobvr)) |
| 1191 |
pjobvr = \'V\'; |
| 1192 |
|
| 1193 |
FORTRAN($TFD(s,d)ggev)( |
| 1194 |
&pjobvl, |
| 1195 |
&pjobvr, |
| 1196 |
&(integer){$SIZE(n)}, |
| 1197 |
$P(A), |
| 1198 |
&(integer){$SIZE(n)}, |
| 1199 |
$P(B), |
| 1200 |
&(integer){$SIZE(n)}, |
| 1201 |
$P(alphar), |
| 1202 |
$P(alphai), |
| 1203 |
$P(beta), |
| 1204 |
$P(VL), |
| 1205 |
&(integer){$SIZE(m)}, |
| 1206 |
$P(VR), |
| 1207 |
&(integer){$SIZE(p)}, |
| 1208 |
&tmp_work, |
| 1209 |
&lwork, |
| 1210 |
$P(info)); |
| 1211 |
|
| 1212 |
lwork = (integer )tmp_work; |
| 1213 |
{ |
| 1214 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 1215 |
FORTRAN($TFD(s,d)ggev)( |
| 1216 |
&pjobvl, |
| 1217 |
&pjobvr, |
| 1218 |
&(integer){$SIZE(n)}, |
| 1219 |
$P(A), |
| 1220 |
&(integer){$SIZE(n)}, |
| 1221 |
$P(B), |
| 1222 |
&(integer){$SIZE(n)}, |
| 1223 |
$P(alphar), |
| 1224 |
$P(alphai), |
| 1225 |
$P(beta), |
| 1226 |
$P(VL), |
| 1227 |
&(integer){$SIZE(m)}, |
| 1228 |
$P(VR), |
| 1229 |
&(integer){$SIZE(p)}, |
| 1230 |
work, |
| 1231 |
&lwork, |
| 1232 |
$P(info)); |
| 1233 |
free(work); |
| 1234 |
} |
| 1235 |
|
| 1236 |
', |
| 1237 |
Doc => ' |
| 1238 |
|
| 1239 |
=for ref |
| 1240 |
|
| 1241 |
Computes for a pair of N-by-N real nonsymmetric matrices (A,B) |
| 1242 |
the generalized eigenvalues, and optionally, the left and/or right |
| 1243 |
generalized eigenvectors. |
| 1244 |
|
| 1245 |
A generalized eigenvalue for a pair of matrices (A,B) is a scalar |
| 1246 |
lambda or a ratio alpha/beta = lambda, such that A - lambda*B is |
| 1247 |
singular. It is usually represented as the pair (alpha,beta), as |
| 1248 |
there is a reasonable interpretation for beta=0, and even for both |
| 1249 |
being zero. |
| 1250 |
|
| 1251 |
The right eigenvector v(j) corresponding to the eigenvalue lambda(j) |
| 1252 |
of (A,B) satisfies |
| 1253 |
|
| 1254 |
A * v(j) = lambda(j) * B * v(j). |
| 1255 |
|
| 1256 |
The left eigenvector u(j) corresponding to the eigenvalue lambda(j) |
| 1257 |
of (A,B) satisfies |
| 1258 |
|
| 1259 |
u(j)**H * A = lambda(j) * u(j)**H * B . |
| 1260 |
|
| 1261 |
where u(j)**H is the conjugate-transpose of u(j). |
| 1262 |
|
| 1263 |
|
| 1264 |
Arguments |
| 1265 |
========= |
| 1266 |
|
| 1267 |
jobvl: = 0: do not compute the left generalized eigenvectors; |
| 1268 |
= 1: compute the left generalized eigenvectors. |
| 1269 |
|
| 1270 |
jobvr: = 0: do not compute the right generalized eigenvectors; |
| 1271 |
= 1: compute the right generalized eigenvectors. |
| 1272 |
|
| 1273 |
A: On entry, the matrix A in the pair (A,B). |
| 1274 |
On exit, A has been overwritten. |
| 1275 |
|
| 1276 |
B: On entry, the matrix B in the pair (A,B). |
| 1277 |
On exit, B has been overwritten. |
| 1278 |
|
| 1279 |
alphar: |
| 1280 |
alphai: |
| 1281 |
beta: On exit, (alphar(j) + alphai(j)*i)/beta(j), j=1,...,N, will |
| 1282 |
be the generalized eigenvalues. If alphai(j) is zero, then |
| 1283 |
the j-th eigenvalue is real; if positive, then the j-th and |
| 1284 |
(j+1)-st eigenvalues are a complex conjugate pair, with |
| 1285 |
alphai(j+1) negative. |
| 1286 |
|
| 1287 |
Note: the quotients alphar(j)/beta(j) and alphai(j)/beta(j) |
| 1288 |
may easily over- or underflow, and beta(j) may even be zero. |
| 1289 |
Thus, the user should avoid naively computing the ratio |
| 1290 |
alpha/beta. However, alphar and alphai will be always less |
| 1291 |
than and usually comparable with norm(A) in magnitude, and |
| 1292 |
beta always less than and usually comparable with norm(B). |
| 1293 |
|
| 1294 |
VL: If jobvl = 1, the left eigenvectors u(j) are stored one |
| 1295 |
after another in the columns of VL, in the same order as |
| 1296 |
their eigenvalues. If the j-th eigenvalue is real, then |
| 1297 |
u(j) = VL(:,j), the j-th column of VL. If the j-th and |
| 1298 |
(j+1)-th eigenvalues form a complex conjugate pair, then |
| 1299 |
u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1). |
| 1300 |
Each eigenvector will be scaled so the largest component have |
| 1301 |
abs(real part)+abs(imag. part)=1. |
| 1302 |
Not referenced if jobvl = 0. |
| 1303 |
|
| 1304 |
VR: If jobvr = 1, the right eigenvectors v(j) are stored one |
| 1305 |
after another in the columns of VR, in the same order as |
| 1306 |
their eigenvalues. If the j-th eigenvalue is real, then |
| 1307 |
v(j) = VR(:,j), the j-th column of VR. If the j-th and |
| 1308 |
(j+1)-th eigenvalues form a complex conjugate pair, then |
| 1309 |
v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). |
| 1310 |
Each eigenvector will be scaled so the largest component have |
| 1311 |
abs(real part)+abs(imag. part)=1. |
| 1312 |
Not referenced if jobvr = 0. |
| 1313 |
|
| 1314 |
info: = 0: successful exit |
| 1315 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 1316 |
= 1,...,N: |
| 1317 |
The QZ iteration failed. No eigenvectors have been |
| 1318 |
calculated, but alphar(j), alphai(j), and beta(j) |
| 1319 |
should be correct for j=info+1,...,N. |
| 1320 |
> N: =N+1: other than QZ iteration failed in hgeqz. |
| 1321 |
=N+2: error return from tgevc. |
| 1322 |
|
| 1323 |
=for example |
| 1324 |
|
| 1325 |
$a = random(5,5); |
| 1326 |
$b = random(5,5); |
| 1327 |
$alphar = zeroes(5); |
| 1328 |
$alphai = zeroes(5); |
| 1329 |
$beta = zeroes(5); |
| 1330 |
$vl = zeroes(5,5); |
| 1331 |
$vr = zeroes(5,5); |
| 1332 |
ggev($a, 1, 1, $b, $alphar, $alphai, $beta, $vl, $vr, ($info=null)); |
| 1333 |
|
| 1334 |
'); |
| 1335 |
|
| 1336 |
pp_def("ggevx", |
| 1337 |
HandleBad => 0, |
| 1338 |
Pars => '[io]A(n,n);[io]B(n,n);[o]alphar(n);[o]alphai(n);[o]beta(n);[o]VL(m,m);[o]VR(p,p);int [o]ilo();int [o]ihi();[o]lscale(n);[o]rscale(n);[o]abnrm();[o]bbnrm();[o]rconde(r);[o]rcondv(s);int [o]info(); int [t]bwork(bworkn); int [t]iwork(iworkn);', |
| 1339 |
OtherPars => 'int balanc; int jobvl; int jobvr; int sense', |
| 1340 |
ArgOrder => [qw{A balanc jobvl jobvr sense B alphar alphai beta VL VR ilo ihi lscale rscale abnrm bbnrm rconde rcondv info}], |
| 1341 |
RedoDimsCode => ' |
| 1342 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvl), tmp, $PDL(VL), $SIZE(m), $SIZE(n)) |
| 1343 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvr), tmp, $PDL(VR), $SIZE(p), $SIZE(n)) |
| 1344 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp != 2, $PDL(rconde), $SIZE(r), $SIZE(n)) |
| 1345 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp != 1, $PDL(rcondv), $SIZE(s), $SIZE(n)) |
| 1346 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp != 1, $PDL(iwork), $SIZE(iworkn), $SIZE(n) + 6) |
| 1347 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sense), tmp == 1 || tmp == 2 || tmp == 3, $PDL(bwork), $SIZE(bworkn), $SIZE(n)) |
| 1348 |
', |
| 1349 |
GenericTypes => [F,D], |
| 1350 |
Code => generate_code ' |
| 1351 |
integer lwork = -1; |
| 1352 |
char pjobvl = \'N\', pjobvr = \'N\'; |
| 1353 |
char pbalanc, psens; |
| 1354 |
|
| 1355 |
extern int FORTRAN($TFD(s,d)ggevx)(char *balanc, char *jobvl, char *jobvr, char * |
| 1356 |
sense, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *b, |
| 1357 |
integer *ldb, $GENERIC() *alphar, $GENERIC() *alphai, $GENERIC() * |
| 1358 |
beta, $GENERIC() *vl, integer *ldvl, $GENERIC() *vr, integer *ldvr, |
| 1359 |
integer *ilo, integer *ihi, $GENERIC() *lscale, $GENERIC() *rscale, |
| 1360 |
$GENERIC() *abnrm, $GENERIC() *bbnrm, $GENERIC() *rconde, $GENERIC() * |
| 1361 |
rcondv, $GENERIC() *work, integer *lwork, integer *iwork, logical * |
| 1362 |
bwork, integer *info); |
| 1363 |
$GENERIC() tmp_work; |
| 1364 |
if ($COMP(jobvl)) |
| 1365 |
pjobvl = \'V\'; |
| 1366 |
if ($COMP(jobvr)) |
| 1367 |
pjobvr = \'V\'; |
| 1368 |
|
| 1369 |
switch ($COMP(balanc)) |
| 1370 |
{ |
| 1371 |
case 1: pbalanc = \'P\'; |
| 1372 |
break; |
| 1373 |
case 2: pbalanc = \'S\'; |
| 1374 |
break; |
| 1375 |
case 3: pbalanc = \'B\'; |
| 1376 |
break; |
| 1377 |
default: pbalanc = \'N\'; |
| 1378 |
} |
| 1379 |
switch ($COMP(sense)) |
| 1380 |
{ |
| 1381 |
case 1: psens = \'E\'; |
| 1382 |
break; |
| 1383 |
case 2: psens = \'V\'; |
| 1384 |
break; |
| 1385 |
case 3: psens = \'B\'; |
| 1386 |
break; |
| 1387 |
default: psens = \'N\'; |
| 1388 |
} |
| 1389 |
|
| 1390 |
FORTRAN($TFD(s,d)ggevx)( |
| 1391 |
&pbalanc, |
| 1392 |
&pjobvl, |
| 1393 |
&pjobvr, |
| 1394 |
&psens, |
| 1395 |
&(integer){$SIZE(n)}, |
| 1396 |
$P(A), |
| 1397 |
&(integer){$SIZE(n)}, |
| 1398 |
$P(B), |
| 1399 |
&(integer){$SIZE(n)}, |
| 1400 |
$P(alphar), |
| 1401 |
$P(alphai), |
| 1402 |
$P(beta), |
| 1403 |
$P(VL), |
| 1404 |
&(integer){$SIZE(m)}, |
| 1405 |
$P(VR), |
| 1406 |
&(integer){$SIZE(p)}, |
| 1407 |
$P(ilo), |
| 1408 |
$P(ihi), |
| 1409 |
$P(lscale), |
| 1410 |
$P(rscale), |
| 1411 |
$P(abnrm), |
| 1412 |
$P(bbnrm), |
| 1413 |
$P(rconde), |
| 1414 |
$P(rcondv), |
| 1415 |
&tmp_work, |
| 1416 |
&lwork, |
| 1417 |
$P(iwork), |
| 1418 |
$P(bwork), |
| 1419 |
$P(info)); |
| 1420 |
|
| 1421 |
lwork = (integer )tmp_work; |
| 1422 |
{ |
| 1423 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 1424 |
FORTRAN($TFD(s,d)ggevx)( |
| 1425 |
&pbalanc, |
| 1426 |
&pjobvl, |
| 1427 |
&pjobvr, |
| 1428 |
&psens, |
| 1429 |
&(integer){$SIZE(n)}, |
| 1430 |
$P(A), |
| 1431 |
&(integer){$SIZE(n)}, |
| 1432 |
$P(B), |
| 1433 |
&(integer){$SIZE(n)}, |
| 1434 |
$P(alphar), |
| 1435 |
$P(alphai), |
| 1436 |
$P(beta), |
| 1437 |
$P(VL), |
| 1438 |
&(integer){$SIZE(m)}, |
| 1439 |
$P(VR), |
| 1440 |
&(integer){$SIZE(p)}, |
| 1441 |
$P(ilo), |
| 1442 |
$P(ihi), |
| 1443 |
$P(lscale), |
| 1444 |
$P(rscale), |
| 1445 |
$P(abnrm), |
| 1446 |
$P(bbnrm), |
| 1447 |
$P(rconde), |
| 1448 |
$P(rcondv), |
| 1449 |
work, |
| 1450 |
&lwork, |
| 1451 |
$P(iwork), |
| 1452 |
$P(bwork), |
| 1453 |
$P(info)); |
| 1454 |
free(work); |
| 1455 |
} |
| 1456 |
', |
| 1457 |
Doc => ' |
| 1458 |
=for ref |
| 1459 |
|
| 1460 |
Computes for a pair of N-by-N real nonsymmetric matrices (A,B) |
| 1461 |
the generalized eigenvalues, and optionally, the left and/or right |
| 1462 |
generalized eigenvectors. |
| 1463 |
|
| 1464 |
Optionally also, it computes a balancing transformation to improve |
| 1465 |
the conditioning of the eigenvalues and eigenvectors (ilo, ihi, |
| 1466 |
lscale, rscale, abnrm, and bbnrm), reciprocal condition numbers for |
| 1467 |
the eigenvalues (rconde), and reciprocal condition numbers for the |
| 1468 |
right eigenvectors (rcondv). |
| 1469 |
|
| 1470 |
A generalized eigenvalue for a pair of matrices (A,B) is a scalar |
| 1471 |
lambda or a ratio alpha/beta = lambda, such that A - lambda*B is |
| 1472 |
singular. It is usually represented as the pair (alpha,beta), as |
| 1473 |
there is a reasonable interpretation for beta=0, and even for both |
| 1474 |
being zero. |
| 1475 |
|
| 1476 |
The right eigenvector v(j) corresponding to the eigenvalue lambda(j) |
| 1477 |
of (A,B) satisfies |
| 1478 |
|
| 1479 |
A * v(j) = lambda(j) * B * v(j) . |
| 1480 |
|
| 1481 |
The left eigenvector u(j) corresponding to the eigenvalue lambda(j) |
| 1482 |
of (A,B) satisfies |
| 1483 |
|
| 1484 |
u(j)**H * A = lambda(j) * u(j)**H * B. |
| 1485 |
|
| 1486 |
where u(j)**H is the conjugate-transpose of u(j). |
| 1487 |
|
| 1488 |
Further Details |
| 1489 |
=============== |
| 1490 |
|
| 1491 |
Balancing a matrix pair (A,B) includes, first, permuting rows and |
| 1492 |
columns to isolate eigenvalues, second, applying diagonal similarity |
| 1493 |
transformation to the rows and columns to make the rows and columns |
| 1494 |
as close in norm as possible. The computed reciprocal condition |
| 1495 |
numbers correspond to the balanced matrix. Permuting rows and columns |
| 1496 |
will not change the condition numbers (in exact arithmetic) but |
| 1497 |
diagonal scaling will. For further explanation of balancing, see |
| 1498 |
section 4.11.1.2 of LAPACK Users\' Guide. |
| 1499 |
|
| 1500 |
An approximate error bound on the chordal distance between the i-th |
| 1501 |
computed generalized eigenvalue w and the corresponding exact |
| 1502 |
eigenvalue lambda is |
| 1503 |
|
| 1504 |
chord(w, lambda) <= EPS * norm(abnrm, bbnrm) / rconde(I) |
| 1505 |
|
| 1506 |
An approximate error bound for the angle between the i-th computed |
| 1507 |
eigenvector vl(i) or vr(i) is given by |
| 1508 |
|
| 1509 |
EPS * norm(abnrm, bbnrm) / DIF(i). |
| 1510 |
|
| 1511 |
For further explanation of the reciprocal condition numbers rconde |
| 1512 |
and rcondv, see section 4.11 of LAPACK User\'s Guide. |
| 1513 |
|
| 1514 |
|
| 1515 |
Arguments |
| 1516 |
========= |
| 1517 |
|
| 1518 |
balanc: Specifies the balance option to be performed. |
| 1519 |
= 0: do not diagonally scale or permute; |
| 1520 |
= 1: permute only; |
| 1521 |
= 2: scale only; |
| 1522 |
= 3: both permute and scale. |
| 1523 |
Computed reciprocal condition numbers will be for the |
| 1524 |
matrices after permuting and/or balancing. Permuting does |
| 1525 |
not change condition numbers (in exact arithmetic), but |
| 1526 |
balancing does. |
| 1527 |
|
| 1528 |
jobvl: = 0: do not compute the left generalized eigenvectors; |
| 1529 |
= 1: compute the left generalized eigenvectors. |
| 1530 |
|
| 1531 |
jobvr: = 0: do not compute the right generalized eigenvectors; |
| 1532 |
= 1: compute the right generalized eigenvectors. |
| 1533 |
|
| 1534 |
sense: Determines which reciprocal condition numbers are computed. |
| 1535 |
= 0: none are computed; |
| 1536 |
= 1: computed for eigenvalues only; |
| 1537 |
= 2: computed for eigenvectors only; |
| 1538 |
= 3: computed for eigenvalues and eigenvectors. |
| 1539 |
|
| 1540 |
A: On entry, the matrix A in the pair (A,B). |
| 1541 |
On exit, A has been overwritten. If jobvl=1 or jobvr=1 |
| 1542 |
or both, then A contains the first part of the real Schur |
| 1543 |
form of the "balanced" versions of the input A and B. |
| 1544 |
|
| 1545 |
B: On entry, the matrix B in the pair (A,B). |
| 1546 |
On exit, B has been overwritten. If jobvl=1 or jobvr=1 |
| 1547 |
or both, then B contains the second part of the real Schur |
| 1548 |
form of the "balanced" versions of the input A and B. |
| 1549 |
|
| 1550 |
alphar: |
| 1551 |
alphai: |
| 1552 |
beta: On exit, (alphar(j) + alphai(j)*i)/beta(j), j=1,...,N, will |
| 1553 |
be the generalized eigenvalues. If alphai(j) is zero, then |
| 1554 |
the j-th eigenvalue is real; if positive, then the j-th and |
| 1555 |
(j+1)-st eigenvalues are a complex conjugate pair, with |
| 1556 |
alphai(j+1) negative. |
| 1557 |
|
| 1558 |
Note: the quotients alphar(j)/beta(j) and alphai(j)/beta(j) |
| 1559 |
may easily over- or underflow, and beta(j) may even be zero. |
| 1560 |
Thus, the user should avoid naively computing the ratio |
| 1561 |
ALPHA/beta. However, alphar and alphai will be always less |
| 1562 |
than and usually comparable with norm(A) in magnitude, and |
| 1563 |
beta always less than and usually comparable with norm(B). |
| 1564 |
|
| 1565 |
vl: If jobvl = 1, the left eigenvectors u(j) are stored one |
| 1566 |
after another in the columns of vl, in the same order as |
| 1567 |
their eigenvalues. If the j-th eigenvalue is real, then |
| 1568 |
u(j) = vl(:,j), the j-th column of vl. If the j-th and |
| 1569 |
(j+1)-th eigenvalues form a complex conjugate pair, then |
| 1570 |
u(j) = vl(:,j)+i*vl(:,j+1) and u(j+1) = vl(:,j)-i*vl(:,j+1). |
| 1571 |
Each eigenvector will be scaled so the largest component have |
| 1572 |
abs(real part) + abs(imag. part) = 1. |
| 1573 |
Not referenced if jobvl = 0. |
| 1574 |
|
| 1575 |
vr: If jobvr = 1, the right eigenvectors v(j) are stored one |
| 1576 |
after another in the columns of vr, in the same order as |
| 1577 |
their eigenvalues. If the j-th eigenvalue is real, then |
| 1578 |
v(j) = vr(:,j), the j-th column of vr. If the j-th and |
| 1579 |
(j+1)-th eigenvalues form a complex conjugate pair, then |
| 1580 |
v(j) = vr(:,j)+i*vr(:,j+1) and v(j+1) = vr(:,j)-i*vr(:,j+1). |
| 1581 |
Each eigenvector will be scaled so the largest component have |
| 1582 |
abs(real part) + abs(imag. part) = 1. |
| 1583 |
Not referenced if jobvr = 0. |
| 1584 |
|
| 1585 |
ilo,ihi:ilo and ihi are integer values such that on exit |
| 1586 |
A(i,j) = 0 and B(i,j) = 0 if i > j and |
| 1587 |
j = 1,...,ilo-1 or i = ihi+1,...,N. |
| 1588 |
If balanc = 0 or 2, ilo = 1 and ihi = N. |
| 1589 |
|
| 1590 |
lscale: Details of the permutations and scaling factors applied |
| 1591 |
to the left side of A and B. If PL(j) is the index of the |
| 1592 |
row interchanged with row j, and DL(j) is the scaling |
| 1593 |
factor applied to row j, then |
| 1594 |
lscale(j) = PL(j) for j = 1,...,ilo-1 |
| 1595 |
= DL(j) for j = ilo,...,ihi |
| 1596 |
= PL(j) for j = ihi+1,...,N. |
| 1597 |
The order in which the interchanges are made is N to ihi+1, |
| 1598 |
then 1 to ilo-1. |
| 1599 |
|
| 1600 |
rscale: Details of the permutations and scaling factors applied |
| 1601 |
to the right side of A and B. If PR(j) is the index of the |
| 1602 |
column interchanged with column j, and DR(j) is the scaling |
| 1603 |
factor applied to column j, then |
| 1604 |
rscale(j) = PR(j) for j = 1,...,ilo-1 |
| 1605 |
= DR(j) for j = ilo,...,ihi |
| 1606 |
= PR(j) for j = ihi+1,...,N |
| 1607 |
The order in which the interchanges are made is N to ihi+1, |
| 1608 |
then 1 to ilo-1. |
| 1609 |
|
| 1610 |
abnrm: The one-norm of the balanced matrix A. |
| 1611 |
|
| 1612 |
bbnrm: The one-norm of the balanced matrix B. |
| 1613 |
|
| 1614 |
rconde: If sense = 1 or 3, the reciprocal condition numbers of |
| 1615 |
the selected eigenvalues, stored in consecutive elements of |
| 1616 |
the array. For a complex conjugate pair of eigenvalues two |
| 1617 |
consecutive elements of rconde are set to the same value. |
| 1618 |
Thus rconde(j), rcondv(j), and the j-th columns of vl and vr |
| 1619 |
all correspond to the same eigenpair (but not in general the |
| 1620 |
j-th eigenpair, unless all eigenpairs are selected). |
| 1621 |
If sense = 2, rconde is not referenced. |
| 1622 |
|
| 1623 |
rcondv: If sense = 2 or 3, the estimated reciprocal condition |
| 1624 |
numbers of the selected eigenvectors, stored in consecutive |
| 1625 |
elements of the array. For a complex eigenvector two |
| 1626 |
consecutive elements of rcondv are set to the same value. If |
| 1627 |
the eigenvalues cannot be reordered to compute rcondv(j), |
| 1628 |
rcondv(j) is set to 0; this can only occur when the true |
| 1629 |
value would be very small anyway. |
| 1630 |
If sense = 1, rcondv is not referenced. |
| 1631 |
|
| 1632 |
info: = 0: successful exit |
| 1633 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 1634 |
= 1,...,N: |
| 1635 |
The QZ iteration failed. No eigenvectors have been |
| 1636 |
calculated, but alphar(j), alphai(j), and beta(j) |
| 1637 |
should be correct for j=info+1,...,N. |
| 1638 |
> N: =N+1: other than QZ iteration failed in hgeqz. |
| 1639 |
=N+2: error return from tgevc. |
| 1640 |
|
| 1641 |
|
| 1642 |
=for example |
| 1643 |
|
| 1644 |
$a = random(5,5); |
| 1645 |
$b = random(5,5); |
| 1646 |
$alphar = zeroes(5); |
| 1647 |
$alphai = zeroes(5); |
| 1648 |
$beta = zeroes(5); |
| 1649 |
$vl = zeroes(5,5); |
| 1650 |
$vr = zeroes(5,5); |
| 1651 |
$lscale = zeroes(5); |
| 1652 |
$rscale = zeroes(5); |
| 1653 |
$ilo = null; |
| 1654 |
$ihi = null; |
| 1655 |
$abnrm = null; |
| 1656 |
$bbnrm = null; |
| 1657 |
$rconde = zeroes(5); |
| 1658 |
$rcondv = zeroes(5); |
| 1659 |
ggevx($a, 3, 1, 1, 3, $b, $alphar, $alphai, $beta, $vl, $vr, |
| 1660 |
$ilo, $ihi, $lscale, $rscale, $abnrm, $bbnrm, $rconde,$rcondv,($info=null)); |
| 1661 |
|
| 1662 |
'); |
| 1663 |
|
| 1664 |
pp_def("gees", |
| 1665 |
HandleBad => 0, |
| 1666 |
Pars => '[io]A(n,n); [o]wr(n); [o]wi(n); [o]vs(p,p); int [o]sdim(); int [o]info(); int [t]bwork(bworkn);', |
| 1667 |
OtherPars => 'int jobvs; int sort; SV* select_func', |
| 1668 |
ArgOrder => [qw{A jobvs sort select_func wr wi vs sdim info}], |
| 1669 |
RedoDimsCode => ' |
| 1670 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvs), tmp, $PDL(vs), $SIZE(p), $SIZE(n)) |
| 1671 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sort), tmp, $PDL(bwork), $SIZE(bworkn), $SIZE(n)) |
| 1672 |
', |
| 1673 |
GenericTypes => [F,D], |
| 1674 |
Code => generate_code ' |
| 1675 |
char jvs = \'N\'; |
| 1676 |
char psort = \'N\'; |
| 1677 |
integer lwork = -1; |
| 1678 |
|
| 1679 |
extern int FORTRAN($TFD(s,d)gees)(char *jobvs, char *sort, L_$TFD(f,d)p select, integer *n, |
| 1680 |
$GENERIC() *a, integer *lda, integer *sdim, $GENERIC() *wr, |
| 1681 |
$GENERIC() *wi, $GENERIC() *vs, integer *ldvs, $GENERIC() *work, |
| 1682 |
integer *lwork, logical *bwork, integer *info); |
| 1683 |
$GENERIC() tmp_work; |
| 1684 |
$TFD(f,d)select_func_set($COMP(select_func)); |
| 1685 |
|
| 1686 |
if ($COMP(jobvs)) |
| 1687 |
jvs = \'V\'; |
| 1688 |
if ($COMP(sort)){ |
| 1689 |
psort = \'S\'; |
| 1690 |
} |
| 1691 |
|
| 1692 |
FORTRAN($TFD(s,d)gees)( |
| 1693 |
&jvs, |
| 1694 |
&psort, |
| 1695 |
$TFD(f,d)select_wrapper, |
| 1696 |
&(integer){$SIZE(n)}, |
| 1697 |
$P(A), |
| 1698 |
&(integer){$SIZE(n)}, |
| 1699 |
$P(sdim), |
| 1700 |
$P(wr), |
| 1701 |
$P(wi), |
| 1702 |
$P(vs), |
| 1703 |
&(integer){$SIZE(p)}, |
| 1704 |
&tmp_work, |
| 1705 |
&lwork, |
| 1706 |
$P(bwork), |
| 1707 |
$P(info)); |
| 1708 |
lwork = (integer )tmp_work; |
| 1709 |
{ |
| 1710 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 1711 |
FORTRAN($TFD(s,d)gees)( |
| 1712 |
&jvs, |
| 1713 |
&psort, |
| 1714 |
$TFD(f,d)select_wrapper, |
| 1715 |
&(integer){$SIZE(n)}, |
| 1716 |
$P(A), |
| 1717 |
&(integer){$SIZE(n)}, |
| 1718 |
$P(sdim), |
| 1719 |
$P(wr), |
| 1720 |
$P(wi), |
| 1721 |
$P(vs), |
| 1722 |
&(integer){$SIZE(p)}, |
| 1723 |
work, |
| 1724 |
&lwork, |
| 1725 |
$P(bwork), |
| 1726 |
$P(info)); |
| 1727 |
free(work); |
| 1728 |
} |
| 1729 |
', |
| 1730 |
Doc => ' |
| 1731 |
|
| 1732 |
=for ref |
| 1733 |
|
| 1734 |
Computes for an N-by-N real nonsymmetric matrix A, the |
| 1735 |
eigenvalues, the real Schur form T, and, optionally, the matrix of |
| 1736 |
Schur vectors Z. This gives the Schur factorization A = Z*T*Z\'. |
| 1737 |
|
| 1738 |
Optionally, it also orders the eigenvalues on the diagonal of the |
| 1739 |
real Schur form so that selected eigenvalues are at the top left. |
| 1740 |
The leading columns of Z then form an orthonormal basis for the |
| 1741 |
invariant subspace corresponding to the selected eigenvalues. |
| 1742 |
|
| 1743 |
A matrix is in real Schur form if it is upper quasi-triangular with |
| 1744 |
1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in the |
| 1745 |
form |
| 1746 |
|
| 1747 |
[ a b ] |
| 1748 |
[ c a ] |
| 1749 |
where b*c < 0. |
| 1750 |
|
| 1751 |
The eigenvalues of such a block are a +- sqrt(bc). |
| 1752 |
|
| 1753 |
Arguments |
| 1754 |
========= |
| 1755 |
|
| 1756 |
jobvs: = 0: Schur vectors are not computed; |
| 1757 |
= 1: Schur vectors are computed. |
| 1758 |
|
| 1759 |
sort: Specifies whether or not to order the eigenvalues on the |
| 1760 |
diagonal of the Schur form. |
| 1761 |
= 0: Eigenvalues are not ordered; |
| 1762 |
= 1: Eigenvalues are ordered (see select_func). |
| 1763 |
|
| 1764 |
select_func: |
| 1765 |
If sort = 1, select_func is used to select eigenvalues to sort |
| 1766 |
to the top left of the Schur form. |
| 1767 |
If sort = 0, select_func is not referenced. |
| 1768 |
An eigenvalue wr(j)+sqrt(-1)*wi(j) is selected if |
| 1769 |
select_func(SCALAR(wr(j)), SCALAR(wi(j))) is true; i.e., |
| 1770 |
if either one of a complex conjugate pair of eigenvalues |
| 1771 |
is selected, then both complex eigenvalues are selected. |
| 1772 |
Note that a selected complex eigenvalue may no longer |
| 1773 |
satisfy select_func(wr(j),wi(j)) = 1 after ordering, since |
| 1774 |
ordering may change the value of complex eigenvalues |
| 1775 |
(especially if the eigenvalue is ill-conditioned); in this |
| 1776 |
case info is set to N+2 (see info below). |
| 1777 |
|
| 1778 |
A: The N-by-N matrix A. |
| 1779 |
On exit, A has been overwritten by its real Schur form T. |
| 1780 |
|
| 1781 |
sdim: If sort = 0, sdim = 0. |
| 1782 |
If sort = 1, sdim = number of eigenvalues (after sorting) |
| 1783 |
for which select_func is true. (Complex conjugate |
| 1784 |
pairs for which select_func is true for either |
| 1785 |
eigenvalue count as 2.) |
| 1786 |
|
| 1787 |
wr: |
| 1788 |
wi: wr and wi contain the real and imaginary parts, |
| 1789 |
respectively, of the computed eigenvalues in the same order |
| 1790 |
that they appear on the diagonal of the output Schur form T. |
| 1791 |
Complex conjugate pairs of eigenvalues will appear |
| 1792 |
consecutively with the eigenvalue having the positive |
| 1793 |
imaginary part first. |
| 1794 |
|
| 1795 |
vs: If jobvs = 1, vs contains the orthogonal matrix Z of Schur |
| 1796 |
vectors else vs is not referenced. |
| 1797 |
|
| 1798 |
info = 0: successful exit |
| 1799 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 1800 |
> 0: if info = i, and i is |
| 1801 |
<= N: the QR algorithm failed to compute all the |
| 1802 |
eigenvalues; elements 1:ILO-1 and i+1:N of wr and wi |
| 1803 |
contain those eigenvalues which have converged; if |
| 1804 |
jobvs = 1, vs contains the matrix which reduces A |
| 1805 |
to its partially converged Schur form. |
| 1806 |
= N+1: the eigenvalues could not be reordered because some |
| 1807 |
eigenvalues were too close to separate (the problem |
| 1808 |
is very ill-conditioned); |
| 1809 |
= N+2: after reordering, roundoff changed values of some |
| 1810 |
complex eigenvalues so that leading eigenvalues in |
| 1811 |
the Schur form no longer satisfy select_func = 1 This |
| 1812 |
could also be caused by underflow due to scaling. |
| 1813 |
|
| 1814 |
=for example |
| 1815 |
|
| 1816 |
sub select_function{ |
| 1817 |
my ($a, $b ) = @_; |
| 1818 |
# Stable "continuous time" eigenspace |
| 1819 |
return $a < 0 ? 1 : 0; |
| 1820 |
} |
| 1821 |
$A = random (5,5); |
| 1822 |
$wr= zeroes(5); |
| 1823 |
$wi = zeroes(5); |
| 1824 |
$vs = zeroes(5,5); |
| 1825 |
$sdim = null; |
| 1826 |
$info = null; |
| 1827 |
gees($A, 1,1, $wr, $wi, $vs, $sdim, $info,\&select_function); |
| 1828 |
|
| 1829 |
'); |
| 1830 |
|
| 1831 |
pp_def("geesx", |
| 1832 |
HandleBad => 0, |
| 1833 |
Pars => '[io]A(n,n); [o]wr(n); [o]wi(n); [o]vs(p,p); int [o]sdim(); [o]rconde();[o]rcondv(); int [o]info(); int [t]bwork(bworkn);', |
| 1834 |
OtherPars => 'int jobvs; int sort; int sense; SV* select_func', |
| 1835 |
ArgOrder => [qw{A jobvs sort sense select_func wr wi vs sdim rconde rcondv info}], |
| 1836 |
RedoDimsCode => ' |
| 1837 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvs), tmp, $PDL(vs), $SIZE(p), $SIZE(n)) |
| 1838 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sort), tmp, $PDL(bwork), $SIZE(bworkn), $SIZE(n)) |
| 1839 |
', |
| 1840 |
GenericTypes => [F,D], |
| 1841 |
Code => generate_code ' |
| 1842 |
char jvs = \'N\'; |
| 1843 |
char psort = \'N\'; |
| 1844 |
integer lwork = 0; |
| 1845 |
integer liwork = 1; |
| 1846 |
integer *iwork; |
| 1847 |
char sens; |
| 1848 |
extern int FORTRAN($TFD(s,d)geesx)(char *jobvs, char *sort, L_$TFD(f,d)p select, char * sense, |
| 1849 |
integer *n, $GENERIC() *a, integer *lda, integer *sdim, $GENERIC() *wr, |
| 1850 |
$GENERIC() *wi, $GENERIC() *vs, integer *ldvs, $GENERIC() *rconde, $GENERIC() *rcondv, |
| 1851 |
$GENERIC() *work, integer *lwork, integer *iwork, integer *liwork, |
| 1852 |
logical *bwork, integer *info); |
| 1853 |
$GENERIC() *work; |
| 1854 |
$TFD(f,d)select_func_set($COMP(select_func)); |
| 1855 |
if ($COMP(jobvs)) |
| 1856 |
jvs = \'V\'; |
| 1857 |
if ($COMP(sort)) |
| 1858 |
psort = \'S\'; |
| 1859 |
|
| 1860 |
switch ($COMP(sense)) |
| 1861 |
{ |
| 1862 |
case 1: sens = \'E\'; |
| 1863 |
lwork = (integer ) ($SIZE(n) + $SIZE(n) * ($SIZE(n)/2+1)); |
| 1864 |
iwork = (integer *) malloc (liwork * sizeof (integer)); |
| 1865 |
break; |
| 1866 |
case 2: sens = \'V\'; |
| 1867 |
lwork = (integer ) ($SIZE(n) + $SIZE(n) * ($SIZE(n)/2+1)); |
| 1868 |
if ($COMP(sort)){ |
| 1869 |
liwork = (integer )(pow((($SIZE(n)/2)+1), 2)); |
| 1870 |
iwork = (integer *) malloc (liwork * sizeof (integer)); |
| 1871 |
} |
| 1872 |
else{iwork = (integer *) malloc (liwork * sizeof (integer));} |
| 1873 |
break; |
| 1874 |
case 3: sens = \'B\'; |
| 1875 |
lwork = (integer ) ($SIZE(n) + $SIZE(n) * ($SIZE(n)/2+1)); |
| 1876 |
if ($COMP(sort)){ |
| 1877 |
liwork = (integer )(pow((($SIZE(n)/2)+1), 2)); |
| 1878 |
iwork = (integer *) malloc (liwork * sizeof (integer)); |
| 1879 |
} |
| 1880 |
else{iwork = (integer *) malloc (liwork * sizeof (integer));} |
| 1881 |
break; |
| 1882 |
default: sens = \'N\'; |
| 1883 |
lwork = (integer ) ($SIZE(n) * 3); |
| 1884 |
iwork = (integer *) malloc (liwork * sizeof (integer)); |
| 1885 |
|
| 1886 |
} |
| 1887 |
work = ($GENERIC() * )malloc(lwork * sizeof ($GENERIC())); |
| 1888 |
FORTRAN($TFD(s,d)geesx)( |
| 1889 |
&jvs, |
| 1890 |
&psort, |
| 1891 |
$TFD(f,d)select_wrapper, |
| 1892 |
&sens, |
| 1893 |
&(integer){$SIZE(n)}, |
| 1894 |
$P(A), |
| 1895 |
&(integer){$SIZE(n)}, |
| 1896 |
$P(sdim), |
| 1897 |
$P(wr), |
| 1898 |
$P(wi), |
| 1899 |
$P(vs), |
| 1900 |
&(integer){$SIZE(p)}, |
| 1901 |
$P(rconde), |
| 1902 |
$P(rcondv), |
| 1903 |
work, |
| 1904 |
&lwork, |
| 1905 |
iwork, |
| 1906 |
&liwork, |
| 1907 |
$P(bwork), |
| 1908 |
$P(info)); |
| 1909 |
|
| 1910 |
free(work); |
| 1911 |
free(iwork); |
| 1912 |
', |
| 1913 |
Doc => ' |
| 1914 |
|
| 1915 |
=for ref |
| 1916 |
|
| 1917 |
Computes for an N-by-N real nonsymmetric matrix A, the |
| 1918 |
eigenvalues, the real Schur form T, and, optionally, the matrix of |
| 1919 |
Schur vectors Z. This gives the Schur factorization A = Z*T*Z\'. |
| 1920 |
|
| 1921 |
Optionally, it also orders the eigenvalues on the diagonal of the |
| 1922 |
real Schur form so that selected eigenvalues are at the top left; |
| 1923 |
computes a reciprocal condition number for the average of the |
| 1924 |
selected eigenvalues (rconde); and computes a reciprocal condition |
| 1925 |
number for the right invariant subspace corresponding to the |
| 1926 |
selected eigenvalues (rcondv). The leading columns of Z form an |
| 1927 |
orthonormal basis for this invariant subspace. |
| 1928 |
|
| 1929 |
For further explanation of the reciprocal condition numbers rconde |
| 1930 |
and rcondv, see Section 4.10 of the LAPACK Users\' Guide (where |
| 1931 |
these quantities are called s and sep respectively). |
| 1932 |
|
| 1933 |
A real matrix is in real Schur form if it is upper quasi-triangular |
| 1934 |
with 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in |
| 1935 |
the form |
| 1936 |
|
| 1937 |
[ a b ] |
| 1938 |
[ c a ] |
| 1939 |
where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc). |
| 1940 |
|
| 1941 |
Arguments |
| 1942 |
========= |
| 1943 |
|
| 1944 |
jobvs: = 0: Schur vectors are not computed; |
| 1945 |
= 1: Schur vectors are computed. |
| 1946 |
|
| 1947 |
sort: Specifies whether or not to order the eigenvalues on the |
| 1948 |
diagonal of the Schur form. |
| 1949 |
= 0: Eigenvalues are not ordered; |
| 1950 |
= 1: Eigenvalues are ordered (see select_func). |
| 1951 |
|
| 1952 |
select_func: |
| 1953 |
If sort = 1, select_func is used to select eigenvalues to sort |
| 1954 |
to the top left of the Schur form else select_func is not referenced. |
| 1955 |
An eigenvalue wr(j)+sqrt(-1)*wi(j) is selected if |
| 1956 |
select_func(wr(j),wi(j)) is true; i.e., if either one of a |
| 1957 |
complex conjugate pair of eigenvalues is selected, then both |
| 1958 |
are. Note that a selected complex eigenvalue may no longer |
| 1959 |
satisfy select_func(wr(j),wi(j)) = 1 after ordering, since |
| 1960 |
ordering may change the value of complex eigenvalues |
| 1961 |
(especially if the eigenvalue is ill-conditioned); in this |
| 1962 |
case info may be set to N+3 (see info below). |
| 1963 |
|
| 1964 |
sense: Determines which reciprocal condition numbers are computed. |
| 1965 |
= 0: None are computed; |
| 1966 |
= 1: Computed for average of selected eigenvalues only; |
| 1967 |
= 2: Computed for selected right invariant subspace only; |
| 1968 |
= 3: Computed for both. |
| 1969 |
If sense = 1, 2 or 3, sort must equal 1. |
| 1970 |
|
| 1971 |
A: On entry, the N-by-N matrix A. |
| 1972 |
On exit, A is overwritten by its real Schur form T. |
| 1973 |
|
| 1974 |
sdim: If sort = 0, sdim = 0. |
| 1975 |
If sort = 1, sdim = number of eigenvalues (after sorting) |
| 1976 |
for which select_func is 1. (Complex conjugate |
| 1977 |
pairs for which select_func is 1 for either |
| 1978 |
eigenvalue count as 2.) |
| 1979 |
|
| 1980 |
wr: |
| 1981 |
wi: wr and wi contain the real and imaginary parts, respectively, |
| 1982 |
of the computed eigenvalues, in the same order that they |
| 1983 |
appear on the diagonal of the output Schur form T. Complex |
| 1984 |
conjugate pairs of eigenvalues appear consecutively with the |
| 1985 |
eigenvalue having the positive imaginary part first. |
| 1986 |
|
| 1987 |
vs If jobvs = 1, vs contains the orthogonal matrix Z of Schur |
| 1988 |
vectors else vs is not referenced. |
| 1989 |
|
| 1990 |
rconde: If sense = 1 or 3, rconde contains the reciprocal |
| 1991 |
condition number for the average of the selected eigenvalues. |
| 1992 |
Not referenced if sense = 0 or 2. |
| 1993 |
|
| 1994 |
rcondv: If sense = 2 or 3, rcondv contains the reciprocal |
| 1995 |
condition number for the selected right invariant subspace. |
| 1996 |
Not referenced if sense = 0 or 1. |
| 1997 |
|
| 1998 |
info: = 0: successful exit |
| 1999 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 2000 |
> 0: if info = i, and i is |
| 2001 |
<= N: the QR algorithm failed to compute all the |
| 2002 |
eigenvalues; elements 1:ilo-1 and i+1:N of wr and wi |
| 2003 |
contain those eigenvalues which have converged; if |
| 2004 |
jobvs = 1, vs contains the transformation which |
| 2005 |
reduces A to its partially converged Schur form. |
| 2006 |
= N+1: the eigenvalues could not be reordered because some |
| 2007 |
eigenvalues were too close to separate (the problem |
| 2008 |
is very ill-conditioned); |
| 2009 |
= N+2: after reordering, roundoff changed values of some |
| 2010 |
complex eigenvalues so that leading eigenvalues in |
| 2011 |
the Schur form no longer satisfy select_func=1 This |
| 2012 |
could also be caused by underflow due to scaling. |
| 2013 |
|
| 2014 |
=for example |
| 2015 |
|
| 2016 |
sub select_function{ |
| 2017 |
my ($a, $b) = @_; |
| 2018 |
# Stable "discrete time" eigenspace |
| 2019 |
return sqrt($a**2 + $b**2) < 1 ? 1 : 0; |
| 2020 |
} |
| 2021 |
$A = random (5,5); |
| 2022 |
$wr= zeroes(5); |
| 2023 |
$wi = zeroes(5); |
| 2024 |
$vs = zeroes(5,5); |
| 2025 |
$sdim = null; |
| 2026 |
$rconde = null; |
| 2027 |
$rcondv = null; |
| 2028 |
$info = null; |
| 2029 |
geesx($A, 1,1, 3, $wr, $wi, $vs, $sdim, $rconde, $rcondv, $info, \&select_function); |
| 2030 |
|
| 2031 |
'); |
| 2032 |
|
| 2033 |
pp_def("gges", |
| 2034 |
HandleBad => 0, |
| 2035 |
Pars => '[io]A(n,n);[io]B(n,n);[o]alphar(n);[o]alphai(n);[o]beta(n);[o]VSL(m,m);[o]VSR(p,p);int [o]sdim();int [o]info(); int [t]bwork(bworkn);', |
| 2036 |
OtherPars => 'int jobvsl; int jobvsr; int sort; SV* select_func', |
| 2037 |
ArgOrder => [qw{A jobvsl jobvsr sort B select_func alphar alphai beta VSL VSR sdim info}], |
| 2038 |
RedoDimsCode => ' |
| 2039 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvsl), tmp, $PDL(VSL), $SIZE(m), $SIZE(n)) |
| 2040 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvsr), tmp, $PDL(VSR), $SIZE(p), $SIZE(n)) |
| 2041 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sort), tmp, $PDL(bwork), $SIZE(bworkn), $SIZE(n)) |
| 2042 |
', |
| 2043 |
GenericTypes => [F,D], |
| 2044 |
Code => generate_code ' |
| 2045 |
integer lwork = -1; |
| 2046 |
char pjobvsl = \'N\', pjobvsr = \'N\', psort = \'N\'; |
| 2047 |
extern int FORTRAN($TFD(s,d)gges)(char *jobvsl, char *jobvsr, char *sort, L_$TFD(f,d)gp |
| 2048 |
delctg, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *b, |
| 2049 |
integer *ldb, integer *sdim, $GENERIC() *alphar, $GENERIC() *alphai, |
| 2050 |
$GENERIC() *beta, $GENERIC() *vsl, integer *ldvsl, $GENERIC() *vsr, |
| 2051 |
integer *ldvsr, $GENERIC() *work, integer *lwork, logical *bwork, |
| 2052 |
integer *info); |
| 2053 |
$GENERIC() tmp_work; |
| 2054 |
$TFD(f,d)gselect_func_set($COMP(select_func)); |
| 2055 |
if ($COMP(jobvsl)) |
| 2056 |
pjobvsl = \'V\'; |
| 2057 |
if ($COMP(jobvsr)) |
| 2058 |
pjobvsr = \'V\'; |
| 2059 |
if ($COMP(sort)){ |
| 2060 |
psort = \'S\'; |
| 2061 |
} |
| 2062 |
FORTRAN($TFD(s,d)gges)( |
| 2063 |
&pjobvsl, |
| 2064 |
&pjobvsr, |
| 2065 |
&psort, |
| 2066 |
$TFD(f,d)gselect_wrapper, |
| 2067 |
&(integer){$SIZE(n)}, |
| 2068 |
$P(A), |
| 2069 |
&(integer){$SIZE(n)}, |
| 2070 |
$P(B), |
| 2071 |
&(integer){$SIZE(n)}, |
| 2072 |
$P(sdim), |
| 2073 |
$P(alphar), |
| 2074 |
$P(alphai), |
| 2075 |
$P(beta), |
| 2076 |
$P(VSL), |
| 2077 |
&(integer){$SIZE(m)}, |
| 2078 |
$P(VSR), |
| 2079 |
&(integer){$SIZE(p)}, |
| 2080 |
&tmp_work, |
| 2081 |
&lwork, |
| 2082 |
$P(bwork), |
| 2083 |
$P(info)); |
| 2084 |
|
| 2085 |
lwork = (integer )tmp_work; |
| 2086 |
{ |
| 2087 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2088 |
FORTRAN($TFD(s,d)gges)( |
| 2089 |
&pjobvsl, |
| 2090 |
&pjobvsr, |
| 2091 |
&psort, |
| 2092 |
$TFD(f,d)gselect_wrapper, |
| 2093 |
&(integer){$SIZE(n)}, |
| 2094 |
$P(A), |
| 2095 |
&(integer){$SIZE(n)}, |
| 2096 |
$P(B), |
| 2097 |
&(integer){$SIZE(n)}, |
| 2098 |
$P(sdim), |
| 2099 |
$P(alphar), |
| 2100 |
$P(alphai), |
| 2101 |
$P(beta), |
| 2102 |
$P(VSL), |
| 2103 |
&(integer){$SIZE(m)}, |
| 2104 |
$P(VSR), |
| 2105 |
&(integer){$SIZE(p)}, |
| 2106 |
work, |
| 2107 |
&lwork, |
| 2108 |
$P(bwork), |
| 2109 |
$P(info)); |
| 2110 |
free(work); |
| 2111 |
} |
| 2112 |
', |
| 2113 |
Doc => ' |
| 2114 |
|
| 2115 |
=for ref |
| 2116 |
|
| 2117 |
Computes for a pair of N-by-N real nonsymmetric matrices (A,B), |
| 2118 |
the generalized eigenvalues, the generalized real Schur form (S,T), |
| 2119 |
optionally, the left and/or right matrices of Schur vectors (VSL and |
| 2120 |
VSR). This gives the generalized Schur factorization |
| 2121 |
|
| 2122 |
(A,B) = ( (VSL)*S*(VSR)\', (VSL)*T*(VSR)\' ) |
| 2123 |
|
| 2124 |
Optionally, it also orders the eigenvalues so that a selected cluster |
| 2125 |
of eigenvalues appears in the leading diagonal blocks of the upper |
| 2126 |
quasi-triangular matrix S and the upper triangular matrix T.The |
| 2127 |
leading columns of VSL and VSR then form an orthonormal basis for the |
| 2128 |
corresponding left and right eigenspaces (deflating subspaces). |
| 2129 |
|
| 2130 |
(If only the generalized eigenvalues are needed, use the driver |
| 2131 |
ggev instead, which is faster.) |
| 2132 |
|
| 2133 |
A generalized eigenvalue for a pair of matrices (A,B) is a scalar w |
| 2134 |
or a ratio alpha/beta = w, such that A - w*B is singular. It is |
| 2135 |
usually represented as the pair (alpha,beta), as there is a |
| 2136 |
reasonable interpretation for beta=0 or both being zero. |
| 2137 |
|
| 2138 |
A pair of matrices (S,T) is in generalized real Schur form if T is |
| 2139 |
upper triangular with non-negative diagonal and S is block upper |
| 2140 |
triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond |
| 2141 |
to real generalized eigenvalues, while 2-by-2 blocks of S will be |
| 2142 |
"standardized" by making the corresponding elements of T have the |
| 2143 |
form: |
| 2144 |
|
| 2145 |
[ a 0 ] |
| 2146 |
[ 0 b ] |
| 2147 |
|
| 2148 |
and the pair of corresponding 2-by-2 blocks in S and T will have a |
| 2149 |
complex conjugate pair of generalized eigenvalues. |
| 2150 |
|
| 2151 |
|
| 2152 |
Arguments |
| 2153 |
========= |
| 2154 |
|
| 2155 |
jobvsl: = 0: do not compute the left Schur vectors; |
| 2156 |
= 1: compute the left Schur vectors. |
| 2157 |
|
| 2158 |
jobvsr: = 0: do not compute the right Schur vectors; |
| 2159 |
= 1: compute the right Schur vectors. |
| 2160 |
|
| 2161 |
sort: Specifies whether or not to order the eigenvalues on the |
| 2162 |
diagonal of the generalized Schur form. |
| 2163 |
= 0: Eigenvalues are not ordered; |
| 2164 |
= 1: Eigenvalues are ordered (see delztg); |
| 2165 |
|
| 2166 |
delztg: If sort = 0, delztg is not referenced. |
| 2167 |
If sort = 1, delztg is used to select eigenvalues to sort |
| 2168 |
to the top left of the Schur form. |
| 2169 |
An eigenvalue (alphar(j)+alphai(j))/beta(j) is selected if |
| 2170 |
delztg(alphar(j),alphai(j),beta(j)) is true; i.e. if either |
| 2171 |
one of a complex conjugate pair of eigenvalues is selected, |
| 2172 |
then both complex eigenvalues are selected. |
| 2173 |
|
| 2174 |
Note that in the ill-conditioned case, a selected complex |
| 2175 |
eigenvalue may no longer satisfy delztg(alphar(j),alphai(j), |
| 2176 |
beta(j)) = 1 after ordering. info is to be set to N+2 |
| 2177 |
in this case. |
| 2178 |
|
| 2179 |
A: On entry, the first of the pair of matrices. |
| 2180 |
On exit, A has been overwritten by its generalized Schur |
| 2181 |
form S. |
| 2182 |
|
| 2183 |
B: On entry, the second of the pair of matrices. |
| 2184 |
On exit, B has been overwritten by its generalized Schur |
| 2185 |
form T. |
| 2186 |
|
| 2187 |
sdim: If sort = 0, sdim = 0. |
| 2188 |
If sort = 1, sdim = number of eigenvalues (after sorting) |
| 2189 |
for which delztg is true. (Complex conjugate pairs for which |
| 2190 |
delztg is true for either eigenvalue count as 2.) |
| 2191 |
|
| 2192 |
alphar: |
| 2193 |
alphai: |
| 2194 |
beta: On exit, (alphar(j) + alphai(j)*i)/beta(j), j=1,...,N, will |
| 2195 |
be the generalized eigenvalues. alphar(j) + alphai(j)*i, |
| 2196 |
and beta(j),j=1,...,N are the diagonals of the complex Schur |
| 2197 |
form (S,T) that would result if the 2-by-2 diagonal blocks of |
| 2198 |
the real Schur form of (A,B) were further reduced to |
| 2199 |
triangular form using 2-by-2 complex unitary transformations. |
| 2200 |
If alphai(j) is zero, then the j-th eigenvalue is real; if |
| 2201 |
positive, then the j-th and (j+1)-st eigenvalues are a |
| 2202 |
complex conjugate pair, with alphai(j+1) negative. |
| 2203 |
|
| 2204 |
Note: the quotients alphar(j)/beta(j) and alphai(j)/beta(j) |
| 2205 |
may easily over- or underflow, and beta(j) may even be zero. |
| 2206 |
Thus, the user should avoid naively computing the ratio. |
| 2207 |
However, alphar and alphai will be always less than and |
| 2208 |
usually comparable with norm(A) in magnitude, and beta always |
| 2209 |
less than and usually comparable with norm(B). |
| 2210 |
|
| 2211 |
VSL: If jobvsl = 1, VSL will contain the left Schur vectors. |
| 2212 |
Not referenced if jobvsl = 0. |
| 2213 |
The leading dimension must always be >=1. |
| 2214 |
|
| 2215 |
VSR: If jobvsr = 1, VSR will contain the right Schur vectors. |
| 2216 |
Not referenced if jobvsr = 0. |
| 2217 |
The leading dimension must always be >=1. |
| 2218 |
|
| 2219 |
info: = 0: successful exit |
| 2220 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 2221 |
= 1,...,N: |
| 2222 |
The QZ iteration failed. (A,B) are not in Schur |
| 2223 |
form, but alphar(j), alphai(j), and beta(j) should |
| 2224 |
be correct for j=info+1,...,N. |
| 2225 |
> N: =N+1: other than QZ iteration failed in hgeqz. |
| 2226 |
=N+2: after reordering, roundoff changed values of |
| 2227 |
some complex eigenvalues so that leading |
| 2228 |
eigenvalues in the Generalized Schur form no |
| 2229 |
longer satisfy delztg=1 This could also |
| 2230 |
be caused due to scaling. |
| 2231 |
=N+3: reordering failed in tgsen. |
| 2232 |
|
| 2233 |
|
| 2234 |
=for example |
| 2235 |
|
| 2236 |
sub my_select{ |
| 2237 |
my ($zr, $zi, $d) = @_; |
| 2238 |
# stable generalized eigenvalues for continuous time |
| 2239 |
return ( ($zr < 0 && $d > 0 ) || ($zr > 0 && $d < 0) ) ? 1 : 0; |
| 2240 |
} |
| 2241 |
$a = random(5,5); |
| 2242 |
$b = random(5,5); |
| 2243 |
$sdim = null; |
| 2244 |
$alphar = zeroes(5); |
| 2245 |
$alphai = zeroes(5); |
| 2246 |
$beta = zeroes(5); |
| 2247 |
$vsl = zeroes(5,5); |
| 2248 |
$vsr = zeroes(5,5); |
| 2249 |
gges($a, 1, 1, 1, $b, $alphar, $alphai, $beta, $vsl, $vsr, $sdim,($info=null), \&my_select); |
| 2250 |
|
| 2251 |
'); |
| 2252 |
|
| 2253 |
pp_def("ggesx", |
| 2254 |
HandleBad => 0, |
| 2255 |
Pars => '[io]A(n,n);[io]B(n,n);[o]alphar(n);[o]alphai(n);[o]beta(n);[o]VSL(m,m);[o]VSR(p,p);int [o]sdim();[o]rconde(q=2);[o]rcondv(q=2);int [o]info(); int [t]bwork(bworkn); int [t]iwork(iworkn);', |
| 2256 |
OtherPars => 'int jobvsl; int jobvsr; int sort; int sense; SV* select_func', |
| 2257 |
ArgOrder => [qw{A jobvsl jobvsr sort sense B select_func alphar alphai beta VSL VSR sdim rconde rcondv info}], |
| 2258 |
RedoDimsCode => ' |
| 2259 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvsl), tmp, $PDL(VSL), $SIZE(m), $SIZE(n)) |
| 2260 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobvsr), tmp, $PDL(VSR), $SIZE(p), $SIZE(n)) |
| 2261 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(sort), tmp, $PDL(bwork), $SIZE(bworkn), $SIZE(n)) |
| 2262 |
$SIZE(iworkn) = $SIZE(n) + 6; // Bug in Lapack ????? |
| 2263 |
', |
| 2264 |
GenericTypes => [F,D], |
| 2265 |
Code => generate_code ' |
| 2266 |
integer maxwrk, lwork; |
| 2267 |
integer minwrk = 1; |
| 2268 |
static integer c__0 = 0; |
| 2269 |
static integer c__1 = 1; |
| 2270 |
static integer c_n1 = -1; |
| 2271 |
char pjobvsl = \'N\'; |
| 2272 |
char pjobvsr = \'N\'; |
| 2273 |
char psort = \'N\'; |
| 2274 |
char psens = \'N\'; |
| 2275 |
integer *iwork; |
| 2276 |
extern int FORTRAN($TFD(s,d)ggesx)(char *jobvsl, char *jobvsr, char *sort, L_$TFD(f,d)gp |
| 2277 |
delctg, char *sense, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *b, |
| 2278 |
integer *ldb, integer *sdim, $GENERIC() *alphar, $GENERIC() *alphai, |
| 2279 |
$GENERIC() *beta, $GENERIC() *vsl, integer *ldvsl, $GENERIC() *vsr, |
| 2280 |
integer *ldvsr, $GENERIC() *rconde, $GENERIC() *rcondv, $GENERIC() *work, |
| 2281 |
integer *lwork, integer *iwork, integer *liwork, logical *bwork, |
| 2282 |
integer *info); |
| 2283 |
$TFD(f,d)gselect_func_set($COMP(select_func)); |
| 2284 |
if ($COMP(jobvsr)) |
| 2285 |
pjobvsr = \'V\'; |
| 2286 |
|
| 2287 |
if ($COMP(sort)){ |
| 2288 |
psort = \'S\'; |
| 2289 |
} |
| 2290 |
|
| 2291 |
switch ($COMP(sense)) |
| 2292 |
{ |
| 2293 |
case 1: psens = \'E\'; |
| 2294 |
break; |
| 2295 |
case 2: psens = \'V\'; |
| 2296 |
break; |
| 2297 |
case 3: psens = \'B\'; |
| 2298 |
break; |
| 2299 |
default: psens = \'N\'; |
| 2300 |
} |
| 2301 |
|
| 2302 |
// Code modified from Lapack |
| 2303 |
// TODO other schur form above |
| 2304 |
// The actual updated release (clapack 09/20/2000) do not allow |
| 2305 |
// querying the workspace. See release notes of Lapack |
| 2306 |
// for this feature. |
| 2307 |
|
| 2308 |
minwrk = (($SIZE(n) + 1) << 3) + 16; |
| 2309 |
maxwrk = ($SIZE(n) + 1) * 7 + $SIZE(n) * (integer)FORTRAN(ilaenv)(&c__1, "DGEQRF", " ", &(integer){$SIZE(n)}, &c__1, |
| 2310 |
&(integer){$SIZE(n)}, &c__0, (ftnlen)6, (ftnlen)1) + 16; |
| 2311 |
|
| 2312 |
if ($COMP(jobvsl)) |
| 2313 |
{ |
| 2314 |
integer i__1 = maxwrk; |
| 2315 |
integer i__2 = minwrk + $SIZE(n) * (integer)FORTRAN(ilaenv)(&c__1, "DORGQR" |
| 2316 |
, " ", &(integer){$SIZE(n)}, &c__1, &(integer){$SIZE(n)}, &c_n1, (ftnlen)6, (ftnlen)1); |
| 2317 |
maxwrk = (integer ) PDLMAX(i__1,i__2); |
| 2318 |
pjobvsl = \'V\'; |
| 2319 |
} |
| 2320 |
lwork = (integer ) PDLMAX(maxwrk,minwrk); |
| 2321 |
|
| 2322 |
{ |
| 2323 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2324 |
FORTRAN($TFD(s,d)ggesx)( |
| 2325 |
&pjobvsl, |
| 2326 |
&pjobvsr, |
| 2327 |
&psort, |
| 2328 |
$TFD(f,d)gselect_wrapper, |
| 2329 |
&psens, |
| 2330 |
&(integer){$SIZE(n)}, |
| 2331 |
$P(A), |
| 2332 |
&(integer){$SIZE(n)}, |
| 2333 |
$P(B), |
| 2334 |
&(integer){$SIZE(n)}, |
| 2335 |
$P(sdim), |
| 2336 |
$P(alphar), |
| 2337 |
$P(alphai), |
| 2338 |
$P(beta), |
| 2339 |
$P(VSL), |
| 2340 |
&(integer){$SIZE(m)}, |
| 2341 |
$P(VSR), |
| 2342 |
&(integer){$SIZE(p)}, |
| 2343 |
$P(rconde), |
| 2344 |
$P(rcondv), |
| 2345 |
work, |
| 2346 |
&lwork, |
| 2347 |
$P(iwork), |
| 2348 |
&(integer){$SIZE(iworkn)}, |
| 2349 |
$P(bwork), |
| 2350 |
$P(info)); |
| 2351 |
free(work); |
| 2352 |
} |
| 2353 |
', |
| 2354 |
Doc => ' |
| 2355 |
|
| 2356 |
=for ref |
| 2357 |
|
| 2358 |
Computes for a pair of N-by-N real nonsymmetric matrices |
| 2359 |
(A,B), the generalized eigenvalues, the real Schur form (S,T), and, |
| 2360 |
optionally, the left and/or right matrices of Schur vectors (VSL and |
| 2361 |
VSR). This gives the generalized Schur factorization |
| 2362 |
|
| 2363 |
(A,B) = ( (VSL) S (VSR)\', (VSL) T (VSR)\' ) |
| 2364 |
|
| 2365 |
Optionally, it also orders the eigenvalues so that a selected cluster |
| 2366 |
of eigenvalues appears in the leading diagonal blocks of the upper |
| 2367 |
quasi-triangular matrix S and the upper triangular matrix T; computes |
| 2368 |
a reciprocal condition number for the average of the selected |
| 2369 |
eigenvalues (RCONDE); and computes a reciprocal condition number for |
| 2370 |
the right and left deflating subspaces corresponding to the selected |
| 2371 |
eigenvalues (RCONDV). The leading columns of VSL and VSR then form |
| 2372 |
an orthonormal basis for the corresponding left and right eigenspaces |
| 2373 |
(deflating subspaces). |
| 2374 |
|
| 2375 |
A generalized eigenvalue for a pair of matrices (A,B) is a scalar w |
| 2376 |
or a ratio alpha/beta = w, such that A - w*B is singular. It is |
| 2377 |
usually represented as the pair (alpha,beta), as there is a |
| 2378 |
reasonable interpretation for beta=0 or for both being zero. |
| 2379 |
|
| 2380 |
A pair of matrices (S,T) is in generalized real Schur form if T is |
| 2381 |
upper triangular with non-negative diagonal and S is block upper |
| 2382 |
triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond |
| 2383 |
to real generalized eigenvalues, while 2-by-2 blocks of S will be |
| 2384 |
"standardized" by making the corresponding elements of T have the |
| 2385 |
form: |
| 2386 |
|
| 2387 |
[ a 0 ] |
| 2388 |
[ 0 b ] |
| 2389 |
|
| 2390 |
and the pair of corresponding 2-by-2 blocks in S and T will have a |
| 2391 |
complex conjugate pair of generalized eigenvalues. |
| 2392 |
|
| 2393 |
Further details |
| 2394 |
=============== |
| 2395 |
|
| 2396 |
An approximate (asymptotic) bound on the average absolute error of |
| 2397 |
the selected eigenvalues is |
| 2398 |
|
| 2399 |
EPS * norm((A, B)) / RCONDE( 1 ). |
| 2400 |
|
| 2401 |
An approximate (asymptotic) bound on the maximum angular error in |
| 2402 |
the computed deflating subspaces is |
| 2403 |
|
| 2404 |
EPS * norm((A, B)) / RCONDV( 2 ). |
| 2405 |
|
| 2406 |
See LAPACK User\'s Guide, section 4.11 for more information. |
| 2407 |
|
| 2408 |
|
| 2409 |
Arguments |
| 2410 |
========= |
| 2411 |
|
| 2412 |
jobvsl: = 0: do not compute the left Schur vectors; |
| 2413 |
= 1: compute the left Schur vectors. |
| 2414 |
|
| 2415 |
jobvsr: = 0: do not compute the right Schur vectors; |
| 2416 |
= 1: compute the right Schur vectors. |
| 2417 |
|
| 2418 |
sort: Specifies whether or not to order the eigenvalues on the |
| 2419 |
diagonal of the generalized Schur form. |
| 2420 |
= 0: Eigenvalues are not ordered; |
| 2421 |
= 1: Eigenvalues are ordered (see delztg); |
| 2422 |
|
| 2423 |
delztg: If sort = 0, delztg is not referenced. |
| 2424 |
If sort = 1, delztg is used to select eigenvalues to sort |
| 2425 |
to the top left of the Schur form. |
| 2426 |
An eigenvalue (alphar(j)+alphai(j))/beta(j) is selected if |
| 2427 |
delztg(alphar(j),alphai(j),beta(j)) is true; i.e. if either |
| 2428 |
one of a complex conjugate pair of eigenvalues is selected, |
| 2429 |
then both complex eigenvalues are selected. |
| 2430 |
|
| 2431 |
Note that in the ill-conditioned case, a selected complex |
| 2432 |
eigenvalue may no longer satisfy delztg(alphar(j),alphai(j), |
| 2433 |
beta(j)) = 1 after ordering. info is to be set to N+2 |
| 2434 |
in this case. |
| 2435 |
|
| 2436 |
sense: Determines which reciprocal condition numbers are computed. |
| 2437 |
= 0 : None are computed; |
| 2438 |
= 1 : Computed for average of selected eigenvalues only; |
| 2439 |
= 2 : Computed for selected deflating subspaces only; |
| 2440 |
= 3 : Computed for both. |
| 2441 |
If sense = 1, 2, or 3, sort must equal 1. |
| 2442 |
|
| 2443 |
A: On entry, the first of the pair of matrices. |
| 2444 |
On exit, A has been overwritten by its generalized Schur |
| 2445 |
form S. |
| 2446 |
|
| 2447 |
B: On entry, the second of the pair of matrices. |
| 2448 |
On exit, B has been overwritten by its generalized Schur |
| 2449 |
form T. |
| 2450 |
|
| 2451 |
sdim: If sort = 0, sdim = 0. |
| 2452 |
If sort = 1, sdim = number of eigenvalues (after sorting) |
| 2453 |
for which delztg is true. (Complex conjugate pairs for which |
| 2454 |
delztg is true for either eigenvalue count as 2.) |
| 2455 |
|
| 2456 |
alphar: |
| 2457 |
alphai: |
| 2458 |
beta: On exit, (alphar(j) + alphai(j)*i)/beta(j), j=1,...,N, will |
| 2459 |
be the generalized eigenvalues. alphar(j) + alphai(j)*i, |
| 2460 |
and beta(j),j=1,...,N are the diagonals of the complex Schur |
| 2461 |
form (S,T) that would result if the 2-by-2 diagonal blocks of |
| 2462 |
the real Schur form of (A,B) were further reduced to |
| 2463 |
triangular form using 2-by-2 complex unitary transformations. |
| 2464 |
If alphai(j) is zero, then the j-th eigenvalue is real; if |
| 2465 |
positive, then the j-th and (j+1)-st eigenvalues are a |
| 2466 |
complex conjugate pair, with alphai(j+1) negative. |
| 2467 |
|
| 2468 |
Note: the quotients alphar(j)/beta(j) and alphai(j)/beta(j) |
| 2469 |
may easily over- or underflow, and beta(j) may even be zero. |
| 2470 |
Thus, the user should avoid naively computing the ratio. |
| 2471 |
However, alphar and alphai will be always less than and |
| 2472 |
usually comparable with norm(A) in magnitude, and beta always |
| 2473 |
less than and usually comparable with norm(B). |
| 2474 |
|
| 2475 |
VSL: If jobvsl = 1, VSL will contain the left Schur vectors. |
| 2476 |
Not referenced if jobvsl = 0. |
| 2477 |
The leading dimension must always be >=1. |
| 2478 |
|
| 2479 |
VSR: If jobvsr = 1, VSR will contain the right Schur vectors. |
| 2480 |
Not referenced if jobvsr = 0. |
| 2481 |
The leading dimension must always be >=1. |
| 2482 |
|
| 2483 |
rconde: If sense = 1 or 3, rconde(1) and rconde(2) contain the |
| 2484 |
reciprocal condition numbers for the average of the selected |
| 2485 |
eigenvalues. |
| 2486 |
Not referenced if sense = 0 or 2. |
| 2487 |
|
| 2488 |
rcondv: If sense = 2 or 3, rcondv(1) and rcondv(2) contain the |
| 2489 |
reciprocal condition numbers for the selected deflating |
| 2490 |
subspaces. |
| 2491 |
Not referenced if sense = 0 or 1. |
| 2492 |
|
| 2493 |
info: = 0: successful exit |
| 2494 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 2495 |
= 1,...,N: |
| 2496 |
The QZ iteration failed. (A,B) are not in Schur |
| 2497 |
form, but alphar(j), alphai(j), and beta(j) should |
| 2498 |
be correct for j=info+1,...,N. |
| 2499 |
> N: =N+1: other than QZ iteration failed in hgeqz. |
| 2500 |
=N+2: after reordering, roundoff changed values of |
| 2501 |
some complex eigenvalues so that leading |
| 2502 |
eigenvalues in the Generalized Schur form no |
| 2503 |
longer satisfy delztg=1 This could also |
| 2504 |
be caused due to scaling. |
| 2505 |
=N+3: reordering failed in tgsen. |
| 2506 |
|
| 2507 |
|
| 2508 |
=for example |
| 2509 |
|
| 2510 |
sub my_select{ |
| 2511 |
my ($zr, $zi, $d) = @_; |
| 2512 |
# Eigenvalue : (ZR/D) + sqrt(-1)*(ZI/D) |
| 2513 |
# stable generalized eigenvalues for discrete time |
| 2514 |
return (sqrt($zr**2 + $zi**2) < abs($d) ) ? 1 : 0; |
| 2515 |
|
| 2516 |
} |
| 2517 |
$a = random(5,5); |
| 2518 |
$b = random(5,5); |
| 2519 |
$sdim = null; |
| 2520 |
$alphar = zeroes(5); |
| 2521 |
$alphai = zeroes(5); |
| 2522 |
$beta = zeroes(5); |
| 2523 |
$vsl = zeroes(5,5); |
| 2524 |
$vsr = zeroes(5,5); |
| 2525 |
$rconde = zeroes(2); |
| 2526 |
$rcondv = zeroes(2); |
| 2527 |
ggesx($a, 1, 1, 1, 3,$b, $alphar, $alphai, $beta, $vsl, $vsr, $sdim, $rconde, $rcondv, ($info=null), \&my_select); |
| 2528 |
|
| 2529 |
'); |
| 2530 |
|
| 2531 |
|
| 2532 |
pp_def("syev", |
| 2533 |
HandleBad => 0, |
| 2534 |
Pars => '[io]A(n,n); int jobz(); int uplo(); [o]w(n); int [o]info()', |
| 2535 |
GenericTypes => [F,D], |
| 2536 |
Code => generate_code ' |
| 2537 |
char jz = \'N\'; |
| 2538 |
char puplo = \'U\'; |
| 2539 |
integer lwork = -1; |
| 2540 |
|
| 2541 |
extern int FORTRAN($TFD(s,d)syev)(char *jobz, char *uplo, integer *n, $GENERIC() *a, |
| 2542 |
integer *lda, $GENERIC() *w, $GENERIC() *work, integer *lwork, |
| 2543 |
integer *info); |
| 2544 |
|
| 2545 |
$GENERIC() tmp_work; |
| 2546 |
|
| 2547 |
if ($jobz()) |
| 2548 |
jz = \'V\'; |
| 2549 |
if ($uplo()) |
| 2550 |
puplo = \'L\'; |
| 2551 |
|
| 2552 |
|
| 2553 |
FORTRAN($TFD(s,d)syev)( |
| 2554 |
&jz, |
| 2555 |
&puplo, |
| 2556 |
&(integer){$SIZE(n)}, |
| 2557 |
$P(A), |
| 2558 |
&(integer){$SIZE(n)}, |
| 2559 |
$P(w), |
| 2560 |
&tmp_work, |
| 2561 |
&lwork, |
| 2562 |
$P(info)); |
| 2563 |
|
| 2564 |
lwork = (integer )tmp_work; |
| 2565 |
{ |
| 2566 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2567 |
FORTRAN($TFD(s,d)syev)( |
| 2568 |
&jz, |
| 2569 |
&puplo, |
| 2570 |
&(integer){$SIZE(n)}, |
| 2571 |
$P(A), |
| 2572 |
&(integer){$SIZE(n)}, |
| 2573 |
$P(w), |
| 2574 |
work, |
| 2575 |
&lwork, |
| 2576 |
$P(info)); |
| 2577 |
free(work); |
| 2578 |
} |
| 2579 |
', |
| 2580 |
Doc => ' |
| 2581 |
|
| 2582 |
=for ref |
| 2583 |
|
| 2584 |
Computes all eigenvalues and, optionally, eigenvectors of a |
| 2585 |
real symmetric matrix A. |
| 2586 |
|
| 2587 |
Arguments |
| 2588 |
========= |
| 2589 |
|
| 2590 |
jobz: = 0: Compute eigenvalues only; |
| 2591 |
= 1: Compute eigenvalues and eigenvectors. |
| 2592 |
|
| 2593 |
uplo = 0: Upper triangle of A is stored; |
| 2594 |
= 1: Lower triangle of A is stored. |
| 2595 |
|
| 2596 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 2597 |
leading N-by-N upper triangular part of A contains the |
| 2598 |
upper triangular part of the matrix A. If uplo = 1, |
| 2599 |
the leading N-by-N lower triangular part of A contains |
| 2600 |
the lower triangular part of the matrix A. |
| 2601 |
On exit, if jobz = 1, then if info = 0, A contains the |
| 2602 |
orthonormal eigenvectors of the matrix A. |
| 2603 |
If jobz = 0, then on exit the lower triangle (if uplo=1) |
| 2604 |
or the upper triangle (if uplo=0) of A, including the |
| 2605 |
diagonal, is destroyed. |
| 2606 |
|
| 2607 |
w: If info = 0, the eigenvalues in ascending order. |
| 2608 |
|
| 2609 |
info: = 0: successful exit |
| 2610 |
< 0: if info = -i, the i-th argument had an illegal value |
| 2611 |
> 0: if info = i, the algorithm failed to converge; i |
| 2612 |
off-diagonal elements of an intermediate tridiagonal |
| 2613 |
form did not converge to zero. |
| 2614 |
|
| 2615 |
=for example |
| 2616 |
|
| 2617 |
# Assume $a is symmetric ;) |
| 2618 |
$a = random (5,5); |
| 2619 |
syev($a, 1,1, (my $w = zeroes(5)), (my $info=null)); |
| 2620 |
|
| 2621 |
'); |
| 2622 |
|
| 2623 |
pp_def("syevd", |
| 2624 |
HandleBad => 0, |
| 2625 |
Pars => '[io]A(n,n); int jobz(); int uplo(); [o]w(n); int [o]info()', |
| 2626 |
GenericTypes => [F,D], |
| 2627 |
Code => generate_code ' |
| 2628 |
char jz = \'N\'; |
| 2629 |
char puplo = \'U\'; |
| 2630 |
integer lwork = -1; |
| 2631 |
integer liwork = -1; |
| 2632 |
integer tmp_liwork; |
| 2633 |
integer *iwork; |
| 2634 |
|
| 2635 |
extern int FORTRAN($TFD(s,d)syevd)(char *jobz, char *uplo, integer *n, $GENERIC() *a, |
| 2636 |
integer *lda, $GENERIC() *w, $GENERIC() *work, integer *lwork, |
| 2637 |
integer *iwork, integer *liwork, integer *info); |
| 2638 |
|
| 2639 |
$GENERIC() tmp_work; |
| 2640 |
|
| 2641 |
if ($jobz()) |
| 2642 |
jz = \'V\'; |
| 2643 |
if ($uplo()) |
| 2644 |
puplo = \'L\'; |
| 2645 |
|
| 2646 |
|
| 2647 |
FORTRAN($TFD(s,d)syevd)( |
| 2648 |
&jz, |
| 2649 |
&puplo, |
| 2650 |
&(integer){$SIZE(n)}, |
| 2651 |
$P(A), |
| 2652 |
&(integer){$SIZE(n)}, |
| 2653 |
$P(w), |
| 2654 |
&tmp_work, |
| 2655 |
&lwork, |
| 2656 |
&tmp_liwork, |
| 2657 |
&liwork, |
| 2658 |
$P(info)); |
| 2659 |
|
| 2660 |
lwork = (integer )tmp_work; |
| 2661 |
liwork = (integer )tmp_liwork; |
| 2662 |
iwork = (integer *)malloc(liwork * sizeof(integer)); |
| 2663 |
{ |
| 2664 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2665 |
FORTRAN($TFD(s,d)syevd)( |
| 2666 |
&jz, |
| 2667 |
&puplo, |
| 2668 |
&(integer){$SIZE(n)}, |
| 2669 |
$P(A), |
| 2670 |
&(integer){$SIZE(n)}, |
| 2671 |
$P(w), |
| 2672 |
work, |
| 2673 |
&lwork, |
| 2674 |
iwork, |
| 2675 |
&liwork, |
| 2676 |
$P(info)); |
| 2677 |
free(work); |
| 2678 |
free(iwork); |
| 2679 |
} |
| 2680 |
', |
| 2681 |
Doc => ' |
| 2682 |
|
| 2683 |
=for ref |
| 2684 |
|
| 2685 |
Computes all eigenvalues and, optionally, eigenvectors of a |
| 2686 |
real symmetric matrix A. If eigenvectors are desired, it uses a |
| 2687 |
divide and conquer algorithm. |
| 2688 |
|
| 2689 |
The divide and conquer algorithm makes very mild assumptions about |
| 2690 |
floating point arithmetic. It will work on machines with a guard |
| 2691 |
digit in add/subtract, or on those binary machines without guard |
| 2692 |
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or |
| 2693 |
Cray-2. It could conceivably fail on hexadecimal or decimal machines |
| 2694 |
without guard digits, but we know of none. |
| 2695 |
|
| 2696 |
Because of large use of BLAS of level 3, syevd needs N**2 more |
| 2697 |
workspace than syevx. |
| 2698 |
|
| 2699 |
Arguments |
| 2700 |
========= |
| 2701 |
|
| 2702 |
jobz: = 0: Compute eigenvalues only; |
| 2703 |
= 1: Compute eigenvalues and eigenvectors. |
| 2704 |
|
| 2705 |
uplo = 0: Upper triangle of A is stored; |
| 2706 |
= 1: Lower triangle of A is stored. |
| 2707 |
|
| 2708 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 2709 |
leading N-by-N upper triangular part of A contains the |
| 2710 |
upper triangular part of the matrix A. If uplo = 1, |
| 2711 |
the leading N-by-N lower triangular part of A contains |
| 2712 |
the lower triangular part of the matrix A. |
| 2713 |
On exit, if jobz = 1, then if info = 0, A contains the |
| 2714 |
orthonormal eigenvectors of the matrix A. |
| 2715 |
If jobz = 0, then on exit the lower triangle (if uplo=1) |
| 2716 |
or the upper triangle (if uplo=0) of A, including the |
| 2717 |
diagonal, is destroyed. |
| 2718 |
|
| 2719 |
w: If info = 0, the eigenvalues in ascending order. |
| 2720 |
|
| 2721 |
info: = 0: successful exit |
| 2722 |
< 0: if info = -i, the i-th argument had an illegal value |
| 2723 |
> 0: if info = i, the algorithm failed to converge; i |
| 2724 |
off-diagonal elements of an intermediate tridiagonal |
| 2725 |
form did not converge to zero. |
| 2726 |
|
| 2727 |
=for example |
| 2728 |
|
| 2729 |
# Assume $a is symmetric ;) |
| 2730 |
$a = random (5,5); |
| 2731 |
syevd($a, 1,1, (my $w = zeroes(5)), (my $info=null)); |
| 2732 |
|
| 2733 |
'); |
| 2734 |
|
| 2735 |
pp_def("syevx", |
| 2736 |
HandleBad => 0, |
| 2737 |
Pars => '[io]A(n,n); vl(); vu(); int il(); int iu(); abstol(); int [o]m(); [o]w(n); [o]z(p,p);int [o]ifail(n); int [o]info(); int [t]iwork(iworkn=CALC(5*$SIZE(n)));', |
| 2738 |
OtherPars => 'int jobz; int range; int uplo', |
| 2739 |
ArgOrder => [qw{A jobz range uplo vl vu il iu abstol m w z ifail info}], |
| 2740 |
RedoDimsCode => ' |
| 2741 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobz), tmp, $PDL(z), $SIZE(p), $SIZE(n)) |
| 2742 |
', |
| 2743 |
GenericTypes => [F,D], |
| 2744 |
Code => generate_code ' |
| 2745 |
char jz = \'N\'; |
| 2746 |
char puplo = \'U\'; |
| 2747 |
char prange = \'A\'; |
| 2748 |
integer lwork = -1; |
| 2749 |
|
| 2750 |
extern int FORTRAN($TFD(s,d)syevx)(char *jobz, char *range, char *uplo, integer *n, |
| 2751 |
$GENERIC() *a, integer *lda, $GENERIC() *vl, $GENERIC() *vu, integer * |
| 2752 |
il, integer *iu, $GENERIC() *abstol, integer *m, $GENERIC() *w, |
| 2753 |
$GENERIC() *z__, integer *ldz, $GENERIC() *work, integer *lwork, |
| 2754 |
integer *iwork, integer *ifail, integer *info); |
| 2755 |
|
| 2756 |
$GENERIC() tmp_work; |
| 2757 |
|
| 2758 |
if ($COMP(jobz)) |
| 2759 |
jz = \'V\'; |
| 2760 |
if ($COMP(uplo)) |
| 2761 |
puplo = \'L\'; |
| 2762 |
|
| 2763 |
switch ($COMP(range)) |
| 2764 |
{ |
| 2765 |
case 1: prange = \'V\'; |
| 2766 |
break; |
| 2767 |
case 2: prange = \'I\'; |
| 2768 |
break; |
| 2769 |
default: prange = \'A\'; |
| 2770 |
} |
| 2771 |
|
| 2772 |
FORTRAN($TFD(s,d)syevx)( |
| 2773 |
&jz, |
| 2774 |
&prange, |
| 2775 |
&puplo, |
| 2776 |
&(integer){$SIZE(n)}, |
| 2777 |
$P(A), |
| 2778 |
&(integer){$SIZE(n)}, |
| 2779 |
$P(vl), |
| 2780 |
$P(vu), |
| 2781 |
$P(il), |
| 2782 |
$P(iu), |
| 2783 |
$P(abstol), |
| 2784 |
$P(m), |
| 2785 |
$P(w), |
| 2786 |
$P(z), |
| 2787 |
&(integer){$SIZE(p)}, |
| 2788 |
&tmp_work, |
| 2789 |
&lwork, |
| 2790 |
$P(iwork), |
| 2791 |
$P(ifail), |
| 2792 |
$P(info)); |
| 2793 |
|
| 2794 |
lwork = (integer )tmp_work; |
| 2795 |
{ |
| 2796 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2797 |
FORTRAN($TFD(s,d)syevx)( |
| 2798 |
&jz, |
| 2799 |
&prange, |
| 2800 |
&puplo, |
| 2801 |
&(integer){$SIZE(n)}, |
| 2802 |
$P(A), |
| 2803 |
&(integer){$SIZE(n)}, |
| 2804 |
$P(vl), |
| 2805 |
$P(vu), |
| 2806 |
$P(il), |
| 2807 |
$P(iu), |
| 2808 |
$P(abstol), |
| 2809 |
$P(m), |
| 2810 |
$P(w), |
| 2811 |
$P(z), |
| 2812 |
&(integer){$SIZE(p)}, |
| 2813 |
work, |
| 2814 |
&lwork, |
| 2815 |
$P(iwork), |
| 2816 |
$P(ifail), |
| 2817 |
$P(info)); |
| 2818 |
free(work); |
| 2819 |
} |
| 2820 |
', |
| 2821 |
Doc => ' |
| 2822 |
|
| 2823 |
=for ref |
| 2824 |
|
| 2825 |
Computes selected eigenvalues and, optionally, eigenvectors |
| 2826 |
of a real symmetric matrix A. Eigenvalues and eigenvectors can be |
| 2827 |
selected by specifying either a range of values or a range of indices |
| 2828 |
for the desired eigenvalues. |
| 2829 |
|
| 2830 |
Arguments |
| 2831 |
========= |
| 2832 |
|
| 2833 |
jobz: = 0: Compute eigenvalues only; |
| 2834 |
= 1: Compute eigenvalues and eigenvectors. |
| 2835 |
|
| 2836 |
|
| 2837 |
range: = 0: all eigenvalues will be found. |
| 2838 |
= 1: all eigenvalues in the half-open interval (vl,vu] |
| 2839 |
will be found. |
| 2840 |
= 1: the il-th through iu-th eigenvalues will be found. |
| 2841 |
|
| 2842 |
uplo = 0: Upper triangle of A is stored; |
| 2843 |
= 1: Lower triangle of A is stored. |
| 2844 |
|
| 2845 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 2846 |
leading N-by-N upper triangular part of A contains the |
| 2847 |
upper triangular part of the matrix A. If uplo = 1, |
| 2848 |
the leading N-by-N lower triangular part of A contains |
| 2849 |
the lower triangular part of the matrix A. |
| 2850 |
On exit, the lower triangle (if uplo=1) or the upper |
| 2851 |
triangle (if uplo=0) of A, including the diagonal, is |
| 2852 |
destroyed. |
| 2853 |
|
| 2854 |
vl: |
| 2855 |
vu: If range=1, the lower and upper bounds of the interval to |
| 2856 |
be searched for eigenvalues. vl < vu. |
| 2857 |
Not referenced if range = 0 or 2. |
| 2858 |
|
| 2859 |
il: |
| 2860 |
iu: If range=2, the indices (in ascending order) of the |
| 2861 |
smallest and largest eigenvalues to be returned. |
| 2862 |
1 <= il <= iu <= N, if N > 0; il = 1 and iu = 0 if N = 0. |
| 2863 |
Not referenced if range = 0 or 1. |
| 2864 |
|
| 2865 |
abstol: The absolute error tolerance for the eigenvalues. |
| 2866 |
An approximate eigenvalue is accepted as converged |
| 2867 |
when it is determined to lie in an interval [a,b] |
| 2868 |
of width less than or equal to |
| 2869 |
|
| 2870 |
abstol + EPS * max( |a|,|b| ) , |
| 2871 |
|
| 2872 |
where EPS is the machine precision. If abstol is less than |
| 2873 |
or equal to zero, then EPS*|T| will be used in its place, |
| 2874 |
where |T| is the 1-norm of the tridiagonal matrix obtained |
| 2875 |
by reducing A to tridiagonal form. |
| 2876 |
|
| 2877 |
Eigenvalues will be computed most accurately when abstol is |
| 2878 |
set to twice the underflow threshold 2*lamch(1), not zero. |
| 2879 |
If this routine returns with info>0, indicating that some |
| 2880 |
eigenvectors did not converge, try setting abstol to |
| 2881 |
2*lamch(1). |
| 2882 |
|
| 2883 |
See "Computing Small Singular Values of Bidiagonal Matrices |
| 2884 |
with Guaranteed High Relative Accuracy," by Demmel and |
| 2885 |
Kahan, LAPACK Working Note #3. |
| 2886 |
|
| 2887 |
m: The total number of eigenvalues found. 0 <= m <= N. |
| 2888 |
If range = 0, m = N, and if range = 2, m = iu-il+1. |
| 2889 |
|
| 2890 |
w: On normal exit, the first M elements contain the selected |
| 2891 |
eigenvalues in ascending order. |
| 2892 |
|
| 2893 |
z: If jobz = 1, then if info = 0, the first m columns of z |
| 2894 |
contain the orthonormal eigenvectors of the matrix A |
| 2895 |
corresponding to the selected eigenvalues, with the i-th |
| 2896 |
column of z holding the eigenvector associated with w(i). |
| 2897 |
If an eigenvector fails to converge, then that column of z |
| 2898 |
contains the latest approximation to the eigenvector, and the |
| 2899 |
index of the eigenvector is returned in ifail. |
| 2900 |
If jobz = 0, then z is not referenced. |
| 2901 |
Note: the user must ensure that at least max(1,m) columns are |
| 2902 |
supplied in the array z; if range = 1, the exact value of m |
| 2903 |
is not known in advance and an upper bound must be used. |
| 2904 |
|
| 2905 |
ifail: If jobz = 1, then if info = 0, the first m elements of |
| 2906 |
ifail are zero. If info > 0, then ifail contains the |
| 2907 |
indices of the eigenvectors that failed to converge. |
| 2908 |
If jobz = 0, then ifail is not referenced. |
| 2909 |
|
| 2910 |
info: = 0: successful exit |
| 2911 |
< 0: if info = -i, the i-th argument had an illegal value |
| 2912 |
> 0: if info = i, then i eigenvectors failed to converge. |
| 2913 |
Their indices are stored in array ifail. |
| 2914 |
|
| 2915 |
=for example |
| 2916 |
|
| 2917 |
# Assume $a is symmetric ;) |
| 2918 |
$a = random (5,5); |
| 2919 |
$unfl = lamch(1); |
| 2920 |
$ovfl = lamch(9); |
| 2921 |
labad($unfl, $ovfl); |
| 2922 |
$abstol = $unfl + $unfl; |
| 2923 |
$m = null; |
| 2924 |
$info = null; |
| 2925 |
$ifail = zeroes(5); |
| 2926 |
$w = zeroes(5); |
| 2927 |
$z = zeroes(5,5); |
| 2928 |
syevx($a, 1,0,1,0,0,0,0,$abstol, $m, $w, $z ,$ifail, $info); |
| 2929 |
|
| 2930 |
'); |
| 2931 |
|
| 2932 |
pp_def("syevr", |
| 2933 |
HandleBad => 0, |
| 2934 |
Pars => '[io]A(n,n); int jobz(); int range(); int uplo(); vl(); vu(); int il(); int iu();abstol();int [o]m();[o]w(n); [o]z(p,q);int [o]isuppz(r); int [o]info()', |
| 2935 |
GenericTypes => [F,D], |
| 2936 |
Code => generate_code ' |
| 2937 |
char jz = \'N\'; |
| 2938 |
char puplo = \'U\'; |
| 2939 |
char prange = \'A\'; |
| 2940 |
integer lwork = -1; |
| 2941 |
integer liwork = -1; |
| 2942 |
integer *iwork; |
| 2943 |
integer tmp_iwork; |
| 2944 |
|
| 2945 |
extern int FORTRAN($TFD(s,d)syevr)(char *jobz, char *range, char *uplo, integer *n, |
| 2946 |
$GENERIC() *a, integer *lda, $GENERIC() *vl, $GENERIC() *vu, integer * |
| 2947 |
il, integer *iu, $GENERIC() *abstol, integer *m, $GENERIC() *w, |
| 2948 |
$GENERIC() *z__, integer *ldz, integer *isuppz, $GENERIC() *work, |
| 2949 |
integer *lwork, integer *iwork, integer *liwork, integer *info); |
| 2950 |
|
| 2951 |
$GENERIC() tmp_work; |
| 2952 |
|
| 2953 |
if ($jobz()) |
| 2954 |
jz = \'V\'; |
| 2955 |
if ($uplo()) |
| 2956 |
puplo = \'L\'; |
| 2957 |
|
| 2958 |
switch ($range()) |
| 2959 |
{ |
| 2960 |
case 1: prange = \'V\'; |
| 2961 |
break; |
| 2962 |
case 2: prange = \'I\'; |
| 2963 |
break; |
| 2964 |
default: prange = \'A\'; |
| 2965 |
} |
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
FORTRAN($TFD(s,d)syevr)( |
| 2970 |
&jz, |
| 2971 |
&prange, |
| 2972 |
&puplo, |
| 2973 |
&(integer){$SIZE(n)}, |
| 2974 |
$P(A), |
| 2975 |
&(integer){$SIZE(n)}, |
| 2976 |
$P(vl), |
| 2977 |
$P(vu), |
| 2978 |
$P(il), |
| 2979 |
$P(iu), |
| 2980 |
$P(abstol), |
| 2981 |
$P(m), |
| 2982 |
$P(w), |
| 2983 |
$P(z), |
| 2984 |
&(integer){$SIZE(p)}, |
| 2985 |
$P(isuppz), |
| 2986 |
&tmp_work, |
| 2987 |
&lwork, |
| 2988 |
&tmp_iwork, |
| 2989 |
&liwork, |
| 2990 |
$P(info)); |
| 2991 |
|
| 2992 |
lwork = (integer )tmp_work; |
| 2993 |
liwork = (integer )tmp_iwork; |
| 2994 |
{ |
| 2995 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 2996 |
iwork = (integer *)malloc(liwork * sizeof(integer)); |
| 2997 |
|
| 2998 |
FORTRAN($TFD(s,d)syevr)( |
| 2999 |
&jz, |
| 3000 |
&prange, |
| 3001 |
&puplo, |
| 3002 |
&(integer){$SIZE(n)}, |
| 3003 |
$P(A), |
| 3004 |
&(integer){$SIZE(n)}, |
| 3005 |
$P(vl), |
| 3006 |
$P(vu), |
| 3007 |
$P(il), |
| 3008 |
$P(iu), |
| 3009 |
$P(abstol), |
| 3010 |
$P(m), |
| 3011 |
$P(w), |
| 3012 |
$P(z), |
| 3013 |
&(integer){$SIZE(p)}, |
| 3014 |
$P(isuppz), |
| 3015 |
work, |
| 3016 |
&lwork, |
| 3017 |
iwork, |
| 3018 |
&liwork, |
| 3019 |
$P(info)); |
| 3020 |
free(work); |
| 3021 |
free(iwork); |
| 3022 |
} |
| 3023 |
', |
| 3024 |
Doc => ' |
| 3025 |
|
| 3026 |
=for ref |
| 3027 |
|
| 3028 |
Computes selected eigenvalues and, optionally, eigenvectors |
| 3029 |
of a real symmetric matrix T. Eigenvalues and eigenvectors can be |
| 3030 |
selected by specifying either a range of values or a range of |
| 3031 |
indices for the desired eigenvalues. |
| 3032 |
|
| 3033 |
Whenever possible, syevr calls stegr to compute the |
| 3034 |
eigenspectrum using Relatively Robust Representations. stegr |
| 3035 |
computes eigenvalues by the dqds algorithm, while orthogonal |
| 3036 |
eigenvectors are computed from various "good" L D L^T representations |
| 3037 |
(also known as Relatively Robust Representations). Gram-Schmidt |
| 3038 |
orthogonalization is avoided as far as possible. More specifically, |
| 3039 |
the various steps of the algorithm are as follows. For the i-th |
| 3040 |
unreduced block of T, |
| 3041 |
|
| 3042 |
(a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T |
| 3043 |
is a relatively robust representation, |
| 3044 |
(b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high |
| 3045 |
relative accuracy by the dqds algorithm, |
| 3046 |
(c) If there is a cluster of close eigenvalues, "choose" sigma_i |
| 3047 |
close to the cluster, and go to step (a), |
| 3048 |
(d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T, |
| 3049 |
compute the corresponding eigenvector by forming a |
| 3050 |
rank-revealing twisted factorization. |
| 3051 |
|
| 3052 |
The desired accuracy of the output can be specified by the input |
| 3053 |
parameter abstol. |
| 3054 |
|
| 3055 |
For more details, see "A new O(n^2) algorithm for the symmetric |
| 3056 |
tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon, |
| 3057 |
Computer Science Division Technical Report No. UCB//CSD-97-971, |
| 3058 |
UC Berkeley, May 1997. |
| 3059 |
|
| 3060 |
|
| 3061 |
Note 1 : syevr calls stegr when the full spectrum is requested |
| 3062 |
on machines which conform to the ieee-754 floating point standard. |
| 3063 |
syevr calls stebz and stein on non-ieee machines and |
| 3064 |
when partial spectrum requests are made. |
| 3065 |
|
| 3066 |
Normal execution of stegr may create NaNs and infinities and |
| 3067 |
hence may abort due to a floating point exception in environments |
| 3068 |
which do not handle NaNs and infinities in the ieee standard default |
| 3069 |
manner. |
| 3070 |
|
| 3071 |
Arguments |
| 3072 |
========= |
| 3073 |
|
| 3074 |
jobz: = 0: Compute eigenvalues only; |
| 3075 |
= 1: Compute eigenvalues and eigenvectors. |
| 3076 |
|
| 3077 |
range: = 0: all eigenvalues will be found. |
| 3078 |
= 1: all eigenvalues in the half-open interval (vl,vu] |
| 3079 |
will be found. |
| 3080 |
= 2: the il-th through iu-th eigenvalues will be found. |
| 3081 |
********* For range = 1 or 2 and iu - il < N - 1, stebz and |
| 3082 |
********* stein are called |
| 3083 |
|
| 3084 |
uplo: = 0: Upper triangle of A is stored; |
| 3085 |
= 1: Lower triangle of A is stored. |
| 3086 |
|
| 3087 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 3088 |
leading N-by-N upper triangular part of A contains the |
| 3089 |
upper triangular part of the matrix A. If uplo = 1, |
| 3090 |
the leading N-by-N lower triangular part of A contains |
| 3091 |
the lower triangular part of the matrix A. |
| 3092 |
On exit, the lower triangle (if uplo=1) or the upper |
| 3093 |
triangle (if uplo=0) of A, including the diagonal, is |
| 3094 |
destroyed. |
| 3095 |
|
| 3096 |
vl: |
| 3097 |
vu: If range=1, the lower and upper bounds of the interval to |
| 3098 |
be searched for eigenvalues. vl < vu. |
| 3099 |
Not referenced if range = 0 or 2. |
| 3100 |
|
| 3101 |
il: |
| 3102 |
iu: If range=2, the indices (in ascending order) of the |
| 3103 |
smallest and largest eigenvalues to be returned. |
| 3104 |
1 <= il <= iu <= N, if N > 0; il = 1 and iu = 0 if N = 0. |
| 3105 |
Not referenced if range = 0 or 1. |
| 3106 |
|
| 3107 |
abstol: The absolute error tolerance for the eigenvalues. |
| 3108 |
An approximate eigenvalue is accepted as converged |
| 3109 |
when it is determined to lie in an interval [a,b] |
| 3110 |
of width less than or equal to |
| 3111 |
|
| 3112 |
abstol + EPS * max( |a|,|b| ) , |
| 3113 |
|
| 3114 |
where EPS is the machine precision. If abstol is less than |
| 3115 |
or equal to zero, then EPS*|T| will be used in its place, |
| 3116 |
where |T| is the 1-norm of the tridiagonal matrix obtained |
| 3117 |
by reducing A to tridiagonal form. |
| 3118 |
|
| 3119 |
See "Computing Small Singular Values of Bidiagonal Matrices |
| 3120 |
with Guaranteed High Relative Accuracy," by Demmel and |
| 3121 |
Kahan, LAPACK Working Note #3. |
| 3122 |
|
| 3123 |
If high relative accuracy is important, set abstol to |
| 3124 |
lamch(1). Doing so will guarantee that |
| 3125 |
eigenvalues are computed to high relative accuracy when |
| 3126 |
possible in future releases. The current code does not |
| 3127 |
make any guarantees about high relative accuracy, but |
| 3128 |
future releases will. See J. Barlow and J. Demmel, |
| 3129 |
"Computing Accurate Eigensystems of Scaled Diagonally |
| 3130 |
Dominant Matrices", LAPACK Working Note #7, for a discussion |
| 3131 |
of which matrices define their eigenvalues to high relative |
| 3132 |
accuracy. |
| 3133 |
|
| 3134 |
m: The total number of eigenvalues found. 0 <= m <= N. |
| 3135 |
If range = 0, m = N, and if range = 2, m = iu-il+1. |
| 3136 |
|
| 3137 |
w: The first m elements contain the selected eigenvalues in |
| 3138 |
ascending order. |
| 3139 |
|
| 3140 |
z: If jobz = 1, then if info = 0, the first m columns of z |
| 3141 |
contain the orthonormal eigenvectors of the matrix A |
| 3142 |
corresponding to the selected eigenvalues, with the i-th |
| 3143 |
column of z holding the eigenvector associated with w(i). |
| 3144 |
If jobz = 0, then z is not referenced. |
| 3145 |
Note: the user must ensure that at least max(1,m) columns are |
| 3146 |
supplied in the array z; if range = 1, the exact value of m |
| 3147 |
is not known in advance and an upper bound must be used. |
| 3148 |
|
| 3149 |
isuppz: array of int, dimension ( 2*max(1,m) ) |
| 3150 |
The support of the eigenvectors in z, i.e., the indices |
| 3151 |
indicating the nonzero elements in z. The i-th eigenvector |
| 3152 |
is nonzero only in elements isuppz( 2*i-1 ) through |
| 3153 |
isuppz( 2*i ). |
| 3154 |
********* Implemented only for range = 0 or 2 and iu - il = N - 1 |
| 3155 |
|
| 3156 |
info: = 0: successful exit |
| 3157 |
< 0: if info = -i, the i-th argument had an illegal value |
| 3158 |
> 0: Internal error |
| 3159 |
|
| 3160 |
=for example |
| 3161 |
|
| 3162 |
# Assume $a is symmetric ;) |
| 3163 |
$a = random (5,5); |
| 3164 |
$unfl = lamch(1); |
| 3165 |
$ovfl = lamch(9); |
| 3166 |
labad($unfl, $ovfl); |
| 3167 |
$abstol = $unfl + $unfl; |
| 3168 |
$m = null; |
| 3169 |
$info = null; |
| 3170 |
$isuppz = zeroes(10); |
| 3171 |
$w = zeroes(5); |
| 3172 |
$z = zeroes(5,5); |
| 3173 |
syevr($a, 1,0,1,0,0,0,0,$abstol, $m, $w, $z ,$isuppz, $info); |
| 3174 |
|
| 3175 |
'); |
| 3176 |
|
| 3177 |
pp_def("sygv", |
| 3178 |
HandleBad => 0, |
| 3179 |
Pars => '[io]A(n,n);int itype();int jobz(); int uplo();[io]B(n,n);[o]w(n); int [o]info()', |
| 3180 |
GenericTypes => [F,D], |
| 3181 |
Code => generate_code ' |
| 3182 |
char jz = \'N\'; |
| 3183 |
char puplo = \'U\'; |
| 3184 |
integer lwork = -1; |
| 3185 |
|
| 3186 |
extern int FORTRAN($TFD(s,d)sygv)(integer *itype, char *jobz, char *uplo, integer * |
| 3187 |
n, $GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, |
| 3188 |
$GENERIC() *w, $GENERIC() *work, integer *lwork, integer *info); |
| 3189 |
$GENERIC() tmp_work; |
| 3190 |
|
| 3191 |
if ($jobz()) |
| 3192 |
jz = \'V\'; |
| 3193 |
if ($uplo()) |
| 3194 |
puplo = \'L\'; |
| 3195 |
|
| 3196 |
|
| 3197 |
FORTRAN($TFD(s,d)sygv)( |
| 3198 |
$P(itype), |
| 3199 |
&jz, |
| 3200 |
&puplo, |
| 3201 |
&(integer){$SIZE(n)}, |
| 3202 |
$P(A), |
| 3203 |
&(integer){$SIZE(n)}, |
| 3204 |
$P(B), |
| 3205 |
&(integer){$SIZE(n)}, |
| 3206 |
$P(w), |
| 3207 |
&tmp_work, |
| 3208 |
&lwork, |
| 3209 |
$P(info)); |
| 3210 |
|
| 3211 |
lwork = (integer )tmp_work; |
| 3212 |
{ |
| 3213 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 3214 |
FORTRAN($TFD(s,d)sygv)( |
| 3215 |
$P(itype), |
| 3216 |
&jz, |
| 3217 |
&puplo, |
| 3218 |
&(integer){$SIZE(n)}, |
| 3219 |
$P(A), |
| 3220 |
&(integer){$SIZE(n)}, |
| 3221 |
$P(B), |
| 3222 |
&(integer){$SIZE(n)}, |
| 3223 |
$P(w), |
| 3224 |
work, |
| 3225 |
&lwork, |
| 3226 |
$P(info)); |
| 3227 |
free(work); |
| 3228 |
} |
| 3229 |
', |
| 3230 |
Doc => ' |
| 3231 |
|
| 3232 |
=for ref |
| 3233 |
|
| 3234 |
Computes all the eigenvalues, and optionally, the eigenvectors |
| 3235 |
of a real generalized symmetric-definite eigenproblem, of the form |
| 3236 |
A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. |
| 3237 |
Here A and B are assumed to be symmetric and B is also |
| 3238 |
positive definite. |
| 3239 |
|
| 3240 |
Arguments |
| 3241 |
========= |
| 3242 |
|
| 3243 |
itype: Specifies the problem type to be solved: |
| 3244 |
= 1: A*x = (lambda)*B*x |
| 3245 |
= 2: A*B*x = (lambda)*x |
| 3246 |
= 3: B*A*x = (lambda)*x |
| 3247 |
|
| 3248 |
jobz: = 0: Compute eigenvalues only; |
| 3249 |
= 1: Compute eigenvalues and eigenvectors. |
| 3250 |
|
| 3251 |
uplo: = 0: Upper triangles of A and B are stored; |
| 3252 |
= 1: Lower triangles of A and B are stored. |
| 3253 |
|
| 3254 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 3255 |
leading N-by-N upper triangular part of A contains the |
| 3256 |
upper triangular part of the matrix A. If uplo = 1, |
| 3257 |
the leading N-by-N lower triangular part of A contains |
| 3258 |
the lower triangular part of the matrix A. |
| 3259 |
|
| 3260 |
On exit, if jobz = 1, then if info = 0, A contains the |
| 3261 |
matrix Z of eigenvectors. The eigenvectors are normalized |
| 3262 |
as follows: |
| 3263 |
if itype = 1 or 2, Z\'*B*Z = I; |
| 3264 |
if itype = 3, Z\'*inv(B)*Z = I. |
| 3265 |
If jobz = 0, then on exit the upper triangle (if uplo=0) |
| 3266 |
or the lower triangle (if uplo=1) of A, including the |
| 3267 |
diagonal, is destroyed. |
| 3268 |
|
| 3269 |
B: On entry, the symmetric positive definite matrix B. |
| 3270 |
If uplo = 0, the leading N-by-N upper triangular part of B |
| 3271 |
contains the upper triangular part of the matrix B. |
| 3272 |
If uplo = 1, the leading N-by-N lower triangular part of B |
| 3273 |
contains the lower triangular part of the matrix B. |
| 3274 |
|
| 3275 |
On exit, if info <= N, the part of B containing the matrix is |
| 3276 |
overwritten by the triangular factor U or L from the Cholesky |
| 3277 |
factorization B = U\'*U or B = L*L\'. |
| 3278 |
|
| 3279 |
W: If info = 0, the eigenvalues in ascending order. |
| 3280 |
|
| 3281 |
info: = 0: successful exit |
| 3282 |
< 0: if info = -i, the i-th argument had an illegal value |
| 3283 |
> 0: potrf or syev returned an error code: |
| 3284 |
<= N: if info = i, syev failed to converge; |
| 3285 |
i off-diagonal elements of an intermediate |
| 3286 |
tridiagonal form did not converge to zero; |
| 3287 |
> N: if info = N + i, for 1 <= i <= N, then the leading |
| 3288 |
minor of order i of B is not positive definite. |
| 3289 |
The factorization of B could not be completed and |
| 3290 |
no eigenvalues or eigenvectors were computed. |
| 3291 |
|
| 3292 |
=for example |
| 3293 |
|
| 3294 |
# Assume $a is symmetric ;) |
| 3295 |
$a = random (5,5); |
| 3296 |
# Assume $a is symmetric and positive definite ;) |
| 3297 |
$b = random (5,5); |
| 3298 |
sygv($a, 1,1, 0, $b, (my $w = zeroes(5)), (my $info=null)); |
| 3299 |
|
| 3300 |
'); |
| 3301 |
|
| 3302 |
pp_def("sygvd", |
| 3303 |
HandleBad => 0, |
| 3304 |
Pars => '[io]A(n,n);int itype();int jobz(); int uplo();[io]B(n,n);[o]w(n); int [o]info()', |
| 3305 |
GenericTypes => [F,D], |
| 3306 |
Code => generate_code ' |
| 3307 |
char jz = \'N\'; |
| 3308 |
char puplo = \'U\'; |
| 3309 |
integer lwork = -1; |
| 3310 |
integer liwork = -1; |
| 3311 |
integer *iwork; |
| 3312 |
integer tmp_iwork; |
| 3313 |
|
| 3314 |
extern int FORTRAN($TFD(s,d)sygvd)(integer *itype, char *jobz, char *uplo, integer * |
| 3315 |
n, $GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, |
| 3316 |
$GENERIC() *w, $GENERIC() *work, integer *lwork, integer *iwork, |
| 3317 |
integer *liwork, integer *info); |
| 3318 |
|
| 3319 |
$GENERIC() tmp_work; |
| 3320 |
|
| 3321 |
if ($jobz()) |
| 3322 |
jz = \'V\'; |
| 3323 |
if ($uplo()) |
| 3324 |
puplo = \'L\'; |
| 3325 |
|
| 3326 |
|
| 3327 |
FORTRAN($TFD(s,d)sygvd)( |
| 3328 |
$P(itype), |
| 3329 |
&jz, |
| 3330 |
&puplo, |
| 3331 |
&(integer){$SIZE(n)}, |
| 3332 |
$P(A), |
| 3333 |
&(integer){$SIZE(n)}, |
| 3334 |
$P(B), |
| 3335 |
&(integer){$SIZE(n)}, |
| 3336 |
$P(w), |
| 3337 |
&tmp_work, |
| 3338 |
&lwork, |
| 3339 |
&tmp_iwork, |
| 3340 |
&liwork, |
| 3341 |
$P(info)); |
| 3342 |
|
| 3343 |
lwork = (integer )tmp_work; |
| 3344 |
liwork = (integer )tmp_iwork; |
| 3345 |
iwork = (integer *)malloc(liwork * sizeof(integer)); |
| 3346 |
|
| 3347 |
{ |
| 3348 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 3349 |
FORTRAN($TFD(s,d)sygvd)( |
| 3350 |
$P(itype), |
| 3351 |
&jz, |
| 3352 |
&puplo, |
| 3353 |
&(integer){$SIZE(n)}, |
| 3354 |
$P(A), |
| 3355 |
&(integer){$SIZE(n)}, |
| 3356 |
$P(B), |
| 3357 |
&(integer){$SIZE(n)}, |
| 3358 |
$P(w), |
| 3359 |
work, |
| 3360 |
&lwork, |
| 3361 |
iwork, |
| 3362 |
&liwork, |
| 3363 |
$P(info)); |
| 3364 |
free(work); |
| 3365 |
} |
| 3366 |
free(iwork); |
| 3367 |
', |
| 3368 |
Doc => ' |
| 3369 |
|
| 3370 |
=for ref |
| 3371 |
|
| 3372 |
Computes all the eigenvalues, and optionally, the eigenvectors |
| 3373 |
of a real generalized symmetric-definite eigenproblem, of the form |
| 3374 |
A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. |
| 3375 |
Here A and B are assumed to be symmetric and B is also |
| 3376 |
positive definite. |
| 3377 |
|
| 3378 |
The divide and conquer algorithm makes very mild assumptions about |
| 3379 |
floating point arithmetic. It will work on machines with a guard |
| 3380 |
digit in add/subtract, or on those binary machines without guard |
| 3381 |
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or |
| 3382 |
Cray-2. It could conceivably fail on hexadecimal or decimal machines |
| 3383 |
without guard digits, but we know of none. |
| 3384 |
|
| 3385 |
Arguments |
| 3386 |
========= |
| 3387 |
|
| 3388 |
itype: Specifies the problem type to be solved: |
| 3389 |
= 1: A*x = (lambda)*B*x |
| 3390 |
= 2: A*B*x = (lambda)*x |
| 3391 |
= 3: B*A*x = (lambda)*x |
| 3392 |
|
| 3393 |
jobz: = 0: Compute eigenvalues only; |
| 3394 |
= 1: Compute eigenvalues and eigenvectors. |
| 3395 |
|
| 3396 |
uplo: = 0: Upper triangles of A and B are stored; |
| 3397 |
= 1: Lower triangles of A and B are stored. |
| 3398 |
|
| 3399 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 3400 |
leading N-by-N upper triangular part of A contains the |
| 3401 |
upper triangular part of the matrix A. If uplo = 1, |
| 3402 |
the leading N-by-N lower triangular part of A contains |
| 3403 |
the lower triangular part of the matrix A. |
| 3404 |
|
| 3405 |
On exit, if jobz = 1, then if info = 0, A contains the |
| 3406 |
matrix Z of eigenvectors. The eigenvectors are normalized |
| 3407 |
as follows: |
| 3408 |
if itype = 1 or 2, Z\'*B*Z = I; |
| 3409 |
if itype = 3, Z\'*inv(B)*Z = I. |
| 3410 |
If jobz = 0, then on exit the upper triangle (if uplo=0) |
| 3411 |
or the lower triangle (if uplo=1) of A, including the |
| 3412 |
diagonal, is destroyed. |
| 3413 |
|
| 3414 |
B: On entry, the symmetric positive definite matrix B. |
| 3415 |
If uplo = 0, the leading N-by-N upper triangular part of B |
| 3416 |
contains the upper triangular part of the matrix B. |
| 3417 |
If uplo = 1, the leading N-by-N lower triangular part of B |
| 3418 |
contains the lower triangular part of the matrix B. |
| 3419 |
|
| 3420 |
On exit, if info <= N, the part of B containing the matrix is |
| 3421 |
overwritten by the triangular factor U or L from the Cholesky |
| 3422 |
factorization B = U\'*U or B = L*L\'. |
| 3423 |
|
| 3424 |
W: If info = 0, the eigenvalues in ascending order. |
| 3425 |
|
| 3426 |
info: = 0: successful exit |
| 3427 |
< 0: if info = -i, the i-th argument had an illegal value |
| 3428 |
> 0: potrf or syev returned an error code: |
| 3429 |
<= N: if info = i, syevd failed to converge; |
| 3430 |
i off-diagonal elements of an intermediate |
| 3431 |
tridiagonal form did not converge to zero; |
| 3432 |
> N: if info = N + i, for 1 <= i <= N, then the leading |
| 3433 |
minor of order i of B is not positive definite. |
| 3434 |
The factorization of B could not be completed and |
| 3435 |
no eigenvalues or eigenvectors were computed. |
| 3436 |
|
| 3437 |
=for example |
| 3438 |
|
| 3439 |
# Assume $a is symmetric ;) |
| 3440 |
$a = random (5,5); |
| 3441 |
# Assume $b is symmetric positive definite ;) |
| 3442 |
$b = random (5,5); |
| 3443 |
sygvd($a, 1,1, 0, $b, (my $w = zeroes(5)), (my $info=null)); |
| 3444 |
|
| 3445 |
'); |
| 3446 |
|
| 3447 |
pp_def("sygvx", |
| 3448 |
HandleBad => 0, |
| 3449 |
Pars => '[io]A(n,n); int itype(); |
| 3450 |
[io]B(n,n); vl(); vu(); int il(); int iu(); abstol(); |
| 3451 |
int [o]m(); [o]w(n); [o]Z(p,p); int [o]ifail(n); int [o]info(); |
| 3452 |
int [t]iwork(iworkn=CALC(5*$SIZE(n))); |
| 3453 |
', |
| 3454 |
OtherPars => 'int jobz; int range; int uplo', |
| 3455 |
ArgOrder => [qw{A itype jobz range uplo B vl vu il iu abstol m w Z ifail info }], |
| 3456 |
RedoDimsCode => ' |
| 3457 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(jobz), tmp, $PDL(Z), $SIZE(p), $SIZE(n)) |
| 3458 |
', |
| 3459 |
GenericTypes => [F,D], |
| 3460 |
Code => generate_code ' |
| 3461 |
char jz = \'N\'; |
| 3462 |
char puplo = \'U\'; |
| 3463 |
char prange; |
| 3464 |
integer lwork = -1; |
| 3465 |
extern int FORTRAN($TFD(s,d)sygvx)(integer *itype, char *jobz, char *range, char * |
| 3466 |
uplo, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *b, integer |
| 3467 |
*ldb, $GENERIC() *vl, $GENERIC() *vu, integer *il, integer *iu, |
| 3468 |
$GENERIC() *abstol, integer *m, $GENERIC() *w, $GENERIC() *z__, |
| 3469 |
integer *ldz, $GENERIC() *work, integer *lwork, integer *iwork, |
| 3470 |
integer *ifail, integer *info); |
| 3471 |
|
| 3472 |
$GENERIC() tmp_work; |
| 3473 |
|
| 3474 |
if ($COMP(jobz)) |
| 3475 |
jz = \'V\'; |
| 3476 |
if ($COMP(uplo)) |
| 3477 |
puplo = \'L\'; |
| 3478 |
|
| 3479 |
switch ($COMP(range)) |
| 3480 |
{ |
| 3481 |
case 1: prange = \'V\'; |
| 3482 |
break; |
| 3483 |
case 2: prange = \'I\'; |
| 3484 |
break; |
| 3485 |
default: prange = \'A\'; |
| 3486 |
} |
| 3487 |
|
| 3488 |
FORTRAN($TFD(s,d)sygvx)( |
| 3489 |
$P(itype), |
| 3490 |
&jz, |
| 3491 |
&prange, |
| 3492 |
&puplo, |
| 3493 |
&(integer){$SIZE(n)}, |
| 3494 |
$P(A), |
| 3495 |
&(integer){$SIZE(n)}, |
| 3496 |
$P(B), |
| 3497 |
&(integer){$SIZE(n)}, |
| 3498 |
$P(vl), |
| 3499 |
$P(vu), |
| 3500 |
$P(il), |
| 3501 |
$P(iu), |
| 3502 |
$P(abstol), |
| 3503 |
$P(m), |
| 3504 |
$P(w), |
| 3505 |
$P(Z), |
| 3506 |
&(integer){$SIZE(p)}, |
| 3507 |
&tmp_work, |
| 3508 |
&lwork, |
| 3509 |
$P(iwork), |
| 3510 |
$P(ifail), |
| 3511 |
$P(info)); |
| 3512 |
|
| 3513 |
lwork = (integer )tmp_work; |
| 3514 |
{ |
| 3515 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 3516 |
FORTRAN($TFD(s,d)sygvx)( |
| 3517 |
$P(itype), |
| 3518 |
&jz, |
| 3519 |
&prange, |
| 3520 |
&puplo, |
| 3521 |
&(integer){$SIZE(n)}, |
| 3522 |
$P(A), |
| 3523 |
&(integer){$SIZE(n)}, |
| 3524 |
$P(B), |
| 3525 |
&(integer){$SIZE(n)}, |
| 3526 |
$P(vl), |
| 3527 |
$P(vu), |
| 3528 |
$P(il), |
| 3529 |
$P(iu), |
| 3530 |
$P(abstol), |
| 3531 |
$P(m), |
| 3532 |
$P(w), |
| 3533 |
$P(Z), |
| 3534 |
&(integer){$SIZE(p)}, |
| 3535 |
work, |
| 3536 |
&lwork, |
| 3537 |
$P(iwork), |
| 3538 |
$P(ifail), |
| 3539 |
$P(info)); |
| 3540 |
free(work); |
| 3541 |
} |
| 3542 |
', |
| 3543 |
Doc => ' |
| 3544 |
|
| 3545 |
=for ref |
| 3546 |
|
| 3547 |
Computes selected eigenvalues, and optionally, eigenvectors |
| 3548 |
of a real generalized symmetric-definite eigenproblem, of the form |
| 3549 |
A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A |
| 3550 |
and B are assumed to be symmetric and B is also positive definite. |
| 3551 |
Eigenvalues and eigenvectors can be selected by specifying either a |
| 3552 |
range of values or a range of indices for the desired eigenvalues. |
| 3553 |
|
| 3554 |
Arguments |
| 3555 |
========= |
| 3556 |
|
| 3557 |
itype: Specifies the problem type to be solved: |
| 3558 |
= 1: A*x = (lambda)*B*x |
| 3559 |
= 2: A*B*x = (lambda)*x |
| 3560 |
= 3: B*A*x = (lambda)*x |
| 3561 |
|
| 3562 |
jobz: = 0: Compute eigenvalues only; |
| 3563 |
= 1: Compute eigenvalues and eigenvectors. |
| 3564 |
|
| 3565 |
range: = 0: all eigenvalues will be found. |
| 3566 |
= 1: all eigenvalues in the half-open interval (vl,vu] |
| 3567 |
will be found. |
| 3568 |
= 2: the il-th through iu-th eigenvalues will be found. |
| 3569 |
|
| 3570 |
uplo: = 0: Upper triangle of A and B are stored; |
| 3571 |
= 1: Lower triangle of A and B are stored. |
| 3572 |
|
| 3573 |
A: On entry, the symmetric matrix A. If uplo = 0, the |
| 3574 |
leading N-by-N upper triangular part of A contains the |
| 3575 |
upper triangular part of the matrix A. If uplo = 1, |
| 3576 |
the leading N-by-N lower triangular part of A contains |
| 3577 |
the lower triangular part of the matrix A. |
| 3578 |
|
| 3579 |
On exit, the lower triangle (if uplo=1) or the upper |
| 3580 |
triangle (if uplo=0) of A, including the diagonal, is |
| 3581 |
destroyed. |
| 3582 |
|
| 3583 |
B: On entry, the symmetric matrix B. If uplo = 0, the |
| 3584 |
leading N-by-N upper triangular part of B contains the |
| 3585 |
upper triangular part of the matrix B. If uplo = 1, |
| 3586 |
the leading N-by-N lower triangular part of B contains |
| 3587 |
the lower triangular part of the matrix B. |
| 3588 |
|
| 3589 |
On exit, if info <= N, the part of B containing the matrix is |
| 3590 |
overwritten by the triangular factor U or L from the Cholesky |
| 3591 |
factorization B = U\'*U or B = L*L\'. |
| 3592 |
|
| 3593 |
vl: |
| 3594 |
vu: If range=1, the lower and upper bounds of the interval to |
| 3595 |
be searched for eigenvalues. vl < vu. |
| 3596 |
Not referenced if range = 0 or 2. |
| 3597 |
|
| 3598 |
il: |
| 3599 |
iu: If range=2, the indices (in ascending order) of the |
| 3600 |
smallest and largest eigenvalues to be returned. |
| 3601 |
1 <= il <= iu <= N, if N > 0; il = 1 and iu = 0 if N = 0. |
| 3602 |
Not referenced if range = 0 or 1. |
| 3603 |
|
| 3604 |
abstol: The absolute error tolerance for the eigenvalues. |
| 3605 |
An approximate eigenvalue is accepted as converged |
| 3606 |
when it is determined to lie in an interval [a,b] |
| 3607 |
of width less than or equal to |
| 3608 |
|
| 3609 |
abstol + EPS * max( |a|,|b| ) , |
| 3610 |
|
| 3611 |
where EPS is the machine precision. If abstol is less than |
| 3612 |
or equal to zero, then EPS*|T| will be used in its place, |
| 3613 |
where |T| is the 1-norm of the tridiagonal matrix obtained |
| 3614 |
by reducing A to tridiagonal form. |
| 3615 |
|
| 3616 |
Eigenvalues will be computed most accurately when abstol is |
| 3617 |
set to twice the underflow threshold 2*lamch(1), not zero. |
| 3618 |
If this routine returns with info>0, indicating that some |
| 3619 |
eigenvectors did not converge, try setting abstol to |
| 3620 |
2* lamch(1). |
| 3621 |
|
| 3622 |
m: The total number of eigenvalues found. 0 <= m <= N. |
| 3623 |
If range = 0, m = N, and if range = 2, m = iu-il+1. |
| 3624 |
|
| 3625 |
w: On normal exit, the first m elements contain the selected |
| 3626 |
eigenvalues in ascending order. |
| 3627 |
|
| 3628 |
Z: If jobz = 0, then Z is not referenced. |
| 3629 |
If jobz = 1, then if info = 0, the first m columns of Z |
| 3630 |
contain the orthonormal eigenvectors of the matrix A |
| 3631 |
corresponding to the selected eigenvalues, with the i-th |
| 3632 |
column of Z holding the eigenvector associated with w(i). |
| 3633 |
The eigenvectors are normalized as follows: |
| 3634 |
if itype = 1 or 2, Z\'*B*Z = I; |
| 3635 |
if itype = 3, Z\'*inv(B)*Z = I. |
| 3636 |
|
| 3637 |
If an eigenvector fails to converge, then that column of Z |
| 3638 |
contains the latest approximation to the eigenvector, and the |
| 3639 |
index of the eigenvector is returned in ifail. |
| 3640 |
Note: the user must ensure that at least max(1,m) columns are |
| 3641 |
supplied in the array Z; if range = 1, the exact value of m |
| 3642 |
is not known in advance and an upper bound must be used. |
| 3643 |
|
| 3644 |
ifail: If jobz = 1, then if info = 0, the first M elements of |
| 3645 |
ifail are zero. If info > 0, then ifail contains the |
| 3646 |
indices of the eigenvectors that failed to converge. |
| 3647 |
If jobz = 0, then ifail is not referenced. |
| 3648 |
|
| 3649 |
info: = 0: successful exit |
| 3650 |
< 0: if info = -i, the i-th argument had an illegal value |
| 3651 |
> 0: potrf or syevx returned an error code: |
| 3652 |
<= N: if info = i, syevx failed to converge; |
| 3653 |
i eigenvectors failed to converge. Their indices |
| 3654 |
are stored in array ifail. |
| 3655 |
> N: if info = N + i, for 1 <= i <= N, then the leading |
| 3656 |
minor of order i of B is not positive definite. |
| 3657 |
The factorization of B could not be completed and |
| 3658 |
no eigenvalues or eigenvectors were computed. |
| 3659 |
|
| 3660 |
=for example |
| 3661 |
|
| 3662 |
# Assume $a is symmetric ;) |
| 3663 |
$a = random (5,5); |
| 3664 |
# Assume $b is symmetric positive definite ;) |
| 3665 |
$b = random (5,5); |
| 3666 |
$unfl = lamch(1); |
| 3667 |
$ovfl = lamch(9); |
| 3668 |
labad($unfl, $ovfl); |
| 3669 |
$abstol = $unfl + $unfl; |
| 3670 |
$m = null; |
| 3671 |
$w=zeroes(5); |
| 3672 |
$z = zeroes(5,5); |
| 3673 |
$ifail = zeroes(5); |
| 3674 |
sygvx($a, 1,1, 0,0, $b, 0, 0, 0, 0, $abstol, $m, $w, $z,$ifail,(my $info=null)); |
| 3675 |
|
| 3676 |
'); |
| 3677 |
|
| 3678 |
|
| 3679 |
pp_def("gesv", |
| 3680 |
HandleBad => 0, |
| 3681 |
Pars => '[io]A(n,n); [io]B(n,m); int [o]ipiv(n); int [o]info()', |
| 3682 |
GenericTypes => [F,D], |
| 3683 |
Code => generate_code ' |
| 3684 |
extern int FORTRAN($TFD(s,d)gesv)(integer *n, integer *nrhs, $GENERIC() *a, integer |
| 3685 |
*lda, integer *ipiv, $GENERIC() *b, integer *ldb, integer *info); |
| 3686 |
FORTRAN($TFD(s,d)gesv)( |
| 3687 |
&(integer){$SIZE(n)}, |
| 3688 |
&(integer){$SIZE(m)}, |
| 3689 |
$P(A), |
| 3690 |
&(integer){$SIZE(n)}, |
| 3691 |
$P(ipiv), |
| 3692 |
$P(B), |
| 3693 |
&(integer){$SIZE(n)}, |
| 3694 |
$P(info)); |
| 3695 |
', |
| 3696 |
Doc => ' |
| 3697 |
|
| 3698 |
=for ref |
| 3699 |
|
| 3700 |
Computes the solution to a real system of linear equations |
| 3701 |
|
| 3702 |
A * X = B, |
| 3703 |
where A is an N-by-N matrix and X and B are N-by-NRHS matrices. |
| 3704 |
|
| 3705 |
The LU decomposition with partial pivoting and row interchanges is |
| 3706 |
used to factor A as |
| 3707 |
|
| 3708 |
A = P * L * U, |
| 3709 |
where P is a permutation matrix, L is unit lower triangular, and U is |
| 3710 |
upper triangular. |
| 3711 |
|
| 3712 |
The factored form of A is then used to solve the |
| 3713 |
system of equations A * X = B. |
| 3714 |
|
| 3715 |
Arguments |
| 3716 |
========= |
| 3717 |
|
| 3718 |
A: On entry, the N-by-N coefficient matrix A. |
| 3719 |
On exit, the factors L and U from the factorization |
| 3720 |
A = P*L*U; the unit diagonal elements of L are not stored. |
| 3721 |
|
| 3722 |
ipiv: The pivot indices that define the permutation matrix P; |
| 3723 |
row i of the matrix was interchanged with row ipiv(i). |
| 3724 |
|
| 3725 |
B: On entry, the N-by-NRHS matrix of right hand side matrix B. |
| 3726 |
On exit, if info = 0, the N-by-NRHS solution matrix X. |
| 3727 |
|
| 3728 |
info: = 0: successful exit |
| 3729 |
< 0: if info = -i, the i-th argument had an illegal value |
| 3730 |
> 0: if info = i, U(i,i) is exactly zero. The factorization |
| 3731 |
has been completed, but the factor U is exactly |
| 3732 |
singular, so the solution could not be computed. |
| 3733 |
|
| 3734 |
=for example |
| 3735 |
|
| 3736 |
$a = random (5,5); |
| 3737 |
$a = transpose($a); |
| 3738 |
$b = random (5,5); |
| 3739 |
$b = transpose($b); |
| 3740 |
gesv($a,$b, (my $ipiv=zeroes(5)),(my $info=null)); |
| 3741 |
print "The solution matrix X is :". transpose($b)."\n" unless $info; |
| 3742 |
|
| 3743 |
'); |
| 3744 |
|
| 3745 |
|
| 3746 |
pp_def("gesvx", |
| 3747 |
HandleBad => 0, |
| 3748 |
Pars => '[io]A(n,n); int trans(); int fact(); [io]B(n,m); [io]af(n,n); int [io]ipiv(n); int [io]equed(); [o]r(p); [o]c(q); [o]X(n,m); [o]rcond(); [o]ferr(m); [o]berr(m);[o]rpvgrw();int [o]info(); [t]work(workn=CALC(4*$SIZE(n))); int [t]iwork(n);', |
| 3749 |
RedoDimsCode => ' |
| 3750 |
$SIZE(p) = $SIZE(n); /* Ubuntu LAPACK 3 writes to r anyway */ |
| 3751 |
$SIZE(q) = $SIZE(n); /* Ubuntu LAPACK 3 writes to c anyway */ |
| 3752 |
', |
| 3753 |
GenericTypes => [F,D], |
| 3754 |
Code => generate_code ' |
| 3755 |
char ptrans, pfact, pequed; |
| 3756 |
extern int FORTRAN($TFD(s,d)gesvx)(char *fact, char *trans, integer *n, integer * |
| 3757 |
nrhs, $GENERIC() *a, integer *lda, $GENERIC() *af, integer *ldaf, |
| 3758 |
integer *ipiv, char *equed, $GENERIC() *r__, $GENERIC() *c__, |
| 3759 |
$GENERIC() *b, integer *ldb, $GENERIC() *x, integer *ldx, $GENERIC() * |
| 3760 |
rcond, $GENERIC() *ferr, $GENERIC() *berr, $GENERIC() *work, integer * |
| 3761 |
iwork, integer *info); |
| 3762 |
switch ($trans()) |
| 3763 |
{ |
| 3764 |
case 1: ptrans = \'T\'; |
| 3765 |
break; |
| 3766 |
case 2: ptrans = \'C\'; |
| 3767 |
break; |
| 3768 |
default: ptrans = \'N\'; |
| 3769 |
} |
| 3770 |
switch ($fact()) |
| 3771 |
{ |
| 3772 |
case 1: pfact = \'N\'; |
| 3773 |
break; |
| 3774 |
case 2: pfact = \'E\'; |
| 3775 |
break; |
| 3776 |
default: pfact = \'F\'; |
| 3777 |
} |
| 3778 |
switch ($equed()) |
| 3779 |
{ |
| 3780 |
case 1: pequed = \'R\'; |
| 3781 |
break; |
| 3782 |
case 2: pequed = \'C\'; |
| 3783 |
break; |
| 3784 |
case 3: pequed = \'B\'; |
| 3785 |
break; |
| 3786 |
default: pequed = \'N\'; |
| 3787 |
} |
| 3788 |
|
| 3789 |
FORTRAN($TFD(s,d)gesvx)( |
| 3790 |
&pfact, |
| 3791 |
&ptrans, |
| 3792 |
&(integer){$SIZE(n)}, |
| 3793 |
&(integer){$SIZE(m)}, |
| 3794 |
$P(A), |
| 3795 |
&(integer){$SIZE(n)}, |
| 3796 |
$P(af), |
| 3797 |
&(integer){$SIZE(n)}, |
| 3798 |
$P(ipiv), |
| 3799 |
&pequed, |
| 3800 |
$P(r), |
| 3801 |
$P(c), |
| 3802 |
$P(B), |
| 3803 |
&(integer){$SIZE(n)}, |
| 3804 |
$P(X), |
| 3805 |
&(integer){$SIZE(n)}, |
| 3806 |
$P(rcond), |
| 3807 |
$P(ferr), |
| 3808 |
$P(berr), |
| 3809 |
$P(work), |
| 3810 |
$P(iwork), |
| 3811 |
$P(info)); |
| 3812 |
|
| 3813 |
switch (pequed) |
| 3814 |
{ |
| 3815 |
case \'R\': $equed() = 1; |
| 3816 |
break; |
| 3817 |
case \'C\': $equed() = 2; |
| 3818 |
break; |
| 3819 |
case \'B\': $equed() = 3; |
| 3820 |
break; |
| 3821 |
default: $equed()= 0; |
| 3822 |
} |
| 3823 |
$rpvgrw()=$work(workn=>0); |
| 3824 |
', |
| 3825 |
Doc => ' |
| 3826 |
=for ref |
| 3827 |
|
| 3828 |
Uses the LU factorization to compute the solution to a real |
| 3829 |
system of linear equations |
| 3830 |
|
| 3831 |
A * X = B, |
| 3832 |
where A is an N-by-N matrix and X and B are N-by-NRHS matrices. |
| 3833 |
|
| 3834 |
Error bounds on the solution and a condition estimate are also |
| 3835 |
provided. |
| 3836 |
|
| 3837 |
=for desc |
| 3838 |
|
| 3839 |
The following steps are performed: |
| 3840 |
|
| 3841 |
=over 3 |
| 3842 |
|
| 3843 |
=item 1 |
| 3844 |
|
| 3845 |
If fact = 2, real scaling factors are computed to equilibrate |
| 3846 |
the system: |
| 3847 |
|
| 3848 |
trans = 0: diag(r)*A*diag(c) *inv(diag(c))*X = diag(c)*B |
| 3849 |
trans = 1: (diag(r)*A*diag(c))\' *inv(diag(r))*X = diag(c)*B |
| 3850 |
trans = 2: (diag(r)*A*diag(c))**H *inv(diag(r))*X = diag(c)*B |
| 3851 |
|
| 3852 |
Whether or not the system will be equilibrated depends on the |
| 3853 |
scaling of the matrix A, but if equilibration is used, A is |
| 3854 |
overwritten by diag(r)*A*diag(c) and B by diag(r)*B (if trans=0) |
| 3855 |
or diag(c)*B (if trans = 1 or 2). |
| 3856 |
|
| 3857 |
=item 2 |
| 3858 |
|
| 3859 |
If fact = 1 or 2, the LU decomposition is used to factor the |
| 3860 |
matrix A (after equilibration if fact = 2) as |
| 3861 |
|
| 3862 |
A = P * L * U, |
| 3863 |
where P is a permutation matrix, L is a unit lower triangular |
| 3864 |
matrix, and U is upper triangular. |
| 3865 |
|
| 3866 |
=item 3 |
| 3867 |
|
| 3868 |
If some U(i,i)=0, so that U is exactly singular, then the routine |
| 3869 |
returns with info = i. Otherwise, the factored form of A is used |
| 3870 |
to estimate the condition number of the matrix A. If the |
| 3871 |
reciprocal of the condition number is less than machine precision, |
| 3872 |
info = N+1 is returned as a warning, but the routine still goes on |
| 3873 |
to solve for X and compute error bounds as described below. |
| 3874 |
|
| 3875 |
=item 4 |
| 3876 |
|
| 3877 |
The system of equations is solved for X using the factored form |
| 3878 |
of A. |
| 3879 |
|
| 3880 |
=item 5 |
| 3881 |
|
| 3882 |
Iterative refinement is applied to improve the computed solution |
| 3883 |
matrix and calculate error bounds and backward error estimates |
| 3884 |
for it. |
| 3885 |
|
| 3886 |
=item 6 |
| 3887 |
|
| 3888 |
If equilibration was used, the matrix X is premultiplied by |
| 3889 |
diag(c) (if trans = 0) or diag(r) (if trans = 1 or 2) so |
| 3890 |
that it solves the original system before equilibration. |
| 3891 |
|
| 3892 |
=back |
| 3893 |
|
| 3894 |
|
| 3895 |
Arguments |
| 3896 |
========= |
| 3897 |
|
| 3898 |
fact: Specifies whether or not the factored form of the matrix A is |
| 3899 |
supplied on entry, and if not, whether the matrix A should be |
| 3900 |
equilibrated before it is factored. |
| 3901 |
= 0: On entry, af and ipiv contain the factored form of A. |
| 3902 |
If equed is not 0, the matrix A has been |
| 3903 |
equilibrated with scaling factors given by r and c. |
| 3904 |
A, af, and ipiv are not modified. |
| 3905 |
= 1: The matrix A will be copied to af and factored. |
| 3906 |
= 2: The matrix A will be equilibrated if necessary, then |
| 3907 |
copied to af and factored. |
| 3908 |
|
| 3909 |
trans: Specifies the form of the system of equations: |
| 3910 |
= 0: A * X = B (No transpose) |
| 3911 |
= 1: A\' * X = B (Transpose) |
| 3912 |
= 2: A**H * X = B (Transpose) |
| 3913 |
|
| 3914 |
A: On entry, the N-by-N matrix A. If fact = 0 and equed is |
| 3915 |
not 0, then A must have been equilibrated by the scaling |
| 3916 |
factors in r and/or c. A is not modified if fact = 0 or |
| 3917 |
1, or if fact = 2 and equed = 0 on exit. |
| 3918 |
|
| 3919 |
On exit, if equed != 0, A is scaled as follows: |
| 3920 |
equed = 1: A := diag(r) * A |
| 3921 |
equed = 2: A := A * diag(c) |
| 3922 |
equed = 3: A := diag(r) * A * diag(c). |
| 3923 |
|
| 3924 |
af: If fact = 0, then af is an input argument and on entry |
| 3925 |
contains the factors L and U from the factorization |
| 3926 |
A = P*L*U as computed by getrf. If equed != 0, then |
| 3927 |
af is the factored form of the equilibrated matrix A. |
| 3928 |
|
| 3929 |
If fact = 1, then af is an output argument and on exit |
| 3930 |
returns the factors L and U from the factorization A = P*L*U |
| 3931 |
of the original matrix A. |
| 3932 |
|
| 3933 |
If fact = 2, then af is an output argument and on exit |
| 3934 |
returns the factors L and U from the factorization A = P*L*U |
| 3935 |
of the equilibrated matrix A (see the description of A for |
| 3936 |
the form of the equilibrated matrix). |
| 3937 |
|
| 3938 |
|
| 3939 |
ipiv: If fact = 0, then ipiv is an input argument and on entry |
| 3940 |
contains the pivot indices from the factorization A = P*L*U |
| 3941 |
as computed by getrf; row i of the matrix was interchanged |
| 3942 |
with row ipiv(i). |
| 3943 |
|
| 3944 |
If fact = 1, then ipiv is an output argument and on exit |
| 3945 |
contains the pivot indices from the factorization A = P*L*U |
| 3946 |
of the original matrix A. |
| 3947 |
|
| 3948 |
If fact = 2, then ipiv is an output argument and on exit |
| 3949 |
contains the pivot indices from the factorization A = P*L*U |
| 3950 |
of the equilibrated matrix A. |
| 3951 |
|
| 3952 |
equed: Specifies the form of equilibration that was done. |
| 3953 |
= 0: No equilibration (always true if fact = 1). |
| 3954 |
= 1: Row equilibration, i.e., A has been premultiplied by |
| 3955 |
diag(r). |
| 3956 |
= 2: Column equilibration, i.e., A has been postmultiplied |
| 3957 |
by diag(c). |
| 3958 |
= 3: Both row and column equilibration, i.e., A has been |
| 3959 |
replaced by diag(r) * A * diag(c). |
| 3960 |
equed is an input argument if fact = 0; otherwise, it is an |
| 3961 |
output argument. |
| 3962 |
|
| 3963 |
r: The row scale factors for A. If equed = 1 or 3, A is |
| 3964 |
multiplied on the left by diag(r); if equed = 0 or 2, r |
| 3965 |
is not accessed. r is an input argument if fact = 0; |
| 3966 |
otherwise, r is an output argument. If fact = 0 and |
| 3967 |
equed = 1 or 3, each element of r must be positive. |
| 3968 |
|
| 3969 |
c: The column scale factors for A. If equed = 2 or 3, A is |
| 3970 |
multiplied on the right by diag(c); if equed = 0 or 1, c |
| 3971 |
is not accessed. c is an input argument if fact = 0; |
| 3972 |
otherwise, c is an output argument. If fact = 0 and |
| 3973 |
equed = 2 or 3, each element of c must be positive. |
| 3974 |
|
| 3975 |
B: On entry, the N-by-NRHS right hand side matrix B. |
| 3976 |
On exit, |
| 3977 |
if equed = 0, B is not modified; |
| 3978 |
if trans = 0 and equed = 1 or 3, B is overwritten by |
| 3979 |
diag(r)*B; |
| 3980 |
if trans = 1 or 2 and equed = 2 or 3, B is |
| 3981 |
overwritten by diag(c)*B. |
| 3982 |
|
| 3983 |
X: If info = 0 or info = N+1, the N-by-NRHS solution matrix X |
| 3984 |
to the original system of equations. Note that A and B are |
| 3985 |
modified on exit if equed != 0, and the solution to the |
| 3986 |
equilibrated system is inv(diag(c))*X if trans = 0 and |
| 3987 |
equed = 2 or 3, or inv(diag(r))*X if trans = 1 or 2 |
| 3988 |
and equed = 1 or 3. |
| 3989 |
|
| 3990 |
rcond: The estimate of the reciprocal condition number of the matrix |
| 3991 |
A after equilibration (if done). If rcond is less than the |
| 3992 |
machine precision (in particular, if rcond = 0), the matrix |
| 3993 |
is singular to working precision. This condition is |
| 3994 |
indicated by a return code of info > 0. |
| 3995 |
|
| 3996 |
ferr: The estimated forward error bound for each solution vector |
| 3997 |
X(j) (the j-th column of the solution matrix X). |
| 3998 |
If XTRUE is the true solution corresponding to X(j), ferr(j) |
| 3999 |
is an estimated upper bound for the magnitude of the largest |
| 4000 |
element in (X(j) - XTRUE) divided by the magnitude of the |
| 4001 |
largest element in X(j). The estimate is as reliable as |
| 4002 |
the estimate for rcond, and is almost always a slight |
| 4003 |
overestimate of the true error. |
| 4004 |
|
| 4005 |
berr: The componentwise relative backward error of each solution |
| 4006 |
vector X(j) (i.e., the smallest relative change in |
| 4007 |
any element of A or B that makes X(j) an exact solution). |
| 4008 |
|
| 4009 |
rpvgrw: Contains the reciprocal pivot growth factor norm(A)/norm(U). |
| 4010 |
The "max absolute element" norm is used. If it is much less |
| 4011 |
than 1, then the stability of the LU factorization of the |
| 4012 |
(equilibrated) matrix A could be poor. This also means that |
| 4013 |
the solution X, condition estimator rcond, and forward error |
| 4014 |
bound ferr could be unreliable. If factorization fails with |
| 4015 |
0<info<=N, then it contains the reciprocal pivot growth factor |
| 4016 |
for the leading info columns of A. |
| 4017 |
|
| 4018 |
info: = 0: successful exit |
| 4019 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4020 |
> 0: if info = i, and i is |
| 4021 |
<= N: U(i,i) is exactly zero. The factorization has |
| 4022 |
been completed, but the factor U is exactly |
| 4023 |
singular, so the solution and error bounds |
| 4024 |
could not be computed. rcond = 0 is returned. |
| 4025 |
= N+1: U is nonsingular, but rcond is less than machine |
| 4026 |
precision, meaning that the matrix is singular |
| 4027 |
to working precision. Nevertheless, the |
| 4028 |
solution and error bounds are computed because |
| 4029 |
there are a number of situations where the |
| 4030 |
computed solution can be more accurate than the |
| 4031 |
value of rcond would suggest. |
| 4032 |
|
| 4033 |
=for example |
| 4034 |
|
| 4035 |
$a= random(5,5); |
| 4036 |
$b = random(5,5); |
| 4037 |
$a = transpose($a); |
| 4038 |
$b = transpose($b); |
| 4039 |
$rcond = pdl(0); |
| 4040 |
$rpvgrw = pdl(0); |
| 4041 |
$equed = pdl(long,0); |
| 4042 |
$info = pdl(long,0); |
| 4043 |
$berr = zeroes(5); |
| 4044 |
$ipiv = zeroes(5); |
| 4045 |
$ferr = zeroes(5); |
| 4046 |
$r = zeroes(5); |
| 4047 |
$c = zeroes(5); |
| 4048 |
$X = zeroes(5,5); |
| 4049 |
$af = zeroes(5,5); |
| 4050 |
gesvx($a,0, 2, $b, $af, $ipiv, $equed, $r, $c, $X, $rcond, $ferr, $berr, $rpvgrw, $info); |
| 4051 |
print "The solution matrix X is :". transpose($X)."\n" unless $info; |
| 4052 |
|
| 4053 |
'); |
| 4054 |
|
| 4055 |
|
| 4056 |
pp_def("sysv", |
| 4057 |
HandleBad => 0, |
| 4058 |
Pars => '[io]A(n,n); int uplo(); [io]B(n,m); int [o]ipiv(n); int [o]info()', |
| 4059 |
GenericTypes => [F,D], |
| 4060 |
Code => generate_code ' |
| 4061 |
char puplo = \'U\'; |
| 4062 |
integer lwork = -1; |
| 4063 |
extern int FORTRAN($TFD(s,d)sysv)(char *uplo, integer *n, integer *nrhs, $GENERIC() |
| 4064 |
*a, integer *lda, integer *ipiv, $GENERIC() *b, integer *ldb, |
| 4065 |
$GENERIC() *work, integer *lwork, integer *info); |
| 4066 |
$GENERIC() tmp_work; |
| 4067 |
if ($uplo()) |
| 4068 |
puplo = \'L\'; |
| 4069 |
|
| 4070 |
FORTRAN($TFD(s,d)sysv)( |
| 4071 |
&puplo, |
| 4072 |
&(integer){$SIZE(n)}, |
| 4073 |
&(integer){$SIZE(m)}, |
| 4074 |
$P(A), |
| 4075 |
&(integer){$SIZE(n)}, |
| 4076 |
$P(ipiv), |
| 4077 |
$P(B), |
| 4078 |
&(integer){$SIZE(n)}, |
| 4079 |
&tmp_work, |
| 4080 |
&lwork, |
| 4081 |
$P(info)); |
| 4082 |
|
| 4083 |
lwork = (integer )tmp_work; |
| 4084 |
{ |
| 4085 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 4086 |
FORTRAN($TFD(s,d)sysv)( |
| 4087 |
&puplo, |
| 4088 |
&(integer){$SIZE(n)}, |
| 4089 |
&(integer){$SIZE(m)}, |
| 4090 |
$P(A), |
| 4091 |
&(integer){$SIZE(n)}, |
| 4092 |
$P(ipiv), |
| 4093 |
$P(B), |
| 4094 |
&(integer){$SIZE(n)}, |
| 4095 |
work, |
| 4096 |
&lwork, |
| 4097 |
$P(info)); |
| 4098 |
free(work); |
| 4099 |
} |
| 4100 |
', |
| 4101 |
Doc => ' |
| 4102 |
|
| 4103 |
=for ref |
| 4104 |
|
| 4105 |
Computes the solution to a real system of linear equations |
| 4106 |
|
| 4107 |
A * X = B, |
| 4108 |
where A is an N-by-N symmetric matrix and X and B are N-by-NRHS |
| 4109 |
matrices. |
| 4110 |
|
| 4111 |
The diagonal pivoting method is used to factor A as |
| 4112 |
|
| 4113 |
A = U * D * U\', if uplo = 0, or |
| 4114 |
A = L * D * L\', if uplo = 1, |
| 4115 |
where U (or L) is a product of permutation and unit upper (lower) |
| 4116 |
triangular matrices, and D is symmetric and block diagonal with |
| 4117 |
1-by-1 and 2-by-2 diagonal blocks. |
| 4118 |
|
| 4119 |
The factored form of A is then |
| 4120 |
used to solve the system of equations A * X = B. |
| 4121 |
|
| 4122 |
Arguments |
| 4123 |
========= |
| 4124 |
|
| 4125 |
uplo: = 0: Upper triangle of A is stored; |
| 4126 |
= 1: Lower triangle of A is stored. |
| 4127 |
|
| 4128 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 4129 |
N-by-N upper triangular part of A contains the upper |
| 4130 |
triangular part of the matrix A, and the strictly lower |
| 4131 |
triangular part of A is not referenced. If uplo = 1, the |
| 4132 |
leading N-by-N lower triangular part of A contains the lower |
| 4133 |
triangular part of the matrix A, and the strictly upper |
| 4134 |
triangular part of A is not referenced. |
| 4135 |
|
| 4136 |
On exit, if info = 0, the block diagonal matrix D and the |
| 4137 |
multipliers used to obtain the factor U or L from the |
| 4138 |
factorization A = U*D*U\' or A = L*D*L\' as computed by |
| 4139 |
sytrf. |
| 4140 |
|
| 4141 |
ipiv: Details of the interchanges and the block structure of D, as |
| 4142 |
determined by sytrf. If ipiv(k) > 0, then rows and columns |
| 4143 |
k and ipiv(k) were interchanged, and D(k,k) is a 1-by-1 |
| 4144 |
diagonal block. If uplo = 0 and ipiv(k) = ipiv(k-1) < 0, |
| 4145 |
then rows and columns k-1 and -ipiv(k) were interchanged and |
| 4146 |
D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If uplo = 1 and |
| 4147 |
ipiv(k) = ipiv(k+1) < 0, then rows and columns k+1 and |
| 4148 |
-ipiv(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 |
| 4149 |
diagonal block. |
| 4150 |
|
| 4151 |
B: On entry, the N-by-NRHS right hand side matrix B. |
| 4152 |
On exit, if info = 0, the N-by-NRHS solution matrix X. |
| 4153 |
|
| 4154 |
|
| 4155 |
info: = 0: successful exit |
| 4156 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4157 |
> 0: if info = i, D(i,i) is exactly zero. The factorization |
| 4158 |
has been completed, but the block diagonal matrix D is |
| 4159 |
exactly singular, so the solution could not be computed. |
| 4160 |
|
| 4161 |
=for example |
| 4162 |
|
| 4163 |
# Assume $a is symmetric ;) |
| 4164 |
$a = random (5,5); |
| 4165 |
$a = transpose($a); |
| 4166 |
$b = random(4,5); |
| 4167 |
$b = transpose($b); |
| 4168 |
sysv($a, 1, $b, (my $ipiv=zeroes(5)),(my $info=null)); |
| 4169 |
print "The solution matrix X is :". transpose($b)."\n" unless $info; |
| 4170 |
|
| 4171 |
'); |
| 4172 |
|
| 4173 |
pp_def("sysvx", |
| 4174 |
HandleBad => 0, |
| 4175 |
Pars => 'A(n,n); int uplo(); int fact(); B(n,m); [io]af(n,n); int [io]ipiv(n); [o]X(n,m); [o]rcond(); [o]ferr(m); [o]berr(m); int [o]info(); int [t]iwork(n);', |
| 4176 |
GenericTypes => [F,D], |
| 4177 |
Code => generate_code ' |
| 4178 |
char pfact = \'N\'; |
| 4179 |
char puplo = \'U\'; |
| 4180 |
integer lwork = -1; |
| 4181 |
extern int FORTRAN($TFD(s,d)sysvx)(char *fact, char *uplo, integer *n, integer * |
| 4182 |
nrhs, $GENERIC() *a, integer *lda, $GENERIC() *af, integer *ldaf, |
| 4183 |
integer *ipiv, $GENERIC() *b, integer *ldb, $GENERIC() *x, integer * |
| 4184 |
ldx, $GENERIC() *rcond, $GENERIC() *ferr, $GENERIC() *berr, |
| 4185 |
$GENERIC() *work, integer *lwork, integer *iwork, integer *info); |
| 4186 |
$GENERIC() tmp_work; |
| 4187 |
if($fact()) |
| 4188 |
pfact = \'F\'; |
| 4189 |
|
| 4190 |
if ($uplo()) |
| 4191 |
puplo = \'L\'; |
| 4192 |
|
| 4193 |
FORTRAN($TFD(s,d)sysvx)( |
| 4194 |
&pfact, |
| 4195 |
&puplo, |
| 4196 |
&(integer){$SIZE(n)}, |
| 4197 |
&(integer){$SIZE(m)}, |
| 4198 |
$P(A), |
| 4199 |
&(integer){$SIZE(n)}, |
| 4200 |
$P(af), |
| 4201 |
&(integer){$SIZE(n)}, |
| 4202 |
$P(ipiv), |
| 4203 |
$P(B), |
| 4204 |
&(integer){$SIZE(n)}, |
| 4205 |
$P(X), |
| 4206 |
&(integer){$SIZE(n)}, |
| 4207 |
$P(rcond), |
| 4208 |
$P(ferr), |
| 4209 |
$P(berr), |
| 4210 |
&tmp_work, |
| 4211 |
&lwork, |
| 4212 |
$P(iwork), |
| 4213 |
$P(info)); |
| 4214 |
|
| 4215 |
lwork = (integer )tmp_work; |
| 4216 |
{ |
| 4217 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 4218 |
|
| 4219 |
FORTRAN($TFD(s,d)sysvx)( |
| 4220 |
&pfact, |
| 4221 |
&puplo, |
| 4222 |
&(integer){$SIZE(n)}, |
| 4223 |
&(integer){$SIZE(m)}, |
| 4224 |
$P(A), |
| 4225 |
&(integer){$SIZE(n)}, |
| 4226 |
$P(af), |
| 4227 |
&(integer){$SIZE(n)}, |
| 4228 |
$P(ipiv), |
| 4229 |
$P(B), |
| 4230 |
&(integer){$SIZE(n)}, |
| 4231 |
$P(X), |
| 4232 |
&(integer){$SIZE(n)}, |
| 4233 |
$P(rcond), |
| 4234 |
$P(ferr), |
| 4235 |
$P(berr), |
| 4236 |
work, |
| 4237 |
&lwork, |
| 4238 |
$P(iwork), |
| 4239 |
$P(info)); |
| 4240 |
free(work); |
| 4241 |
} |
| 4242 |
', |
| 4243 |
Doc => ' |
| 4244 |
|
| 4245 |
=for ref |
| 4246 |
|
| 4247 |
Uses the diagonal pivoting factorization to compute the |
| 4248 |
solution to a real system of linear equations A * X = B, |
| 4249 |
where A is an N-by-N symmetric matrix and X and B are N-by-NRHS |
| 4250 |
matrices. |
| 4251 |
|
| 4252 |
Error bounds on the solution and a condition estimate are also |
| 4253 |
provided. |
| 4254 |
|
| 4255 |
The following steps are performed: |
| 4256 |
|
| 4257 |
=over 3 |
| 4258 |
|
| 4259 |
=item 1 |
| 4260 |
|
| 4261 |
If fact = 0, the diagonal pivoting method is used to factor A. |
| 4262 |
The form of the factorization is |
| 4263 |
|
| 4264 |
A = U * D * U\', if uplo = 0, or |
| 4265 |
A = L * D * L\', if uplo = 1, |
| 4266 |
where U (or L) is a product of permutation and unit upper (lower) |
| 4267 |
triangular matrices, and D is symmetric and block diagonal with |
| 4268 |
1-by-1 and 2-by-2 diagonal blocks. |
| 4269 |
|
| 4270 |
|
| 4271 |
=item 2 |
| 4272 |
|
| 4273 |
If some D(i,i)=0, so that D is exactly singular, then the routine |
| 4274 |
returns with info = i. Otherwise, the factored form of A is used |
| 4275 |
to estimate the condition number of the matrix A. If the |
| 4276 |
reciprocal of the condition number is less than machine precision, |
| 4277 |
info = N+1 is returned as a warning, but the routine still goes on |
| 4278 |
to solve for X and compute error bounds as described below. |
| 4279 |
|
| 4280 |
=item 3 |
| 4281 |
|
| 4282 |
The system of equations is solved for X using the factored form |
| 4283 |
of A. |
| 4284 |
|
| 4285 |
=item 4 |
| 4286 |
|
| 4287 |
Iterative refinement is applied to improve the computed solution |
| 4288 |
matrix and calculate error bounds and backward error estimates |
| 4289 |
for it. |
| 4290 |
|
| 4291 |
=back |
| 4292 |
|
| 4293 |
|
| 4294 |
Arguments |
| 4295 |
========= |
| 4296 |
|
| 4297 |
fact: Specifies whether or not the factored form of A has been |
| 4298 |
supplied on entry. |
| 4299 |
= 0: The matrix A will be copied to af and factored. |
| 4300 |
= 1: On entry, af and ipiv contain the factored form of |
| 4301 |
A. af and ipiv will not be modified. |
| 4302 |
|
| 4303 |
uplo: = 0: Upper triangle of A is stored; |
| 4304 |
= 1: Lower triangle of A is stored. |
| 4305 |
|
| 4306 |
A: The symmetric matrix A. If uplo = 0, the leading N-by-N |
| 4307 |
upper triangular part of A contains the upper triangular part |
| 4308 |
of the matrix A, and the strictly lower triangular part of A |
| 4309 |
is not referenced. If uplo = 1, the leading N-by-N lower |
| 4310 |
triangular part of A contains the lower triangular part of |
| 4311 |
the matrix A, and the strictly upper triangular part of A is |
| 4312 |
not referenced. |
| 4313 |
|
| 4314 |
af: If fact = 1, then af is an input argument and on entry |
| 4315 |
contains the block diagonal matrix D and the multipliers used |
| 4316 |
to obtain the factor U or L from the factorization |
| 4317 |
A = U*D*U\' or A = L*D*L\' as computed by sytrf. |
| 4318 |
|
| 4319 |
If fact = 0, then af is an output argument and on exit |
| 4320 |
returns the block diagonal matrix D and the multipliers used |
| 4321 |
to obtain the factor U or L from the factorization |
| 4322 |
A = U*D*U\' or A = L*D*L\'. |
| 4323 |
|
| 4324 |
ipiv: If fact = 1, then ipiv is an input argument and on entry |
| 4325 |
contains details of the interchanges and the block structure |
| 4326 |
of D, as determined by sytrf. |
| 4327 |
If ipiv(k) > 0, then rows and columns k and ipiv(k) were |
| 4328 |
interchanged and D(k,k) is a 1-by-1 diagonal block. |
| 4329 |
If uplo = 0 and ipiv(k) = ipiv(k-1) < 0, then rows and |
| 4330 |
columns k-1 and -ipiv(k) were interchanged and D(k-1:k,k-1:k) |
| 4331 |
is a 2-by-2 diagonal block. If uplo = 1 and ipiv(k) = |
| 4332 |
ipiv(k+1) < 0, then rows and columns k+1 and -ipiv(k) were |
| 4333 |
interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. |
| 4334 |
|
| 4335 |
If fact = 0, then ipiv is an output argument and on exit |
| 4336 |
contains details of the interchanges and the block structure |
| 4337 |
of D, as determined by sytrf. |
| 4338 |
|
| 4339 |
B: The N-by-NRHS right hand side matrix B. |
| 4340 |
|
| 4341 |
X: If info = 0 or info = N+1, the N-by-NRHS solution matrix X. |
| 4342 |
|
| 4343 |
rcond: The estimate of the reciprocal condition number of the matrix |
| 4344 |
A. If rcond is less than the machine precision (in |
| 4345 |
particular, if rcond = 0), the matrix is singular to working |
| 4346 |
precision. This condition is indicated by a return code of |
| 4347 |
info > 0. |
| 4348 |
|
| 4349 |
ferr: The estimated forward error bound for each solution vector |
| 4350 |
X(j) (the j-th column of the solution matrix X). |
| 4351 |
If XTRUE is the true solution corresponding to X(j), ferr(j) |
| 4352 |
is an estimated upper bound for the magnitude of the largest |
| 4353 |
element in (X(j) - XTRUE) divided by the magnitude of the |
| 4354 |
largest element in X(j). The estimate is as reliable as |
| 4355 |
the estimate for rcond, and is almost always a slight |
| 4356 |
overestimate of the true error. |
| 4357 |
|
| 4358 |
berr: The componentwise relative backward error of each solution |
| 4359 |
vector X(j) (i.e., the smallest relative change in |
| 4360 |
any element of A or B that makes X(j) an exact solution). |
| 4361 |
|
| 4362 |
info: = 0: successful exit |
| 4363 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4364 |
> 0: if info = i, and i is |
| 4365 |
<= N: D(i,i) is exactly zero. The factorization |
| 4366 |
has been completed but the factor D is exactly |
| 4367 |
singular, so the solution and error bounds could |
| 4368 |
not be computed. rcond = 0 is returned. |
| 4369 |
= N+1: D is nonsingular, but rcond is less than machine |
| 4370 |
precision, meaning that the matrix is singular |
| 4371 |
to working precision. Nevertheless, the |
| 4372 |
solution and error bounds are computed because |
| 4373 |
there are a number of situations where the |
| 4374 |
computed solution can be more accurate than the |
| 4375 |
value of rcond would suggest. |
| 4376 |
|
| 4377 |
|
| 4378 |
=for example |
| 4379 |
|
| 4380 |
$a= random(5,5); |
| 4381 |
$b = random(10,5); |
| 4382 |
$a = transpose($a); |
| 4383 |
$b = transpose($b); |
| 4384 |
$X = zeroes($b); |
| 4385 |
$af = zeroes($a); |
| 4386 |
$ipiv = zeroes(long, 5); |
| 4387 |
$rcond = pdl(0); |
| 4388 |
$ferr = zeroes(10); |
| 4389 |
$berr = zeroes(10); |
| 4390 |
$info = pdl(long, 0); |
| 4391 |
# Assume $a is symmetric |
| 4392 |
sysvx($a, 0, 0, $b,$af, $ipiv, $X, $rcond, $ferr, $berr,$info); |
| 4393 |
print "The solution matrix X is :". transpose($X)."\n"; |
| 4394 |
|
| 4395 |
'); |
| 4396 |
|
| 4397 |
pp_def("posv", |
| 4398 |
HandleBad => 0, |
| 4399 |
Pars => '[io]A(n,n); int uplo(); [io]B(n,m); int [o]info()', |
| 4400 |
GenericTypes => [F,D], |
| 4401 |
Code => generate_code ' |
| 4402 |
char puplo = \'U\'; |
| 4403 |
|
| 4404 |
extern int FORTRAN($TFD(s,d)posv)(char *uplo, integer *n, integer *nrhs, $GENERIC() |
| 4405 |
*a, integer *lda, $GENERIC() *b, integer *ldb, integer *info); |
| 4406 |
|
| 4407 |
if ($uplo()) |
| 4408 |
puplo = \'L\'; |
| 4409 |
|
| 4410 |
FORTRAN($TFD(s,d)posv)( |
| 4411 |
&puplo, |
| 4412 |
&(integer){$SIZE(n)}, |
| 4413 |
&(integer){$SIZE(m)}, |
| 4414 |
$P(A), |
| 4415 |
&(integer){$SIZE(n)}, |
| 4416 |
$P(B), |
| 4417 |
&(integer){$SIZE(n)}, |
| 4418 |
$P(info)); |
| 4419 |
', |
| 4420 |
Doc => ' |
| 4421 |
|
| 4422 |
=for ref |
| 4423 |
|
| 4424 |
Computes the solution to a real system of linear equations |
| 4425 |
|
| 4426 |
A * X = B, |
| 4427 |
where A is an N-by-N symmetric positive definite matrix and X and B |
| 4428 |
are N-by-NRHS matrices. |
| 4429 |
|
| 4430 |
The Cholesky decomposition is used to factor A as |
| 4431 |
|
| 4432 |
A = U\'* U, if uplo = 0, or |
| 4433 |
A = L * L\', if uplo = 1, |
| 4434 |
where U is an upper triangular matrix and L is a lower triangular |
| 4435 |
matrix. |
| 4436 |
|
| 4437 |
The factored form of A is then used to solve the system of |
| 4438 |
equations A * X = B. |
| 4439 |
|
| 4440 |
Arguments |
| 4441 |
========= |
| 4442 |
|
| 4443 |
uplo: = 0: Upper triangle of A is stored; |
| 4444 |
= 1: Lower triangle of A is stored. |
| 4445 |
|
| 4446 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 4447 |
N-by-N upper triangular part of A contains the upper |
| 4448 |
triangular part of the matrix A, and the strictly lower |
| 4449 |
triangular part of A is not referenced. If uplo = 1, the |
| 4450 |
leading N-by-N lower triangular part of A contains the lower |
| 4451 |
triangular part of the matrix A, and the strictly upper |
| 4452 |
triangular part of A is not referenced. |
| 4453 |
|
| 4454 |
On exit, if info = 0, the factor U or L from the Cholesky |
| 4455 |
factorization A = U\'*U or A = L*L\'. |
| 4456 |
|
| 4457 |
B: On entry, the N-by-NRHS right hand side matrix B. |
| 4458 |
On exit, if info = 0, the N-by-NRHS solution matrix X. |
| 4459 |
|
| 4460 |
info: = 0: successful exit |
| 4461 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4462 |
> 0: if info = i, the leading minor of order i of A is not |
| 4463 |
positive definite, so the factorization could not be |
| 4464 |
completed, and the solution has not been computed. |
| 4465 |
|
| 4466 |
=for example |
| 4467 |
|
| 4468 |
# Assume $a is symmetric positive definite ;) |
| 4469 |
$a = random (5,5); |
| 4470 |
$a = transpose($a); |
| 4471 |
$b = random(4,5); |
| 4472 |
$b = transpose($b); |
| 4473 |
posv($a, 1, $b, (my $info=null)); |
| 4474 |
print "The solution matrix X is :". transpose($b)."\n" unless $info; |
| 4475 |
|
| 4476 |
'); |
| 4477 |
|
| 4478 |
pp_def("posvx", |
| 4479 |
HandleBad => 0, |
| 4480 |
Pars => '[io]A(n,n); int uplo(); int fact(); [io]B(n,m); [io]af(n,n); int [io]equed(); [o]s(p); [o]X(n,m); [o]rcond(); [o]ferr(m); [o]berr(m); int [o]info(); int [t]iwork(n); [t]work(workn=CALC(3*$SIZE(n)));', |
| 4481 |
RedoDimsCode => ' |
| 4482 |
$SIZE(p) = $SIZE(n); /* Ubuntu LAPACK 3 writes to s anyway */ |
| 4483 |
', |
| 4484 |
GenericTypes => [F,D], |
| 4485 |
Code => generate_code ' |
| 4486 |
char pfact; |
| 4487 |
char pequed = \'N\'; |
| 4488 |
char puplo = \'U\'; |
| 4489 |
extern int FORTRAN($TFD(s,d)posvx)(char *fact, char *uplo, integer *n, integer * |
| 4490 |
nrhs, $GENERIC() *a, integer *lda, $GENERIC() *af, integer *ldaf, |
| 4491 |
char *equed, $GENERIC() *s, $GENERIC() *b, integer *ldb, $GENERIC() * |
| 4492 |
x, integer *ldx, $GENERIC() *rcond, $GENERIC() *ferr, $GENERIC() * |
| 4493 |
berr, $GENERIC() *work, integer *iwork, integer *info); |
| 4494 |
switch ($fact()) |
| 4495 |
{ |
| 4496 |
case 1: pfact = \'N\'; |
| 4497 |
break; |
| 4498 |
case 2: pfact = \'E\'; |
| 4499 |
break; |
| 4500 |
default: pfact = \'F\'; |
| 4501 |
} |
| 4502 |
if ($equed()) |
| 4503 |
pequed = \'Y\'; |
| 4504 |
if ($uplo()) |
| 4505 |
puplo = \'L\'; |
| 4506 |
|
| 4507 |
FORTRAN($TFD(s,d)posvx)( |
| 4508 |
&pfact, |
| 4509 |
&puplo, |
| 4510 |
&(integer){$SIZE(n)}, |
| 4511 |
&(integer){$SIZE(m)}, |
| 4512 |
$P(A), |
| 4513 |
&(integer){$SIZE(n)}, |
| 4514 |
$P(af), |
| 4515 |
&(integer){$SIZE(n)}, |
| 4516 |
&pequed, |
| 4517 |
$P(s), |
| 4518 |
$P(B), |
| 4519 |
&(integer){$SIZE(n)}, |
| 4520 |
$P(X), |
| 4521 |
&(integer){$SIZE(n)}, |
| 4522 |
$P(rcond), |
| 4523 |
$P(ferr), |
| 4524 |
$P(berr), |
| 4525 |
$P(work), |
| 4526 |
$P(iwork), |
| 4527 |
$P(info)); |
| 4528 |
|
| 4529 |
switch (pequed) |
| 4530 |
{ |
| 4531 |
case \'Y\': $equed() = 1; |
| 4532 |
break; |
| 4533 |
default: $equed()= 0; |
| 4534 |
} |
| 4535 |
', |
| 4536 |
Doc => ' |
| 4537 |
|
| 4538 |
=for ref |
| 4539 |
|
| 4540 |
Uses the Cholesky factorization A = U\'*U or A = L*L\' to |
| 4541 |
compute the solution to a real system of linear equations |
| 4542 |
|
| 4543 |
A * X = B, |
| 4544 |
where A is an N-by-N symmetric positive definite matrix and X and B |
| 4545 |
are N-by-NRHS matrices. |
| 4546 |
|
| 4547 |
Error bounds on the solution and a condition estimate are also |
| 4548 |
provided. |
| 4549 |
|
| 4550 |
The following steps are performed: |
| 4551 |
|
| 4552 |
=over 3 |
| 4553 |
|
| 4554 |
|
| 4555 |
=item 1 |
| 4556 |
|
| 4557 |
If fact = 2, real scaling factors are computed to equilibrate |
| 4558 |
the system: |
| 4559 |
|
| 4560 |
diag(s) * A * diag(s) * inv(diag(s)) * X = diag(s) * B |
| 4561 |
|
| 4562 |
Whether or not the system will be equilibrated depends on the |
| 4563 |
scaling of the matrix A, but if equilibration is used, A is |
| 4564 |
overwritten by diag(s)*A*diag(s) and B by diag(s)*B. |
| 4565 |
|
| 4566 |
=item 2 |
| 4567 |
|
| 4568 |
If fact = 1 or 2, the Cholesky decomposition is used to |
| 4569 |
factor the matrix A (after equilibration if fact = 2) as |
| 4570 |
|
| 4571 |
A = U\'* U, if uplo = 0, or |
| 4572 |
A = L * L\', if uplo = 1, |
| 4573 |
where U is an upper triangular matrix and L is a lower triangular |
| 4574 |
matrix. |
| 4575 |
|
| 4576 |
=item 3 |
| 4577 |
|
| 4578 |
If the leading i-by-i principal minor is not positive definite, |
| 4579 |
then the routine returns with info = i. Otherwise, the factored |
| 4580 |
form of A is used to estimate the condition number of the matrix |
| 4581 |
A. If the reciprocal of the condition number is less than machine |
| 4582 |
precision, info = N+1 is returned as a warning, but the routine |
| 4583 |
still goes on to solve for X and compute error bounds as |
| 4584 |
described below. |
| 4585 |
|
| 4586 |
=item 4 |
| 4587 |
|
| 4588 |
The system of equations is solved for X using the factored form |
| 4589 |
of A. |
| 4590 |
|
| 4591 |
=item 5 |
| 4592 |
|
| 4593 |
Iterative refinement is applied to improve the computed solution |
| 4594 |
matrix and calculate error bounds and backward error estimates |
| 4595 |
for it. |
| 4596 |
|
| 4597 |
=item 6 |
| 4598 |
|
| 4599 |
If equilibration was used, the matrix X is premultiplied by |
| 4600 |
diag(s) so that it solves the original system before |
| 4601 |
equilibration. |
| 4602 |
|
| 4603 |
=back |
| 4604 |
|
| 4605 |
Arguments |
| 4606 |
========= |
| 4607 |
|
| 4608 |
fact: Specifies whether or not the factored form of the matrix A is |
| 4609 |
supplied on entry, and if not, whether the matrix A should be |
| 4610 |
equilibrated before it is factored. |
| 4611 |
= 0: On entry, af contains the factored form of A. |
| 4612 |
If equed = 1, the matrix A has been equilibrated |
| 4613 |
with scaling factors given by s. A and af will not |
| 4614 |
be modified. |
| 4615 |
= 1: The matrix A will be copied to af and factored. |
| 4616 |
= 2: The matrix A will be equilibrated if necessary, then |
| 4617 |
copied to af and factored. |
| 4618 |
|
| 4619 |
uplo: = 0: Upper triangle of A is stored; |
| 4620 |
= 1: Lower triangle of A is stored. |
| 4621 |
|
| 4622 |
A: On entry, the symmetric matrix A, except if fact = 0 and |
| 4623 |
equed = 1, then A must contain the equilibrated matrix |
| 4624 |
diag(s)*A*diag(s). If uplo = 0, the leading |
| 4625 |
N-by-N upper triangular part of A contains the upper |
| 4626 |
triangular part of the matrix A, and the strictly lower |
| 4627 |
triangular part of A is not referenced. If uplo = 1, the |
| 4628 |
leading N-by-N lower triangular part of A contains the lower |
| 4629 |
triangular part of the matrix A, and the strictly upper |
| 4630 |
triangular part of A is not referenced. A is not modified if |
| 4631 |
fact = 0 or 1, or if fact = 2 and equed = 0 on exit. |
| 4632 |
|
| 4633 |
On exit, if fact = 2 and equed = 1, A is overwritten by |
| 4634 |
diag(s)*A*diag(s). |
| 4635 |
|
| 4636 |
af: If fact = 0, then af is an input argument and on entry |
| 4637 |
contains the triangular factor U or L from the Cholesky |
| 4638 |
factorization A = U\'*U or A = L*L\', in the same storage |
| 4639 |
format as A. If equed != 0, then af is the factored form |
| 4640 |
of the equilibrated matrix diag(s)*A*diag(s). |
| 4641 |
|
| 4642 |
If fact = 1, then af is an output argument and on exit |
| 4643 |
returns the triangular factor U or L from the Cholesky |
| 4644 |
factorization A = U\'*U or A = L*L\' of the original |
| 4645 |
matrix A. |
| 4646 |
|
| 4647 |
If fact = 2, then af is an output argument and on exit |
| 4648 |
returns the triangular factor U or L from the Cholesky |
| 4649 |
factorization A = U\'*U or A = L*L\' of the equilibrated |
| 4650 |
matrix A (see the description of A for the form of the |
| 4651 |
equilibrated matrix). |
| 4652 |
|
| 4653 |
equed: Specifies the form of equilibration that was done. |
| 4654 |
= 0: No equilibration (always true if fact = 1). |
| 4655 |
= 1: Equilibration was done, i.e., A has been replaced by |
| 4656 |
diag(s) * A * diag(s). |
| 4657 |
equed is an input argument if fact = 0; otherwise, it is an |
| 4658 |
output argument. |
| 4659 |
|
| 4660 |
s: The scale factors for A; not accessed if equed = 0. s is |
| 4661 |
an input argument if fact = 0; otherwise, s is an output |
| 4662 |
argument. If fact = 0 and equed = 1, each element of s |
| 4663 |
must be positive. |
| 4664 |
|
| 4665 |
B: On entry, the N-by-NRHS right hand side matrix B. |
| 4666 |
On exit, if equed = 0, B is not modified; if equed = 1, |
| 4667 |
B is overwritten by diag(s) * B. |
| 4668 |
|
| 4669 |
X: If info = 0 or info = N+1, the N-by-NRHS solution matrix X to |
| 4670 |
the original system of equations. Note that if equed = 1, |
| 4671 |
A and B are modified on exit, and the solution to the |
| 4672 |
equilibrated system is inv(diag(s))*X. |
| 4673 |
|
| 4674 |
rcond: The estimate of the reciprocal condition number of the matrix |
| 4675 |
A after equilibration (if done). If rcond is less than the |
| 4676 |
machine precision (in particular, if rcond = 0), the matrix |
| 4677 |
is singular to working precision. This condition is |
| 4678 |
indicated by a return code of info > 0. |
| 4679 |
|
| 4680 |
ferr: The estimated forward error bound for each solution vector |
| 4681 |
X(j) (the j-th column of the solution matrix X). |
| 4682 |
If XTRUE is the true solution corresponding to X(j), FERR(j) |
| 4683 |
is an estimated upper bound for the magnitude of the largest |
| 4684 |
element in (X(j) - XTRUE) divided by the magnitude of the |
| 4685 |
largest element in X(j). The estimate is as reliable as |
| 4686 |
the estimate for rcond, and is almost always a slight |
| 4687 |
overestimate of the true error. |
| 4688 |
|
| 4689 |
berr: The componentwise relative backward error of each solution |
| 4690 |
vector X(j) (i.e., the smallest relative change in |
| 4691 |
any element of A or B that makes X(j) an exact solution). |
| 4692 |
|
| 4693 |
info: = 0: successful exit |
| 4694 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4695 |
> 0: if info = i, and i is |
| 4696 |
<= N: the leading minor of order i of A is |
| 4697 |
not positive definite, so the factorization |
| 4698 |
could not be completed, and the solution has not |
| 4699 |
been computed. rcond = 0 is returned. |
| 4700 |
= N+1: U is nonsingular, but rcond is less than machine |
| 4701 |
precision, meaning that the matrix is singular |
| 4702 |
to working precision. Nevertheless, the |
| 4703 |
solution and error bounds are computed because |
| 4704 |
there are a number of situations where the |
| 4705 |
computed solution can be more accurate than the |
| 4706 |
value of rcond would suggest. |
| 4707 |
|
| 4708 |
|
| 4709 |
=for example |
| 4710 |
|
| 4711 |
$a= random(5,5); |
| 4712 |
$b = random(5,5); |
| 4713 |
$a = transpose($a); |
| 4714 |
$b = transpose($b); |
| 4715 |
# Assume $a is symmetric positive definite |
| 4716 |
$rcond = pdl(0); |
| 4717 |
$equed = pdl(long,0); |
| 4718 |
$info = pdl(long,0); |
| 4719 |
$berr = zeroes(5); |
| 4720 |
$ferr = zeroes(5); |
| 4721 |
$s = zeroes(5); |
| 4722 |
$X = zeroes(5,5); |
| 4723 |
$af = zeroes(5,5); |
| 4724 |
posvx($a,0,2,$b,$af, $equed, $s, $X, $rcond, $ferr, $berr,$info); |
| 4725 |
print "The solution matrix X is :". transpose($X)."\n" unless $info; |
| 4726 |
|
| 4727 |
'); |
| 4728 |
|
| 4729 |
pp_def("gels", |
| 4730 |
HandleBad => 0, |
| 4731 |
Pars => '[io]A(m,n); int trans(); [io]B(p,q);int [o]info()', |
| 4732 |
GenericTypes => [F,D], |
| 4733 |
Code => generate_code ' |
| 4734 |
char ptrans = \'N\'; |
| 4735 |
integer lwork = -1; |
| 4736 |
|
| 4737 |
extern int FORTRAN($TFD(s,d)gels)(char *trans, integer *m, integer *n, integer * |
| 4738 |
nrhs, $GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, |
| 4739 |
$GENERIC() *work, integer *lwork, integer *info); |
| 4740 |
$GENERIC() tmp_work; |
| 4741 |
|
| 4742 |
if($trans()) |
| 4743 |
ptrans = \'T\'; |
| 4744 |
|
| 4745 |
FORTRAN($TFD(s,d)gels)( |
| 4746 |
&ptrans, |
| 4747 |
&(integer){$SIZE(m)}, |
| 4748 |
&(integer){$SIZE(n)}, |
| 4749 |
&(integer){$SIZE(q)}, |
| 4750 |
$P(A), |
| 4751 |
&(integer){$SIZE(m)}, |
| 4752 |
$P(B), |
| 4753 |
&(integer){$SIZE(p)}, |
| 4754 |
&tmp_work, |
| 4755 |
&lwork, |
| 4756 |
$P(info)); |
| 4757 |
|
| 4758 |
lwork = (integer )tmp_work; |
| 4759 |
{ |
| 4760 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 4761 |
|
| 4762 |
FORTRAN($TFD(s,d)gels)( |
| 4763 |
&ptrans, |
| 4764 |
&(integer){$SIZE(m)}, |
| 4765 |
&(integer){$SIZE(n)}, |
| 4766 |
&(integer){$SIZE(q)}, |
| 4767 |
$P(A), |
| 4768 |
&(integer){$SIZE(m)}, |
| 4769 |
$P(B), |
| 4770 |
&(integer){$SIZE(p)}, |
| 4771 |
work, |
| 4772 |
&lwork, |
| 4773 |
$P(info)); |
| 4774 |
free(work); |
| 4775 |
} |
| 4776 |
|
| 4777 |
', |
| 4778 |
Doc => ' |
| 4779 |
|
| 4780 |
=for ref |
| 4781 |
|
| 4782 |
Solves overdetermined or underdetermined real linear systems |
| 4783 |
involving an M-by-N matrix A, or its transpose, using a QR or LQ |
| 4784 |
factorization of A. It is assumed that A has full rank. |
| 4785 |
|
| 4786 |
The following options are provided: |
| 4787 |
|
| 4788 |
=over 3 |
| 4789 |
|
| 4790 |
=item 1 |
| 4791 |
|
| 4792 |
If trans = 0 and m >= n: find the least squares solution of |
| 4793 |
an overdetermined system, i.e., solve the least squares problem |
| 4794 |
minimize || B - A*X ||. |
| 4795 |
|
| 4796 |
=item 2 |
| 4797 |
|
| 4798 |
If trans = 0 and m < n: find the minimum norm solution of |
| 4799 |
an underdetermined system A * X = B. |
| 4800 |
|
| 4801 |
=item 3 |
| 4802 |
|
| 4803 |
If trans = 1 and m >= n: find the minimum norm solution of |
| 4804 |
an undetermined system A\' * X = B. |
| 4805 |
|
| 4806 |
=item 4 |
| 4807 |
|
| 4808 |
If trans = 1 and m < n: find the least squares solution of |
| 4809 |
an overdetermined system, i.e., solve the least squares problem |
| 4810 |
minimize || B - A\' * X ||. |
| 4811 |
|
| 4812 |
=back |
| 4813 |
|
| 4814 |
Several right hand side vectors b and solution vectors x can be |
| 4815 |
handled in a single call; they are stored as the columns of the |
| 4816 |
M-by-NRHS right hand side matrix B and the N-by-NRHS solution |
| 4817 |
matrix X. |
| 4818 |
|
| 4819 |
Arguments |
| 4820 |
========= |
| 4821 |
|
| 4822 |
trans: = 0: the linear system involves A; |
| 4823 |
= 1: the linear system involves A\'. |
| 4824 |
|
| 4825 |
A: On entry, the M-by-N matrix A. |
| 4826 |
On exit, |
| 4827 |
if M >= N, A is overwritten by details of its QR |
| 4828 |
factorization as returned by geqrf; |
| 4829 |
if M < N, A is overwritten by details of its LQ |
| 4830 |
factorization as returned by gelqf. |
| 4831 |
|
| 4832 |
B: On entry, the matrix B of right hand side vectors, stored |
| 4833 |
columnwise; B is M-by-NRHS if trans = 0, or N-by-NRHS |
| 4834 |
if trans = 1. |
| 4835 |
On exit, B is overwritten by the solution vectors, stored |
| 4836 |
columnwise: |
| 4837 |
if trans = 0 and m >= n, rows 1 to n of B contain the least |
| 4838 |
squares solution vectors; the residual sum of squares for the |
| 4839 |
solution in each column is given by the sum of squares of |
| 4840 |
elements N+1 to M in that column; |
| 4841 |
if trans = 0 and m < n, rows 1 to N of B contain the |
| 4842 |
minimum norm solution vectors; |
| 4843 |
if trans = 1 and m >= n, rows 1 to M of B contain the |
| 4844 |
minimum norm solution vectors; |
| 4845 |
if trans = 1 and m < n, rows 1 to M of B contain the |
| 4846 |
least squares solution vectors; the residual sum of squares |
| 4847 |
for the solution in each column is given by the sum of |
| 4848 |
squares of elements M+1 to N in that column. |
| 4849 |
The leading dimension of the array B >= max(1,M,N). |
| 4850 |
|
| 4851 |
info: = 0: successful exit |
| 4852 |
< 0: if info = -i, the i-th argument had an illegal value |
| 4853 |
|
| 4854 |
|
| 4855 |
=for example |
| 4856 |
|
| 4857 |
$a= random(7,5); |
| 4858 |
# $b will contain X |
| 4859 |
# TODO better example with slice |
| 4860 |
$b = random(7,6); |
| 4861 |
gels($a, 1, $b, ($info = null)); |
| 4862 |
|
| 4863 |
'); |
| 4864 |
|
| 4865 |
pp_def("gelsy", |
| 4866 |
HandleBad => 0, |
| 4867 |
Pars => '[io]A(m,n); [io]B(p,q); rcond(); int [io]jpvt(n); int [o]rank();int [o]info()', |
| 4868 |
GenericTypes => [F,D], |
| 4869 |
Code => generate_code ' |
| 4870 |
integer lwork = -1; |
| 4871 |
|
| 4872 |
extern int FORTRAN($TFD(s,d)gelsy)(integer *m, integer *n, integer *nrhs, |
| 4873 |
$GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, integer * |
| 4874 |
jpvt, $GENERIC() *rcond, integer *rank, $GENERIC() *work, integer * |
| 4875 |
lwork, integer *info); |
| 4876 |
$GENERIC() tmp_work; |
| 4877 |
|
| 4878 |
FORTRAN($TFD(s,d)gelsy)( |
| 4879 |
&(integer){$SIZE(m)}, |
| 4880 |
&(integer){$SIZE(n)}, |
| 4881 |
&(integer){$SIZE(q)}, |
| 4882 |
$P(A), |
| 4883 |
&(integer){$SIZE(m)}, |
| 4884 |
$P(B), |
| 4885 |
&(integer){$SIZE(p)}, |
| 4886 |
$P(jpvt), |
| 4887 |
$P(rcond), |
| 4888 |
$P(rank), |
| 4889 |
&tmp_work, |
| 4890 |
&lwork, |
| 4891 |
$P(info)); |
| 4892 |
|
| 4893 |
lwork = (integer )tmp_work; |
| 4894 |
{ |
| 4895 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 4896 |
|
| 4897 |
FORTRAN($TFD(s,d)gelsy)( |
| 4898 |
&(integer){$SIZE(m)}, |
| 4899 |
&(integer){$SIZE(n)}, |
| 4900 |
&(integer){$SIZE(q)}, |
| 4901 |
$P(A), |
| 4902 |
&(integer){$SIZE(m)}, |
| 4903 |
$P(B), |
| 4904 |
&(integer){$SIZE(p)}, |
| 4905 |
$P(jpvt), |
| 4906 |
$P(rcond), |
| 4907 |
$P(rank), |
| 4908 |
work, |
| 4909 |
&lwork, |
| 4910 |
$P(info)); |
| 4911 |
free(work); |
| 4912 |
} |
| 4913 |
|
| 4914 |
', |
| 4915 |
Doc => ' |
| 4916 |
|
| 4917 |
=for ref |
| 4918 |
|
| 4919 |
Computes the minimum-norm solution to a real linear least |
| 4920 |
squares problem: |
| 4921 |
|
| 4922 |
minimize || A * X - B || |
| 4923 |
|
| 4924 |
using a complete orthogonal factorization of A. |
| 4925 |
|
| 4926 |
A is an M-by-N matrix which may be rank-deficient. |
| 4927 |
|
| 4928 |
Several right hand side vectors b and solution vectors x can be |
| 4929 |
handled in a single call; they are stored as the columns of the |
| 4930 |
M-by-NRHS right hand side matrix B and the N-by-NRHS solution |
| 4931 |
matrix X. |
| 4932 |
|
| 4933 |
The routine first computes a QR factorization with column pivoting: |
| 4934 |
|
| 4935 |
A * P = Q * [ R11 R12 ] |
| 4936 |
[ 0 R22 ] |
| 4937 |
|
| 4938 |
with R11 defined as the largest leading submatrix whose estimated |
| 4939 |
condition number is less than 1/rcond. The order of R11, rank, |
| 4940 |
is the effective rank of A. |
| 4941 |
|
| 4942 |
Then, R22 is considered to be negligible, and R12 is annihilated |
| 4943 |
by orthogonal transformations from the right, arriving at the |
| 4944 |
complete orthogonal factorization: |
| 4945 |
|
| 4946 |
A * P = Q * [ T11 0 ] * Z |
| 4947 |
[ 0 0 ] |
| 4948 |
|
| 4949 |
The minimum-norm solution is then |
| 4950 |
|
| 4951 |
X = P * Z\' [ inv(T11)*Q1\'*B ] |
| 4952 |
[ 0 ] |
| 4953 |
where Q1 consists of the first rank columns of Q. |
| 4954 |
|
| 4955 |
|
| 4956 |
Arguments |
| 4957 |
========= |
| 4958 |
|
| 4959 |
A: On entry, the M-by-N matrix A. |
| 4960 |
On exit, A has been overwritten by details of its |
| 4961 |
complete orthogonal factorization. |
| 4962 |
|
| 4963 |
B: On entry, the M-by-NRHS right hand side matrix B. |
| 4964 |
On exit, the N-by-NRHS solution matrix X. |
| 4965 |
The leading dimension of the array B >= max(1,M,N). |
| 4966 |
|
| 4967 |
jpvt: On entry, if jpvt(i) != 0, the i-th column of A is permuted |
| 4968 |
to the front of AP, otherwise column i is a free column. |
| 4969 |
On exit, if jpvt(i) = k, then the i-th column of AP |
| 4970 |
was the k-th column of A. |
| 4971 |
|
| 4972 |
rcond: rcond is used to determine the effective rank of A, which |
| 4973 |
is defined as the order of the largest leading triangular |
| 4974 |
submatrix R11 in the QR factorization with pivoting of A, |
| 4975 |
whose estimated condition number < 1/rcond. |
| 4976 |
|
| 4977 |
rank: The effective rank of A, i.e., the order of the submatrix |
| 4978 |
R11. This is the same as the order of the submatrix T11 |
| 4979 |
in the complete orthogonal factorization of A. |
| 4980 |
|
| 4981 |
|
| 4982 |
info: = 0: successful exit |
| 4983 |
< 0: If info = -i, the i-th argument had an illegal value. |
| 4984 |
|
| 4985 |
|
| 4986 |
=for example |
| 4987 |
|
| 4988 |
$a= random(7,5); |
| 4989 |
# $b will contain X |
| 4990 |
# TODO better example with slice |
| 4991 |
$b = random(7,6); |
| 4992 |
$jpvt = zeroes(long, 5); |
| 4993 |
$eps = lamch(0); |
| 4994 |
#Threshold for rank estimation |
| 4995 |
$rcond = sqrt($eps) - (sqrt($eps) - $eps) / 2; |
| 4996 |
gelsy($a, $b, $rcond, $jpvt,($rank=null),($info = null)); |
| 4997 |
|
| 4998 |
'); |
| 4999 |
|
| 5000 |
pp_def("gelss", |
| 5001 |
HandleBad => 0, |
| 5002 |
Pars => '[io]A(m,n); [io]B(p,q); rcond(); [o]s(r); int [o]rank();int [o]info()', |
| 5003 |
GenericTypes => [F,D], |
| 5004 |
Code => generate_code ' |
| 5005 |
integer lwork = -1; |
| 5006 |
|
| 5007 |
extern int FORTRAN($TFD(s,d)gelss)(integer *m, integer *n, integer *nrhs, |
| 5008 |
$GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *s, |
| 5009 |
$GENERIC() *rcond, integer *rank, $GENERIC() *work, integer * |
| 5010 |
lwork, integer *info); |
| 5011 |
$GENERIC() tmp_work; |
| 5012 |
|
| 5013 |
FORTRAN($TFD(s,d)gelss)( |
| 5014 |
&(integer){$SIZE(m)}, |
| 5015 |
&(integer){$SIZE(n)}, |
| 5016 |
&(integer){$SIZE(q)}, |
| 5017 |
$P(A), |
| 5018 |
&(integer){$SIZE(m)}, |
| 5019 |
$P(B), |
| 5020 |
&(integer){$SIZE(p)}, |
| 5021 |
$P(s), |
| 5022 |
$P(rcond), |
| 5023 |
$P(rank), |
| 5024 |
&tmp_work, |
| 5025 |
&lwork, |
| 5026 |
$P(info)); |
| 5027 |
|
| 5028 |
lwork = (integer )tmp_work; |
| 5029 |
{ |
| 5030 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5031 |
FORTRAN($TFD(s,d)gelss)( |
| 5032 |
&(integer){$SIZE(m)}, |
| 5033 |
&(integer){$SIZE(n)}, |
| 5034 |
&(integer){$SIZE(q)}, |
| 5035 |
$P(A), |
| 5036 |
&(integer){$SIZE(m)}, |
| 5037 |
$P(B), |
| 5038 |
&(integer){$SIZE(p)}, |
| 5039 |
$P(s), |
| 5040 |
$P(rcond), |
| 5041 |
$P(rank), |
| 5042 |
work, |
| 5043 |
&lwork, |
| 5044 |
$P(info)); |
| 5045 |
free(work); |
| 5046 |
} |
| 5047 |
|
| 5048 |
', |
| 5049 |
Doc => ' |
| 5050 |
|
| 5051 |
=for ref |
| 5052 |
|
| 5053 |
Computes the minimum norm solution to a real linear least |
| 5054 |
squares problem: |
| 5055 |
|
| 5056 |
Minimize 2-norm(| b - A*x |). |
| 5057 |
|
| 5058 |
using the singular value decomposition (SVD) of A. A is an M-by-N |
| 5059 |
matrix which may be rank-deficient. |
| 5060 |
|
| 5061 |
Several right hand side vectors b and solution vectors x can be |
| 5062 |
handled in a single call; they are stored as the columns of the |
| 5063 |
M-by-NRHS right hand side matrix B and the N-by-NRHS solution matrix |
| 5064 |
X. |
| 5065 |
|
| 5066 |
The effective rank of A is determined by treating as zero those |
| 5067 |
singular values which are less than rcond times the largest singular |
| 5068 |
value. |
| 5069 |
|
| 5070 |
Arguments |
| 5071 |
========= |
| 5072 |
|
| 5073 |
A: On entry, the M-by-N matrix A. |
| 5074 |
On exit, the first min(m,n) rows of A are overwritten with |
| 5075 |
its right singular vectors, stored rowwise. |
| 5076 |
|
| 5077 |
B: On entry, the M-by-NRHS right hand side matrix B. |
| 5078 |
On exit, B is overwritten by the N-by-NRHS solution |
| 5079 |
matrix X. If m >= n and rank = n, the residual |
| 5080 |
sum-of-squares for the solution in the i-th column is given |
| 5081 |
by the sum of squares of elements n+1:m in that column. |
| 5082 |
The leading dimension of the array B >= max(1,M,N). |
| 5083 |
|
| 5084 |
s: The singular values of A in decreasing order. |
| 5085 |
The condition number of A in the 2-norm = s(1)/s(min(m,n)). |
| 5086 |
|
| 5087 |
rcond: rcond is used to determine the effective rank of A. |
| 5088 |
Singular values s(i) <= rcond*s(1) are treated as zero. |
| 5089 |
If rcond < 0, machine precision is used instead. |
| 5090 |
|
| 5091 |
rank: The effective rank of A, i.e., the number of singular values |
| 5092 |
which are greater than rcond*s(1). |
| 5093 |
|
| 5094 |
info: = 0: successful exit |
| 5095 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 5096 |
> 0: the algorithm for computing the SVD failed to converge; |
| 5097 |
if info = i, i off-diagonal elements of an intermediate |
| 5098 |
bidiagonal form did not converge to zero. |
| 5099 |
|
| 5100 |
|
| 5101 |
=for example |
| 5102 |
|
| 5103 |
$a= random(7,5); |
| 5104 |
# $b will contain X |
| 5105 |
# TODO better example with slice |
| 5106 |
$b = random(7,6); |
| 5107 |
$eps = lamch(0); |
| 5108 |
$s =zeroes(5); |
| 5109 |
#Threshold for rank estimation |
| 5110 |
$rcond = sqrt($eps) - (sqrt($eps) - $eps) / 2; |
| 5111 |
gelss($a, $b, $rcond, $s, ($rank=null),($info = null)); |
| 5112 |
|
| 5113 |
'); |
| 5114 |
|
| 5115 |
pp_def("gelsd", |
| 5116 |
HandleBad => 0, |
| 5117 |
Pars => '[io]A(m,n); [io]B(p,q); rcond(); [o]s(minmn=CALC(PDLMAX(1,PDLMIN($SIZE(m),$SIZE(n))))); int [o]rank();int [o]info(); int [t]iwork(iworkn);', |
| 5118 |
GenericTypes => [F,D], |
| 5119 |
RedoDimsCode => ' |
| 5120 |
integer smlsiz = FORTRAN(ilaenv)(&c_nine, "DGELSD", " ", &c_zero, &c_zero, &c_zero, &c_zero, (ftnlen)6, (ftnlen)1); |
| 5121 |
integer size_i = (integer) (log((double) $SIZE(minmn) / (double) (smlsiz + 1)) /log(2.)) + 1; |
| 5122 |
$SIZE(iworkn) = $SIZE(minmn) * (3 * PDLMAX(size_i,0) + 11); |
| 5123 |
', |
| 5124 |
Code => generate_code ' |
| 5125 |
integer lwork = -1; |
| 5126 |
integer minmn = $SIZE(minmn); |
| 5127 |
|
| 5128 |
extern int FORTRAN($TFD(s,d)gelsd)(integer *m, integer *n, integer *nrhs, |
| 5129 |
$GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *s, |
| 5130 |
$GENERIC() *rcond, integer *rank, $GENERIC() *work, integer * |
| 5131 |
lwork, integer *iwork, integer *info); |
| 5132 |
|
| 5133 |
$GENERIC() tmp_work; |
| 5134 |
|
| 5135 |
FORTRAN($TFD(s,d)gelsd)( |
| 5136 |
&(integer){$SIZE(m)}, |
| 5137 |
&(integer){$SIZE(n)}, |
| 5138 |
&(integer){$SIZE(q)}, |
| 5139 |
$P(A), |
| 5140 |
&(integer){$SIZE(m)}, |
| 5141 |
$P(B), |
| 5142 |
&(integer){$SIZE(p)}, |
| 5143 |
$P(s), |
| 5144 |
$P(rcond), |
| 5145 |
$P(rank), |
| 5146 |
&tmp_work, |
| 5147 |
&lwork, |
| 5148 |
$P(iwork), |
| 5149 |
$P(info)); |
| 5150 |
if ($info() != 0) $CROAK("workspace query failed: info=%d", $info()); |
| 5151 |
|
| 5152 |
lwork = (integer )tmp_work; |
| 5153 |
{ |
| 5154 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5155 |
|
| 5156 |
FORTRAN($TFD(s,d)gelsd)( |
| 5157 |
&(integer){$SIZE(m)}, |
| 5158 |
&(integer){$SIZE(n)}, |
| 5159 |
&(integer){$SIZE(q)}, |
| 5160 |
$P(A), |
| 5161 |
&(integer){$SIZE(m)}, |
| 5162 |
$P(B), |
| 5163 |
&(integer){$SIZE(p)}, |
| 5164 |
$P(s), |
| 5165 |
$P(rcond), |
| 5166 |
$P(rank), |
| 5167 |
work, |
| 5168 |
&lwork, |
| 5169 |
$P(iwork), |
| 5170 |
$P(info)); |
| 5171 |
free(work); |
| 5172 |
} |
| 5173 |
', |
| 5174 |
Doc => ' |
| 5175 |
|
| 5176 |
=for ref |
| 5177 |
|
| 5178 |
Computes the minimum-norm solution to a real linear least |
| 5179 |
squares problem: |
| 5180 |
|
| 5181 |
minimize 2-norm(| b - A*x |) |
| 5182 |
|
| 5183 |
using the singular value decomposition (SVD) of A. A is an M-by-N |
| 5184 |
matrix which may be rank-deficient. |
| 5185 |
|
| 5186 |
Several right hand side vectors b and solution vectors x can be |
| 5187 |
handled in a single call; they are stored as the columns of the |
| 5188 |
M-by-NRHS right hand side matrix B and the N-by-NRHS solution |
| 5189 |
matrix X. |
| 5190 |
|
| 5191 |
The problem is solved in three steps: |
| 5192 |
|
| 5193 |
=over 3 |
| 5194 |
|
| 5195 |
=item 1 |
| 5196 |
|
| 5197 |
Reduce the coefficient matrix A to bidiagonal form with |
| 5198 |
Householder transformations, reducing the original problem |
| 5199 |
into a "bidiagonal least squares problem" (BLS) |
| 5200 |
|
| 5201 |
=item 2 |
| 5202 |
|
| 5203 |
Solve the BLS using a divide and conquer approach. |
| 5204 |
|
| 5205 |
=item 3 |
| 5206 |
|
| 5207 |
Apply back all the Householder transformations to solve |
| 5208 |
the original least squares problem. |
| 5209 |
|
| 5210 |
=back |
| 5211 |
|
| 5212 |
The effective rank of A is determined by treating as zero those |
| 5213 |
singular values which are less than rcond times the largest singular |
| 5214 |
value. |
| 5215 |
|
| 5216 |
The divide and conquer algorithm makes very mild assumptions about |
| 5217 |
floating point arithmetic. It will work on machines with a guard |
| 5218 |
digit in add/subtract, or on those binary machines without guard |
| 5219 |
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or |
| 5220 |
Cray-2. It could conceivably fail on hexadecimal or decimal machines |
| 5221 |
without guard digits, but we know of none. |
| 5222 |
|
| 5223 |
Arguments |
| 5224 |
========= |
| 5225 |
|
| 5226 |
A: On entry, the M-by-N matrix A. |
| 5227 |
On exit, A has been destroyed. |
| 5228 |
|
| 5229 |
B: On entry, the M-by-NRHS right hand side matrix B. |
| 5230 |
On exit, B is overwritten by the N-by-NRHS solution |
| 5231 |
matrix X. If m >= n and rank = n, the residual |
| 5232 |
sum-of-squares for the solution in the i-th column is given |
| 5233 |
by the sum of squares of elements n+1:m in that column. |
| 5234 |
The leading dimension of the array B >= max(1,M,N). |
| 5235 |
|
| 5236 |
s: The singular values of A in decreasing order. |
| 5237 |
The condition number of A in the 2-norm = s(1)/s(min(m,n)). |
| 5238 |
|
| 5239 |
rcond: rcond is used to determine the effective rank of A. |
| 5240 |
Singular values s(i) <= rcond*s(1) are treated as zero. |
| 5241 |
If rcond < 0, machine precision is used instead. |
| 5242 |
|
| 5243 |
rank: The effective rank of A, i.e., the number of singular values |
| 5244 |
which are greater than rcond*s(1). |
| 5245 |
|
| 5246 |
info: = 0: successful exit |
| 5247 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 5248 |
> 0: the algorithm for computing the SVD failed to converge; |
| 5249 |
if info = i, i off-diagonal elements of an intermediate |
| 5250 |
bidiagonal form did not converge to zero. |
| 5251 |
|
| 5252 |
|
| 5253 |
=for example |
| 5254 |
|
| 5255 |
$a= random(7,5); |
| 5256 |
# $b will contain X |
| 5257 |
# TODO better example with slice |
| 5258 |
$b = random(7,6); |
| 5259 |
$eps = lamch(0); |
| 5260 |
$s =zeroes(5); |
| 5261 |
#Threshold for rank estimation |
| 5262 |
$rcond = sqrt($eps) - (sqrt($eps) - $eps) / 2; |
| 5263 |
gelsd($a, $b, $rcond, $s, ($rank=null),($info = null)); |
| 5264 |
|
| 5265 |
'); |
| 5266 |
|
| 5267 |
pp_def("gglse", |
| 5268 |
HandleBad => 0, |
| 5269 |
Pars => '[io]A(m,n); [io]B(p,n);[io]c(m);[io]d(p);[o]x(n);int [o]info()', |
| 5270 |
GenericTypes => [F,D], |
| 5271 |
Code => generate_code ' |
| 5272 |
integer lwork = -1; |
| 5273 |
|
| 5274 |
extern int FORTRAN($TFD(s,d)gglse)(integer *m, integer *n, integer *p, $GENERIC() * |
| 5275 |
a, integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *c__, |
| 5276 |
$GENERIC() *d__, $GENERIC() *x, $GENERIC() *work, integer *lwork, |
| 5277 |
integer *info); |
| 5278 |
$GENERIC() tmp_work; |
| 5279 |
FORTRAN($TFD(s,d)gglse)( |
| 5280 |
&(integer){$SIZE(m)}, |
| 5281 |
&(integer){$SIZE(n)}, |
| 5282 |
&(integer){$SIZE(p)}, |
| 5283 |
$P(A), |
| 5284 |
&(integer){$SIZE(m)}, |
| 5285 |
$P(B), |
| 5286 |
&(integer){$SIZE(p)}, |
| 5287 |
$P(c), |
| 5288 |
$P(d), |
| 5289 |
$P(x), |
| 5290 |
&tmp_work, |
| 5291 |
&lwork, |
| 5292 |
$P(info)); |
| 5293 |
|
| 5294 |
lwork = (integer )tmp_work; |
| 5295 |
{ |
| 5296 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5297 |
|
| 5298 |
FORTRAN($TFD(s,d)gglse)( |
| 5299 |
&(integer){$SIZE(m)}, |
| 5300 |
&(integer){$SIZE(n)}, |
| 5301 |
&(integer){$SIZE(p)}, |
| 5302 |
$P(A), |
| 5303 |
&(integer){$SIZE(m)}, |
| 5304 |
$P(B), |
| 5305 |
&(integer){$SIZE(p)}, |
| 5306 |
$P(c), |
| 5307 |
$P(d), |
| 5308 |
$P(x), |
| 5309 |
work, |
| 5310 |
&lwork, |
| 5311 |
$P(info)); |
| 5312 |
free(work); |
| 5313 |
} |
| 5314 |
|
| 5315 |
', |
| 5316 |
Doc => ' |
| 5317 |
|
| 5318 |
=for ref |
| 5319 |
|
| 5320 |
Solves the linear equality-constrained least squares (LSE) |
| 5321 |
problem: |
| 5322 |
|
| 5323 |
minimize || c - A*x ||_2 subject to B*x = d |
| 5324 |
|
| 5325 |
where A is an M-by-N matrix, B is a P-by-N matrix, c is a given |
| 5326 |
M-vector, and d is a given P-vector. It is assumed that |
| 5327 |
P <= N <= M+P, and |
| 5328 |
|
| 5329 |
rank(B) = P and rank( ( A ) ) = N. |
| 5330 |
( ( B ) ) |
| 5331 |
|
| 5332 |
These conditions ensure that the LSE problem has a unique solution, |
| 5333 |
which is obtained using a GRQ factorization of the matrices B and A. |
| 5334 |
|
| 5335 |
Arguments |
| 5336 |
========= |
| 5337 |
|
| 5338 |
A: On entry, the M-by-N matrix A. |
| 5339 |
On exit, A is destroyed. |
| 5340 |
|
| 5341 |
B: On entry, the P-by-N matrix B. |
| 5342 |
On exit, B is destroyed. |
| 5343 |
|
| 5344 |
c: On entry, c contains the right hand side vector for the |
| 5345 |
least squares part of the LSE problem. |
| 5346 |
On exit, the residual sum of squares for the solution |
| 5347 |
is given by the sum of squares of elements N-P+1 to M of |
| 5348 |
vector c. |
| 5349 |
|
| 5350 |
d: On entry, d contains the right hand side vector for the |
| 5351 |
constrained equation. |
| 5352 |
On exit, d is destroyed. |
| 5353 |
|
| 5354 |
x: On exit, x is the solution of the LSE problem. |
| 5355 |
|
| 5356 |
|
| 5357 |
info: = 0: successful exit. |
| 5358 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 5359 |
|
| 5360 |
|
| 5361 |
=for example |
| 5362 |
|
| 5363 |
$a = random(7,5); |
| 5364 |
$b = random(4,5); |
| 5365 |
$c = random(7); |
| 5366 |
$d = random(4); |
| 5367 |
$x = zeroes(5); |
| 5368 |
gglse($a, $b, $c, $d, $x, ($info=null)); |
| 5369 |
|
| 5370 |
|
| 5371 |
'); |
| 5372 |
|
| 5373 |
pp_def("ggglm", |
| 5374 |
HandleBad => 0, |
| 5375 |
Pars => '[io]A(n,m); [io]B(n,p);[io]d(n);[o]x(m);[o]y(p);int [o]info()', |
| 5376 |
GenericTypes => [F,D], |
| 5377 |
Code => generate_code ' |
| 5378 |
integer lwork = -1; |
| 5379 |
|
| 5380 |
extern int FORTRAN($TFD(s,d)ggglm)(integer *n, integer *m, integer *p, $GENERIC() * |
| 5381 |
a, integer *lda, $GENERIC() *b, integer *ldb, $GENERIC() *d__, |
| 5382 |
$GENERIC() *x, $GENERIC() *y, $GENERIC() *work, integer *lwork, |
| 5383 |
integer *info); |
| 5384 |
$GENERIC() tmp_work; |
| 5385 |
FORTRAN($TFD(s,d)ggglm)( |
| 5386 |
&(integer){$SIZE(n)}, |
| 5387 |
&(integer){$SIZE(m)}, |
| 5388 |
&(integer){$SIZE(p)}, |
| 5389 |
$P(A), |
| 5390 |
&(integer){$SIZE(n)}, |
| 5391 |
$P(B), |
| 5392 |
&(integer){$SIZE(n)}, |
| 5393 |
$P(d), |
| 5394 |
$P(x), |
| 5395 |
$P(y), |
| 5396 |
&tmp_work, |
| 5397 |
&lwork, |
| 5398 |
$P(info)); |
| 5399 |
|
| 5400 |
lwork = (integer )tmp_work; |
| 5401 |
{ |
| 5402 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5403 |
FORTRAN($TFD(s,d)ggglm)( |
| 5404 |
&(integer){$SIZE(n)}, |
| 5405 |
&(integer){$SIZE(m)}, |
| 5406 |
&(integer){$SIZE(p)}, |
| 5407 |
$P(A), |
| 5408 |
&(integer){$SIZE(n)}, |
| 5409 |
$P(B), |
| 5410 |
&(integer){$SIZE(n)}, |
| 5411 |
$P(d), |
| 5412 |
$P(x), |
| 5413 |
$P(y), |
| 5414 |
work, |
| 5415 |
&lwork, |
| 5416 |
$P(info)); |
| 5417 |
free(work); |
| 5418 |
} |
| 5419 |
|
| 5420 |
', |
| 5421 |
Doc => ' |
| 5422 |
|
| 5423 |
=for ref |
| 5424 |
|
| 5425 |
Solves a general Gauss-Markov linear model (GLM) problem: |
| 5426 |
|
| 5427 |
minimize || y ||_2 subject to d = A*x + B*y |
| 5428 |
x |
| 5429 |
|
| 5430 |
where A is an N-by-M matrix, B is an N-by-P matrix, and d is a |
| 5431 |
given N-vector. It is assumed that M <= N <= M+P, and |
| 5432 |
|
| 5433 |
rank(A) = M and rank( A B ) = N. |
| 5434 |
|
| 5435 |
Under these assumptions, the constrained equation is always |
| 5436 |
consistent, and there is a unique solution x and a minimal 2-norm |
| 5437 |
solution y, which is obtained using a generalized QR factorization |
| 5438 |
of A and B. |
| 5439 |
|
| 5440 |
In particular, if matrix B is square nonsingular, then the problem |
| 5441 |
GLM is equivalent to the following weighted linear least squares |
| 5442 |
problem |
| 5443 |
|
| 5444 |
minimize || inv(B)*(d-A*x) ||_2 |
| 5445 |
x |
| 5446 |
|
| 5447 |
where inv(B) denotes the inverse of B. |
| 5448 |
|
| 5449 |
Arguments |
| 5450 |
========= |
| 5451 |
|
| 5452 |
A: On entry, the N-by-M matrix A. |
| 5453 |
On exit, A is destroyed. |
| 5454 |
|
| 5455 |
B: On entry, the N-by-P matrix B. |
| 5456 |
On exit, B is destroyed. |
| 5457 |
|
| 5458 |
d: On entry, d is the left hand side of the GLM equation. |
| 5459 |
On exit, d is destroyed. |
| 5460 |
|
| 5461 |
x: |
| 5462 |
y: On exit, x and y are the solutions of the GLM problem. |
| 5463 |
|
| 5464 |
info: = 0: successful exit. |
| 5465 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 5466 |
|
| 5467 |
|
| 5468 |
=for example |
| 5469 |
|
| 5470 |
$a = random(7,5); |
| 5471 |
$b = random(7,4); |
| 5472 |
$d = random(7); |
| 5473 |
$x = zeroes(5); |
| 5474 |
$y = zeroes(4); |
| 5475 |
ggglm($a, $b, $d, $x, $y,($info=null)); |
| 5476 |
|
| 5477 |
'); |
| 5478 |
|
| 5479 |
|
| 5480 |
|
| 5481 |
################################################################################ |
| 5482 |
# |
| 5483 |
# COMPUTATIONAL LEVEL ROUTINES |
| 5484 |
# |
| 5485 |
################################################################################ |
| 5486 |
pp_def("getrf", |
| 5487 |
HandleBad => 0, |
| 5488 |
Pars => '[io]A(m,n); int [o]ipiv(p=CALC(PDLMIN($SIZE(m),$SIZE(n)))); int [o]info()', |
| 5489 |
GenericTypes => [F,D], |
| 5490 |
Code => generate_code ' |
| 5491 |
extern int FORTRAN($TFD(s,d)getrf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 5492 |
lda, integer *ipiv, integer *info); |
| 5493 |
FORTRAN($TFD(s,d)getrf)( |
| 5494 |
&(integer){$SIZE(m)}, |
| 5495 |
&(integer){$SIZE(n)}, |
| 5496 |
$P(A), |
| 5497 |
&(integer){$SIZE(m)}, |
| 5498 |
$P(ipiv), |
| 5499 |
$P(info)); |
| 5500 |
', |
| 5501 |
Doc => ' |
| 5502 |
|
| 5503 |
=for ref |
| 5504 |
|
| 5505 |
Computes an LU factorization of a general M-by-N matrix A |
| 5506 |
using partial pivoting with row interchanges. |
| 5507 |
|
| 5508 |
The factorization has the form |
| 5509 |
|
| 5510 |
A = P * L * U |
| 5511 |
|
| 5512 |
where P is a permutation matrix, L is lower triangular with unit |
| 5513 |
diagonal elements (lower trapezoidal if m > n), and U is upper |
| 5514 |
triangular (upper trapezoidal if m < n). |
| 5515 |
|
| 5516 |
This is the right-looking Level 3 BLAS version of the algorithm. |
| 5517 |
|
| 5518 |
Arguments |
| 5519 |
========= |
| 5520 |
|
| 5521 |
A: On entry, the M-by-N matrix to be factored. |
| 5522 |
On exit, the factors L and U from the factorization |
| 5523 |
A = P*L*U; the unit diagonal elements of L are not stored. |
| 5524 |
|
| 5525 |
ipiv: The pivot indices; for 1 <= i <= min(M,N), row i of the |
| 5526 |
matrix was interchanged with row ipiv(i). |
| 5527 |
|
| 5528 |
info: = 0: successful exit |
| 5529 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5530 |
> 0: if info = i, U(i,i) is exactly zero. The factorization |
| 5531 |
has been completed, but the factor U is exactly |
| 5532 |
singular, and division by zero will occur if it is used |
| 5533 |
to solve a system of equations. |
| 5534 |
|
| 5535 |
=for example |
| 5536 |
|
| 5537 |
$a = random (float, 100,50); |
| 5538 |
$ipiv = zeroes(long, 50); |
| 5539 |
$info = null; |
| 5540 |
getrf($a, $ipiv, $info); |
| 5541 |
|
| 5542 |
'); |
| 5543 |
|
| 5544 |
pp_def("getf2", |
| 5545 |
HandleBad => 0, |
| 5546 |
Pars => '[io]A(m,n); int [o]ipiv(p=CALC(PDLMIN($SIZE(m),$SIZE(n)))); int [o]info()', |
| 5547 |
GenericTypes => [F,D], |
| 5548 |
Code => generate_code ' |
| 5549 |
extern int FORTRAN($TFD(s,d)getf2)(integer *m, integer *n, $GENERIC() *a, integer * |
| 5550 |
lda, integer *ipiv, integer *info); |
| 5551 |
FORTRAN($TFD(s,d)getf2)( |
| 5552 |
&(integer){$SIZE(m)}, |
| 5553 |
&(integer){$SIZE(n)}, |
| 5554 |
$P(A), |
| 5555 |
&(integer){$SIZE(m)}, |
| 5556 |
$P(ipiv), |
| 5557 |
$P(info)); |
| 5558 |
', |
| 5559 |
Doc => ' |
| 5560 |
|
| 5561 |
=for ref |
| 5562 |
|
| 5563 |
Computes an LU factorization of a general M-by-N matrix A |
| 5564 |
using partial pivoting with row interchanges. |
| 5565 |
|
| 5566 |
The factorization has the form |
| 5567 |
|
| 5568 |
A = P * L * U |
| 5569 |
|
| 5570 |
where P is a permutation matrix, L is lower triangular with unit |
| 5571 |
diagonal elements (lower trapezoidal if m > n), and U is upper |
| 5572 |
triangular (upper trapezoidal if m < n). |
| 5573 |
|
| 5574 |
This is the right-looking Level 2 BLAS version of the algorithm. |
| 5575 |
|
| 5576 |
Arguments |
| 5577 |
========= |
| 5578 |
|
| 5579 |
A: On entry, the M-by-N matrix to be factored. |
| 5580 |
On exit, the factors L and U from the factorization |
| 5581 |
A = P*L*U; the unit diagonal elements of L are not stored. |
| 5582 |
|
| 5583 |
ipiv: The pivot indices; for 1 <= i <= min(M,N), row i of the |
| 5584 |
matrix was interchanged with row ipiv(i). |
| 5585 |
|
| 5586 |
info: = 0: successful exit |
| 5587 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5588 |
> 0: if info = i, U(i,i) is exactly zero. The factorization |
| 5589 |
has been completed, but the factor U is exactly |
| 5590 |
singular, and division by zero will occur if it is used |
| 5591 |
to solve a system of equations. |
| 5592 |
|
| 5593 |
=for example |
| 5594 |
|
| 5595 |
$a = random (float, 100,50); |
| 5596 |
$ipiv = zeroes(long, 50); |
| 5597 |
$info = null; |
| 5598 |
getf2($a, $ipiv, $info); |
| 5599 |
|
| 5600 |
'); |
| 5601 |
|
| 5602 |
pp_def("sytrf", |
| 5603 |
HandleBad => 0, |
| 5604 |
Pars => '[io]A(n,n); int uplo(); int [o]ipiv(n); int [o]info()', |
| 5605 |
GenericTypes => [F,D], |
| 5606 |
Code => generate_code ' |
| 5607 |
char puplo = \'U\'; |
| 5608 |
integer lwork = -1; |
| 5609 |
|
| 5610 |
extern int FORTRAN($TFD(s,d)sytrf)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 5611 |
lda, integer *ipiv, $GENERIC() *work, integer *lwork, integer *info); |
| 5612 |
|
| 5613 |
$GENERIC() tmp_work; |
| 5614 |
if ($uplo()) |
| 5615 |
puplo = \'L\'; |
| 5616 |
|
| 5617 |
FORTRAN($TFD(s,d)sytrf)( |
| 5618 |
&puplo, |
| 5619 |
&(integer){$SIZE(n)}, |
| 5620 |
$P(A), |
| 5621 |
&(integer){$SIZE(n)}, |
| 5622 |
$P(ipiv), |
| 5623 |
&tmp_work, |
| 5624 |
&lwork, |
| 5625 |
$P(info)); |
| 5626 |
|
| 5627 |
lwork = (integer )tmp_work; |
| 5628 |
{ |
| 5629 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5630 |
FORTRAN($TFD(s,d)sytrf)( |
| 5631 |
&puplo, |
| 5632 |
&(integer){$SIZE(n)}, |
| 5633 |
$P(A), |
| 5634 |
&(integer){$SIZE(n)}, |
| 5635 |
$P(ipiv), |
| 5636 |
work, |
| 5637 |
&lwork, |
| 5638 |
$P(info)); |
| 5639 |
free (work); |
| 5640 |
} |
| 5641 |
', |
| 5642 |
Doc => ' |
| 5643 |
|
| 5644 |
=for ref |
| 5645 |
|
| 5646 |
Computes the factorization of a real symmetric matrix A using |
| 5647 |
the Bunch-Kaufman diagonal pivoting method. The form of the |
| 5648 |
factorization is |
| 5649 |
|
| 5650 |
A = U*D*U\' or A = L*D*L\' |
| 5651 |
where U (or L) is a product of permutation and unit upper (lower) |
| 5652 |
triangular matrices, and D is symmetric and block diagonal with |
| 5653 |
1-by-1 and 2-by-2 diagonal blocks. |
| 5654 |
|
| 5655 |
This is the blocked version of the algorithm, calling Level 3 BLAS. |
| 5656 |
|
| 5657 |
Arguments |
| 5658 |
========= |
| 5659 |
|
| 5660 |
uplo: = 0: Upper triangle of A is stored; |
| 5661 |
= 1: Lower triangle of A is stored. |
| 5662 |
|
| 5663 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 5664 |
N-by-N upper triangular part of A contains the upper |
| 5665 |
triangular part of the matrix A, and the strictly lower |
| 5666 |
triangular part of A is not referenced. If uplo = 1, the |
| 5667 |
leading N-by-N lower triangular part of A contains the lower |
| 5668 |
triangular part of the matrix A, and the strictly upper |
| 5669 |
triangular part of A is not referenced. |
| 5670 |
|
| 5671 |
On exit, the block diagonal matrix D and the multipliers used |
| 5672 |
to obtain the factor U or L (see below for further details). |
| 5673 |
|
| 5674 |
ipiv: Details of the interchanges and the block structure of D. |
| 5675 |
If ipiv(k) > 0, then rows and columns k and ipiv(k) were |
| 5676 |
interchanged and D(k,k) is a 1-by-1 diagonal block. |
| 5677 |
If uplo = 0 and ipiv(k) = ipiv(k-1) < 0, then rows and |
| 5678 |
columns k-1 and -ipiv(k) were interchanged and D(k-1:k,k-1:k) |
| 5679 |
is a 2-by-2 diagonal block. If uplo = 1 and ipiv(k) = |
| 5680 |
ipiv(k+1) < 0, then rows and columns k+1 and -ipiv(k) were |
| 5681 |
interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. |
| 5682 |
|
| 5683 |
info: = 0: successful exit |
| 5684 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5685 |
> 0: if info = i, D(i,i) is exactly zero. The factorization |
| 5686 |
has been completed, but the block diagonal matrix D is |
| 5687 |
exactly singular, and division by zero will occur if it |
| 5688 |
is used to solve a system of equations. |
| 5689 |
|
| 5690 |
Further Details |
| 5691 |
=============== |
| 5692 |
|
| 5693 |
If uplo = 0, then A = U*D*U\', where |
| 5694 |
U = P(n)*U(n)* ... *P(k)U(k)* ..., |
| 5695 |
i.e., U is a product of terms P(k)*U(k), where k decreases from n to |
| 5696 |
1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 |
| 5697 |
and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as |
| 5698 |
defined by ipiv(k), and U(k) is a unit upper triangular matrix, such |
| 5699 |
that if the diagonal block D(k) is of order s (s = 1 or 2), then |
| 5700 |
|
| 5701 |
( I v 0 ) k-s |
| 5702 |
U(k) = ( 0 I 0 ) s |
| 5703 |
( 0 0 I ) n-k |
| 5704 |
k-s s n-k |
| 5705 |
|
| 5706 |
If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). |
| 5707 |
If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), |
| 5708 |
and A(k,k), and v overwrites A(1:k-2,k-1:k). |
| 5709 |
|
| 5710 |
If uplo = 1, then A = L*D*L\', where |
| 5711 |
L = P(1)*L(1)* ... *P(k)*L(k)* ..., |
| 5712 |
i.e., L is a product of terms P(k)*L(k), where k increases from 1 to |
| 5713 |
n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 |
| 5714 |
and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as |
| 5715 |
defined by ipiv(k), and L(k) is a unit lower triangular matrix, such |
| 5716 |
that if the diagonal block D(k) is of order s (s = 1 or 2), then |
| 5717 |
|
| 5718 |
( I 0 0 ) k-1 |
| 5719 |
L(k) = ( 0 I 0 ) s |
| 5720 |
( 0 v I ) n-k-s+1 |
| 5721 |
k-1 s n-k-s+1 |
| 5722 |
|
| 5723 |
If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). |
| 5724 |
If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), |
| 5725 |
and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). |
| 5726 |
|
| 5727 |
=for example |
| 5728 |
|
| 5729 |
$a = random(100,100); |
| 5730 |
$ipiv = zeroes(100); |
| 5731 |
$info = null; |
| 5732 |
# Assume $a is symmetric |
| 5733 |
sytrf($a, 0, $ipiv, $info); |
| 5734 |
|
| 5735 |
'); |
| 5736 |
|
| 5737 |
pp_def("sytf2", |
| 5738 |
HandleBad => 0, |
| 5739 |
Pars => '[io]A(n,n); int uplo(); int [o]ipiv(n); int [o]info()', |
| 5740 |
GenericTypes => [F,D], |
| 5741 |
Code => generate_code ' |
| 5742 |
char puplo = \'U\'; |
| 5743 |
|
| 5744 |
extern int FORTRAN($TFD(s,d)sytf2)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 5745 |
lda, integer *ipiv, integer *info); |
| 5746 |
if ($uplo()) |
| 5747 |
puplo = \'L\'; |
| 5748 |
|
| 5749 |
FORTRAN($TFD(s,d)sytf2)( |
| 5750 |
&puplo, |
| 5751 |
&(integer){$SIZE(n)}, |
| 5752 |
$P(A), |
| 5753 |
&(integer){$SIZE(n)}, |
| 5754 |
$P(ipiv), |
| 5755 |
$P(info)); |
| 5756 |
', |
| 5757 |
Doc => ' |
| 5758 |
|
| 5759 |
=for ref |
| 5760 |
|
| 5761 |
Computes the factorization of a real symmetric matrix A using |
| 5762 |
the Bunch-Kaufman diagonal pivoting method. The form of the |
| 5763 |
factorization is |
| 5764 |
|
| 5765 |
A = U*D*U\' or A = L*D*L\' |
| 5766 |
where U (or L) is a product of permutation and unit upper (lower) |
| 5767 |
triangular matrices, and D is symmetric and block diagonal with |
| 5768 |
1-by-1 and 2-by-2 diagonal blocks. |
| 5769 |
|
| 5770 |
This is the unblocked version of the algorithm, calling Level 2 BLAS. |
| 5771 |
|
| 5772 |
Arguments |
| 5773 |
========= |
| 5774 |
|
| 5775 |
uplo: = 0: Upper triangle of A is stored; |
| 5776 |
= 1: Lower triangle of A is stored. |
| 5777 |
|
| 5778 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 5779 |
N-by-N upper triangular part of A contains the upper |
| 5780 |
triangular part of the matrix A, and the strictly lower |
| 5781 |
triangular part of A is not referenced. If uplo = 1, the |
| 5782 |
leading N-by-N lower triangular part of A contains the lower |
| 5783 |
triangular part of the matrix A, and the strictly upper |
| 5784 |
triangular part of A is not referenced. |
| 5785 |
|
| 5786 |
On exit, the block diagonal matrix D and the multipliers used |
| 5787 |
to obtain the factor U or L (see below for further details). |
| 5788 |
|
| 5789 |
ipiv: Details of the interchanges and the block structure of D. |
| 5790 |
If ipiv(k) > 0, then rows and columns k and ipiv(k) were |
| 5791 |
interchanged and D(k,k) is a 1-by-1 diagonal block. |
| 5792 |
If uplo = 0 and ipiv(k) = ipiv(k-1) < 0, then rows and |
| 5793 |
columns k-1 and -ipiv(k) were interchanged and D(k-1:k,k-1:k) |
| 5794 |
is a 2-by-2 diagonal block. If uplo = 1 and ipiv(k) = |
| 5795 |
ipiv(k+1) < 0, then rows and columns k+1 and -ipiv(k) were |
| 5796 |
interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. |
| 5797 |
|
| 5798 |
info: = 0: successful exit |
| 5799 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5800 |
> 0: if info = i, D(i,i) is exactly zero. The factorization |
| 5801 |
has been completed, but the block diagonal matrix D is |
| 5802 |
exactly singular, and division by zero will occur if it |
| 5803 |
is used to solve a system of equations. |
| 5804 |
|
| 5805 |
For further details see sytrf |
| 5806 |
|
| 5807 |
=for example |
| 5808 |
|
| 5809 |
$a = random(100,100); |
| 5810 |
$ipiv = zeroes(100); |
| 5811 |
$info = null; |
| 5812 |
# Assume $a is symmetric |
| 5813 |
sytf2($a, 0, $ipiv, $info); |
| 5814 |
|
| 5815 |
'); |
| 5816 |
|
| 5817 |
pp_def("potrf", |
| 5818 |
HandleBad => 0, |
| 5819 |
Pars => '[io]A(n,n); int uplo(); int [o]info()', |
| 5820 |
GenericTypes => [F,D], |
| 5821 |
Code => generate_code ' |
| 5822 |
|
| 5823 |
char puplo = \'U\'; |
| 5824 |
|
| 5825 |
extern int FORTRAN($TFD(s,d)potrf)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 5826 |
lda, integer *info); |
| 5827 |
if ($uplo()) |
| 5828 |
puplo = \'L\'; |
| 5829 |
|
| 5830 |
FORTRAN($TFD(s,d)potrf)( |
| 5831 |
&puplo, |
| 5832 |
&(integer){$SIZE(n)}, |
| 5833 |
$P(A), |
| 5834 |
&(integer){$SIZE(n)}, |
| 5835 |
$P(info)); |
| 5836 |
', |
| 5837 |
Doc => ' |
| 5838 |
|
| 5839 |
=for ref |
| 5840 |
|
| 5841 |
Computes the Cholesky factorization of a real symmetric |
| 5842 |
positive definite matrix A. |
| 5843 |
|
| 5844 |
The factorization has the form |
| 5845 |
|
| 5846 |
A = U\' * U, if uplo = 0, or |
| 5847 |
A = L * L\', if uplo = 1, |
| 5848 |
where U is an upper triangular matrix and L is lower triangular. |
| 5849 |
|
| 5850 |
This is the block version of the algorithm, calling Level 3 BLAS. |
| 5851 |
|
| 5852 |
Arguments |
| 5853 |
========= |
| 5854 |
|
| 5855 |
uplo: = 0: Upper triangle of A is stored; |
| 5856 |
= 1: Lower triangle of A is stored. |
| 5857 |
|
| 5858 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 5859 |
N-by-N upper triangular part of A contains the upper |
| 5860 |
triangular part of the matrix A, and the strictly lower |
| 5861 |
triangular part of A is not referenced. If uplo = 1, the |
| 5862 |
leading N-by-N lower triangular part of A contains the lower |
| 5863 |
triangular part of the matrix A, and the strictly upper |
| 5864 |
triangular part of A is not referenced. |
| 5865 |
|
| 5866 |
On exit, if info = 0, the factor U or L from the Cholesky |
| 5867 |
factorization A = U\'*U or A = L*L\'. |
| 5868 |
|
| 5869 |
info: = 0: successful exit |
| 5870 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5871 |
> 0: if info = i, the leading minor of order i is not |
| 5872 |
positive definite, and the factorization could not be |
| 5873 |
completed. |
| 5874 |
|
| 5875 |
=for example |
| 5876 |
|
| 5877 |
$a = random(100,100); |
| 5878 |
# Assume $a is symmetric positive definite |
| 5879 |
potrf($a, 0, ($info = null)); |
| 5880 |
|
| 5881 |
'); |
| 5882 |
|
| 5883 |
pp_def("potf2", |
| 5884 |
HandleBad => 0, |
| 5885 |
Pars => '[io]A(n,n); int uplo(); int [o]info()', |
| 5886 |
GenericTypes => [F,D], |
| 5887 |
Code => generate_code ' |
| 5888 |
char puplo = \'U\'; |
| 5889 |
|
| 5890 |
extern int FORTRAN($TFD(s,d)potf2)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 5891 |
lda, integer *info); |
| 5892 |
if ($uplo()) |
| 5893 |
puplo = \'L\'; |
| 5894 |
|
| 5895 |
FORTRAN($TFD(s,d)potf2)( |
| 5896 |
&puplo, |
| 5897 |
&(integer){$SIZE(n)}, |
| 5898 |
$P(A), |
| 5899 |
&(integer){$SIZE(n)}, |
| 5900 |
$P(info)); |
| 5901 |
', |
| 5902 |
Doc => ' |
| 5903 |
|
| 5904 |
=for ref |
| 5905 |
|
| 5906 |
Computes the Cholesky factorization of a real symmetric |
| 5907 |
positive definite matrix A. |
| 5908 |
|
| 5909 |
The factorization has the form |
| 5910 |
|
| 5911 |
A = U\' * U, if uplo = 0, or |
| 5912 |
A = L * L\', if uplo = 1, |
| 5913 |
where U is an upper triangular matrix and L is lower triangular. |
| 5914 |
|
| 5915 |
This is the unblocked version of the algorithm, calling Level 2 BLAS. |
| 5916 |
|
| 5917 |
Arguments |
| 5918 |
========= |
| 5919 |
|
| 5920 |
uplo: = 0: Upper triangle of A is stored; |
| 5921 |
= 1: Lower triangle of A is stored. |
| 5922 |
|
| 5923 |
A: On entry, the symmetric matrix A. If uplo = 0, the leading |
| 5924 |
N-by-N upper triangular part of A contains the upper |
| 5925 |
triangular part of the matrix A, and the strictly lower |
| 5926 |
triangular part of A is not referenced. If uplo = 1, the |
| 5927 |
leading N-by-N lower triangular part of A contains the lower |
| 5928 |
triangular part of the matrix A, and the strictly upper |
| 5929 |
triangular part of A is not referenced. |
| 5930 |
|
| 5931 |
On exit, if info = 0, the factor U or L from the Cholesky |
| 5932 |
factorization A = U\'*U or A = L*L\'. |
| 5933 |
|
| 5934 |
info: = 0: successful exit |
| 5935 |
< 0: if info = -i, the i-th argument had an illegal value |
| 5936 |
> 0: if info = i, the leading minor of order i is not |
| 5937 |
positive definite, and the factorization could not be |
| 5938 |
completed. |
| 5939 |
|
| 5940 |
=for example |
| 5941 |
|
| 5942 |
$a = random(100,100); |
| 5943 |
# Assume $a is symmetric positive definite |
| 5944 |
potf2($a, 0, ($info = null)); |
| 5945 |
|
| 5946 |
'); |
| 5947 |
|
| 5948 |
pp_def("getri", |
| 5949 |
HandleBad => 0, |
| 5950 |
Pars => '[io]A(n,n); int ipiv(n); int [o]info()', |
| 5951 |
GenericTypes => [F,D], |
| 5952 |
Code => generate_code ' |
| 5953 |
integer lwork = -1; |
| 5954 |
extern int FORTRAN($TFD(s,d)getri)(integer *n, $GENERIC() *a, integer *lda, integer |
| 5955 |
*ipiv, $GENERIC() *work, integer *lwork, integer *info); |
| 5956 |
|
| 5957 |
$GENERIC() tmp_work; |
| 5958 |
FORTRAN($TFD(s,d)getri)( |
| 5959 |
&(integer){$SIZE(n)}, |
| 5960 |
$P(A), |
| 5961 |
&(integer){$SIZE(n)}, |
| 5962 |
$P(ipiv), |
| 5963 |
&tmp_work, |
| 5964 |
&lwork, |
| 5965 |
$P(info)); |
| 5966 |
|
| 5967 |
lwork = (integer )tmp_work; |
| 5968 |
{ |
| 5969 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 5970 |
FORTRAN($TFD(s,d)getri)( |
| 5971 |
&(integer){$SIZE(n)}, |
| 5972 |
$P(A), |
| 5973 |
&(integer){$SIZE(n)}, |
| 5974 |
$P(ipiv), |
| 5975 |
work, |
| 5976 |
&lwork, |
| 5977 |
$P(info)); |
| 5978 |
free(work); |
| 5979 |
} |
| 5980 |
', |
| 5981 |
Doc => ' |
| 5982 |
=for ref |
| 5983 |
|
| 5984 |
Computes the inverse of a matrix using the LU factorization |
| 5985 |
computed by C<getrf>. |
| 5986 |
|
| 5987 |
This method inverts U and then computes inv(A) by solving the system |
| 5988 |
|
| 5989 |
inv(A)*L = inv(U) for inv(A). |
| 5990 |
|
| 5991 |
Arguments |
| 5992 |
========= |
| 5993 |
|
| 5994 |
A: On entry, the factors L and U from the factorization |
| 5995 |
A = P*L*U as computed by getrf. |
| 5996 |
On exit, if info = 0, the inverse of the original matrix A. |
| 5997 |
|
| 5998 |
ipiv: The pivot indices from getrf; for 1<=i<=N, row i of the |
| 5999 |
matrix was interchanged with row ipiv(i). |
| 6000 |
|
| 6001 |
info: = 0: successful exit |
| 6002 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6003 |
> 0: if info = i, U(i,i) is exactly zero; the matrix is |
| 6004 |
singular and its inverse could not be computed. |
| 6005 |
|
| 6006 |
|
| 6007 |
|
| 6008 |
=for example |
| 6009 |
|
| 6010 |
$a = random (float, 100, 100); |
| 6011 |
$ipiv = zeroes(long, 100); |
| 6012 |
$info = null; |
| 6013 |
getrf($a, $ipiv, $info); |
| 6014 |
if ($info == 0){ |
| 6015 |
getri($a, $ipiv, $info); |
| 6016 |
} |
| 6017 |
print "Inverse of \$a is :\n $a" unless $info; |
| 6018 |
|
| 6019 |
'); |
| 6020 |
|
| 6021 |
pp_def("sytri", |
| 6022 |
HandleBad => 0, |
| 6023 |
Pars => '[io]A(n,n); int uplo(); int ipiv(n); int [o]info(); [t]work(n);', |
| 6024 |
GenericTypes => [F,D], |
| 6025 |
Code => generate_code ' |
| 6026 |
char puplo = \'U\'; |
| 6027 |
extern int FORTRAN($TFD(s,d)sytri)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 6028 |
lda, integer *ipiv, $GENERIC() *work, integer *info); |
| 6029 |
|
| 6030 |
if ($uplo()) |
| 6031 |
puplo = \'L\'; |
| 6032 |
|
| 6033 |
FORTRAN($TFD(s,d)sytri)( |
| 6034 |
&puplo, |
| 6035 |
&(integer){$SIZE(n)}, |
| 6036 |
$P(A), |
| 6037 |
&(integer){$SIZE(n)}, |
| 6038 |
$P(ipiv), |
| 6039 |
$P(work), |
| 6040 |
$P(info)); |
| 6041 |
', |
| 6042 |
Doc => ' |
| 6043 |
=for ref |
| 6044 |
|
| 6045 |
Computes the inverse of a real symmetric indefinite matrix |
| 6046 |
A using the factorization A = U*D*U\' or A = L*D*L\' computed by |
| 6047 |
C<sytrf>. |
| 6048 |
|
| 6049 |
Arguments |
| 6050 |
========= |
| 6051 |
|
| 6052 |
uplo: Specifies whether the details of the factorization are stored |
| 6053 |
as an upper or lower triangular matrix. |
| 6054 |
= 0: Upper triangular, form is A = U*D*U\'; |
| 6055 |
= 1: Lower triangular, form is A = L*D*L\'. |
| 6056 |
|
| 6057 |
A: On entry, the block diagonal matrix D and the multipliers |
| 6058 |
used to obtain the factor U or L as computed by sytrf. |
| 6059 |
|
| 6060 |
On exit, if info = 0, the (symmetric) inverse of the original |
| 6061 |
matrix. If uplo = 0, the upper triangular part of the |
| 6062 |
inverse is formed and the part of A below the diagonal is not |
| 6063 |
referenced; if uplo = 1 the lower triangular part of the |
| 6064 |
inverse is formed and the part of A above the diagonal is |
| 6065 |
not referenced. |
| 6066 |
|
| 6067 |
ipiv: Details of the interchanges and the block structure of D |
| 6068 |
as determined by sytrf. |
| 6069 |
|
| 6070 |
info: = 0: successful exit |
| 6071 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6072 |
> 0: if info = i, D(i,i) = 0; the matrix is singular and its |
| 6073 |
inverse could not be computed. |
| 6074 |
|
| 6075 |
=for example |
| 6076 |
|
| 6077 |
$a = random (float, 100, 100); |
| 6078 |
# assume $a is symmetric |
| 6079 |
$ipiv = zeroes(long, 100); |
| 6080 |
sytrf($a, 0, $ipiv, ($info=null)); |
| 6081 |
if ($info == 0){ |
| 6082 |
sytri($a, 0, $ipiv, $info); |
| 6083 |
} |
| 6084 |
print "Inverse of \$a is :\n $a" unless $info; |
| 6085 |
|
| 6086 |
'); |
| 6087 |
|
| 6088 |
pp_def("potri", |
| 6089 |
HandleBad => 0, |
| 6090 |
Pars => '[io]A(n,n); int uplo(); int [o]info()', |
| 6091 |
GenericTypes => [F,D], |
| 6092 |
Code => generate_code ' |
| 6093 |
char puplo = \'U\'; |
| 6094 |
extern int FORTRAN($TFD(s,d)potri)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 6095 |
lda, integer *info); |
| 6096 |
if ($uplo()) |
| 6097 |
puplo = \'L\'; |
| 6098 |
|
| 6099 |
FORTRAN($TFD(s,d)potri)( |
| 6100 |
&puplo, |
| 6101 |
&(integer){$SIZE(n)}, |
| 6102 |
$P(A), |
| 6103 |
&(integer){$SIZE(n)}, |
| 6104 |
$P(info)); |
| 6105 |
', |
| 6106 |
Doc => ' |
| 6107 |
|
| 6108 |
=for ref |
| 6109 |
|
| 6110 |
Computes the inverse of a real symmetric positive definite |
| 6111 |
matrix A using the Cholesky factorization A = U\'*U or A = L*L\' |
| 6112 |
computed by C<potrf>. |
| 6113 |
|
| 6114 |
Arguments |
| 6115 |
========= |
| 6116 |
|
| 6117 |
uplo: = 0: Upper triangle of A is stored; |
| 6118 |
= 1: Lower triangle of A is stored. |
| 6119 |
|
| 6120 |
A: On entry, the triangular factor U or L from the Cholesky |
| 6121 |
factorization A = U\'*U or A = L*L\', as computed by |
| 6122 |
potrf. |
| 6123 |
On exit, the upper or lower triangle of the (symmetric) |
| 6124 |
inverse of A, overwriting the input factor U or L. |
| 6125 |
|
| 6126 |
info: = 0: successful exit |
| 6127 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6128 |
> 0: if info = i, the (i,i) element of the factor U or L is |
| 6129 |
zero, and the inverse could not be computed. |
| 6130 |
|
| 6131 |
|
| 6132 |
|
| 6133 |
=for example |
| 6134 |
|
| 6135 |
$a = random (float, 100, 100); |
| 6136 |
# Assume $a is symmetric positive definite |
| 6137 |
potrf($a, 0, ($info = null)); |
| 6138 |
if ($info == 0){ # Hum... is it positive definite???? |
| 6139 |
potri($a, 0,$info); |
| 6140 |
} |
| 6141 |
print "Inverse of \$a is :\n $a" unless $info; |
| 6142 |
|
| 6143 |
'); |
| 6144 |
|
| 6145 |
pp_def("trtri", |
| 6146 |
HandleBad => 0, |
| 6147 |
Pars => '[io]A(n,n); int uplo(); int diag(); int [o]info()', |
| 6148 |
GenericTypes => [F,D], |
| 6149 |
Code => generate_code ' |
| 6150 |
char puplo = \'U\'; |
| 6151 |
char pdiag = \'N\'; |
| 6152 |
extern int FORTRAN($TFD(s,d)trtri)(char *uplo, char *diag, integer *n, $GENERIC() *a, integer * |
| 6153 |
lda, integer *info); |
| 6154 |
if ($uplo()) |
| 6155 |
puplo = \'L\'; |
| 6156 |
if ($diag()) |
| 6157 |
pdiag = \'U\'; |
| 6158 |
|
| 6159 |
FORTRAN($TFD(s,d)trtri)( |
| 6160 |
&puplo, |
| 6161 |
&pdiag, |
| 6162 |
&(integer){$SIZE(n)}, |
| 6163 |
$P(A), |
| 6164 |
&(integer){$SIZE(n)}, |
| 6165 |
$P(info)); |
| 6166 |
', |
| 6167 |
Doc => ' |
| 6168 |
|
| 6169 |
=for ref |
| 6170 |
|
| 6171 |
Computes the inverse of a real upper or lower triangular |
| 6172 |
matrix A. |
| 6173 |
|
| 6174 |
This is the Level 3 BLAS version of the algorithm. |
| 6175 |
|
| 6176 |
Arguments |
| 6177 |
========= |
| 6178 |
|
| 6179 |
uplo: = 0: A is upper triangular; |
| 6180 |
= 1: A is lower triangular. |
| 6181 |
|
| 6182 |
diag: = 0: A is non-unit triangular; |
| 6183 |
= 1: A is unit triangular. |
| 6184 |
|
| 6185 |
A: On entry, the triangular matrix A. If uplo = 0, the |
| 6186 |
leading N-by-N upper triangular part of the array A contains |
| 6187 |
the upper triangular matrix, and the strictly lower |
| 6188 |
triangular part of A is not referenced. If uplo = 1, the |
| 6189 |
leading N-by-N lower triangular part of the array A contains |
| 6190 |
the lower triangular matrix, and the strictly upper |
| 6191 |
triangular part of A is not referenced. If diag = 1, the |
| 6192 |
diagonal elements of A are also not referenced and are |
| 6193 |
assumed to be 1. |
| 6194 |
On exit, the (triangular) inverse of the original matrix, in |
| 6195 |
the same storage format. |
| 6196 |
|
| 6197 |
info: = 0: successful exit |
| 6198 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6199 |
> 0: if info = i, A(i,i) is exactly zero. The triangular |
| 6200 |
matrix is singular and its inverse can not be computed. |
| 6201 |
|
| 6202 |
|
| 6203 |
|
| 6204 |
=for example |
| 6205 |
|
| 6206 |
$a = random (float, 100, 100); |
| 6207 |
# assume $a is upper triangular |
| 6208 |
trtri($a, 1, ($info=null)); |
| 6209 |
print "Inverse of \$a is :\n transpose($a)" unless $info; |
| 6210 |
|
| 6211 |
'); |
| 6212 |
|
| 6213 |
pp_def("trti2", |
| 6214 |
HandleBad => 0, |
| 6215 |
Pars => '[io]A(n,n); int uplo(); int diag(); int [o]info()', |
| 6216 |
GenericTypes => [F,D], |
| 6217 |
Code => generate_code ' |
| 6218 |
char puplo = \'U\'; |
| 6219 |
char pdiag = \'N\'; |
| 6220 |
extern int FORTRAN($TFD(s,d)trti2)(char *uplo, char *diag, integer *n, $GENERIC() *a, integer * |
| 6221 |
lda, integer *info); |
| 6222 |
if ($uplo()) |
| 6223 |
puplo = \'L\'; |
| 6224 |
if ($diag()) |
| 6225 |
pdiag = \'U\'; |
| 6226 |
|
| 6227 |
FORTRAN($TFD(s,d)trti2)( |
| 6228 |
&puplo, |
| 6229 |
&pdiag, |
| 6230 |
&(integer){$SIZE(n)}, |
| 6231 |
$P(A), |
| 6232 |
&(integer){$SIZE(n)}, |
| 6233 |
$P(info)); |
| 6234 |
', |
| 6235 |
Doc => ' |
| 6236 |
|
| 6237 |
=for ref |
| 6238 |
|
| 6239 |
Computes the inverse of a real upper or lower triangular |
| 6240 |
matrix A. |
| 6241 |
|
| 6242 |
This is the Level 2 BLAS version of the algorithm. |
| 6243 |
|
| 6244 |
Arguments |
| 6245 |
========= |
| 6246 |
|
| 6247 |
uplo: = 0: A is upper triangular; |
| 6248 |
= 1: A is lower triangular. |
| 6249 |
|
| 6250 |
diag: = 0: A is non-unit triangular; |
| 6251 |
= 1: A is unit triangular. |
| 6252 |
|
| 6253 |
A: On entry, the triangular matrix A. If uplo = 0, the |
| 6254 |
leading N-by-N upper triangular part of the array A contains |
| 6255 |
the upper triangular matrix, and the strictly lower |
| 6256 |
triangular part of A is not referenced. If uplo = 1, the |
| 6257 |
leading N-by-N lower triangular part of the array A contains |
| 6258 |
the lower triangular matrix, and the strictly upper |
| 6259 |
triangular part of A is not referenced. If diag = 1, the |
| 6260 |
diagonal elements of A are also not referenced and are |
| 6261 |
assumed to be 1. |
| 6262 |
On exit, the (triangular) inverse of the original matrix, in |
| 6263 |
the same storage format. |
| 6264 |
|
| 6265 |
info: = 0: successful exit |
| 6266 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6267 |
|
| 6268 |
=for example |
| 6269 |
|
| 6270 |
$a = random (float, 100, 100); |
| 6271 |
# assume $a is upper triangular |
| 6272 |
trtri2($a, 1, ($info=null)); |
| 6273 |
print "Inverse of \$a is :\n transpose($a)" unless $info; |
| 6274 |
|
| 6275 |
'); |
| 6276 |
|
| 6277 |
pp_def("getrs", |
| 6278 |
HandleBad => 0, |
| 6279 |
Pars => 'A(n,n); int trans(); [io]B(n,m); int ipiv(n); int [o]info()', |
| 6280 |
GenericTypes => [F,D], |
| 6281 |
Code => generate_code ' |
| 6282 |
char transp = \'N\'; |
| 6283 |
extern int FORTRAN($TFD(s,d)getrs)(char *trans, integer *n, integer *nrhs, |
| 6284 |
$GENERIC() *a, integer *lda, integer *ipiv, $GENERIC() *b, integer * |
| 6285 |
ldb, integer *info); |
| 6286 |
if($trans()) |
| 6287 |
transp = \'T\'; |
| 6288 |
|
| 6289 |
FORTRAN($TFD(s,d)getrs)( |
| 6290 |
&transp, |
| 6291 |
&(integer){$SIZE(n)}, |
| 6292 |
&(integer){$SIZE(m)}, |
| 6293 |
$P(A), |
| 6294 |
&(integer){$SIZE(n)}, |
| 6295 |
$P(ipiv), |
| 6296 |
$P(B), |
| 6297 |
&(integer){$SIZE(n)}, |
| 6298 |
$P(info)); |
| 6299 |
', |
| 6300 |
Doc => ' |
| 6301 |
|
| 6302 |
=for ref |
| 6303 |
|
| 6304 |
Solves a system of linear equations |
| 6305 |
|
| 6306 |
A * X = B or A\' * X = B |
| 6307 |
|
| 6308 |
with a general N-by-N matrix A using the LU factorization computed |
| 6309 |
by getrf. |
| 6310 |
|
| 6311 |
Arguments |
| 6312 |
========= |
| 6313 |
|
| 6314 |
trans: Specifies the form of the system of equations: |
| 6315 |
= 0: A * X = B (No transpose) |
| 6316 |
= 1: A\'* X = B (Transpose) |
| 6317 |
|
| 6318 |
A: The factors L and U from the factorization A = P*L*U |
| 6319 |
as computed by getrf. |
| 6320 |
|
| 6321 |
ipiv: The pivot indices from getrf; for 1<=i<=N, row i of the |
| 6322 |
matrix was interchanged with row ipiv(i). |
| 6323 |
|
| 6324 |
B: On entry, the right hand side matrix B. |
| 6325 |
On exit, the solution matrix X. |
| 6326 |
|
| 6327 |
info: = 0: successful exit |
| 6328 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6329 |
|
| 6330 |
=for example |
| 6331 |
|
| 6332 |
$a = random (float, 100, 100); |
| 6333 |
$ipiv = zeroes(long, 100); |
| 6334 |
$b = random(100,50); |
| 6335 |
getrf($a, $ipiv, ($info=null)); |
| 6336 |
if ($info == 0){ |
| 6337 |
getrs($a, 0, $b, $ipiv, $info); |
| 6338 |
} |
| 6339 |
print "X is :\n $b" unless $info; |
| 6340 |
|
| 6341 |
'); |
| 6342 |
|
| 6343 |
pp_def("sytrs", |
| 6344 |
HandleBad => 0, |
| 6345 |
Pars => 'A(n,n); int uplo();[io]B(n,m); int ipiv(n); int [o]info()', |
| 6346 |
GenericTypes => [F,D], |
| 6347 |
Code => generate_code ' |
| 6348 |
char puplo = \'U\'; |
| 6349 |
extern int FORTRAN($TFD(s,d)sytrs)(char *uplo, integer *n, integer *nrhs, |
| 6350 |
$GENERIC() *a, integer *lda, integer *ipiv, $GENERIC() *b, integer * |
| 6351 |
ldb, integer *info); |
| 6352 |
if($uplo()) |
| 6353 |
puplo = \'L\'; |
| 6354 |
|
| 6355 |
FORTRAN($TFD(s,d)sytrs)( |
| 6356 |
&puplo, |
| 6357 |
&(integer){$SIZE(n)}, |
| 6358 |
&(integer){$SIZE(m)}, |
| 6359 |
$P(A), |
| 6360 |
&(integer){$SIZE(n)}, |
| 6361 |
$P(ipiv), |
| 6362 |
$P(B), |
| 6363 |
&(integer){$SIZE(n)}, |
| 6364 |
$P(info)); |
| 6365 |
', |
| 6366 |
Doc => ' |
| 6367 |
|
| 6368 |
=for ref |
| 6369 |
|
| 6370 |
Solves a system of linear equations A*X = B with a real |
| 6371 |
symmetric matrix A using the factorization A = U*D*U\' or |
| 6372 |
A = L*D*L\' computed by C<sytrf>. |
| 6373 |
|
| 6374 |
Arguments |
| 6375 |
========= |
| 6376 |
|
| 6377 |
uplo: Specifies whether the details of the factorization are stored |
| 6378 |
as an upper or lower triangular matrix. |
| 6379 |
= 0: Upper triangular, form is A = U*D*U\'; |
| 6380 |
= 1: Lower triangular, form is A = L*D*L\'. |
| 6381 |
|
| 6382 |
A: The block diagonal matrix D and the multipliers used to |
| 6383 |
obtain the factor U or L as computed by sytrf. |
| 6384 |
|
| 6385 |
ipiv: Details of the interchanges and the block structure of D |
| 6386 |
as determined by sytrf. |
| 6387 |
|
| 6388 |
B: On entry, the right hand side matrix B. |
| 6389 |
On exit, the solution matrix X. |
| 6390 |
|
| 6391 |
info: = 0: successful exit |
| 6392 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6393 |
|
| 6394 |
=for example |
| 6395 |
|
| 6396 |
$a = random (float, 100, 100); |
| 6397 |
$b = random(50,100); |
| 6398 |
$a = transpose($a); |
| 6399 |
$b = transpose($b); |
| 6400 |
# Assume $a is symmetric |
| 6401 |
sytrf($a, 0, ($ipiv=zeroes(100)), ($info=null)); |
| 6402 |
if ($info == 0){ |
| 6403 |
sytrs($a, 0, $b, $ipiv, $info); |
| 6404 |
} |
| 6405 |
print("X is :\n".transpose($b))unless $info; |
| 6406 |
|
| 6407 |
'); |
| 6408 |
|
| 6409 |
|
| 6410 |
pp_def("potrs", |
| 6411 |
HandleBad => 0, |
| 6412 |
Pars => 'A(n,n); int uplo(); [io]B(n,m); int [o]info()', |
| 6413 |
GenericTypes => [F,D], |
| 6414 |
Code => generate_code ' |
| 6415 |
char puplo = \'U\'; |
| 6416 |
extern int FORTRAN($TFD(s,d)potrs)(char *uplo, integer *n, integer *nrhs, |
| 6417 |
$GENERIC() *a, integer *lda, $GENERIC() *b, integer *ldb, integer * |
| 6418 |
info); |
| 6419 |
if($uplo()) |
| 6420 |
puplo = \'L\'; |
| 6421 |
|
| 6422 |
FORTRAN($TFD(s,d)potrs)( |
| 6423 |
&puplo, |
| 6424 |
&(integer){$SIZE(n)}, |
| 6425 |
&(integer){$SIZE(m)}, |
| 6426 |
$P(A), |
| 6427 |
&(integer){$SIZE(n)}, |
| 6428 |
$P(B), |
| 6429 |
&(integer){$SIZE(n)}, |
| 6430 |
$P(info)); |
| 6431 |
', |
| 6432 |
Doc => ' |
| 6433 |
|
| 6434 |
=for ref |
| 6435 |
|
| 6436 |
Solves a system of linear equations A*X = B with a symmetric |
| 6437 |
positive definite matrix A using the Cholesky factorization |
| 6438 |
A = U\'*U or A = L*L\' computed by C<potrf>. |
| 6439 |
|
| 6440 |
Arguments |
| 6441 |
========= |
| 6442 |
|
| 6443 |
uplo: = 0: Upper triangle of A is stored; |
| 6444 |
= 1: Lower triangle of A is stored. |
| 6445 |
|
| 6446 |
A: The triangular factor U or L from the Cholesky factorization |
| 6447 |
A = U\'*U or A = L*L\', as computed by potrf. |
| 6448 |
|
| 6449 |
B: On entry, the right hand side matrix B. |
| 6450 |
On exit, the solution matrix X. |
| 6451 |
|
| 6452 |
info: = 0: successful exit |
| 6453 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6454 |
|
| 6455 |
=for example |
| 6456 |
|
| 6457 |
$a = random (float, 100, 100); |
| 6458 |
$b = random(50,100); |
| 6459 |
$a = transpose($a); |
| 6460 |
$b = transpose($b); |
| 6461 |
# Assume $a is symmetric positive definite |
| 6462 |
potrf($a, 0, ($info=null)); |
| 6463 |
if ($info == 0){ |
| 6464 |
potrs($a, 0, $b, $info); |
| 6465 |
} |
| 6466 |
print("X is :\n".transpose($b))unless $info; |
| 6467 |
|
| 6468 |
'); |
| 6469 |
|
| 6470 |
pp_def("trtrs", |
| 6471 |
HandleBad => 0, |
| 6472 |
Pars => 'A(n,n); int uplo(); int trans(); int diag();[io]B(n,m); int [o]info()', |
| 6473 |
GenericTypes => [F,D], |
| 6474 |
Code => generate_code ' |
| 6475 |
char puplo = \'U\'; |
| 6476 |
char ptrans = \'N\'; |
| 6477 |
char pdiag = \'N\'; |
| 6478 |
extern int FORTRAN($TFD(s,d)trtrs)(char *uplo, char *trans, char *diag, |
| 6479 |
integer *n, integer *nrhs, |
| 6480 |
$GENERIC() *a, integer *lda, $GENERIC() *b, integer * |
| 6481 |
ldb, integer *info); |
| 6482 |
if($uplo()) |
| 6483 |
puplo = \'L\'; |
| 6484 |
if($trans()) |
| 6485 |
ptrans = \'T\'; |
| 6486 |
if($diag()) |
| 6487 |
pdiag = \'U\'; |
| 6488 |
|
| 6489 |
FORTRAN($TFD(s,d)trtrs)( |
| 6490 |
&puplo, |
| 6491 |
&ptrans, |
| 6492 |
&pdiag, |
| 6493 |
&(integer){$SIZE(n)}, |
| 6494 |
&(integer){$SIZE(m)}, |
| 6495 |
$P(A), |
| 6496 |
&(integer){$SIZE(n)}, |
| 6497 |
$P(B), |
| 6498 |
&(integer){$SIZE(n)}, |
| 6499 |
$P(info)); |
| 6500 |
', |
| 6501 |
Doc => ' |
| 6502 |
|
| 6503 |
=for ref |
| 6504 |
|
| 6505 |
Solves a triangular system of the form |
| 6506 |
|
| 6507 |
A * X = B or A\' * X = B, |
| 6508 |
|
| 6509 |
where A is a triangular matrix of order N, and B is an N-by-NRHS |
| 6510 |
matrix. |
| 6511 |
|
| 6512 |
A check is made to verify that A is nonsingular. |
| 6513 |
|
| 6514 |
Arguments |
| 6515 |
========= |
| 6516 |
|
| 6517 |
uplo: = 0: A is upper triangular; |
| 6518 |
= 1: A is lower triangular. |
| 6519 |
|
| 6520 |
trans: Specifies the form of the system of equations: |
| 6521 |
= 0: A * X = B (No transpose) |
| 6522 |
= 1: A**T * X = B (Transpose) |
| 6523 |
|
| 6524 |
diag: = 0: A is non-unit triangular; |
| 6525 |
= 1: A is unit triangular. |
| 6526 |
|
| 6527 |
A: The triangular matrix A. If uplo = 0, the leading N-by-N |
| 6528 |
upper triangular part of the array A contains the upper |
| 6529 |
triangular matrix, and the strictly lower triangular part of |
| 6530 |
A is not referenced. If uplo = 1, the leading N-by-N lower |
| 6531 |
triangular part of the array A contains the lower triangular |
| 6532 |
matrix, and the strictly upper triangular part of A is not |
| 6533 |
referenced. If diag = 1, the diagonal elements of A are |
| 6534 |
also not referenced and are assumed to be 1. |
| 6535 |
|
| 6536 |
B: On entry, the right hand side matrix B. |
| 6537 |
On exit, if info = 0, the solution matrix X. |
| 6538 |
|
| 6539 |
info = 0: successful exit |
| 6540 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6541 |
> 0: if info = i, the i-th diagonal element of A is zero, |
| 6542 |
indicating that the matrix is singular and the solutions |
| 6543 |
X have not been computed. |
| 6544 |
|
| 6545 |
=for example |
| 6546 |
|
| 6547 |
# Assume $a is upper triangular |
| 6548 |
$a = random (float, 100, 100); |
| 6549 |
$b = random(50,100); |
| 6550 |
$a = transpose($a); |
| 6551 |
$b = transpose($b); |
| 6552 |
$info = null; |
| 6553 |
trtrs($a, 0, 0, 0, $b, $info); |
| 6554 |
print("X is :\n".transpose($b))unless $info; |
| 6555 |
|
| 6556 |
'); |
| 6557 |
|
| 6558 |
|
| 6559 |
pp_def("latrs", |
| 6560 |
HandleBad => 0, |
| 6561 |
Pars => 'A(n,n); int uplo(); int trans(); int diag(); int normin();[io]x(n); [o]scale();[io]cnorm(n);int [o]info()', |
| 6562 |
GenericTypes => [F,D], |
| 6563 |
Code => generate_code ' |
| 6564 |
char puplo = \'U\'; |
| 6565 |
char ptrans = \'N\'; |
| 6566 |
char pdiag = \'N\'; |
| 6567 |
char pnormin = \'N\'; |
| 6568 |
|
| 6569 |
extern int FORTRAN($TFD(s,d)latrs)(char *uplo, char *trans, char *diag, char * |
| 6570 |
normin, integer *n, $GENERIC() *a, integer *lda, $GENERIC() *x, |
| 6571 |
$GENERIC() *scale, $GENERIC() *cnorm, integer *info); |
| 6572 |
if($uplo()) |
| 6573 |
puplo = \'L\'; |
| 6574 |
if($trans()) |
| 6575 |
ptrans = \'T\'; |
| 6576 |
if($diag()) |
| 6577 |
pdiag = \'U\'; |
| 6578 |
if($normin()) |
| 6579 |
pnormin = \'Y\'; |
| 6580 |
|
| 6581 |
FORTRAN($TFD(s,d)latrs)( |
| 6582 |
&puplo, |
| 6583 |
&ptrans, |
| 6584 |
&pdiag, |
| 6585 |
&pnormin, |
| 6586 |
&(integer){$SIZE(n)}, |
| 6587 |
$P(A), |
| 6588 |
&(integer){$SIZE(n)}, |
| 6589 |
$P(x), |
| 6590 |
$P(scale), |
| 6591 |
$P(cnorm), |
| 6592 |
$P(info)); |
| 6593 |
', |
| 6594 |
Doc => ' |
| 6595 |
|
| 6596 |
=for ref |
| 6597 |
|
| 6598 |
Solves one of the triangular systems |
| 6599 |
|
| 6600 |
A *x = s*b or A\'*x = s*b |
| 6601 |
|
| 6602 |
with scaling to prevent overflow. Here A is an upper or lower |
| 6603 |
triangular matrix, A\' denotes the transpose of A, x and b are |
| 6604 |
n-element vectors, and s is a scaling factor, usually less than |
| 6605 |
or equal to 1, chosen so that the components of x will be less than |
| 6606 |
the overflow threshold. If the unscaled problem will not cause |
| 6607 |
overflow, the Level 2 BLAS routine C<trsv> is called. If the matrix A |
| 6608 |
is singular (A(j,j) = 0 for some j), then s is set to 0 and a |
| 6609 |
non-trivial solution to A*x = 0 is returned. |
| 6610 |
|
| 6611 |
Further Details |
| 6612 |
======= ======= |
| 6613 |
|
| 6614 |
A rough bound on x is computed; if that is less than overflow, trsv |
| 6615 |
is called, otherwise, specific code is used which checks for possible |
| 6616 |
overflow or divide-by-zero at every operation. |
| 6617 |
|
| 6618 |
A columnwise scheme is used for solving A*x = b. The basic algorithm |
| 6619 |
if A is lower triangular is |
| 6620 |
|
| 6621 |
x[1:n] := b[1:n] |
| 6622 |
for j = 1, ..., n |
| 6623 |
x(j) := x(j) / A(j,j) |
| 6624 |
x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] |
| 6625 |
end |
| 6626 |
|
| 6627 |
Define bounds on the components of x after j iterations of the loop: |
| 6628 |
|
| 6629 |
M(j) = bound on x[1:j] |
| 6630 |
G(j) = bound on x[j+1:n] |
| 6631 |
|
| 6632 |
Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. |
| 6633 |
|
| 6634 |
Then for iteration j+1 we have |
| 6635 |
M(j+1) <= G(j) / | A(j+1,j+1) | |
| 6636 |
G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | |
| 6637 |
<= G(j) ( 1 + cnorm(j+1) / | A(j+1,j+1) | ) |
| 6638 |
|
| 6639 |
where cnorm(j+1) is greater than or equal to the infinity-norm of |
| 6640 |
column j+1 of A, not counting the diagonal. |
| 6641 |
|
| 6642 |
Hence |
| 6643 |
|
| 6644 |
G(j) <= G(0) product ( 1 + cnorm(i) / | A(i,i) | ) |
| 6645 |
1<=i<=j |
| 6646 |
and |
| 6647 |
|
| 6648 |
|x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + cnorm(i) / |A(i,i)| ) |
| 6649 |
1<=i< j |
| 6650 |
|
| 6651 |
Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTRSV if the |
| 6652 |
reciprocal of the largest M(j), j=1,..,n, is larger than |
| 6653 |
max(underflow, 1/overflow). |
| 6654 |
|
| 6655 |
The bound on x(j) is also used to determine when a step in the |
| 6656 |
columnwise method can be performed without fear of overflow. If |
| 6657 |
the computed bound is greater than a large constant, x is scaled to |
| 6658 |
prevent overflow, but if the bound overflows, x is set to 0, x(j) to |
| 6659 |
1, and scale to 0, and a non-trivial solution to A*x = 0 is found. |
| 6660 |
|
| 6661 |
Similarly, a row-wise scheme is used to solve A\'*x = b. The basic |
| 6662 |
algorithm for A upper triangular is |
| 6663 |
|
| 6664 |
for j = 1, ..., n |
| 6665 |
x(j) := ( b(j) - A[1:j-1,j]\' * x[1:j-1] ) / A(j,j) |
| 6666 |
end |
| 6667 |
|
| 6668 |
We simultaneously compute two bounds |
| 6669 |
|
| 6670 |
G(j) = bound on ( b(i) - A[1:i-1,i]\' * x[1:i-1] ), 1<=i<=j |
| 6671 |
M(j) = bound on x(i), 1<=i<=j |
| 6672 |
|
| 6673 |
The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we |
| 6674 |
add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. |
| 6675 |
Then the bound on x(j) is |
| 6676 |
|
| 6677 |
M(j) <= M(j-1) * ( 1 + cnorm(j) ) / | A(j,j) | |
| 6678 |
|
| 6679 |
<= M(0) * product ( ( 1 + cnorm(i) ) / |A(i,i)| ) |
| 6680 |
1<=i<=j |
| 6681 |
|
| 6682 |
and we can safely call trsv if 1/M(n) and 1/G(n) are both greater |
| 6683 |
than max(underflow, 1/overflow). |
| 6684 |
|
| 6685 |
Arguments |
| 6686 |
========= |
| 6687 |
|
| 6688 |
uplo: Specifies whether the matrix A is upper or lower triangular. |
| 6689 |
= 0: Upper triangular |
| 6690 |
= 1: Lower triangular |
| 6691 |
|
| 6692 |
trans: Specifies the operation applied to A. |
| 6693 |
= 0: Solve A * x = s*b (No transpose) |
| 6694 |
= 1: Solve A\'* x = s*b (Transpose) |
| 6695 |
|
| 6696 |
diag: Specifies whether or not the matrix A is unit triangular. |
| 6697 |
= 0: Non-unit triangular |
| 6698 |
= 1: Unit triangular |
| 6699 |
|
| 6700 |
normin: Specifies whether cnorm has been set or not. |
| 6701 |
= 1: cnorm contains the column norms on entry |
| 6702 |
= 0: cnorm is not set on entry. On exit, the norms will |
| 6703 |
be computed and stored in cnorm. |
| 6704 |
|
| 6705 |
A: The triangular matrix A. If uplo = 0, the leading n by n |
| 6706 |
upper triangular part of the array A contains the upper |
| 6707 |
triangular matrix, and the strictly lower triangular part of |
| 6708 |
A is not referenced. If uplo = 1, the leading n by n lower |
| 6709 |
triangular part of the array A contains the lower triangular |
| 6710 |
matrix, and the strictly upper triangular part of A is not |
| 6711 |
referenced. If diag = 1, the diagonal elements of A are |
| 6712 |
also not referenced and are assumed to be 1. |
| 6713 |
|
| 6714 |
x: On entry, the right hand side b of the triangular system. |
| 6715 |
On exit, x is overwritten by the solution vector x. |
| 6716 |
|
| 6717 |
scale: The scaling factor s for the triangular system |
| 6718 |
A * x = s*b or A\'* x = s*b. |
| 6719 |
If scale = 0, the matrix A is singular or badly scaled, and |
| 6720 |
the vector x is an exact or approximate solution to A*x = 0. |
| 6721 |
|
| 6722 |
cnorm: If normin = 0, cnorm is an output argument and cnorm(j) |
| 6723 |
returns the 1-norm of the offdiagonal part of the j-th column |
| 6724 |
of A. |
| 6725 |
If normin = 1, cnorm is an input argument and cnorm(j) |
| 6726 |
contains the norm of the off-diagonal part of the j-th column |
| 6727 |
of A. If trans = 0, cnorm(j) must be greater than or equal |
| 6728 |
to the infinity-norm, and if trans = 1, cnorm(j) |
| 6729 |
must be greater than or equal to the 1-norm. |
| 6730 |
|
| 6731 |
|
| 6732 |
|
| 6733 |
info: = 0: successful exit |
| 6734 |
< 0: if info = -k, the k-th argument had an illegal value |
| 6735 |
|
| 6736 |
|
| 6737 |
=for example |
| 6738 |
|
| 6739 |
# Assume $a is upper triangular |
| 6740 |
$a = random (float, 100, 100); |
| 6741 |
$b = random(100); |
| 6742 |
$a = transpose($a); |
| 6743 |
$info = null; |
| 6744 |
$scale= null; |
| 6745 |
$cnorm = zeroes(100); |
| 6746 |
latrs($a, 0, 0, 0, 0,$b, $scale, $cnorm,$info); |
| 6747 |
|
| 6748 |
'); |
| 6749 |
|
| 6750 |
|
| 6751 |
|
| 6752 |
pp_def("gecon", |
| 6753 |
HandleBad => 0, |
| 6754 |
Pars => 'A(n,n); int norm(); anorm(); [o]rcond();int [o]info(); int [t]iwork(n); [t]work(workn=CALC(4*$SIZE(n)));', |
| 6755 |
GenericTypes => [F,D], |
| 6756 |
Code => generate_code ' |
| 6757 |
char pnorm = \'I\'; |
| 6758 |
extern int FORTRAN($TFD(s,d)gecon)(char *norm, integer *n, $GENERIC() *a, integer * |
| 6759 |
lda, $GENERIC() *anorm, $GENERIC() *rcond, $GENERIC() *work, integer * |
| 6760 |
iwork, integer *info); |
| 6761 |
if($norm()) |
| 6762 |
pnorm = \'O\'; |
| 6763 |
|
| 6764 |
FORTRAN($TFD(s,d)gecon)( |
| 6765 |
&pnorm, |
| 6766 |
&(integer){$SIZE(n)}, |
| 6767 |
$P(A), |
| 6768 |
&(integer){$SIZE(n)}, |
| 6769 |
$P(anorm), |
| 6770 |
$P(rcond), |
| 6771 |
$P(work), |
| 6772 |
$P(iwork), |
| 6773 |
$P(info)); |
| 6774 |
', |
| 6775 |
Doc => ' |
| 6776 |
|
| 6777 |
=for ref |
| 6778 |
|
| 6779 |
Estimates the reciprocal of the condition number of a general |
| 6780 |
real matrix A, in either the 1-norm or the infinity-norm, using |
| 6781 |
the LU factorization computed by C<getrf>. |
| 6782 |
|
| 6783 |
An estimate is obtained for norm(inv(A)), and the reciprocal of the |
| 6784 |
condition number is computed as |
| 6785 |
|
| 6786 |
rcond = 1 / ( norm(A) * norm(inv(A)) ). |
| 6787 |
|
| 6788 |
Arguments |
| 6789 |
========= |
| 6790 |
|
| 6791 |
norm: Specifies whether the 1-norm condition number or the |
| 6792 |
infinity-norm condition number is required: |
| 6793 |
= 0: Infinity-norm. |
| 6794 |
= 1: 1-norm; |
| 6795 |
|
| 6796 |
A: The factors L and U from the factorization A = P*L*U |
| 6797 |
as computed by getrf. |
| 6798 |
|
| 6799 |
anorm: If norm = 0, the infinity-norm of the original matrix A. |
| 6800 |
If norm = 1, the 1-norm of the original matrix A. |
| 6801 |
|
| 6802 |
|
| 6803 |
rcond: The reciprocal of the condition number of the matrix A, |
| 6804 |
computed as rcond = 1/(norm(A) * norm(inv(A))). |
| 6805 |
|
| 6806 |
info: = 0: successful exit |
| 6807 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6808 |
|
| 6809 |
|
| 6810 |
=for example |
| 6811 |
|
| 6812 |
$a = random (float, 100, 100); |
| 6813 |
$anorm = $a->lange(1); |
| 6814 |
$ipiv = zeroes(long, 100); |
| 6815 |
$info = null; |
| 6816 |
getrf($a, $ipiv, $info); |
| 6817 |
($rcond, $info) = gecon($a, 1, $anorm) unless $info != 0; |
| 6818 |
'); |
| 6819 |
|
| 6820 |
pp_def("sycon", |
| 6821 |
HandleBad => 0, |
| 6822 |
Pars => 'A(n,n); int uplo(); int ipiv(n); anorm(); [o]rcond();int [o]info(); int [t]iwork(n); [t]work(workn=CALC(2*$SIZE(n)));', |
| 6823 |
GenericTypes => [F,D], |
| 6824 |
Code => generate_code ' |
| 6825 |
char puplo = \'U\'; |
| 6826 |
extern int FORTRAN($TFD(s,d)sycon)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 6827 |
lda, integer *ipiv, $GENERIC() *anorm, $GENERIC() *rcond, $GENERIC() * |
| 6828 |
work, integer *iwork, integer *info); |
| 6829 |
if($uplo()) |
| 6830 |
puplo = \'L\'; |
| 6831 |
FORTRAN($TFD(s,d)sycon)( |
| 6832 |
&puplo, |
| 6833 |
&(integer){$SIZE(n)}, |
| 6834 |
$P(A), |
| 6835 |
&(integer){$SIZE(n)}, |
| 6836 |
$P(ipiv), |
| 6837 |
$P(anorm), |
| 6838 |
$P(rcond), |
| 6839 |
$P(work), |
| 6840 |
$P(iwork), |
| 6841 |
$P(info)); |
| 6842 |
', |
| 6843 |
Doc => ' |
| 6844 |
=for ref |
| 6845 |
|
| 6846 |
Estimates the reciprocal of the condition number (in the |
| 6847 |
1-norm) of a real symmetric matrix A using the factorization |
| 6848 |
A = U*D*U\' or A = L*D*L\' computed by C<sytrf>. |
| 6849 |
|
| 6850 |
An estimate is obtained for norm(inv(A)), and the reciprocal of the |
| 6851 |
condition number is computed as rcond = 1 / (anorm * norm(inv(A))). |
| 6852 |
|
| 6853 |
Arguments |
| 6854 |
========= |
| 6855 |
|
| 6856 |
uplo: Specifies whether the details of the factorization are stored |
| 6857 |
as an upper or lower triangular matrix. |
| 6858 |
= 0: Upper triangular, form is A = U*D*U\'; |
| 6859 |
= 1: Lower triangular, form is A = L*D*L\'. |
| 6860 |
|
| 6861 |
A: The block diagonal matrix D and the multipliers used to |
| 6862 |
obtain the factor U or L as computed by sytrf. |
| 6863 |
|
| 6864 |
ipiv: Details of the interchanges and the block structure of D |
| 6865 |
as determined by sytrf. |
| 6866 |
|
| 6867 |
anorm: The 1-norm of the original matrix A. |
| 6868 |
|
| 6869 |
rcond: The reciprocal of the condition number of the matrix A, |
| 6870 |
computed as rcond = 1/(anorm * aimvnm), where ainvnm is an |
| 6871 |
estimate of the 1-norm of inv(A) computed in this routine. |
| 6872 |
|
| 6873 |
info: = 0: successful exit |
| 6874 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 6875 |
|
| 6876 |
|
| 6877 |
=for example |
| 6878 |
|
| 6879 |
# Assume $a is symmetric |
| 6880 |
$a = random (float, 100, 100); |
| 6881 |
$anorm = $a->lansy(1,1); |
| 6882 |
$ipiv = zeroes(long, 100); |
| 6883 |
$info = null; |
| 6884 |
sytrf($a, 1,$ipiv, $info); |
| 6885 |
($rcond, $info) = sycon($a, 1, $anorm) unless $info != 0; |
| 6886 |
'); |
| 6887 |
|
| 6888 |
pp_def("pocon", |
| 6889 |
HandleBad => 0, |
| 6890 |
Pars => 'A(n,n); int uplo(); anorm(); [o]rcond();int [o]info(); int [t]iwork(n); [t]work(workn=CALC(3*$SIZE(n)));', |
| 6891 |
GenericTypes => [F,D], |
| 6892 |
Code => generate_code ' |
| 6893 |
char puplo = \'U\'; |
| 6894 |
extern int FORTRAN($TFD(s,d)pocon)(char *uplo, integer *n, $GENERIC() *a, integer * |
| 6895 |
lda, $GENERIC() *anorm, $GENERIC() *rcond, $GENERIC() *work, integer * |
| 6896 |
iwork, integer *info); |
| 6897 |
if($uplo()) |
| 6898 |
puplo = \'L\'; |
| 6899 |
FORTRAN($TFD(s,d)pocon)( |
| 6900 |
&puplo, |
| 6901 |
&(integer){$SIZE(n)}, |
| 6902 |
$P(A), |
| 6903 |
&(integer){$SIZE(n)}, |
| 6904 |
$P(anorm), |
| 6905 |
$P(rcond), |
| 6906 |
$P(work), |
| 6907 |
$P(iwork), |
| 6908 |
$P(info)); |
| 6909 |
', |
| 6910 |
Doc => ' |
| 6911 |
|
| 6912 |
=for ref |
| 6913 |
|
| 6914 |
Estimates the reciprocal of the condition number (in the |
| 6915 |
1-norm) of a real symmetric positive definite matrix using the |
| 6916 |
Cholesky factorization A = U\'*U or A = L*L\' computed by C<potrf>. |
| 6917 |
|
| 6918 |
An estimate is obtained for norm(inv(A)), and the reciprocal of the |
| 6919 |
condition number is computed as rcond = 1 / (anorm * norm(inv(A))). |
| 6920 |
|
| 6921 |
Arguments |
| 6922 |
========= |
| 6923 |
|
| 6924 |
uplo: = 0: Upper triangle of A is stored; |
| 6925 |
= 1: Lower triangle of A is stored. |
| 6926 |
|
| 6927 |
A: The triangular factor U or L from the Cholesky factorization |
| 6928 |
A = U\'*U or A = L*L\', as computed by potrf. |
| 6929 |
|
| 6930 |
anorm: The 1-norm of the matrix A. |
| 6931 |
|
| 6932 |
rcond: The reciprocal of the condition number of the matrix A, |
| 6933 |
computed as rcond = 1/(anorm * ainvnm), where ainvnm is an |
| 6934 |
estimate of the 1-norm of inv(A) computed in this routine. |
| 6935 |
|
| 6936 |
info: = 0: successful exit |
| 6937 |
< 0: if info = -i, the i-th argument had an illegal value |
| 6938 |
|
| 6939 |
|
| 6940 |
=for example |
| 6941 |
|
| 6942 |
# Assume $a is symmetric positive definite |
| 6943 |
$a = random (float, 100, 100); |
| 6944 |
$anorm = $a->lansy(1,1); |
| 6945 |
$info = null; |
| 6946 |
potrf($a, 0, $info); |
| 6947 |
($rcond, $info) = pocon($a, 1, $anorm) unless $info != 0; |
| 6948 |
'); |
| 6949 |
|
| 6950 |
pp_def("trcon", |
| 6951 |
HandleBad => 0, |
| 6952 |
Pars => 'A(n,n); int norm();int uplo();int diag(); [o]rcond();int [o]info(); int [t]iwork(n); [t]work(workn=CALC(3*$SIZE(n)));', |
| 6953 |
GenericTypes => [F,D], |
| 6954 |
Code => generate_code ' |
| 6955 |
char puplo = \'U\'; |
| 6956 |
char pdiag = \'N\'; |
| 6957 |
char pnorm = \'I\'; |
| 6958 |
extern int FORTRAN($TFD(s,d)trcon)(char *norm, char *uplo, char *diag,integer *n, $GENERIC() *a, integer * |
| 6959 |
lda, $GENERIC() *rcond, $GENERIC() *work, integer *iwork, integer *info); |
| 6960 |
if($uplo()) |
| 6961 |
puplo = \'L\'; |
| 6962 |
if($diag()) |
| 6963 |
pdiag = \'U\'; |
| 6964 |
if($norm()) |
| 6965 |
pnorm = \'O\'; |
| 6966 |
|
| 6967 |
FORTRAN($TFD(s,d)trcon)( |
| 6968 |
&pnorm, |
| 6969 |
&puplo, |
| 6970 |
&pdiag, |
| 6971 |
&(integer){$SIZE(n)}, |
| 6972 |
$P(A), |
| 6973 |
&(integer){$SIZE(n)}, |
| 6974 |
$P(rcond), |
| 6975 |
$P(work), |
| 6976 |
$P(iwork), |
| 6977 |
$P(info)); |
| 6978 |
', |
| 6979 |
Doc => ' |
| 6980 |
=for ref |
| 6981 |
|
| 6982 |
Estimates the reciprocal of the condition number of a |
| 6983 |
triangular matrix A, in either the 1-norm or the infinity-norm. |
| 6984 |
|
| 6985 |
The norm of A is computed and an estimate is obtained for |
| 6986 |
norm(inv(A)), then the reciprocal of the condition number is |
| 6987 |
computed as |
| 6988 |
|
| 6989 |
rcond = 1 / ( norm(A) * norm(inv(A)) ). |
| 6990 |
|
| 6991 |
Arguments |
| 6992 |
========= |
| 6993 |
|
| 6994 |
norm: Specifies whether the 1-norm condition number or the |
| 6995 |
infinity-norm condition number is required: |
| 6996 |
= 0: Infinity-norm. |
| 6997 |
= 1: 1-norm; |
| 6998 |
|
| 6999 |
|
| 7000 |
uplo: = 0: A is upper triangular; |
| 7001 |
= 1: A is lower triangular. |
| 7002 |
|
| 7003 |
diag: = 0: A is non-unit triangular; |
| 7004 |
= 1: A is unit triangular. |
| 7005 |
|
| 7006 |
A: The triangular matrix A. If uplo = 0, the leading N-by-N |
| 7007 |
upper triangular part of the array A contains the upper |
| 7008 |
triangular matrix, and the strictly lower triangular part of |
| 7009 |
A is not referenced. If uplo = 1, the leading N-by-N lower |
| 7010 |
triangular part of the array A contains the lower triangular |
| 7011 |
matrix, and the strictly upper triangular part of A is not |
| 7012 |
referenced. If diag = 1, the diagonal elements of A are |
| 7013 |
also not referenced and are assumed to be 1. |
| 7014 |
|
| 7015 |
rcond: The reciprocal of the condition number of the matrix A, |
| 7016 |
computed as rcond = 1/(norm(A) * norm(inv(A))). |
| 7017 |
|
| 7018 |
info: = 0: successful exit |
| 7019 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7020 |
|
| 7021 |
=for example |
| 7022 |
|
| 7023 |
# Assume $a is upper triangular |
| 7024 |
$a = random (float, 100, 100); |
| 7025 |
$info = null; |
| 7026 |
($rcond, $info) = trcon($a, 1, 1, 0) unless $info != 0; |
| 7027 |
'); |
| 7028 |
|
| 7029 |
|
| 7030 |
pp_def("geqp3", |
| 7031 |
HandleBad => 0, |
| 7032 |
Pars => '[io]A(m,n); int [io]jpvt(n); [o]tau(k); int [o]info()', |
| 7033 |
GenericTypes => [F,D], |
| 7034 |
Code => generate_code ' |
| 7035 |
integer lwork = -1; |
| 7036 |
|
| 7037 |
extern int FORTRAN($TFD(s,d)geqp3)(integer *m, integer *n, $GENERIC() *a, integer * |
| 7038 |
lda, integer *jpvt, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 7039 |
integer *info); |
| 7040 |
$GENERIC() tmp_work; |
| 7041 |
|
| 7042 |
FORTRAN($TFD(s,d)geqp3)( |
| 7043 |
&(integer){$SIZE(m)}, |
| 7044 |
&(integer){$SIZE(n)}, |
| 7045 |
$P(A), |
| 7046 |
&(integer){$SIZE(m)}, |
| 7047 |
$P(jpvt), |
| 7048 |
$P(tau), |
| 7049 |
&tmp_work, |
| 7050 |
&lwork, |
| 7051 |
$P(info)); |
| 7052 |
|
| 7053 |
lwork = (integer )tmp_work; |
| 7054 |
{ |
| 7055 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7056 |
FORTRAN($TFD(s,d)geqp3)( |
| 7057 |
&(integer){$SIZE(m)}, |
| 7058 |
&(integer){$SIZE(n)}, |
| 7059 |
$P(A), |
| 7060 |
&(integer){$SIZE(m)}, |
| 7061 |
$P(jpvt), |
| 7062 |
$P(tau), |
| 7063 |
work, |
| 7064 |
&lwork, |
| 7065 |
$P(info)); |
| 7066 |
free(work); |
| 7067 |
} |
| 7068 |
|
| 7069 |
', |
| 7070 |
Doc => ' |
| 7071 |
|
| 7072 |
=for ref |
| 7073 |
|
| 7074 |
geqp3 computes a QR factorization using Level 3 BLAS with column pivoting of a |
| 7075 |
matrix A: |
| 7076 |
|
| 7077 |
A*P = Q*R |
| 7078 |
|
| 7079 |
The matrix Q is represented as a product of elementary reflectors |
| 7080 |
|
| 7081 |
Q = H(1) H(2) . . . H(k), where k = min(m,n). |
| 7082 |
|
| 7083 |
Each H(i) has the form |
| 7084 |
|
| 7085 |
H(i) = I - tau * v * v\' |
| 7086 |
|
| 7087 |
where tau is a real/complex scalar, and v is a real/complex vector |
| 7088 |
with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in |
| 7089 |
A(i+1:m,i), and tau in tau(i). |
| 7090 |
|
| 7091 |
Arguments |
| 7092 |
========= |
| 7093 |
|
| 7094 |
A: On entry, the M-by-N matrix A. |
| 7095 |
On exit, the upper triangle of the array contains the |
| 7096 |
min(M,N)-by-N upper trapezoidal matrix R; the elements below |
| 7097 |
the diagonal, together with the array tau, represent the |
| 7098 |
orthogonal matrix Q as a product of min(M,N) elementary |
| 7099 |
reflectors. |
| 7100 |
|
| 7101 |
jpvt: On entry, if jpvt(J)!=0, the J-th column of A is permuted |
| 7102 |
to the front of A*P (a leading column); if jpvt(J)=0, |
| 7103 |
the J-th column of A is a free column. |
| 7104 |
On exit, if jpvt(J)=K, then the J-th column of A*P was the |
| 7105 |
the K-th column of A. |
| 7106 |
|
| 7107 |
tau: The scalar factors of the elementary reflectors. |
| 7108 |
|
| 7109 |
info: = 0: successful exit. |
| 7110 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 7111 |
|
| 7112 |
=for example |
| 7113 |
|
| 7114 |
$a = random (float, 100, 50); |
| 7115 |
$info = null; |
| 7116 |
$tau = zeroes(float, 50); |
| 7117 |
$jpvt = zeroes(long, 50); |
| 7118 |
geqp3($a, $jpvt, $tau, $info); |
| 7119 |
'); |
| 7120 |
|
| 7121 |
pp_def("geqrf", |
| 7122 |
HandleBad => 0, |
| 7123 |
Pars => '[io]A(m,n); [o]tau(k); int [o]info()', |
| 7124 |
GenericTypes => [F,D], |
| 7125 |
Code => generate_code ' |
| 7126 |
integer lwork = -1; |
| 7127 |
|
| 7128 |
extern int FORTRAN($TFD(s,d)geqrf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 7129 |
lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 7130 |
integer *info); |
| 7131 |
$GENERIC() tmp_work; |
| 7132 |
|
| 7133 |
FORTRAN($TFD(s,d)geqrf)( |
| 7134 |
&(integer){$SIZE(m)}, |
| 7135 |
&(integer){$SIZE(n)}, |
| 7136 |
$P(A), |
| 7137 |
&(integer){$SIZE(m)}, |
| 7138 |
$P(tau), |
| 7139 |
&tmp_work, |
| 7140 |
&lwork, |
| 7141 |
$P(info)); |
| 7142 |
|
| 7143 |
lwork = (integer )tmp_work; |
| 7144 |
{ |
| 7145 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7146 |
FORTRAN($TFD(s,d)geqrf)( |
| 7147 |
&(integer){$SIZE(m)}, |
| 7148 |
&(integer){$SIZE(n)}, |
| 7149 |
$P(A), |
| 7150 |
&(integer){$SIZE(m)}, |
| 7151 |
$P(tau), |
| 7152 |
work, |
| 7153 |
&lwork, |
| 7154 |
$P(info)); |
| 7155 |
free(work); |
| 7156 |
} |
| 7157 |
|
| 7158 |
', |
| 7159 |
Doc => ' |
| 7160 |
|
| 7161 |
=for ref |
| 7162 |
|
| 7163 |
geqrf computes a QR factorization of a |
| 7164 |
matrix A: |
| 7165 |
|
| 7166 |
A = Q * R |
| 7167 |
|
| 7168 |
The matrix Q is represented as a product of elementary reflectors |
| 7169 |
|
| 7170 |
Q = H(1) H(2) . . . H(k), where k = min(m,n). |
| 7171 |
|
| 7172 |
Each H(i) has the form |
| 7173 |
|
| 7174 |
H(i) = I - tau * v * v\' |
| 7175 |
|
| 7176 |
where tau is a real/complex scalar, and v is a real/complex vector |
| 7177 |
with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in |
| 7178 |
A(i+1:m,i), and tau in tau(i). |
| 7179 |
|
| 7180 |
Arguments |
| 7181 |
========= |
| 7182 |
|
| 7183 |
A: On exit, the elements on and above the diagonal of the array |
| 7184 |
contain the min(M,N)-by-N upper trapezoidal matrix R (R is |
| 7185 |
upper triangular if m >= n); the elements below the diagonal, |
| 7186 |
with the array TAU, represent the orthogonal matrix Q as a |
| 7187 |
product of min(m,n) elementary reflectors. |
| 7188 |
|
| 7189 |
|
| 7190 |
tau: The scalar factors of the elementary reflectors. |
| 7191 |
|
| 7192 |
info: = 0: successful exit. |
| 7193 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 7194 |
|
| 7195 |
=for example |
| 7196 |
|
| 7197 |
$a = random (float, 100, 50); |
| 7198 |
$info = null; |
| 7199 |
$tau = zeroes(float, 50); |
| 7200 |
geqrf($a, $tau, $info); |
| 7201 |
'); |
| 7202 |
|
| 7203 |
pp_def("orgqr", |
| 7204 |
HandleBad => 0, |
| 7205 |
Pars => '[io]A(m,n); tau(k); int [o]info()', |
| 7206 |
GenericTypes => [F,D], |
| 7207 |
Code => generate_code ' |
| 7208 |
integer lwork = -1; |
| 7209 |
|
| 7210 |
extern int FORTRAN($TFD(s,d)orgqr)(integer *m, integer *n, integer *k, $GENERIC() * |
| 7211 |
a, integer *lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 7212 |
integer *info); |
| 7213 |
$GENERIC() tmp_work; |
| 7214 |
|
| 7215 |
FORTRAN($TFD(s,d)orgqr)( |
| 7216 |
&(integer){$SIZE(m)}, |
| 7217 |
&(integer){$SIZE(n)}, |
| 7218 |
&(integer){$SIZE(k)}, |
| 7219 |
$P(A), |
| 7220 |
&(integer){$SIZE(m)}, |
| 7221 |
$P(tau), |
| 7222 |
&tmp_work, |
| 7223 |
&lwork, |
| 7224 |
$P(info)); |
| 7225 |
|
| 7226 |
lwork = (integer )tmp_work; |
| 7227 |
{ |
| 7228 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7229 |
FORTRAN($TFD(s,d)orgqr)( |
| 7230 |
&(integer){$SIZE(m)}, |
| 7231 |
&(integer){$SIZE(n)}, |
| 7232 |
&(integer){$SIZE(k)}, |
| 7233 |
$P(A), |
| 7234 |
&(integer){$SIZE(m)}, |
| 7235 |
$P(tau), |
| 7236 |
work, |
| 7237 |
&lwork, |
| 7238 |
$P(info)); |
| 7239 |
free(work); |
| 7240 |
} |
| 7241 |
|
| 7242 |
', |
| 7243 |
Doc => ' |
| 7244 |
|
| 7245 |
=for ref |
| 7246 |
|
| 7247 |
Generates an M-by-N real matrix Q with orthonormal columns, |
| 7248 |
which is defined as the first N columns of a product of K elementary |
| 7249 |
reflectors of order M |
| 7250 |
|
| 7251 |
Q = H(1) H(2) . . . H(k) |
| 7252 |
|
| 7253 |
as returned by geqrf or geqp3. |
| 7254 |
|
| 7255 |
Arguments |
| 7256 |
========= |
| 7257 |
|
| 7258 |
A: On entry, the i-th column must contain the vector which |
| 7259 |
defines the elementary reflector H(i), for i = 1,2,...,k, as |
| 7260 |
returned by geqrf or geqp3 in the first k columns of its array |
| 7261 |
argument A. |
| 7262 |
On exit, the M-by-N matrix Q. |
| 7263 |
|
| 7264 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7265 |
reflector H(i), as returned by geqrf or geqp3. |
| 7266 |
|
| 7267 |
info: = 0: successful exit |
| 7268 |
< 0: if info = -i, the i-th argument has an illegal value |
| 7269 |
|
| 7270 |
|
| 7271 |
=for example |
| 7272 |
|
| 7273 |
$a = random (float, 100, 50); |
| 7274 |
$info = null; |
| 7275 |
$tau = zeroes(float, 50); |
| 7276 |
geqrf($a, $tau, $info); |
| 7277 |
orgqr($a, $tau, $info) unless $info != 0; |
| 7278 |
'); |
| 7279 |
|
| 7280 |
|
| 7281 |
pp_def("ormqr", |
| 7282 |
HandleBad => 0, |
| 7283 |
Pars => 'A(p,k); int side(); int trans(); tau(k); [io]C(m,n);int [o]info()', |
| 7284 |
GenericTypes => [F,D], |
| 7285 |
Code => generate_code ' |
| 7286 |
char ptrans = \'N\', pside = \'L\'; |
| 7287 |
integer lwork = -1; |
| 7288 |
|
| 7289 |
extern int FORTRAN($TFD(s,d)ormqr)(char *side, char *trans, integer *m, integer *n, |
| 7290 |
integer *k, $GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() * |
| 7291 |
c__, integer *ldc, $GENERIC() *work, integer *lwork, integer *info); |
| 7292 |
$GENERIC() tmp_work; |
| 7293 |
if($trans()) |
| 7294 |
ptrans = \'T\'; |
| 7295 |
if($side()) |
| 7296 |
pside = \'R\'; |
| 7297 |
|
| 7298 |
FORTRAN($TFD(s,d)ormqr)( |
| 7299 |
&pside, |
| 7300 |
&ptrans, |
| 7301 |
&(integer){$SIZE(m)}, |
| 7302 |
&(integer){$SIZE(n)}, |
| 7303 |
&(integer){$SIZE(k)}, |
| 7304 |
$P(A), |
| 7305 |
&(integer){$SIZE(p)}, |
| 7306 |
$P(tau), |
| 7307 |
$P(C), |
| 7308 |
&(integer){$SIZE(m)}, |
| 7309 |
&tmp_work, |
| 7310 |
&lwork, |
| 7311 |
$P(info)); |
| 7312 |
|
| 7313 |
lwork = (integer )tmp_work; |
| 7314 |
{ |
| 7315 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7316 |
FORTRAN($TFD(s,d)ormqr)( |
| 7317 |
&pside, |
| 7318 |
&ptrans, |
| 7319 |
&(integer){$SIZE(m)}, |
| 7320 |
&(integer){$SIZE(n)}, |
| 7321 |
&(integer){$SIZE(k)}, |
| 7322 |
$P(A), |
| 7323 |
&(integer){$SIZE(p)}, |
| 7324 |
$P(tau), |
| 7325 |
$P(C), |
| 7326 |
&(integer){$SIZE(m)}, |
| 7327 |
work, |
| 7328 |
&lwork, |
| 7329 |
$P(info)); |
| 7330 |
free(work); |
| 7331 |
} |
| 7332 |
|
| 7333 |
', |
| 7334 |
Doc => ' |
| 7335 |
|
| 7336 |
=for ref |
| 7337 |
|
| 7338 |
Overwrites the general real M-by-N matrix C with |
| 7339 |
|
| 7340 |
side = 0 side = 1 |
| 7341 |
trans = 0: Q * C C * Q |
| 7342 |
trans = 1: Q\' * C C * Q\' |
| 7343 |
|
| 7344 |
where Q is a real orthogonal matrix defined as the product of k |
| 7345 |
elementary reflectors |
| 7346 |
|
| 7347 |
Q = H(1) H(2) . . . H(k) |
| 7348 |
|
| 7349 |
as returned by geqrf or geqp3. |
| 7350 |
|
| 7351 |
Q is of order M if C<side> = 0 and of order N |
| 7352 |
if C<side> = 1. |
| 7353 |
|
| 7354 |
Arguments |
| 7355 |
========= |
| 7356 |
|
| 7357 |
side: = 0: apply Q or Q\' from the Left; |
| 7358 |
= 1: apply Q or Q\' from the Right. |
| 7359 |
|
| 7360 |
trans: = 0: No transpose, apply Q; |
| 7361 |
= 1: Transpose, apply Q\'. |
| 7362 |
|
| 7363 |
A: The i-th column must contain the vector which defines the |
| 7364 |
elementary reflector H(i), for i = 1,2,...,k, as returned by |
| 7365 |
geqrf or geqp3 in the first k columns of its array argument A. |
| 7366 |
A is modified by the routine but restored on exit. |
| 7367 |
|
| 7368 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7369 |
reflector H(i), as returned by geqrf or geqp3. |
| 7370 |
|
| 7371 |
C: On entry, the M-by-N matrix C. |
| 7372 |
On exit, C is overwritten by Q*C or Q\'*C or C*Q\' or C*Q. |
| 7373 |
|
| 7374 |
info: = 0: successful exit |
| 7375 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7376 |
|
| 7377 |
|
| 7378 |
=for example |
| 7379 |
|
| 7380 |
$a = random (float, 50, 100); |
| 7381 |
$a = transpose($a); |
| 7382 |
$info = null; |
| 7383 |
$tau = zeroes(float, 50); |
| 7384 |
geqrf($a, $tau, $info); |
| 7385 |
$c = random(70,50); |
| 7386 |
# $c will contain the result |
| 7387 |
$c->reshape(70,100); |
| 7388 |
$c = transpose($c); |
| 7389 |
ormqr($a, $tau, $c, $info); |
| 7390 |
'); |
| 7391 |
|
| 7392 |
pp_def("gelqf", |
| 7393 |
HandleBad => 0, |
| 7394 |
Pars => '[io]A(m,n); [o]tau(k); int [o]info()', |
| 7395 |
GenericTypes => [F,D], |
| 7396 |
Code => generate_code ' |
| 7397 |
integer lwork = -1; |
| 7398 |
|
| 7399 |
extern int FORTRAN($TFD(s,d)gelqf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 7400 |
lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, integer *info); |
| 7401 |
$GENERIC() tmp_work; |
| 7402 |
|
| 7403 |
FORTRAN($TFD(s,d)gelqf)( |
| 7404 |
&(integer){$SIZE(m)}, |
| 7405 |
&(integer){$SIZE(n)}, |
| 7406 |
$P(A), |
| 7407 |
&(integer){$SIZE(m)}, |
| 7408 |
$P(tau), |
| 7409 |
&tmp_work, |
| 7410 |
&lwork, |
| 7411 |
$P(info)); |
| 7412 |
|
| 7413 |
lwork = (integer )tmp_work; |
| 7414 |
{ |
| 7415 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7416 |
FORTRAN($TFD(s,d)gelqf)( |
| 7417 |
&(integer){$SIZE(m)}, |
| 7418 |
&(integer){$SIZE(n)}, |
| 7419 |
$P(A), |
| 7420 |
&(integer){$SIZE(m)}, |
| 7421 |
$P(tau), |
| 7422 |
work, |
| 7423 |
&lwork, |
| 7424 |
$P(info)); |
| 7425 |
free(work); |
| 7426 |
} |
| 7427 |
|
| 7428 |
', |
| 7429 |
Doc => ' |
| 7430 |
|
| 7431 |
=for ref |
| 7432 |
|
| 7433 |
Computes an LQ factorization of a real M-by-N matrix A: |
| 7434 |
|
| 7435 |
A = L * Q. |
| 7436 |
|
| 7437 |
The matrix Q is represented as a product of elementary reflectors |
| 7438 |
|
| 7439 |
Q = H(k) . . . H(2) H(1), where k = min(m,n). |
| 7440 |
|
| 7441 |
Each H(i) has the form |
| 7442 |
|
| 7443 |
H(i) = I - tau * v * v\' |
| 7444 |
|
| 7445 |
where tau is a real scalar, and v is a real vector with |
| 7446 |
v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n), |
| 7447 |
and tau in tau(i). |
| 7448 |
|
| 7449 |
Arguments |
| 7450 |
========= |
| 7451 |
|
| 7452 |
A: On entry, the M-by-N matrix A. |
| 7453 |
On exit, the elements on and below the diagonal of the array |
| 7454 |
contain the m-by-min(m,n) lower trapezoidal matrix L (L is |
| 7455 |
lower triangular if m <= n); the elements above the diagonal, |
| 7456 |
with the array tau, represent the orthogonal matrix Q as a |
| 7457 |
product of elementary reflectors. |
| 7458 |
|
| 7459 |
tau: The scalar factors of the elementary reflectors. |
| 7460 |
|
| 7461 |
info: = 0: successful exit |
| 7462 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7463 |
|
| 7464 |
=for example |
| 7465 |
|
| 7466 |
$a = random (float, 100, 50); |
| 7467 |
$info = null; |
| 7468 |
$tau = zeroes(float, 50); |
| 7469 |
gelqf($a, $tau, $info); |
| 7470 |
'); |
| 7471 |
|
| 7472 |
pp_def("orglq", |
| 7473 |
HandleBad => 0, |
| 7474 |
Pars => '[io]A(m,n); tau(k); int [o]info()', |
| 7475 |
GenericTypes => [F,D], |
| 7476 |
Code => generate_code ' |
| 7477 |
integer lwork = -1; |
| 7478 |
|
| 7479 |
extern int FORTRAN($TFD(s,d)orglq)(integer *m, integer *n, integer *k, $GENERIC() * |
| 7480 |
a, integer *lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 7481 |
integer *info); |
| 7482 |
$GENERIC() tmp_work; |
| 7483 |
|
| 7484 |
FORTRAN($TFD(s,d)orglq)( |
| 7485 |
&(integer){$SIZE(m)}, |
| 7486 |
&(integer){$SIZE(n)}, |
| 7487 |
&(integer){$SIZE(k)}, |
| 7488 |
$P(A), |
| 7489 |
&(integer){$SIZE(m)}, |
| 7490 |
$P(tau), |
| 7491 |
&tmp_work, |
| 7492 |
&lwork, |
| 7493 |
$P(info)); |
| 7494 |
|
| 7495 |
lwork = (integer )tmp_work; |
| 7496 |
{ |
| 7497 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7498 |
FORTRAN($TFD(s,d)orglq)( |
| 7499 |
&(integer){$SIZE(m)}, |
| 7500 |
&(integer){$SIZE(n)}, |
| 7501 |
&(integer){$SIZE(k)}, |
| 7502 |
$P(A), |
| 7503 |
&(integer){$SIZE(m)}, |
| 7504 |
$P(tau), |
| 7505 |
work, |
| 7506 |
&lwork, |
| 7507 |
$P(info)); |
| 7508 |
free(work); |
| 7509 |
} |
| 7510 |
|
| 7511 |
', |
| 7512 |
Doc => ' |
| 7513 |
|
| 7514 |
=for ref |
| 7515 |
|
| 7516 |
Generates an M-by-N real matrix Q with orthonormal rows, |
| 7517 |
which is defined as the first M rows of a product of K elementary |
| 7518 |
reflectors of order N |
| 7519 |
|
| 7520 |
Q = H(k) . . . H(2) H(1) |
| 7521 |
|
| 7522 |
as returned by gelqf. |
| 7523 |
|
| 7524 |
Arguments |
| 7525 |
========= |
| 7526 |
|
| 7527 |
A: On entry, the i-th row must contain the vector which defines |
| 7528 |
the elementary reflector H(i), for i = 1,2,...,k, as returned |
| 7529 |
by gelqf in the first k rows of its array argument A. |
| 7530 |
On exit, the M-by-N matrix Q. |
| 7531 |
|
| 7532 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7533 |
reflector H(i), as returned by gelqf. |
| 7534 |
|
| 7535 |
info: = 0: successful exit |
| 7536 |
< 0: if info = -i, the i-th argument has an illegal value |
| 7537 |
|
| 7538 |
|
| 7539 |
=for example |
| 7540 |
|
| 7541 |
$a = random (float, 100, 50); |
| 7542 |
$info = null; |
| 7543 |
$tau = zeroes(float, 50); |
| 7544 |
gelqf($a, $tau, $info); |
| 7545 |
orglq($a, $tau, $info) unless $info != 0; |
| 7546 |
'); |
| 7547 |
|
| 7548 |
pp_def("ormlq", |
| 7549 |
HandleBad => 0, |
| 7550 |
Pars => 'A(k,p); int side(); int trans(); tau(k); [io]C(m,n);int [o]info()', |
| 7551 |
GenericTypes => [F,D], |
| 7552 |
Code => generate_code ' |
| 7553 |
char ptrans = \'N\', pside = \'L\'; |
| 7554 |
integer lwork = -1; |
| 7555 |
|
| 7556 |
extern int FORTRAN($TFD(s,d)ormlq)(char *side, char *trans, integer *m, integer *n, |
| 7557 |
integer *k, $GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() * |
| 7558 |
c__, integer *ldc, $GENERIC() *work, integer *lwork, integer *info); |
| 7559 |
$GENERIC() tmp_work; |
| 7560 |
if($trans()) |
| 7561 |
ptrans = \'T\'; |
| 7562 |
if($side()) |
| 7563 |
pside = \'R\'; |
| 7564 |
|
| 7565 |
FORTRAN($TFD(s,d)ormlq)( |
| 7566 |
&pside, |
| 7567 |
&ptrans, |
| 7568 |
&(integer){$SIZE(m)}, |
| 7569 |
&(integer){$SIZE(n)}, |
| 7570 |
&(integer){$SIZE(k)}, |
| 7571 |
$P(A), |
| 7572 |
&(integer){$SIZE(k)}, |
| 7573 |
$P(tau), |
| 7574 |
$P(C), |
| 7575 |
&(integer){$SIZE(m)}, |
| 7576 |
&tmp_work, |
| 7577 |
&lwork, |
| 7578 |
$P(info)); |
| 7579 |
|
| 7580 |
lwork = (integer )tmp_work; |
| 7581 |
{ |
| 7582 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7583 |
FORTRAN($TFD(s,d)ormlq)( |
| 7584 |
&pside, |
| 7585 |
&ptrans, |
| 7586 |
&(integer){$SIZE(m)}, |
| 7587 |
&(integer){$SIZE(n)}, |
| 7588 |
&(integer){$SIZE(k)}, |
| 7589 |
$P(A), |
| 7590 |
&(integer){$SIZE(k)}, |
| 7591 |
$P(tau), |
| 7592 |
$P(C), |
| 7593 |
&(integer){$SIZE(m)}, |
| 7594 |
work, |
| 7595 |
&lwork, |
| 7596 |
$P(info)); |
| 7597 |
free(work); |
| 7598 |
} |
| 7599 |
|
| 7600 |
', |
| 7601 |
Doc => ' |
| 7602 |
|
| 7603 |
=for ref |
| 7604 |
|
| 7605 |
Overwrites the general real M-by-N matrix C with |
| 7606 |
|
| 7607 |
side = 0 side = 1 |
| 7608 |
trans = 0: Q * C C * Q |
| 7609 |
trans = 1: Q\' * C C * Q\' |
| 7610 |
|
| 7611 |
where Q is a real orthogonal matrix defined as the product of k |
| 7612 |
elementary reflectors |
| 7613 |
|
| 7614 |
Q = H(k) . . . H(2) H(1) |
| 7615 |
|
| 7616 |
as returned by gelqf. |
| 7617 |
|
| 7618 |
Q is of order M if C<side> = 0 and of order N |
| 7619 |
if C<side> = 1. |
| 7620 |
|
| 7621 |
Arguments |
| 7622 |
========= |
| 7623 |
|
| 7624 |
side: = 0: apply Q or Q\' from the Left; |
| 7625 |
= 1: apply Q or Q\' from the Right. |
| 7626 |
|
| 7627 |
trans: = 0: No transpose, apply Q; |
| 7628 |
= 1: Transpose, apply Q\'. |
| 7629 |
|
| 7630 |
A: The i-th row must contain the vector which defines the |
| 7631 |
elementary reflector H(i), for i = 1,2,...,k, as returned by |
| 7632 |
gelqf in the first k rows of its array argument A. |
| 7633 |
A is modified by the routine but restored on exit. |
| 7634 |
|
| 7635 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7636 |
reflector H(i), as returned by gelqf. |
| 7637 |
|
| 7638 |
C: On entry, the M-by-N matrix C. |
| 7639 |
On exit, C is overwritten by Q*C or Q\'*C or C*Q\' or C*Q. |
| 7640 |
|
| 7641 |
info: = 0: successful exit |
| 7642 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7643 |
|
| 7644 |
|
| 7645 |
=for example |
| 7646 |
|
| 7647 |
$a = random (float, 50, 100); |
| 7648 |
$a = transpose($a); |
| 7649 |
$info = null; |
| 7650 |
$tau = zeroes(float, 50); |
| 7651 |
gelqf($a, $tau, $info); |
| 7652 |
$c = random(70,50); |
| 7653 |
# $c will contain the result |
| 7654 |
$c->reshape(70,100); |
| 7655 |
$c = transpose($c); |
| 7656 |
ormlq($a, $tau, $c, $info); |
| 7657 |
'); |
| 7658 |
|
| 7659 |
pp_def("geqlf", |
| 7660 |
HandleBad => 0, |
| 7661 |
Pars => '[io]A(m,n); [o]tau(k); int [o]info()', |
| 7662 |
GenericTypes => [F,D], |
| 7663 |
Code => generate_code ' |
| 7664 |
integer lwork = -1; |
| 7665 |
|
| 7666 |
extern int FORTRAN($TFD(s,d)geqlf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 7667 |
lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, integer *info); |
| 7668 |
$GENERIC() tmp_work; |
| 7669 |
|
| 7670 |
FORTRAN($TFD(s,d)geqlf)( |
| 7671 |
&(integer){$SIZE(m)}, |
| 7672 |
&(integer){$SIZE(n)}, |
| 7673 |
$P(A), |
| 7674 |
&(integer){$SIZE(m)}, |
| 7675 |
$P(tau), |
| 7676 |
&tmp_work, |
| 7677 |
&lwork, |
| 7678 |
$P(info)); |
| 7679 |
|
| 7680 |
lwork = (integer )tmp_work; |
| 7681 |
{ |
| 7682 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7683 |
FORTRAN($TFD(s,d)geqlf)( |
| 7684 |
&(integer){$SIZE(m)}, |
| 7685 |
&(integer){$SIZE(n)}, |
| 7686 |
$P(A), |
| 7687 |
&(integer){$SIZE(m)}, |
| 7688 |
$P(tau), |
| 7689 |
work, |
| 7690 |
&lwork, |
| 7691 |
$P(info)); |
| 7692 |
free(work); |
| 7693 |
} |
| 7694 |
|
| 7695 |
', |
| 7696 |
Doc => ' |
| 7697 |
|
| 7698 |
=for ref |
| 7699 |
|
| 7700 |
Computes a QL factorization of a real M-by-N matrix A: |
| 7701 |
|
| 7702 |
A = Q * L |
| 7703 |
|
| 7704 |
The matrix Q is represented as a product of elementary reflectors |
| 7705 |
|
| 7706 |
Q = H(k) . . . H(2) H(1), where k = min(m,n). |
| 7707 |
|
| 7708 |
Each H(i) has the form |
| 7709 |
|
| 7710 |
H(i) = I - tau * v * v\' |
| 7711 |
|
| 7712 |
where tau is a real scalar, and v is a real vector with |
| 7713 |
v(m-k+i+1:m) = 0 and v(m-k+i) = 1; v(1:m-k+i-1) is stored on exit in |
| 7714 |
A(1:m-k+i-1,n-k+i), and tau in TAU(i). |
| 7715 |
|
| 7716 |
Arguments |
| 7717 |
========= |
| 7718 |
|
| 7719 |
A: On entry, the M-by-N matrix A. |
| 7720 |
On exit, |
| 7721 |
if m >= n, the lower triangle of the subarray |
| 7722 |
A(m-n+1:m,1:n) contains the N-by-N lower triangular matrix L; |
| 7723 |
if m <= n, the elements on and below the (n-m)-th |
| 7724 |
superdiagonal contain the M-by-N lower trapezoidal matrix L; |
| 7725 |
the remaining elements, with the array tau, represent the |
| 7726 |
orthogonal matrix Q as a product of elementary reflectors. |
| 7727 |
|
| 7728 |
tau: The scalar factors of the elementary reflectors. |
| 7729 |
|
| 7730 |
info: = 0: successful exit |
| 7731 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7732 |
|
| 7733 |
=for example |
| 7734 |
|
| 7735 |
$a = random (float, 100, 50); |
| 7736 |
$info = null; |
| 7737 |
$tau = zeroes(float, 50); |
| 7738 |
geqlf($a, $tau, $info); |
| 7739 |
'); |
| 7740 |
|
| 7741 |
pp_def("orgql", |
| 7742 |
HandleBad => 0, |
| 7743 |
Pars => '[io]A(m,n); tau(k); int [o]info()', |
| 7744 |
GenericTypes => [F,D], |
| 7745 |
Code => generate_code ' |
| 7746 |
integer lwork = -1; |
| 7747 |
|
| 7748 |
extern int FORTRAN($TFD(s,d)orgql)(integer *m, integer *n, integer *k, $GENERIC() * |
| 7749 |
a, integer *lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 7750 |
integer *info); |
| 7751 |
$GENERIC() tmp_work; |
| 7752 |
|
| 7753 |
FORTRAN($TFD(s,d)orgql)( |
| 7754 |
&(integer){$SIZE(m)}, |
| 7755 |
&(integer){$SIZE(n)}, |
| 7756 |
&(integer){$SIZE(k)}, |
| 7757 |
$P(A), |
| 7758 |
&(integer){$SIZE(m)}, |
| 7759 |
$P(tau), |
| 7760 |
&tmp_work, |
| 7761 |
&lwork, |
| 7762 |
$P(info)); |
| 7763 |
|
| 7764 |
lwork = (integer )tmp_work; |
| 7765 |
{ |
| 7766 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7767 |
FORTRAN($TFD(s,d)orgql)( |
| 7768 |
&(integer){$SIZE(m)}, |
| 7769 |
&(integer){$SIZE(n)}, |
| 7770 |
&(integer){$SIZE(k)}, |
| 7771 |
$P(A), |
| 7772 |
&(integer){$SIZE(m)}, |
| 7773 |
$P(tau), |
| 7774 |
work, |
| 7775 |
&lwork, |
| 7776 |
$P(info)); |
| 7777 |
free(work); |
| 7778 |
} |
| 7779 |
|
| 7780 |
', |
| 7781 |
Doc => ' |
| 7782 |
|
| 7783 |
=for ref |
| 7784 |
|
| 7785 |
Generates an M-by-N real matrix Q with orthonormal columns, |
| 7786 |
which is defined as the last N columns of a product of K elementary |
| 7787 |
reflectors of order M |
| 7788 |
|
| 7789 |
Q = H(k) . . . H(2) H(1) |
| 7790 |
|
| 7791 |
as returned by geqlf. |
| 7792 |
|
| 7793 |
Arguments |
| 7794 |
========= |
| 7795 |
|
| 7796 |
A: On entry, the (n-k+i)-th column must contain the vector which |
| 7797 |
defines the elementary reflector H(i), for i = 1,2,...,k, as |
| 7798 |
returned by geqlf in the last k columns of its array |
| 7799 |
argument A. |
| 7800 |
On exit, the M-by-N matrix Q. |
| 7801 |
|
| 7802 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7803 |
reflector H(i), as returned by geqlf. |
| 7804 |
|
| 7805 |
info: = 0: successful exit |
| 7806 |
< 0: if info = -i, the i-th argument has an illegal value |
| 7807 |
|
| 7808 |
|
| 7809 |
=for example |
| 7810 |
|
| 7811 |
$a = random (float, 100, 50); |
| 7812 |
$info = null; |
| 7813 |
$tau = zeroes(float, 50); |
| 7814 |
geqlf($a, $tau, $info); |
| 7815 |
orgql($a, $tau, $info) unless $info != 0; |
| 7816 |
'); |
| 7817 |
|
| 7818 |
pp_def("ormql", |
| 7819 |
HandleBad => 0, |
| 7820 |
Pars => 'A(p,k); int side(); int trans(); tau(k); [io]C(m,n);int [o]info()', |
| 7821 |
GenericTypes => [F,D], |
| 7822 |
Code => generate_code ' |
| 7823 |
char ptrans = \'N\', pside = \'L\'; |
| 7824 |
integer lwork = -1; |
| 7825 |
|
| 7826 |
extern int FORTRAN($TFD(s,d)ormql)(char *side, char *trans, integer *m, integer *n, |
| 7827 |
integer *k, $GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() * |
| 7828 |
c__, integer *ldc, $GENERIC() *work, integer *lwork, integer *info); |
| 7829 |
$GENERIC() tmp_work; |
| 7830 |
if($trans()) |
| 7831 |
ptrans = \'T\'; |
| 7832 |
if($side()) |
| 7833 |
pside = \'R\'; |
| 7834 |
|
| 7835 |
FORTRAN($TFD(s,d)ormql)( |
| 7836 |
&pside, |
| 7837 |
&ptrans, |
| 7838 |
&(integer){$SIZE(m)}, |
| 7839 |
&(integer){$SIZE(n)}, |
| 7840 |
&(integer){$SIZE(k)}, |
| 7841 |
$P(A), |
| 7842 |
&(integer){$SIZE(p)}, |
| 7843 |
$P(tau), |
| 7844 |
$P(C), |
| 7845 |
&(integer){$SIZE(m)}, |
| 7846 |
&tmp_work, |
| 7847 |
&lwork, |
| 7848 |
$P(info)); |
| 7849 |
|
| 7850 |
lwork = (integer )tmp_work; |
| 7851 |
{ |
| 7852 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7853 |
FORTRAN($TFD(s,d)ormql)( |
| 7854 |
&pside, |
| 7855 |
&ptrans, |
| 7856 |
&(integer){$SIZE(m)}, |
| 7857 |
&(integer){$SIZE(n)}, |
| 7858 |
&(integer){$SIZE(k)}, |
| 7859 |
$P(A), |
| 7860 |
&(integer){$SIZE(p)}, |
| 7861 |
$P(tau), |
| 7862 |
$P(C), |
| 7863 |
&(integer){$SIZE(m)}, |
| 7864 |
work, |
| 7865 |
&lwork, |
| 7866 |
$P(info)); |
| 7867 |
free(work); |
| 7868 |
} |
| 7869 |
|
| 7870 |
', |
| 7871 |
Doc => ' |
| 7872 |
|
| 7873 |
=for ref |
| 7874 |
|
| 7875 |
Overwrites the general real M-by-N matrix C with |
| 7876 |
|
| 7877 |
side = 0 side = 1 |
| 7878 |
trans = 0: Q * C C * Q |
| 7879 |
trans = 1: Q\' * C C * Q\' |
| 7880 |
|
| 7881 |
where Q is a real orthogonal matrix defined as the product of k |
| 7882 |
elementary reflectors |
| 7883 |
|
| 7884 |
Q = H(k) . . . H(2) H(1) |
| 7885 |
|
| 7886 |
as returned by geqlf. |
| 7887 |
|
| 7888 |
Q is of order M if C<side> = 0 and of order N |
| 7889 |
if C<side> = 1. |
| 7890 |
|
| 7891 |
Arguments |
| 7892 |
========= |
| 7893 |
|
| 7894 |
side: = 0: apply Q or Q\' from the Left; |
| 7895 |
= 1: apply Q or Q\' from the Right. |
| 7896 |
|
| 7897 |
trans: = 0: No transpose, apply Q; |
| 7898 |
= 1: Transpose, apply Q\'. |
| 7899 |
|
| 7900 |
A: The i-th row must contain the vector which defines the |
| 7901 |
elementary reflector H(i), for i = 1,2,...,k, as returned by |
| 7902 |
geqlf in the last k rows of its array argument A. |
| 7903 |
A is modified by the routine but restored on exit. |
| 7904 |
|
| 7905 |
tau: tau(i) must contain the scalar factor of the elementary |
| 7906 |
reflector H(i), as returned by geqlf. |
| 7907 |
|
| 7908 |
C: On entry, the M-by-N matrix C. |
| 7909 |
On exit, C is overwritten by Q*C or Q\'*C or C*Q\' or C*Q. |
| 7910 |
|
| 7911 |
info: = 0: successful exit |
| 7912 |
< 0: if info = -i, the i-th argument had an illegal value |
| 7913 |
|
| 7914 |
|
| 7915 |
=for example |
| 7916 |
|
| 7917 |
$a = random (float, 50, 100); |
| 7918 |
$a = transpose($a); |
| 7919 |
$info = null; |
| 7920 |
$tau = zeroes(float, 50); |
| 7921 |
geqlf($a, $tau, $info); |
| 7922 |
$c = random(70,50); |
| 7923 |
# $c will contain the result |
| 7924 |
$c->reshape(70,100); |
| 7925 |
$c = transpose($c); |
| 7926 |
ormql($a, $tau, $c, $info); |
| 7927 |
'); |
| 7928 |
|
| 7929 |
pp_def("gerqf", |
| 7930 |
HandleBad => 0, |
| 7931 |
Pars => '[io]A(m,n); [o]tau(k); int [o]info()', |
| 7932 |
GenericTypes => [F,D], |
| 7933 |
Code => generate_code ' |
| 7934 |
integer lwork = -1; |
| 7935 |
|
| 7936 |
extern int FORTRAN($TFD(s,d)gerqf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 7937 |
lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, integer *info); |
| 7938 |
$GENERIC() tmp_work; |
| 7939 |
|
| 7940 |
FORTRAN($TFD(s,d)gerqf)( |
| 7941 |
&(integer){$SIZE(m)}, |
| 7942 |
&(integer){$SIZE(n)}, |
| 7943 |
$P(A), |
| 7944 |
&(integer){$SIZE(m)}, |
| 7945 |
$P(tau), |
| 7946 |
&tmp_work, |
| 7947 |
&lwork, |
| 7948 |
$P(info)); |
| 7949 |
|
| 7950 |
lwork = (integer )tmp_work; |
| 7951 |
{ |
| 7952 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 7953 |
FORTRAN($TFD(s,d)gerqf)( |
| 7954 |
&(integer){$SIZE(m)}, |
| 7955 |
&(integer){$SIZE(n)}, |
| 7956 |
$P(A), |
| 7957 |
&(integer){$SIZE(m)}, |
| 7958 |
$P(tau), |
| 7959 |
work, |
| 7960 |
&lwork, |
| 7961 |
$P(info)); |
| 7962 |
free(work); |
| 7963 |
} |
| 7964 |
|
| 7965 |
', |
| 7966 |
Doc => ' |
| 7967 |
|
| 7968 |
=for ref |
| 7969 |
|
| 7970 |
Computes an RQ factorization of a real M-by-N matrix A: |
| 7971 |
|
| 7972 |
A = R * Q. |
| 7973 |
|
| 7974 |
The matrix Q is represented as a product of elementary reflectors |
| 7975 |
|
| 7976 |
Q = H(1) H(2) . . . H(k), where k = min(m,n). |
| 7977 |
|
| 7978 |
Each H(i) has the form |
| 7979 |
|
| 7980 |
H(i) = I - tau * v * v\' |
| 7981 |
|
| 7982 |
where tau is a real scalar, and v is a real vector with |
| 7983 |
v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in |
| 7984 |
A(m-k+i,1:n-k+i-1), and tau in TAU(i). |
| 7985 |
|
| 7986 |
Arguments |
| 7987 |
========= |
| 7988 |
|
| 7989 |
A: On entry, the M-by-N matrix A. |
| 7990 |
On exit, |
| 7991 |
if m <= n, the upper triangle of the subarray |
| 7992 |
A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R; |
| 7993 |
if m >= n, the elements on and above the (m-n)-th subdiagonal |
| 7994 |
contain the M-by-N upper trapezoidal matrix R; |
| 7995 |
the remaining elements, with the array tau, represent the |
| 7996 |
orthogonal matrix Q as a product of min(m,n) elementary |
| 7997 |
reflectors (see Further Details). |
| 7998 |
|
| 7999 |
tau: The scalar factors of the elementary reflectors. |
| 8000 |
|
| 8001 |
info: = 0: successful exit |
| 8002 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8003 |
|
| 8004 |
=for example |
| 8005 |
|
| 8006 |
$a = random (float, 100, 50); |
| 8007 |
$info = null; |
| 8008 |
$tau = zeroes(float, 50); |
| 8009 |
gerqf($a, $tau, $info); |
| 8010 |
'); |
| 8011 |
|
| 8012 |
pp_def("orgrq", |
| 8013 |
HandleBad => 0, |
| 8014 |
Pars => '[io]A(m,n); tau(k); int [o]info()', |
| 8015 |
GenericTypes => [F,D], |
| 8016 |
Code => generate_code ' |
| 8017 |
integer lwork = -1; |
| 8018 |
|
| 8019 |
extern int FORTRAN($TFD(s,d)orgrq)(integer *m, integer *n, integer *k, $GENERIC() * |
| 8020 |
a, integer *lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, |
| 8021 |
integer *info); |
| 8022 |
$GENERIC() tmp_work; |
| 8023 |
|
| 8024 |
FORTRAN($TFD(s,d)orgrq)( |
| 8025 |
&(integer){$SIZE(m)}, |
| 8026 |
&(integer){$SIZE(n)}, |
| 8027 |
&(integer){$SIZE(k)}, |
| 8028 |
$P(A), |
| 8029 |
&(integer){$SIZE(m)}, |
| 8030 |
$P(tau), |
| 8031 |
&tmp_work, |
| 8032 |
&lwork, |
| 8033 |
$P(info)); |
| 8034 |
|
| 8035 |
lwork = (integer )tmp_work; |
| 8036 |
{ |
| 8037 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8038 |
FORTRAN($TFD(s,d)orgrq)( |
| 8039 |
&(integer){$SIZE(m)}, |
| 8040 |
&(integer){$SIZE(n)}, |
| 8041 |
&(integer){$SIZE(k)}, |
| 8042 |
$P(A), |
| 8043 |
&(integer){$SIZE(m)}, |
| 8044 |
$P(tau), |
| 8045 |
work, |
| 8046 |
&lwork, |
| 8047 |
$P(info)); |
| 8048 |
free(work); |
| 8049 |
} |
| 8050 |
|
| 8051 |
', |
| 8052 |
Doc => ' |
| 8053 |
|
| 8054 |
=for ref |
| 8055 |
|
| 8056 |
Generates an M-by-N real matrix Q with orthonormal rows, |
| 8057 |
which is defined as the last M rows of a product of K elementary |
| 8058 |
reflectors of order N |
| 8059 |
|
| 8060 |
Q = H(1) H(2) . . . H(k) |
| 8061 |
|
| 8062 |
as returned by gerqf. |
| 8063 |
|
| 8064 |
Arguments |
| 8065 |
========= |
| 8066 |
|
| 8067 |
A: On entry, the (m-k+i)-th row must contain the vector which |
| 8068 |
defines the elementary reflector H(i), for i = 1,2,...,k, as |
| 8069 |
returned by gerqf in the last k rows of its array argument |
| 8070 |
A. |
| 8071 |
On exit, the M-by-N matrix Q. |
| 8072 |
|
| 8073 |
tau: tau(i) must contain the scalar factor of the elementary |
| 8074 |
reflector H(i), as returned by gerqf. |
| 8075 |
|
| 8076 |
info: = 0: successful exit |
| 8077 |
< 0: if info = -i, the i-th argument has an illegal value |
| 8078 |
|
| 8079 |
|
| 8080 |
=for example |
| 8081 |
|
| 8082 |
$a = random (float, 100, 50); |
| 8083 |
$info = null; |
| 8084 |
$tau = zeroes(float, 50); |
| 8085 |
gerqf($a, $tau, $info); |
| 8086 |
orgrq($a, $tau, $info) unless $info != 0; |
| 8087 |
'); |
| 8088 |
|
| 8089 |
pp_def("ormrq", |
| 8090 |
HandleBad => 0, |
| 8091 |
Pars => 'A(k,p); int side(); int trans(); tau(k); [io]C(m,n);int [o]info()', |
| 8092 |
GenericTypes => [F,D], |
| 8093 |
Code => generate_code ' |
| 8094 |
char ptrans = \'N\', pside = \'L\'; |
| 8095 |
integer lwork = -1; |
| 8096 |
|
| 8097 |
extern int FORTRAN($TFD(s,d)ormrq)(char *side, char *trans, integer *m, integer *n, |
| 8098 |
integer *k, $GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() * |
| 8099 |
c__, integer *ldc, $GENERIC() *work, integer *lwork, integer *info); |
| 8100 |
$GENERIC() tmp_work; |
| 8101 |
if($trans()) |
| 8102 |
ptrans = \'T\'; |
| 8103 |
if($side()) |
| 8104 |
pside = \'R\'; |
| 8105 |
|
| 8106 |
FORTRAN($TFD(s,d)ormrq)( |
| 8107 |
&pside, |
| 8108 |
&ptrans, |
| 8109 |
&(integer){$SIZE(m)}, |
| 8110 |
&(integer){$SIZE(n)}, |
| 8111 |
&(integer){$SIZE(k)}, |
| 8112 |
$P(A), |
| 8113 |
&(integer){$SIZE(k)}, |
| 8114 |
$P(tau), |
| 8115 |
$P(C), |
| 8116 |
&(integer){$SIZE(m)}, |
| 8117 |
&tmp_work, |
| 8118 |
&lwork, |
| 8119 |
$P(info)); |
| 8120 |
|
| 8121 |
lwork = (integer )tmp_work; |
| 8122 |
{ |
| 8123 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8124 |
FORTRAN($TFD(s,d)ormrq)( |
| 8125 |
&pside, |
| 8126 |
&ptrans, |
| 8127 |
&(integer){$SIZE(m)}, |
| 8128 |
&(integer){$SIZE(n)}, |
| 8129 |
&(integer){$SIZE(k)}, |
| 8130 |
$P(A), |
| 8131 |
&(integer){$SIZE(k)}, |
| 8132 |
$P(tau), |
| 8133 |
$P(C), |
| 8134 |
&(integer){$SIZE(m)}, |
| 8135 |
work, |
| 8136 |
&lwork, |
| 8137 |
$P(info)); |
| 8138 |
free(work); |
| 8139 |
} |
| 8140 |
|
| 8141 |
', |
| 8142 |
Doc => ' |
| 8143 |
|
| 8144 |
=for ref |
| 8145 |
|
| 8146 |
Overwrites the general real M-by-N matrix C with |
| 8147 |
|
| 8148 |
side = 0 side = 1 |
| 8149 |
trans = 0: Q * C C * Q |
| 8150 |
trans = 1: Q\' * C C * Q\' |
| 8151 |
|
| 8152 |
where Q is a real orthogonal matrix defined as the product of k |
| 8153 |
elementary reflectors |
| 8154 |
|
| 8155 |
Q = H(1) H(2) . . . H(k) |
| 8156 |
|
| 8157 |
as returned by gerqf. |
| 8158 |
|
| 8159 |
Q is of order M if C<side> = 0 and of order N |
| 8160 |
if C<side> = 1. |
| 8161 |
|
| 8162 |
Arguments |
| 8163 |
========= |
| 8164 |
|
| 8165 |
side: = 0: apply Q or Q\' from the Left; |
| 8166 |
= 1: apply Q or Q\' from the Right. |
| 8167 |
|
| 8168 |
trans: = 0: No transpose, apply Q; |
| 8169 |
= 1: Transpose, apply Q\'. |
| 8170 |
|
| 8171 |
A: The i-th row must contain the vector which defines the |
| 8172 |
elementary reflector H(i), for i = 1,2,...,k, as returned by |
| 8173 |
gerqf in the last k rows of its array argument A. |
| 8174 |
A is modified by the routine but restored on exit. |
| 8175 |
|
| 8176 |
tau: tau(i) must contain the scalar factor of the elementary |
| 8177 |
reflector H(i), as returned by gerqf. |
| 8178 |
|
| 8179 |
C: On entry, the M-by-N matrix C. |
| 8180 |
On exit, C is overwritten by Q*C or Q\'*C or C*Q\' or C*Q. |
| 8181 |
|
| 8182 |
info: = 0: successful exit |
| 8183 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8184 |
|
| 8185 |
|
| 8186 |
=for example |
| 8187 |
|
| 8188 |
$a = random (float, 50, 100); |
| 8189 |
$a = transpose($a); |
| 8190 |
$info = null; |
| 8191 |
$tau = zeroes(float, 50); |
| 8192 |
gerqf($a, $tau, $info); |
| 8193 |
$c = random(70,50); |
| 8194 |
# $c will contain the result |
| 8195 |
$c->reshape(70,100); |
| 8196 |
$c = transpose($c); |
| 8197 |
ormrq($a, $tau, $c, $info); |
| 8198 |
'); |
| 8199 |
|
| 8200 |
pp_def("tzrzf", |
| 8201 |
HandleBad => 0, |
| 8202 |
Pars => '[io]A(m,n); [o]tau(k); int [o]info()', |
| 8203 |
GenericTypes => [F,D], |
| 8204 |
Code => generate_code ' |
| 8205 |
integer lwork = -1; |
| 8206 |
|
| 8207 |
extern int FORTRAN($TFD(s,d)tzrzf)(integer *m, integer *n, $GENERIC() *a, integer * |
| 8208 |
lda, $GENERIC() *tau, $GENERIC() *work, integer *lwork, integer *info); |
| 8209 |
$GENERIC() tmp_work; |
| 8210 |
|
| 8211 |
FORTRAN($TFD(s,d)tzrzf)( |
| 8212 |
&(integer){$SIZE(m)}, |
| 8213 |
&(integer){$SIZE(n)}, |
| 8214 |
$P(A), |
| 8215 |
&(integer){$SIZE(m)}, |
| 8216 |
$P(tau), |
| 8217 |
&tmp_work, |
| 8218 |
&lwork, |
| 8219 |
$P(info)); |
| 8220 |
|
| 8221 |
lwork = (integer )tmp_work; |
| 8222 |
{ |
| 8223 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8224 |
FORTRAN($TFD(s,d)tzrzf)( |
| 8225 |
&(integer){$SIZE(m)}, |
| 8226 |
&(integer){$SIZE(n)}, |
| 8227 |
$P(A), |
| 8228 |
&(integer){$SIZE(m)}, |
| 8229 |
$P(tau), |
| 8230 |
work, |
| 8231 |
&lwork, |
| 8232 |
$P(info)); |
| 8233 |
free(work); |
| 8234 |
} |
| 8235 |
|
| 8236 |
', |
| 8237 |
Doc => ' |
| 8238 |
|
| 8239 |
=for ref |
| 8240 |
|
| 8241 |
Reduces the M-by-N ( M <= N ) real upper trapezoidal matrix A |
| 8242 |
to upper triangular form by means of orthogonal transformations. |
| 8243 |
|
| 8244 |
The upper trapezoidal matrix A is factored as |
| 8245 |
|
| 8246 |
A = ( R 0 ) * Z, |
| 8247 |
|
| 8248 |
where Z is an N-by-N orthogonal matrix and R is an M-by-M upper |
| 8249 |
triangular matrix. |
| 8250 |
|
| 8251 |
The factorization is obtained by Householder\'s method. The kth |
| 8252 |
transformation matrix, Z( k ), which is used to introduce zeros into |
| 8253 |
the ( m - k + 1 )th row of A, is given in the form |
| 8254 |
|
| 8255 |
Z( k ) = ( I 0 ), |
| 8256 |
( 0 T( k ) ) |
| 8257 |
|
| 8258 |
where |
| 8259 |
|
| 8260 |
T( k ) = I - tau*u( k )*u( k )\', u( k ) = ( 1 ), |
| 8261 |
( 0 ) |
| 8262 |
( z( k ) ) |
| 8263 |
|
| 8264 |
tau is a scalar and z( k ) is an ( n - m ) element vector. |
| 8265 |
tau and z( k ) are chosen to annihilate the elements of the kth row |
| 8266 |
of X. |
| 8267 |
|
| 8268 |
The scalar tau is returned in the kth element of C<tau> and the vector |
| 8269 |
u( k ) in the kth row of A, such that the elements of z( k ) are |
| 8270 |
in a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in |
| 8271 |
the upper triangular part of A. |
| 8272 |
|
| 8273 |
Z is given by |
| 8274 |
|
| 8275 |
Z = Z( 1 ) * Z( 2 ) * ... * Z( m ). |
| 8276 |
|
| 8277 |
Arguments |
| 8278 |
========= |
| 8279 |
|
| 8280 |
A: On entry, the leading M-by-N upper trapezoidal part of the |
| 8281 |
array A must contain the matrix to be factorized. |
| 8282 |
On exit, the leading M-by-M upper triangular part of A |
| 8283 |
contains the upper triangular matrix R, and elements M+1 to |
| 8284 |
N of the first M rows of A, with the array tau, represent the |
| 8285 |
orthogonal matrix Z as a product of M elementary reflectors. |
| 8286 |
|
| 8287 |
tau: The scalar factors of the elementary reflectors. |
| 8288 |
|
| 8289 |
info: = 0: successful exit |
| 8290 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8291 |
|
| 8292 |
|
| 8293 |
=for example |
| 8294 |
|
| 8295 |
$a = random (float, 50, 100); |
| 8296 |
$info = null; |
| 8297 |
$tau = zeroes(float, 50); |
| 8298 |
tzrzf($a, $tau, $info); |
| 8299 |
'); |
| 8300 |
|
| 8301 |
pp_def("ormrz", |
| 8302 |
HandleBad => 0, |
| 8303 |
Pars => 'A(k,p); int side(); int trans(); tau(k); [io]C(m,n);int [o]info()', |
| 8304 |
GenericTypes => [F,D], |
| 8305 |
Code => generate_code ' |
| 8306 |
char ptrans = \'N\', pside = \'L\'; |
| 8307 |
integer lwork = -1; |
| 8308 |
integer kk = $SIZE(p) - $SIZE(k); |
| 8309 |
|
| 8310 |
extern int FORTRAN($TFD(s,d)ormrz)(char *side, char *trans, integer *m, integer *n, |
| 8311 |
integer *k, integer *l, $GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() * |
| 8312 |
c__, integer *ldc, $GENERIC() *work, integer *lwork, integer *info); |
| 8313 |
$GENERIC() tmp_work; |
| 8314 |
if($trans()) |
| 8315 |
ptrans = \'T\'; |
| 8316 |
if($side()) |
| 8317 |
pside = \'R\'; |
| 8318 |
|
| 8319 |
FORTRAN($TFD(s,d)ormrz)( |
| 8320 |
&pside, |
| 8321 |
&ptrans, |
| 8322 |
&(integer){$SIZE(m)}, |
| 8323 |
&(integer){$SIZE(n)}, |
| 8324 |
&(integer){$SIZE(k)}, |
| 8325 |
&kk, |
| 8326 |
$P(A), |
| 8327 |
&(integer){$SIZE(k)}, |
| 8328 |
$P(tau), |
| 8329 |
$P(C), |
| 8330 |
&(integer){$SIZE(m)}, |
| 8331 |
&tmp_work, |
| 8332 |
&lwork, |
| 8333 |
$P(info)); |
| 8334 |
|
| 8335 |
lwork = (integer )tmp_work; |
| 8336 |
{ |
| 8337 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8338 |
FORTRAN($TFD(s,d)ormrz)( |
| 8339 |
&pside, |
| 8340 |
&ptrans, |
| 8341 |
&(integer){$SIZE(m)}, |
| 8342 |
&(integer){$SIZE(n)}, |
| 8343 |
&(integer){$SIZE(k)}, |
| 8344 |
&kk, |
| 8345 |
$P(A), |
| 8346 |
&(integer){$SIZE(k)}, |
| 8347 |
$P(tau), |
| 8348 |
$P(C), |
| 8349 |
&(integer){$SIZE(m)}, |
| 8350 |
work, |
| 8351 |
&lwork, |
| 8352 |
$P(info)); |
| 8353 |
free(work); |
| 8354 |
} |
| 8355 |
|
| 8356 |
', |
| 8357 |
Doc => ' |
| 8358 |
|
| 8359 |
=for ref |
| 8360 |
|
| 8361 |
Overwrites the general real M-by-N matrix C with |
| 8362 |
|
| 8363 |
side = 0 side = 1 |
| 8364 |
trans = 0: Q * C C * Q |
| 8365 |
trans = 1: Q\' * C C * Q\' |
| 8366 |
|
| 8367 |
where Q is a real orthogonal matrix defined as the product of k |
| 8368 |
elementary reflectors |
| 8369 |
|
| 8370 |
Q = H(1) H(2) . . . H(k) |
| 8371 |
|
| 8372 |
as returned by tzrzf. |
| 8373 |
|
| 8374 |
Q is of order M if C<side> = 0 and of order N |
| 8375 |
if C<side> = 1. |
| 8376 |
|
| 8377 |
Arguments |
| 8378 |
========= |
| 8379 |
|
| 8380 |
side: = 0: apply Q or Q\' from the Left; |
| 8381 |
= 1: apply Q or Q\' from the Right. |
| 8382 |
|
| 8383 |
trans: = 0: No transpose, apply Q; |
| 8384 |
= 1: Transpose, apply Q\'. |
| 8385 |
|
| 8386 |
A: The i-th row must contain the vector which defines the |
| 8387 |
elementary reflector H(i), for i = 1,2,...,k, as returned by |
| 8388 |
tzrzf in the last k rows of its array argument A. |
| 8389 |
A is modified by the routine but restored on exit. |
| 8390 |
|
| 8391 |
tau: tau(i) must contain the scalar factor of the elementary |
| 8392 |
reflector H(i), as returned by tzrzf. |
| 8393 |
|
| 8394 |
C: On entry, the M-by-N matrix C. |
| 8395 |
On exit, C is overwritten by Q*C or Q\'*C or C*Q\' or C*Q. |
| 8396 |
|
| 8397 |
info: = 0: successful exit |
| 8398 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8399 |
|
| 8400 |
|
| 8401 |
=for example |
| 8402 |
|
| 8403 |
$a = random (float, 50, 100); |
| 8404 |
$a = transpose($a); |
| 8405 |
$info = null; |
| 8406 |
$tau = zeroes(float, 50); |
| 8407 |
tzrzf($a, $tau, $info); |
| 8408 |
$c = random(70,50); |
| 8409 |
# $c will contain the result |
| 8410 |
$c->reshape(70,100); |
| 8411 |
$c = transpose($c); |
| 8412 |
ormrz($a, $tau, $c, $info); |
| 8413 |
'); |
| 8414 |
|
| 8415 |
|
| 8416 |
pp_def("gehrd", |
| 8417 |
HandleBad => 0, |
| 8418 |
Pars => '[io]A(n,n); int ilo();int ihi();[o]tau(k); int [o]info()', |
| 8419 |
GenericTypes => [F,D], |
| 8420 |
Code => generate_code ' |
| 8421 |
integer lwork = -1; |
| 8422 |
|
| 8423 |
extern int FORTRAN($TFD(s,d)gehrd)(integer *n, integer *ilo, integer *ihi, |
| 8424 |
$GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() *work, |
| 8425 |
integer *lwork, integer *info); |
| 8426 |
$GENERIC() tmp_work; |
| 8427 |
|
| 8428 |
FORTRAN($TFD(s,d)gehrd)( |
| 8429 |
&(integer){$SIZE(n)}, |
| 8430 |
$P(ilo), |
| 8431 |
$P(ihi), |
| 8432 |
$P(A), |
| 8433 |
&(integer){$SIZE(n)}, |
| 8434 |
$P(tau), |
| 8435 |
&tmp_work, |
| 8436 |
&lwork, |
| 8437 |
$P(info)); |
| 8438 |
|
| 8439 |
lwork = (integer )tmp_work; |
| 8440 |
{ |
| 8441 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8442 |
FORTRAN($TFD(s,d)gehrd)( |
| 8443 |
&(integer){$SIZE(n)}, |
| 8444 |
$P(ilo), |
| 8445 |
$P(ihi), |
| 8446 |
$P(A), |
| 8447 |
&(integer){$SIZE(n)}, |
| 8448 |
$P(tau), |
| 8449 |
work, |
| 8450 |
&lwork, |
| 8451 |
$P(info)); |
| 8452 |
free(work); |
| 8453 |
} |
| 8454 |
|
| 8455 |
', |
| 8456 |
Doc => ' |
| 8457 |
|
| 8458 |
=for ref |
| 8459 |
|
| 8460 |
Reduces a real general matrix A to upper Hessenberg form H by |
| 8461 |
an orthogonal similarity transformation: Q\' * A * Q = H . |
| 8462 |
|
| 8463 |
Further Details |
| 8464 |
=============== |
| 8465 |
|
| 8466 |
The matrix Q is represented as a product of (ihi-ilo) elementary |
| 8467 |
reflectors |
| 8468 |
|
| 8469 |
Q = H(ilo) H(ilo+1) . . . H(ihi-1). |
| 8470 |
|
| 8471 |
Each H(i) has the form |
| 8472 |
|
| 8473 |
H(i) = I - tau * v * v\' |
| 8474 |
where tau is a real scalar, and v is a real vector with |
| 8475 |
v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on |
| 8476 |
exit in A(i+2:ihi,i), and tau in tau(i). |
| 8477 |
|
| 8478 |
The contents of A are illustrated by the following example, with |
| 8479 |
n = 7, ilo = 2 and ihi = 6: |
| 8480 |
|
| 8481 |
on entry, on exit, |
| 8482 |
|
| 8483 |
( a a a a a a a ) ( a a h h h h a ) |
| 8484 |
( a a a a a a ) ( a h h h h a ) |
| 8485 |
( a a a a a a ) ( h h h h h h ) |
| 8486 |
( a a a a a a ) ( v2 h h h h h ) |
| 8487 |
( a a a a a a ) ( v2 v3 h h h h ) |
| 8488 |
( a a a a a a ) ( v2 v3 v4 h h h ) |
| 8489 |
( a ) ( a ) |
| 8490 |
|
| 8491 |
where a denotes an element of the original matrix A, h denotes a |
| 8492 |
modified element of the upper Hessenberg matrix H, and vi denotes an |
| 8493 |
element of the vector defining H(i). |
| 8494 |
|
| 8495 |
|
| 8496 |
Arguments |
| 8497 |
========= |
| 8498 |
|
| 8499 |
ilo: |
| 8500 |
ihi: It is assumed that A is already upper triangular in rows |
| 8501 |
and columns 1:ilo-1 and ihi+1:N. ilo and ihi are normally |
| 8502 |
set by a previous call to gebal; otherwise they should be |
| 8503 |
set to 1 and N respectively. See Further Details. |
| 8504 |
1 <= ilo <= ihi <= N, if N > 0; ilo=1 and ihi=0, if N=0. |
| 8505 |
|
| 8506 |
A: On entry, the N-by-N general matrix to be reduced. |
| 8507 |
On exit, the upper triangle and the first subdiagonal of A |
| 8508 |
are overwritten with the upper Hessenberg matrix H, and the |
| 8509 |
elements below the first subdiagonal, with the array tau, |
| 8510 |
represent the orthogonal matrix Q as a product of elementary |
| 8511 |
reflectors. See Further Details. |
| 8512 |
|
| 8513 |
tau: The scalar factors of the elementary reflectors (see Further |
| 8514 |
Details). Elements 1:ilo-1 and ihi:N-1 of tau are set to |
| 8515 |
zero. (dimension (N-1)) |
| 8516 |
|
| 8517 |
info: = 0: successful exit |
| 8518 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 8519 |
|
| 8520 |
|
| 8521 |
=for example |
| 8522 |
|
| 8523 |
$a = random (50, 50); |
| 8524 |
$info = null; |
| 8525 |
$tau = zeroes(50); |
| 8526 |
gehrd($a, 1, 50, $tau, $info); |
| 8527 |
'); |
| 8528 |
|
| 8529 |
pp_def("orghr", |
| 8530 |
HandleBad => 0, |
| 8531 |
Pars => '[io]A(n,n); int ilo();int ihi();tau(k); int [o]info()', |
| 8532 |
GenericTypes => [F,D], |
| 8533 |
Code => generate_code ' |
| 8534 |
integer lwork = -1; |
| 8535 |
|
| 8536 |
extern int FORTRAN($TFD(s,d)orghr)(integer *n, integer *ilo, integer *ihi, |
| 8537 |
$GENERIC() *a, integer *lda, $GENERIC() *tau, $GENERIC() *work, |
| 8538 |
integer *lwork, integer *info); |
| 8539 |
$GENERIC() tmp_work; |
| 8540 |
|
| 8541 |
FORTRAN($TFD(s,d)orghr)( |
| 8542 |
&(integer){$SIZE(n)}, |
| 8543 |
$P(ilo), |
| 8544 |
$P(ihi), |
| 8545 |
$P(A), |
| 8546 |
&(integer){$SIZE(n)}, |
| 8547 |
$P(tau), |
| 8548 |
&tmp_work, |
| 8549 |
&lwork, |
| 8550 |
$P(info)); |
| 8551 |
|
| 8552 |
lwork = (integer )tmp_work; |
| 8553 |
{ |
| 8554 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8555 |
FORTRAN($TFD(s,d)orghr)( |
| 8556 |
&(integer){$SIZE(n)}, |
| 8557 |
$P(ilo), |
| 8558 |
$P(ihi), |
| 8559 |
$P(A), |
| 8560 |
&(integer){$SIZE(n)}, |
| 8561 |
$P(tau), |
| 8562 |
work, |
| 8563 |
&lwork, |
| 8564 |
$P(info)); |
| 8565 |
free(work); |
| 8566 |
} |
| 8567 |
|
| 8568 |
', |
| 8569 |
Doc => ' |
| 8570 |
|
| 8571 |
=for ref |
| 8572 |
|
| 8573 |
Generates a real orthogonal matrix Q which is defined as the |
| 8574 |
product of ihi-ilo elementary reflectors of order N, as returned by |
| 8575 |
C<gehrd>: |
| 8576 |
|
| 8577 |
Q = H(ilo) H(ilo+1) . . . H(ihi-1). |
| 8578 |
|
| 8579 |
|
| 8580 |
Arguments |
| 8581 |
========= |
| 8582 |
|
| 8583 |
ilo: |
| 8584 |
ihi: ilo and ihi must have the same values as in the previous call |
| 8585 |
of gehrd. Q is equal to the unit matrix except in the |
| 8586 |
submatrix Q(ilo+1:ihi,ilo+1:ihi). |
| 8587 |
1 <= ilo <= ihi <= N, if N > 0; ilo=1 and ihi=0, if N=0. |
| 8588 |
|
| 8589 |
A: On entry, the vectors which define the elementary reflectors, |
| 8590 |
as returned by gehrd. |
| 8591 |
On exit, the N-by-N orthogonal matrix Q. |
| 8592 |
|
| 8593 |
tau: tau(i) must contain the scalar factor of the elementary |
| 8594 |
reflector H(i), as returned by gehrd.(dimension (N-1)) |
| 8595 |
|
| 8596 |
info: = 0: successful exit |
| 8597 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8598 |
|
| 8599 |
|
| 8600 |
=for example |
| 8601 |
|
| 8602 |
$a = random (50, 50); |
| 8603 |
$info = null; |
| 8604 |
$tau = zeroes(50); |
| 8605 |
gehrd($a, 1, 50, $tau, $info); |
| 8606 |
orghr($a, 1, 50, $tau, $info); |
| 8607 |
|
| 8608 |
'); |
| 8609 |
|
| 8610 |
pp_def("hseqr", |
| 8611 |
HandleBad => 0, |
| 8612 |
Pars => '[io]H(n,n); int job();int compz();int ilo();int ihi();[o]wr(n); [o]wi(n);[o]Z(m,m); int [o]info()', |
| 8613 |
GenericTypes => [F,D], |
| 8614 |
Code => generate_code ' |
| 8615 |
char pcompz; |
| 8616 |
char pjob = \'E\'; |
| 8617 |
integer lwork = -1; |
| 8618 |
|
| 8619 |
extern int FORTRAN($TFD(s,d)hseqr)(char *job, char *compz, integer *n, integer *ilo, |
| 8620 |
integer *ihi, $GENERIC() *h__, integer *ldh, $GENERIC() *wr, |
| 8621 |
$GENERIC() *wi, $GENERIC() *z__, integer *ldz, $GENERIC() *work, |
| 8622 |
integer *lwork, integer *info); |
| 8623 |
$GENERIC() tmp_work; |
| 8624 |
|
| 8625 |
if($job()) |
| 8626 |
pjob = \'S\'; |
| 8627 |
|
| 8628 |
switch ($compz()) |
| 8629 |
{ |
| 8630 |
case 1: pcompz = \'I\'; |
| 8631 |
break; |
| 8632 |
case 2: pcompz = \'V\'; |
| 8633 |
break; |
| 8634 |
default: pcompz = \'N\'; |
| 8635 |
} |
| 8636 |
|
| 8637 |
FORTRAN($TFD(s,d)hseqr)( |
| 8638 |
&pjob, |
| 8639 |
&pcompz, |
| 8640 |
&(integer){$SIZE(n)}, |
| 8641 |
$P(ilo), |
| 8642 |
$P(ihi), |
| 8643 |
$P(H), |
| 8644 |
&(integer){$SIZE(n)}, |
| 8645 |
$P(wr), |
| 8646 |
$P(wi), |
| 8647 |
$P(Z), |
| 8648 |
&(integer){$SIZE(m)}, |
| 8649 |
&tmp_work, |
| 8650 |
&lwork, |
| 8651 |
$P(info)); |
| 8652 |
|
| 8653 |
lwork = (integer )tmp_work; |
| 8654 |
{ |
| 8655 |
$GENERIC() *work = ($GENERIC() *)malloc(lwork * sizeof($GENERIC())); |
| 8656 |
FORTRAN($TFD(s,d)hseqr)( |
| 8657 |
&pjob, |
| 8658 |
&pcompz, |
| 8659 |
&(integer){$SIZE(n)}, |
| 8660 |
$P(ilo), |
| 8661 |
$P(ihi), |
| 8662 |
$P(H), |
| 8663 |
&(integer){$SIZE(n)}, |
| 8664 |
$P(wr), |
| 8665 |
$P(wi), |
| 8666 |
$P(Z), |
| 8667 |
&(integer){$SIZE(m)}, |
| 8668 |
work, |
| 8669 |
&lwork, |
| 8670 |
$P(info)); |
| 8671 |
free(work); |
| 8672 |
} |
| 8673 |
|
| 8674 |
', |
| 8675 |
Doc => ' |
| 8676 |
|
| 8677 |
=for ref |
| 8678 |
|
| 8679 |
Computes the eigenvalues of a real upper Hessenberg matrix H |
| 8680 |
and, optionally, the matrices T and Z from the Schur decomposition |
| 8681 |
H = Z T Z**T, where T is an upper quasi-triangular matrix (the Schur |
| 8682 |
form), and Z is the orthogonal matrix of Schur vectors. |
| 8683 |
|
| 8684 |
Optionally Z may be postmultiplied into an input orthogonal matrix Q, |
| 8685 |
so that this routine can give the Schur factorization of a matrix A |
| 8686 |
which has been reduced to the Hessenberg form H by the orthogonal |
| 8687 |
matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T. |
| 8688 |
|
| 8689 |
Arguments |
| 8690 |
========= |
| 8691 |
|
| 8692 |
job: = 0: compute eigenvalues only; |
| 8693 |
= 1: compute eigenvalues and the Schur form T. |
| 8694 |
|
| 8695 |
compz: = 0: no Schur vectors are computed; |
| 8696 |
= 1: Z is initialized to the unit matrix and the matrix Z |
| 8697 |
of Schur vectors of H is returned; |
| 8698 |
= 2: Z must contain an orthogonal matrix Q on entry, and |
| 8699 |
the product Q*Z is returned. |
| 8700 |
|
| 8701 |
ilo: |
| 8702 |
ihi: It is assumed that H is already upper triangular in rows |
| 8703 |
and columns 1:ilo-1 and ihi+1:N. ilo and ihi are normally |
| 8704 |
set by a previous call to gebal, and then passed to gehrd |
| 8705 |
when the matrix output by gebal is reduced to Hessenberg |
| 8706 |
form. Otherwise ilo and ihi should be set to 1 and N |
| 8707 |
respectively. |
| 8708 |
1 <= ilo <= ihi <= N, if N > 0; ilo=1 and ihi=0, if N=0. |
| 8709 |
|
| 8710 |
H: On entry, the upper Hessenberg matrix H. |
| 8711 |
On exit, if job = 1, H contains the upper quasi-triangular |
| 8712 |
matrix T from the Schur decomposition (the Schur form); |
| 8713 |
2-by-2 diagonal blocks (corresponding to complex conjugate |
| 8714 |
pairs of eigenvalues) are returned in standard form, with |
| 8715 |
H(i,i) = H(i+1,i+1) and H(i+1,i)*H(i,i+1) < 0. If job = 0, |
| 8716 |
the contents of H are unspecified on exit. |
| 8717 |
|
| 8718 |
wr: |
| 8719 |
wi: The real and imaginary parts, respectively, of the computed |
| 8720 |
eigenvalues. If two eigenvalues are computed as a complex |
| 8721 |
conjugate pair, they are stored in consecutive elements of |
| 8722 |
wr and wi, say the i-th and (i+1)th, with wi(i) > 0 and |
| 8723 |
wi(i+1) < 0. If job = 1, the eigenvalues are stored in the |
| 8724 |
same order as on the diagonal of the Schur form returned in |
| 8725 |
H, with wr(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 |
| 8726 |
diagonal block, wi(i) = sqrt(H(i+1,i)*H(i,i+1)) and |
| 8727 |
wi(i+1) = -wi(i). |
| 8728 |
|
| 8729 |
Z: If compz = 0: Z is not referenced. |
| 8730 |
If compz = 1: on entry, Z need not be set, and on exit, Z |
| 8731 |
contains the orthogonal matrix Z of the Schur vectors of H. |
| 8732 |
If compz = 2: on entry Z must contain an N-by-N matrix Q, |
| 8733 |
which is assumed to be equal to the unit matrix except for |
| 8734 |
the submatrix Z(ilo:ihi,ilo:ihi); on exit Z contains Q*Z. |
| 8735 |
Normally Q is the orthogonal matrix generated by orghr after |
| 8736 |
the call to gehrd which formed the Hessenberg matrix H. |
| 8737 |
|
| 8738 |
info: = 0: successful exit |
| 8739 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8740 |
> 0: if info = i, hseqr failed to compute all of the |
| 8741 |
eigenvalues in a total of 30*(ihi-ilo+1) iterations; |
| 8742 |
elements 1:ilo-1 and i+1:n of wr and wi contain those |
| 8743 |
eigenvalues which have been successfully computed. |
| 8744 |
|
| 8745 |
|
| 8746 |
=for example |
| 8747 |
|
| 8748 |
$a = random (50, 50); |
| 8749 |
$info = null; |
| 8750 |
$tau = zeroes(50); |
| 8751 |
$z= zeroes(1,1); |
| 8752 |
gehrd($a, 1, 50, $tau, $info); |
| 8753 |
hseqr($a,0,0,1,50,($wr=null),($wi=null),$z,$info); |
| 8754 |
|
| 8755 |
'); |
| 8756 |
|
| 8757 |
pp_def("trevc", |
| 8758 |
HandleBad => 0, |
| 8759 |
Pars => 'T(n,n);int select(q);[o]VL(m,m); [o]VR(p,p);int [o]m(); int [o]info(); [t]work(workn=CALC(3*$SIZE(n)));', |
| 8760 |
OtherPars => 'int side; int howmny', |
| 8761 |
ArgOrder => [qw{T side howmny select VL VR m info}], |
| 8762 |
RedoDimsCode => ' |
| 8763 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(side), tmp != 1, $PDL(VL), $SIZE(m), $SIZE(n)) |
| 8764 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(side), tmp != 2, $PDL(VR), $SIZE(p), $SIZE(n)) |
| 8765 |
', |
| 8766 |
GenericTypes => [F,D], |
| 8767 |
Code => generate_code ' |
| 8768 |
char pside,phowmny; |
| 8769 |
integer mm = PDLMAX($SIZE(m),$SIZE(p)); |
| 8770 |
|
| 8771 |
extern int FORTRAN($TFD(s,d)trevc)(char *side, char *howmny, logical *select, |
| 8772 |
integer *n, $GENERIC() *t, integer *ldt, $GENERIC() *vl, integer * |
| 8773 |
ldvl, $GENERIC() *vr, integer *ldvr, integer *mm, integer *m, |
| 8774 |
$GENERIC() *work, integer *info); |
| 8775 |
switch ($COMP(howmny)) |
| 8776 |
{ |
| 8777 |
case 1: phowmny = \'B\'; |
| 8778 |
break; |
| 8779 |
case 2: phowmny = \'S\'; |
| 8780 |
break; |
| 8781 |
default: phowmny = \'A\'; |
| 8782 |
} |
| 8783 |
|
| 8784 |
switch ($COMP(side)) |
| 8785 |
{ |
| 8786 |
case 1: pside = \'R\'; |
| 8787 |
break; |
| 8788 |
case 2: pside = \'L\'; |
| 8789 |
break; |
| 8790 |
default:pside = \'B\'; |
| 8791 |
} |
| 8792 |
|
| 8793 |
FORTRAN($TFD(s,d)trevc)( |
| 8794 |
&pside, |
| 8795 |
&phowmny, |
| 8796 |
$P(select), |
| 8797 |
&(integer){$SIZE(n)}, |
| 8798 |
$P(T), |
| 8799 |
&(integer){$SIZE(n)}, |
| 8800 |
$P(VL), |
| 8801 |
&(integer){$SIZE(m)}, |
| 8802 |
$P(VR), |
| 8803 |
&(integer){$SIZE(p)}, |
| 8804 |
&mm, |
| 8805 |
$P(m), |
| 8806 |
$P(work), |
| 8807 |
$P(info)); |
| 8808 |
|
| 8809 |
', |
| 8810 |
Doc => ' |
| 8811 |
|
| 8812 |
=for ref |
| 8813 |
|
| 8814 |
Computes some or all of the right and/or left eigenvectors of |
| 8815 |
a real upper quasi-triangular matrix T. |
| 8816 |
|
| 8817 |
The right eigenvector x and the left eigenvector y of T corresponding |
| 8818 |
to an eigenvalue w are defined by: |
| 8819 |
|
| 8820 |
T*x = w*x, y\'*T = w*y\' |
| 8821 |
where y\' denotes the conjugate transpose of the vector y. |
| 8822 |
|
| 8823 |
If all eigenvectors are requested, the routine may either return the |
| 8824 |
matrices X and/or Y of right or left eigenvectors of T, or the |
| 8825 |
products Q*X and/or Q*Y, where Q is an input orthogonal |
| 8826 |
matrix. If T was obtained from the real-Schur factorization of an |
| 8827 |
original matrix A = Q*T*Q\', then Q*X and Q*Y are the matrices of |
| 8828 |
right or left eigenvectors of A. |
| 8829 |
|
| 8830 |
T must be in Schur canonical form (as returned by hseqr), that is, |
| 8831 |
block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each |
| 8832 |
2-by-2 diagonal block has its diagonal elements equal and its |
| 8833 |
off-diagonal elements of opposite sign. Corresponding to each 2-by-2 |
| 8834 |
diagonal block is a complex conjugate pair of eigenvalues and |
| 8835 |
eigenvectors; only one eigenvector of the pair is computed, namely |
| 8836 |
the one corresponding to the eigenvalue with positive imaginary part. |
| 8837 |
|
| 8838 |
Further Details |
| 8839 |
=============== |
| 8840 |
|
| 8841 |
The algorithm used in this program is basically backward (forward) |
| 8842 |
substitution, with scaling to make the the code robust against |
| 8843 |
possible overflow. |
| 8844 |
|
| 8845 |
Each eigenvector is normalized so that the element of largest |
| 8846 |
magnitude has magnitude 1; here the magnitude of a complex number |
| 8847 |
(x,y) is taken to be |x| + |y|. |
| 8848 |
|
| 8849 |
|
| 8850 |
Arguments |
| 8851 |
========= |
| 8852 |
|
| 8853 |
|
| 8854 |
side: = 0 : compute both right and left eigenvectors; |
| 8855 |
= 1 : compute right eigenvectors only; |
| 8856 |
= 2 : compute left eigenvectors only. |
| 8857 |
|
| 8858 |
howmny: = 0: compute all right and/or left eigenvectors; |
| 8859 |
= 1: compute all right and/or left eigenvectors, |
| 8860 |
and backtransform them using the input matrices |
| 8861 |
supplied in VR and/or VL; |
| 8862 |
= 2: compute selected right and/or left eigenvectors, |
| 8863 |
specified by the logical array select. |
| 8864 |
|
| 8865 |
select: If howmny = 2, select specifies the eigenvectors to be |
| 8866 |
computed. |
| 8867 |
If howmny = 0 or 1, select is not referenced. |
| 8868 |
To select the real eigenvector corresponding to a real |
| 8869 |
eigenvalue w(j), select(j) must be set to TRUE. To select |
| 8870 |
the complex eigenvector corresponding to a complex conjugate |
| 8871 |
pair w(j) and w(j+1), either select(j) or select(j+1) must be |
| 8872 |
set to TRUE; then on exit select(j) is TRUE and |
| 8873 |
select(j+1) is FALSE. |
| 8874 |
|
| 8875 |
T: The upper quasi-triangular matrix T in Schur canonical form. |
| 8876 |
|
| 8877 |
VL: On entry, if side = 2 or 0 and howmny = 1, VL must |
| 8878 |
contain an N-by-N matrix Q (usually the orthogonal matrix Q |
| 8879 |
of Schur vectors returned by hseqr). |
| 8880 |
On exit, if side = 2 or 0, VL contains: |
| 8881 |
if howmny = 0, the matrix Y of left eigenvectors of T; |
| 8882 |
VL has the same quasi-lower triangular form |
| 8883 |
as T\'. If T(i,i) is a real eigenvalue, then |
| 8884 |
the i-th column VL(i) of VL is its |
| 8885 |
corresponding eigenvector. If T(i:i+1,i:i+1) |
| 8886 |
is a 2-by-2 block whose eigenvalues are |
| 8887 |
complex-conjugate eigenvalues of T, then |
| 8888 |
VL(i)+sqrt(-1)*VL(i+1) is the complex |
| 8889 |
eigenvector corresponding to the eigenvalue |
| 8890 |
with positive real part. |
| 8891 |
if howmny = 1, the matrix Q*Y; |
| 8892 |
if howmny = 2, the left eigenvectors of T specified by |
| 8893 |
select, stored consecutively in the columns |
| 8894 |
of VL, in the same order as their |
| 8895 |
eigenvalues. |
| 8896 |
A complex eigenvector corresponding to a complex eigenvalue |
| 8897 |
is stored in two consecutive columns, the first holding the |
| 8898 |
real part, and the second the imaginary part. |
| 8899 |
If side = 1, VL is not referenced. |
| 8900 |
|
| 8901 |
VR: On entry, if side = 1 or 0 and howmny = 1, VR must |
| 8902 |
contain an N-by-N matrix Q (usually the orthogonal matrix Q |
| 8903 |
of Schur vectors returned by hseqr). |
| 8904 |
On exit, if side = 1 or 0, VR contains: |
| 8905 |
if howmny = 0, the matrix X of right eigenvectors of T; |
| 8906 |
VR has the same quasi-upper triangular form |
| 8907 |
as T. If T(i,i) is a real eigenvalue, then |
| 8908 |
the i-th column VR(i) of VR is its |
| 8909 |
corresponding eigenvector. If T(i:i+1,i:i+1) |
| 8910 |
is a 2-by-2 block whose eigenvalues are |
| 8911 |
complex-conjugate eigenvalues of T, then |
| 8912 |
VR(i)+sqrt(-1)*VR(i+1) is the complex |
| 8913 |
eigenvector corresponding to the eigenvalue |
| 8914 |
with positive real part. |
| 8915 |
if howmny = 1, the matrix Q*X; |
| 8916 |
if howmny = 2, the right eigenvectors of T specified by |
| 8917 |
select, stored consecutively in the columns |
| 8918 |
of VR, in the same order as their |
| 8919 |
eigenvalues. |
| 8920 |
A complex eigenvector corresponding to a complex eigenvalue |
| 8921 |
is stored in two consecutive columns, the first holding the |
| 8922 |
real part and the second the imaginary part. |
| 8923 |
If side = 2, VR is not referenced. |
| 8924 |
|
| 8925 |
m: The number of columns in the arrays VL and/or VR actually |
| 8926 |
used to store the eigenvectors. |
| 8927 |
If howmny = 0 or 1, m is set to N. |
| 8928 |
Each selected real eigenvector occupies one column and each |
| 8929 |
selected complex eigenvector occupies two columns. |
| 8930 |
|
| 8931 |
info: = 0: successful exit |
| 8932 |
< 0: if info = -i, the i-th argument had an illegal value |
| 8933 |
|
| 8934 |
|
| 8935 |
=for example |
| 8936 |
|
| 8937 |
$a = random (50, 50); |
| 8938 |
$info = null; |
| 8939 |
$tau = zeroes(50); |
| 8940 |
$z= zeroes(1,1); |
| 8941 |
gehrd($a, 1, 50, $tau, $info); |
| 8942 |
hseqr($a,0,0,1,50,($wr=null),($wi=null),$z,$info); |
| 8943 |
|
| 8944 |
'); |
| 8945 |
|
| 8946 |
|
| 8947 |
pp_def("tgevc", |
| 8948 |
HandleBad => 0, |
| 8949 |
Pars => 'A(n,n);B(n,n);int select(q);[o]VL(m,m); [o]VR(p,p);int [o]m(); int [o]info(); [t]work(workn=CALC(6*$SIZE(n)));', |
| 8950 |
OtherPars => 'int side; int howmny', |
| 8951 |
ArgOrder => [qw{A side howmny B select VL VR m info}], |
| 8952 |
RedoDimsCode => ' |
| 8953 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(side), tmp != 1, $PDL(VL), $SIZE(m), $SIZE(n)) |
| 8954 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(side), tmp != 2, $PDL(VR), $SIZE(p), $SIZE(n)) |
| 8955 |
', |
| 8956 |
GenericTypes => [F,D], |
| 8957 |
Code => generate_code ' |
| 8958 |
char pside,phowmny; |
| 8959 |
integer mm = PDLMAX($SIZE(m),$SIZE(p)); |
| 8960 |
|
| 8961 |
extern int FORTRAN($TFD(s,d)tgevc)(char *side, char *howmny, logical *select, |
| 8962 |
integer *n, $GENERIC() *a, integer *lda, $GENERIC() *b,integer *ldb, |
| 8963 |
$GENERIC() *vl, integer *ldvl, $GENERIC() *vr, integer *ldvr, integer *mm, integer *m, |
| 8964 |
$GENERIC() *work, integer *info); |
| 8965 |
switch ($COMP(howmny)) |
| 8966 |
{ |
| 8967 |
case 1: phowmny = \'B\'; |
| 8968 |
break; |
| 8969 |
case 2: phowmny = \'S\'; |
| 8970 |
break; |
| 8971 |
default: phowmny = \'A\'; |
| 8972 |
} |
| 8973 |
|
| 8974 |
switch ($COMP(side)) |
| 8975 |
{ |
| 8976 |
case 1: pside = \'R\'; |
| 8977 |
break; |
| 8978 |
case 2: pside = \'L\'; |
| 8979 |
break; |
| 8980 |
default:pside = \'B\'; |
| 8981 |
} |
| 8982 |
|
| 8983 |
FORTRAN($TFD(s,d)tgevc)( |
| 8984 |
&pside, |
| 8985 |
&phowmny, |
| 8986 |
$P(select), |
| 8987 |
&(integer){$SIZE(n)}, |
| 8988 |
$P(A), |
| 8989 |
&(integer){$SIZE(n)}, |
| 8990 |
$P(B), |
| 8991 |
&(integer){$SIZE(n)}, |
| 8992 |
$P(VL), |
| 8993 |
&(integer){$SIZE(m)}, |
| 8994 |
$P(VR), |
| 8995 |
&(integer){$SIZE(p)}, |
| 8996 |
&mm, |
| 8997 |
$P(m), |
| 8998 |
$P(work), |
| 8999 |
$P(info)); |
| 9000 |
', |
| 9001 |
Doc => ' |
| 9002 |
|
| 9003 |
=for ref |
| 9004 |
|
| 9005 |
Computes some or all of the right and/or left generalized |
| 9006 |
eigenvectors of a pair of real upper triangular matrices (A,B). |
| 9007 |
|
| 9008 |
The right generalized eigenvector x and the left generalized |
| 9009 |
eigenvector y of (A,B) corresponding to a generalized eigenvalue |
| 9010 |
w are defined by: |
| 9011 |
|
| 9012 |
(A - wB) * x = 0 and y**H * (A - wB) = 0 |
| 9013 |
where y**H denotes the conjugate transpose of y. |
| 9014 |
|
| 9015 |
If an eigenvalue w is determined by zero diagonal elements of both A |
| 9016 |
and B, a unit vector is returned as the corresponding eigenvector. |
| 9017 |
|
| 9018 |
If all eigenvectors are requested, the routine may either return |
| 9019 |
the matrices X and/or Y of right or left eigenvectors of (A,B), or |
| 9020 |
the products Z*X and/or Q*Y, where Z and Q are input orthogonal |
| 9021 |
matrices. If (A,B) was obtained from the generalized real-Schur |
| 9022 |
factorization of an original pair of matrices |
| 9023 |
|
| 9024 |
(A0,B0) = (Q*A*Z**H,Q*B*Z**H), |
| 9025 |
|
| 9026 |
then Z*X and Q*Y are the matrices of right or left eigenvectors of |
| 9027 |
A. |
| 9028 |
|
| 9029 |
A must be block upper triangular, with 1-by-1 and 2-by-2 diagonal |
| 9030 |
blocks. Corresponding to each 2-by-2 diagonal block is a complex |
| 9031 |
conjugate pair of eigenvalues and eigenvectors; only one |
| 9032 |
eigenvector of the pair is computed, namely the one corresponding |
| 9033 |
to the eigenvalue with positive imaginary part. |
| 9034 |
|
| 9035 |
Arguments |
| 9036 |
========= |
| 9037 |
|
| 9038 |
|
| 9039 |
side: = 0 : compute both right and left eigenvectors; |
| 9040 |
= 1 : compute right eigenvectors only; |
| 9041 |
= 2 : compute left eigenvectors only. |
| 9042 |
|
| 9043 |
howmny: = 0 : compute all right and/or left eigenvectors; |
| 9044 |
= 1 : compute all right and/or left eigenvectors, and |
| 9045 |
backtransform them using the input matrices supplied |
| 9046 |
in VR and/or VL; |
| 9047 |
= 2 : compute selected right and/or left eigenvectors, |
| 9048 |
specified by the logical array select. |
| 9049 |
|
| 9050 |
select: If howmny=2, select specifies the eigenvectors to be |
| 9051 |
computed. |
| 9052 |
If howmny=0 or 1, select is not referenced. |
| 9053 |
To select the real eigenvector corresponding to the real |
| 9054 |
eigenvalue w(j), select(j) must be set to TRUE To select |
| 9055 |
the complex eigenvector corresponding to a complex conjugate |
| 9056 |
pair w(j) and w(j+1), either select(j) or select(j+1) must |
| 9057 |
be set to TRUE. |
| 9058 |
|
| 9059 |
A: The upper quasi-triangular matrix A. |
| 9060 |
|
| 9061 |
B: The upper triangular matrix B. If A has a 2-by-2 diagonal |
| 9062 |
block, then the corresponding 2-by-2 block of B must be |
| 9063 |
diagonal with positive elements. |
| 9064 |
|
| 9065 |
VL: On entry, if side = 2 or 0 and howmny = 1, VL must |
| 9066 |
contain an N-by-N matrix Q (usually the orthogonal matrix Q |
| 9067 |
of left Schur vectors returned by hgqez). |
| 9068 |
On exit, if side = 2 or 0, VL contains: |
| 9069 |
if howmny = 0, the matrix Y of left eigenvectors of (A,B); |
| 9070 |
if howmny = 1, the matrix Q*Y; |
| 9071 |
if howmny = 2, the left eigenvectors of (A,B) specified by |
| 9072 |
select, stored consecutively in the columns of |
| 9073 |
VL, in the same order as their eigenvalues. |
| 9074 |
If side = 1, VL is not referenced. |
| 9075 |
|
| 9076 |
A complex eigenvector corresponding to a complex eigenvalue |
| 9077 |
is stored in two consecutive columns, the first holding the |
| 9078 |
real part, and the second the imaginary part. |
| 9079 |
|
| 9080 |
VR: On entry, if side = 1 or 0 and howmny = 1, VR must |
| 9081 |
contain an N-by-N matrix Q (usually the orthogonal matrix Z |
| 9082 |
of right Schur vectors returned by hgeqz). |
| 9083 |
On exit, if side = 1 or 0, VR contains: |
| 9084 |
if howmny = 0, the matrix X of right eigenvectors of (A,B); |
| 9085 |
if howmny = 1, the matrix Z*X; |
| 9086 |
if howmny = 2, the right eigenvectors of (A,B) specified by |
| 9087 |
select, stored consecutively in the columns of |
| 9088 |
VR, in the same order as their eigenvalues. |
| 9089 |
If side = 2, VR is not referenced. |
| 9090 |
|
| 9091 |
A complex eigenvector corresponding to a complex eigenvalue |
| 9092 |
is stored in two consecutive columns, the first holding the |
| 9093 |
real part and the second the imaginary part. |
| 9094 |
|
| 9095 |
M: The number of columns in the arrays VL and/or VR actually |
| 9096 |
used to store the eigenvectors. If howmny = 0 or 1, M |
| 9097 |
is set to N. Each selected real eigenvector occupies one |
| 9098 |
column and each selected complex eigenvector occupies two |
| 9099 |
columns. |
| 9100 |
|
| 9101 |
info: = 0: successful exit. |
| 9102 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 9103 |
> 0: the 2-by-2 block (info:info+1) does not have a complex |
| 9104 |
eigenvalue. |
| 9105 |
=for example |
| 9106 |
|
| 9107 |
$a = random (50, 50); |
| 9108 |
$info = null; |
| 9109 |
$tau = zeroes(50); |
| 9110 |
$z= zeroes(1,1); |
| 9111 |
gehrd($a, 1, 50, $tau, $info); |
| 9112 |
hseqr($a,0,0,1,50,($wr=null),($wi=null),$z,$info); |
| 9113 |
|
| 9114 |
'); |
| 9115 |
|
| 9116 |
|
| 9117 |
|
| 9118 |
pp_def("gebal", |
| 9119 |
HandleBad => 0, |
| 9120 |
Pars => '[io]A(n,n); int job(); int [o]ilo();int [o]ihi();[o]scale(n); int [o]info()', |
| 9121 |
GenericTypes => [F,D], |
| 9122 |
Code => generate_code ' |
| 9123 |
char pjob; |
| 9124 |
|
| 9125 |
extern int FORTRAN($TFD(s,d)gebal)(char *job, integer *n, $GENERIC() *a, integer * |
| 9126 |
lda, integer *ilo, integer *ihi, $GENERIC() *scale, integer *info); |
| 9127 |
|
| 9128 |
switch ($job()) |
| 9129 |
{ |
| 9130 |
case 1: pjob = \'P\'; |
| 9131 |
break; |
| 9132 |
case 2: pjob = \'S\'; |
| 9133 |
break; |
| 9134 |
case 3: pjob = \'B\'; |
| 9135 |
break; |
| 9136 |
default: pjob = \'N\'; |
| 9137 |
} |
| 9138 |
|
| 9139 |
FORTRAN($TFD(s,d)gebal)( |
| 9140 |
&pjob, |
| 9141 |
&(integer){$SIZE(n)}, |
| 9142 |
$P(A), |
| 9143 |
&(integer){$SIZE(n)}, |
| 9144 |
$P(ilo), |
| 9145 |
$P(ihi), |
| 9146 |
$P(scale), |
| 9147 |
$P(info)); |
| 9148 |
|
| 9149 |
', |
| 9150 |
Doc => ' |
| 9151 |
|
| 9152 |
=for ref |
| 9153 |
|
| 9154 |
Balances a general real matrix A. This involves, first, |
| 9155 |
permuting A by a similarity transformation to isolate eigenvalues |
| 9156 |
in the first 1 to ilo-1 and last ihi+1 to N elements on the |
| 9157 |
diagonal; and second, applying a diagonal similarity transformation |
| 9158 |
to rows and columns ilo to ihi to make the rows and columns as |
| 9159 |
close in norm as possible. Both steps are optional. |
| 9160 |
|
| 9161 |
Balancing may reduce the 1-norm of the matrix, and improve the |
| 9162 |
accuracy of the computed eigenvalues and/or eigenvectors. |
| 9163 |
|
| 9164 |
Further Details |
| 9165 |
=============== |
| 9166 |
|
| 9167 |
The permutations consist of row and column interchanges which put |
| 9168 |
the matrix in the form |
| 9169 |
|
| 9170 |
( T1 X Y ) |
| 9171 |
P A P = ( 0 B Z ) |
| 9172 |
( 0 0 T2 ) |
| 9173 |
|
| 9174 |
where T1 and T2 are upper triangular matrices whose eigenvalues lie |
| 9175 |
along the diagonal. The column indices ilo and ihi mark the starting |
| 9176 |
and ending columns of the submatrix B. Balancing consists of applying |
| 9177 |
a diagonal similarity transformation inv(D) * B * D to make the |
| 9178 |
1-norms of each row of B and its corresponding column nearly equal. |
| 9179 |
|
| 9180 |
The output matrix is |
| 9181 |
|
| 9182 |
( T1 X*D Y ) |
| 9183 |
( 0 inv(D)*B*D inv(D)*Z ). |
| 9184 |
( 0 0 T2 ) |
| 9185 |
|
| 9186 |
|
| 9187 |
Information about the permutations P and the diagonal matrix D is |
| 9188 |
returned in the vector C<scale>. |
| 9189 |
|
| 9190 |
|
| 9191 |
Arguments |
| 9192 |
========= |
| 9193 |
|
| 9194 |
job: Specifies the operations to be performed on A: |
| 9195 |
= 0: none: simply set ilo = 1, ihi = N, scale(I) = 1.0 |
| 9196 |
for i = 1,...,N; |
| 9197 |
= 1: permute only; |
| 9198 |
= 2: scale only; |
| 9199 |
= 3: both permute and scale. |
| 9200 |
|
| 9201 |
A: On entry, the input matrix A. |
| 9202 |
On exit, A is overwritten by the balanced matrix. |
| 9203 |
If job = 0, A is not referenced. |
| 9204 |
See Further Details. |
| 9205 |
|
| 9206 |
ilo: |
| 9207 |
ihi: ilo and ihi are set to integers such that on exit |
| 9208 |
A(i,j) = 0 if i > j and j = 1,...,ilo-1 or I = ihi+1,...,N. |
| 9209 |
If job = 0 or 2, ilo = 1 and ihi = N. |
| 9210 |
|
| 9211 |
scale: Details of the permutations and scaling factors applied to |
| 9212 |
A. If P(j) is the index of the row and column interchanged |
| 9213 |
with row and column j and D(j) is the scaling factor |
| 9214 |
applied to row and column j, then |
| 9215 |
scale(j) = P(j) for j = 1,...,ilo-1 |
| 9216 |
= D(j) for j = ilo,...,ihi |
| 9217 |
= P(j) for j = ihi+1,...,N. |
| 9218 |
The order in which the interchanges are made is N to ihi+1, |
| 9219 |
then 1 to ilo-1. |
| 9220 |
|
| 9221 |
info: = 0: successful exit. |
| 9222 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 9223 |
|
| 9224 |
|
| 9225 |
|
| 9226 |
|
| 9227 |
=for example |
| 9228 |
|
| 9229 |
$a = random (50, 50); |
| 9230 |
$scale = zeroes(50); |
| 9231 |
$info = null; |
| 9232 |
$ilo = null; |
| 9233 |
$ihi = null; |
| 9234 |
gebal($a, $ilo, $ihi, $scale, $info); |
| 9235 |
|
| 9236 |
'); |
| 9237 |
|
| 9238 |
|
| 9239 |
pp_def("gebak", |
| 9240 |
HandleBad => 0, |
| 9241 |
Pars => '[io]A(n,m); int job(); int side();int ilo();int ihi();scale(n); int [o]info()', |
| 9242 |
GenericTypes => [F,D], |
| 9243 |
Code => generate_code ' |
| 9244 |
char pjob; |
| 9245 |
char pside =\'L\' ; |
| 9246 |
|
| 9247 |
extern int FORTRAN($TFD(s,d)gebak)(char *job, char *side, integer *n, integer *ilo, |
| 9248 |
integer *ihi, $GENERIC() *scale, integer *m, $GENERIC() *v, integer * |
| 9249 |
ldv, integer *info); |
| 9250 |
|
| 9251 |
switch ($job()) |
| 9252 |
{ |
| 9253 |
case 1: pjob = \'P\'; |
| 9254 |
break; |
| 9255 |
case 2: pjob = \'S\'; |
| 9256 |
break; |
| 9257 |
case 3: pjob = \'B\'; |
| 9258 |
break; |
| 9259 |
default: pjob = \'N\'; |
| 9260 |
} |
| 9261 |
if ($side()) |
| 9262 |
pside = \'R\'; |
| 9263 |
|
| 9264 |
FORTRAN($TFD(s,d)gebak)( |
| 9265 |
&pjob, |
| 9266 |
&pside, |
| 9267 |
&(integer){$SIZE(n)}, |
| 9268 |
$P(ilo), |
| 9269 |
$P(ihi), |
| 9270 |
$P(scale), |
| 9271 |
&(integer){$SIZE(m)}, |
| 9272 |
$P(A), |
| 9273 |
&(integer){$SIZE(n)}, |
| 9274 |
$P(info)); |
| 9275 |
|
| 9276 |
', |
| 9277 |
Doc => ' |
| 9278 |
|
| 9279 |
=for ref |
| 9280 |
|
| 9281 |
gebak forms the right or left eigenvectors of a real general matrix |
| 9282 |
by backward transformation on the computed eigenvectors of the |
| 9283 |
balanced matrix output by gebal. |
| 9284 |
|
| 9285 |
Arguments |
| 9286 |
========= |
| 9287 |
|
| 9288 |
A: On entry, the matrix of right or left eigenvectors to be |
| 9289 |
transformed, as returned by hsein or trevc. |
| 9290 |
On exit, A is overwritten by the transformed eigenvectors. |
| 9291 |
|
| 9292 |
job: Specifies the type of backward transformation required: |
| 9293 |
= 0 , do nothing, return immediately; |
| 9294 |
= 1, do backward transformation for permutation only; |
| 9295 |
= 2, do backward transformation for scaling only; |
| 9296 |
= 3, do backward transformations for both permutation and |
| 9297 |
scaling. |
| 9298 |
job must be the same as the argument job supplied to gebal. |
| 9299 |
|
| 9300 |
side: = 0: V contains left eigenvectors. |
| 9301 |
= 1: V contains right eigenvectors; |
| 9302 |
|
| 9303 |
ilo: |
| 9304 |
ihi: The integers ilo and ihi determined by gebal. |
| 9305 |
1 <= ilo <= ihi <= N, if N > 0; ilo=1 and ihi=0, if N=0. |
| 9306 |
Here N is the the number of rows of the matrix A. |
| 9307 |
|
| 9308 |
scale: Details of the permutation and scaling factors, as returned |
| 9309 |
by gebal. |
| 9310 |
|
| 9311 |
info: = 0: successful exit |
| 9312 |
< 0: if info = -i, the i-th argument had an illegal value. |
| 9313 |
|
| 9314 |
|
| 9315 |
|
| 9316 |
|
| 9317 |
=for example |
| 9318 |
|
| 9319 |
$a = random (50, 50); |
| 9320 |
$scale = zeroes(50); |
| 9321 |
$info = null; |
| 9322 |
$ilo = null; |
| 9323 |
$ihi = null; |
| 9324 |
gebal($a, $ilo, $ihi, $scale, $info); |
| 9325 |
# Compute eigenvectors ($ev) |
| 9326 |
gebak($ev, $ilo, $ihi, $scale, $info); |
| 9327 |
|
| 9328 |
'); |
| 9329 |
|
| 9330 |
pp_def("lange", |
| 9331 |
HandleBad => 0, |
| 9332 |
Pars => 'A(n,m); [o]b(); [t]work(workn);', |
| 9333 |
OtherPars => 'int norm', |
| 9334 |
ArgOrder => [qw{A norm b}], |
| 9335 |
RedoDimsCode => ' |
| 9336 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(norm), tmp == 2, $PDL(work), $SIZE(workn), $SIZE(n)) |
| 9337 |
', |
| 9338 |
GenericTypes => [F,D], |
| 9339 |
Code => ' |
| 9340 |
char pnorm; |
| 9341 |
extern $GENERIC() FORTRAN($TFD(s,d)lange)(char *norm, integer *m, integer *n, $GENERIC() *a, integer |
| 9342 |
*lda, $GENERIC() *work); |
| 9343 |
switch ($COMP(norm)) |
| 9344 |
{ |
| 9345 |
case 1: pnorm = \'O\'; |
| 9346 |
break; |
| 9347 |
case 2: pnorm = \'I\'; |
| 9348 |
break; |
| 9349 |
case 3: pnorm = \'F\'; |
| 9350 |
break; |
| 9351 |
default: pnorm = \'M\'; |
| 9352 |
} |
| 9353 |
$b() = FORTRAN($TFD(s,d)lange)( |
| 9354 |
&pnorm, |
| 9355 |
&(integer){$SIZE(n)}, |
| 9356 |
&(integer){$SIZE(m)}, |
| 9357 |
$P(A), |
| 9358 |
&(integer){$SIZE(n)}, |
| 9359 |
$P(work)); |
| 9360 |
', |
| 9361 |
Doc => ' |
| 9362 |
=for ref |
| 9363 |
|
| 9364 |
Computes the value of the one norm, or the Frobenius norm, or |
| 9365 |
the infinity norm, or the element of largest absolute value of a |
| 9366 |
real matrix A. |
| 9367 |
|
| 9368 |
Description |
| 9369 |
=========== |
| 9370 |
|
| 9371 |
returns the value |
| 9372 |
|
| 9373 |
lange = ( max(abs(A(i,j))), norm = 0 |
| 9374 |
( |
| 9375 |
( norm1(A), norm = 1 |
| 9376 |
( |
| 9377 |
( normI(A), norm = 2 |
| 9378 |
( |
| 9379 |
( normF(A), norm = 3 |
| 9380 |
|
| 9381 |
where norm1 denotes the one norm of a matrix (maximum column sum), |
| 9382 |
normI denotes the infinity norm of a matrix (maximum row sum) and |
| 9383 |
normF denotes the Frobenius norm of a matrix (square root of sum of |
| 9384 |
squares). Note that max(abs(A(i,j))) is not a matrix norm. |
| 9385 |
|
| 9386 |
Arguments |
| 9387 |
========= |
| 9388 |
|
| 9389 |
norm: Specifies the value to be returned in lange as described |
| 9390 |
above. |
| 9391 |
|
| 9392 |
A: The n by m matrix A. |
| 9393 |
|
| 9394 |
=for example |
| 9395 |
|
| 9396 |
$a = random (float, 100, 100); |
| 9397 |
$norm = $a->lange(1); |
| 9398 |
'); |
| 9399 |
|
| 9400 |
pp_def("lansy", |
| 9401 |
HandleBad => 0, |
| 9402 |
Pars => 'A(n,n); [o]b(); [t]work(workn);', |
| 9403 |
OtherPars => 'int uplo; int norm', |
| 9404 |
ArgOrder => [qw{A uplo norm b}], |
| 9405 |
RedoDimsCode => ' |
| 9406 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(norm), tmp == 1 || tmp == 2, $PDL(work), $SIZE(workn), $SIZE(n)) |
| 9407 |
', |
| 9408 |
GenericTypes => [F,D], |
| 9409 |
Code => ' |
| 9410 |
char pnorm, puplo = \'U\'; |
| 9411 |
extern $GENERIC() FORTRAN($TFD(s,d)lansy)(char *norm, char *uplo, integer *n, $GENERIC() *a, integer |
| 9412 |
*lda, $GENERIC() *work); |
| 9413 |
switch ($COMP(norm)) |
| 9414 |
{ |
| 9415 |
case 1: pnorm = \'O\'; |
| 9416 |
break; |
| 9417 |
case 2: pnorm = \'I\'; |
| 9418 |
break; |
| 9419 |
case 3: pnorm = \'F\'; |
| 9420 |
break; |
| 9421 |
default: pnorm = \'M\'; |
| 9422 |
} |
| 9423 |
if($COMP(uplo)) |
| 9424 |
puplo = \'L\'; |
| 9425 |
|
| 9426 |
$b() = FORTRAN($TFD(s,d)lansy)( |
| 9427 |
&pnorm, |
| 9428 |
&puplo, |
| 9429 |
&(integer){$SIZE(n)}, |
| 9430 |
$P(A), |
| 9431 |
&(integer){$SIZE(n)}, |
| 9432 |
$P(work)); |
| 9433 |
', |
| 9434 |
Doc => ' |
| 9435 |
=for ref |
| 9436 |
|
| 9437 |
Computes the value of the one norm, or the Frobenius norm, or |
| 9438 |
the infinity norm, or the element of largest absolute value of a |
| 9439 |
real symmetric matrix A. |
| 9440 |
|
| 9441 |
Description |
| 9442 |
=========== |
| 9443 |
|
| 9444 |
returns the value |
| 9445 |
|
| 9446 |
lansy = ( max(abs(A(i,j))), norm = 0 |
| 9447 |
( |
| 9448 |
( norm1(A), norm = 1 |
| 9449 |
( |
| 9450 |
( normI(A), norm = 2 |
| 9451 |
( |
| 9452 |
( normF(A), norm = 3 |
| 9453 |
|
| 9454 |
where norm1 denotes the one norm of a matrix (maximum column sum), |
| 9455 |
normI denotes the infinity norm of a matrix (maximum row sum) and |
| 9456 |
normF denotes the Frobenius norm of a matrix (square root of sum of |
| 9457 |
squares). Note that max(abs(A(i,j))) is not a matrix norm. |
| 9458 |
|
| 9459 |
norm: Specifies the value to be returned in lansy as described |
| 9460 |
above. |
| 9461 |
|
| 9462 |
uplo: Specifies whether the upper or lower triangular part of the |
| 9463 |
symmetric matrix A is to be referenced. |
| 9464 |
= 0: Upper triangular part of A is referenced |
| 9465 |
= 1: Lower triangular part of A is referenced |
| 9466 |
|
| 9467 |
A: The symmetric matrix A. If uplo = 0, the leading n by n |
| 9468 |
upper triangular part of A contains the upper triangular part |
| 9469 |
of the matrix A, and the strictly lower triangular part of A |
| 9470 |
is not referenced. If uplo = 1, the leading n by n lower |
| 9471 |
triangular part of A contains the lower triangular part of |
| 9472 |
the matrix A, and the strictly upper triangular part of A is |
| 9473 |
not referenced. |
| 9474 |
|
| 9475 |
=for example |
| 9476 |
|
| 9477 |
# Assume $a is symmetric |
| 9478 |
$a = random (float, 100, 100); |
| 9479 |
$norm = $a->lansy(1, 1); |
| 9480 |
'); |
| 9481 |
|
| 9482 |
pp_def("lantr", |
| 9483 |
HandleBad => 0, |
| 9484 |
Pars => 'A(m,n); [o]b(); [t]work(workn);', |
| 9485 |
OtherPars => 'int uplo; int norm; int diag', |
| 9486 |
ArgOrder => [qw{A uplo norm diag b}], |
| 9487 |
RedoDimsCode => ' |
| 9488 |
PDL_MAYBE_SIZE(PDL_Long, $COMP(norm), tmp == 2, $PDL(work), $SIZE(workn), $SIZE(m)) |
| 9489 |
', |
| 9490 |
GenericTypes => [F,D], |
| 9491 |
Code => ' |
| 9492 |
char pnorm, puplo = \'U\'; |
| 9493 |
char pdiag = \'N\'; |
| 9494 |
extern $GENERIC() FORTRAN($TFD(s,d)lantr)(char *norm, char *uplo, char *diag, integer *m, integer *n, $GENERIC() *a, integer |
| 9495 |
*lda, $GENERIC() *work); |
| 9496 |
switch ($COMP(norm)) |
| 9497 |
{ |
| 9498 |
case 1: pnorm = \'O\'; |
| 9499 |
break; |
| 9500 |
case 2: pnorm = \'I\'; |
| 9501 |
break; |
| 9502 |
case 3: pnorm = \'F\'; |
| 9503 |
break; |
| 9504 |
default: pnorm = \'M\'; |
| 9505 |
} |
| 9506 |
if($COMP(uplo)) |
| 9507 |
puplo = \'L\'; |
| 9508 |
if($COMP(diag)) |
| 9509 |
pdiag = \'U\'; |
| 9510 |
$b() = FORTRAN($TFD(s,d)lantr)( |
| 9511 |
&pnorm, |
| 9512 |
&puplo, |
| 9513 |
&pdiag, |
| 9514 |
&(integer){$SIZE(m)}, |
| 9515 |
&(integer){$SIZE(n)}, |
| 9516 |
$P(A), |
| 9517 |
&(integer){$SIZE(n)}, |
| 9518 |
$P(work)); |
| 9519 |
', |
| 9520 |
Doc => ' |
| 9521 |
=for ref |
| 9522 |
|
| 9523 |
Computes the value of the one norm, or the Frobenius norm, or |
| 9524 |
the infinity norm, or the element of largest absolute value of a |
| 9525 |
trapezoidal or triangular matrix A. |
| 9526 |
|
| 9527 |
Description |
| 9528 |
=========== |
| 9529 |
|
| 9530 |
returns the value |
| 9531 |
|
| 9532 |
lantr = ( max(abs(A(i,j))), norm = 0 |
| 9533 |
( |
| 9534 |
( norm1(A), norm = 1 |
| 9535 |
( |
| 9536 |
( normI(A), norm = 2 |
| 9537 |
( |
| 9538 |
( normF(A), norm = 3 |
| 9539 |
|
| 9540 |
where norm1 denotes the one norm of a matrix (maximum column sum), |
| 9541 |
normI denotes the infinity norm of a matrix (maximum row sum) and |
| 9542 |
normF denotes the Frobenius norm of a matrix (square root of sum of |
| 9543 |
squares). Note that max(abs(A(i,j))) is not a matrix norm. |
| 9544 |
|
| 9545 |
norm: Specifies the value to be returned in lantr as described |
| 9546 |
above. |
| 9547 |
|
| 9548 |
uplo: Specifies whether the matrix A is upper or lower trapezoidal. |
| 9549 |
= 0: Upper triangular part of A is referenced |
| 9550 |
= 1: Lower triangular part of A is referenced |
| 9551 |
Note that A is triangular instead of trapezoidal if M = N. |
| 9552 |
|
| 9553 |
diag: Specifies whether or not the matrix A has unit diagonal. |
| 9554 |
= 0: Non-unit diagonal |
| 9555 |
= 1: Unit diagonal |
| 9556 |
|
| 9557 |
A: The trapezoidal matrix A (A is triangular if m = n). |
| 9558 |
If uplo = 0, the leading m by n upper trapezoidal part of |
| 9559 |
the array A contains the upper trapezoidal matrix, and the |
| 9560 |
strictly lower triangular part of A is not referenced. |
| 9561 |
If uplo = 1, the leading m by n lower trapezoidal part of |
| 9562 |
the array A contains the lower trapezoidal matrix, and the |
| 9563 |
strictly upper triangular part of A is not referenced. Note |
| 9564 |
that when diag = 1, the diagonal elements of A are not |
| 9565 |
referenced and are assumed to be one. |
| 9566 |
|
| 9567 |
=for example |
| 9568 |
|
| 9569 |
# Assume $a is upper triangular |
| 9570 |
$a = random (float, 100, 100); |
| 9571 |
$norm = $a->lantr(1, 1, 0); |
| 9572 |
'); |
| 9573 |
|
| 9574 |
################################################################################ |
| 9575 |
# |
| 9576 |
# BLAS ROUTINES |
| 9577 |
# |
| 9578 |
################################################################################ |
| 9579 |
pp_def("gemm", |
| 9580 |
HandleBad => 0, |
| 9581 |
Pars => 'A(m,n); int transa(); int transb(); B(p,q);alpha(); beta(); [io]C(r,s)', |
| 9582 |
GenericTypes => [F,D], |
| 9583 |
Code => ' |
| 9584 |
char ptransa = \'N\'; |
| 9585 |
char ptransb = \'N\'; |
| 9586 |
extern int FORTRAN($TFD(s,d)gemm)(char *transa, char *transb, integer *m, integer * |
| 9587 |
n, integer *k, $GENERIC() *alpha, $GENERIC() *a, integer *lda, |
| 9588 |
$GENERIC() *b, integer *ldb, $GENERIC() *beta, $GENERIC() *c__, |
| 9589 |
integer *ldc); |
| 9590 |
integer kk = $transa() ? $SIZE(m) : $SIZE(n); |
| 9591 |
|
| 9592 |
if ($transa()) |
| 9593 |
ptransa = \'T\'; |
| 9594 |
|
| 9595 |
if ($transb()) |
| 9596 |
ptransb = \'T\'; |
| 9597 |
|
| 9598 |
FORTRAN($TFD(s,d)gemm)( |
| 9599 |
&ptransa, |
| 9600 |
&ptransb, |
| 9601 |
&(integer){$SIZE(r)}, |
| 9602 |
&(integer){$SIZE(s)}, |
| 9603 |
&kk, |
| 9604 |
$P(alpha), |
| 9605 |
$P(A), |
| 9606 |
&(integer){$SIZE(m)}, |
| 9607 |
$P(B), |
| 9608 |
&(integer){$SIZE(p)}, |
| 9609 |
$P(beta), |
| 9610 |
$P(C), |
| 9611 |
&(integer){$SIZE(r)}); |
| 9612 |
', |
| 9613 |
Doc => ' |
| 9614 |
=for ref |
| 9615 |
|
| 9616 |
Performs one of the matrix-matrix operations |
| 9617 |
|
| 9618 |
C := alpha*op( A )*op( B ) + beta*C, |
| 9619 |
where op( X ) is one of p( X ) = X or op( X ) = X\', |
| 9620 |
alpha and beta are scalars, and A, B and C are matrices, with op( A ) |
| 9621 |
an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. |
| 9622 |
|
| 9623 |
Parameters |
| 9624 |
========== |
| 9625 |
transa: On entry, transa specifies the form of op( A ) to be used in |
| 9626 |
the matrix multiplication as follows: |
| 9627 |
transa = 0, op( A ) = A. |
| 9628 |
transa = 1, op( A ) = A\'. |
| 9629 |
|
| 9630 |
transb: On entry, transb specifies the form of op( B ) to be used in |
| 9631 |
the matrix multiplication as follows: |
| 9632 |
transb = 0, op( B ) = B. |
| 9633 |
transb = 1, op( B ) = B\'. |
| 9634 |
|
| 9635 |
alpha: On entry, alpha specifies the scalar alpha. |
| 9636 |
|
| 9637 |
A: Before entry with transa = 0, the leading m by k |
| 9638 |
part of the array A must contain the matrix A, otherwise |
| 9639 |
the leading k by m part of the array A must contain the |
| 9640 |
matrix A. |
| 9641 |
|
| 9642 |
B: Before entry with transb = 0, the leading k by n |
| 9643 |
part of the array B must contain the matrix B, otherwise |
| 9644 |
the leading n by k part of the array B must contain the |
| 9645 |
matrix B. |
| 9646 |
|
| 9647 |
beta: On entry, beta specifies the scalar beta. When beta is |
| 9648 |
supplied as zero then C need not be set on input. |
| 9649 |
|
| 9650 |
C: Before entry, the leading m by n part of the array C must |
| 9651 |
contain the matrix C, except when beta is zero, in which |
| 9652 |
case C need not be set on entry. |
| 9653 |
On exit, the array C is overwritten by the m by n matrix |
| 9654 |
( alpha*op( A )*op( B ) + beta*C ). |
| 9655 |
|
| 9656 |
=for example |
| 9657 |
|
| 9658 |
$a = random(5,4); |
| 9659 |
$b = random(5,4); |
| 9660 |
$alpha = pdl(0.5); |
| 9661 |
$beta = pdl(0); |
| 9662 |
$c = zeroes(5,5); |
| 9663 |
gemm($a, 0, 1,$b, $alpha, $beta, $c); |
| 9664 |
'); |
| 9665 |
|
| 9666 |
if ($config{CBLAS}){ |
| 9667 |
|
| 9668 |
pp_def("rmgemm", |
| 9669 |
HandleBad => 0, |
| 9670 |
Pars => 'A(m,n); int transa(); int transb(); B(p,q);alpha(); beta(); [io]C(r,s)', |
| 9671 |
GenericTypes => [F,D], |
| 9672 |
Code => ' |
| 9673 |
int ptransa = CblasNoTrans; |
| 9674 |
int ptransb = CblasNoTrans; |
| 9675 |
|
| 9676 |
extern void cblas_$TFD(s,d)gemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, |
| 9677 |
const enum CBLAS_TRANSPOSE TransB, const int M, const int N, |
| 9678 |
const int K, const $GENERIC() alpha, const $GENERIC() *A, |
| 9679 |
const int lda, const $GENERIC() *B, const int ldb, |
| 9680 |
const $GENERIC() beta, $GENERIC() *C, const int ldc); |
| 9681 |
integer kk = $transa() ? $SIZE(n) : $SIZE(m); |
| 9682 |
|
| 9683 |
if ($transa()) |
| 9684 |
ptransa = CblasTrans; |
| 9685 |
|
| 9686 |
if ($transb()) |
| 9687 |
ptransb = CblasTrans; |
| 9688 |
|
| 9689 |
|
| 9690 |
$TFD(cblas_sgemm,cblas_dgemm)( |
| 9691 |
CblasRowMajor, |
| 9692 |
ptransa, |
| 9693 |
ptransb, |
| 9694 |
$SIZE(s), |
| 9695 |
$SIZE(r), |
| 9696 |
kk, |
| 9697 |
$alpha(), |
| 9698 |
$P(A), |
| 9699 |
$SIZE(m), |
| 9700 |
$P(B), |
| 9701 |
$SIZE(p), |
| 9702 |
$beta(), |
| 9703 |
$P(C), |
| 9704 |
$SIZE(r)); |
| 9705 |
', |
| 9706 |
Doc => ' |
| 9707 |
|
| 9708 |
=for ref |
| 9709 |
|
| 9710 |
Row major version of gemm |
| 9711 |
|
| 9712 |
=for example |
| 9713 |
|
| 9714 |
$a = random(5,4); |
| 9715 |
$b = random(5,4); |
| 9716 |
$alpha = pdl(0.5); |
| 9717 |
$beta = pdl(0); |
| 9718 |
$c = zeroes(4,4); |
| 9719 |
rmgemm($a, 0, 1,$b, $alpha, $beta, $c); |
| 9720 |
'); |
| 9721 |
} |
| 9722 |
|
| 9723 |
pp_def("mmult", |
| 9724 |
HandleBad => 0, |
| 9725 |
Pars => 'A(m,n); B(p,m); [o]C(p,n)', |
| 9726 |
GenericTypes => [F,D], |
| 9727 |
Code => ' |
| 9728 |
char ptrans = \'N\'; |
| 9729 |
extern int FORTRAN($TFD(s,d)gemm)(char *transa, char *transb, integer *m, integer * |
| 9730 |
n, integer *k, $GENERIC() *alpha, $GENERIC() *a, integer *lda, |
| 9731 |
$GENERIC() *b, integer *ldb, $GENERIC() *beta, $GENERIC() *c__, |
| 9732 |
integer *ldc); |
| 9733 |
$GENERIC() alpha = 1; |
| 9734 |
$GENERIC() beta = 0; |
| 9735 |
|
| 9736 |
FORTRAN($TFD(s,d)gemm)( |
| 9737 |
&ptrans, |
| 9738 |
&ptrans, |
| 9739 |
&(integer){$SIZE(p)}, |
| 9740 |
&(integer){$SIZE(n)}, |
| 9741 |
&(integer){$SIZE(m)}, |
| 9742 |
&alpha, |
| 9743 |
$P(B), |
| 9744 |
&(integer){$SIZE(p)}, |
| 9745 |
$P(A), |
| 9746 |
&(integer){$SIZE(m)}, |
| 9747 |
&beta, |
| 9748 |
$P(C), |
| 9749 |
&(integer){$SIZE(p)}); |
| 9750 |
', |
| 9751 |
Doc => ' |
| 9752 |
|
| 9753 |
=for ref |
| 9754 |
|
| 9755 |
Blas matrix multiplication based on gemm |
| 9756 |
|
| 9757 |
'); |
| 9758 |
if ($config{STRASSEN}){ |
| 9759 |
pp_def("smmult", |
| 9760 |
HandleBad => 0, |
| 9761 |
Pars => 'A(m,n); B(p,m); [o]C(p,n)', |
| 9762 |
GenericTypes => [F,D], |
| 9763 |
Code => ' |
| 9764 |
char ptrans = \'N\'; |
| 9765 |
extern int FORTRAN($TFD(s,d)gemmb)(char *transa, char *transb, integer *m, integer * |
| 9766 |
n, integer *k, $GENERIC() *alpha, $GENERIC() *a, integer *lda, |
| 9767 |
$GENERIC() *b, integer *ldb, $GENERIC() *beta, $GENERIC() *c__, |
| 9768 |
integer *ldc); |
| 9769 |
$GENERIC() alpha = 1; |
| 9770 |
$GENERIC() beta = 0; |
| 9771 |
|
| 9772 |
FORTRAN($TFD(s,d)gemmb)( |
| 9773 |
&ptrans, |
| 9774 |
&ptrans, |
| 9775 |
&(integer){$SIZE(p)}, |
| 9776 |
&(integer){$SIZE(n)}, |
| 9777 |
&(integer){$SIZE(m)}, |
| 9778 |
&alpha, |
| 9779 |
$P(B), |
| 9780 |
&(integer){$SIZE(p)}, |
| 9781 |
$P(A), |
| 9782 |
&(integer){$SIZE(m)}, |
| 9783 |
&beta, |
| 9784 |
$P(C), |
| 9785 |
&(integer){$SIZE(p)}); |
| 9786 |
', |
| 9787 |
Doc => ' |
| 9788 |
|
| 9789 |
=for ref |
| 9790 |
|
| 9791 |
Blas matrix multiplication based on Strassen Algorithm. |
| 9792 |
|
| 9793 |
'); |
| 9794 |
} |
| 9795 |
|
| 9796 |
pp_def("crossprod", |
| 9797 |
HandleBad => 0, |
| 9798 |
Pars => 'A(n,m); B(p,m); [o]C(p,n)', |
| 9799 |
GenericTypes => [F,D], |
| 9800 |
Code => ' |
| 9801 |
|
| 9802 |
char btrans = \'N\'; |
| 9803 |
char atrans = \'T\'; |
| 9804 |
extern int FORTRAN($TFD(s,d)gemm)(char *transa, char *transb, integer *m, integer * |
| 9805 |
n, integer *k, $GENERIC() *alpha, $GENERIC() *a, integer *lda, |
| 9806 |
$GENERIC() *b, integer *ldb, $GENERIC() *beta, $GENERIC() *c__, |
| 9807 |
integer *ldc); |
| 9808 |
$GENERIC() alpha = 1; |
| 9809 |
$GENERIC() beta = 0; |
| 9810 |
|
| 9811 |
FORTRAN($TFD(s,d)gemm)( |
| 9812 |
&btrans, |
| 9813 |
&atrans, |
| 9814 |
&(integer){$SIZE(p)}, |
| 9815 |
&(integer){$SIZE(n)}, |
| 9816 |
&(integer){$SIZE(m)}, |
| 9817 |
&alpha, |
| 9818 |
$P(B), |
| 9819 |
&(integer){$SIZE(p)}, |
| 9820 |
$P(A), |
| 9821 |
&(integer){$SIZE(n)}, |
| 9822 |
&beta, |
| 9823 |
$P(C), |
| 9824 |
&(integer){$SIZE(p)}); |
| 9825 |
', |
| 9826 |
Doc => ' |
| 9827 |
|
| 9828 |
=for ref |
| 9829 |
|
| 9830 |
Blas matrix cross product based on gemm |
| 9831 |
|
| 9832 |
'); |
| 9833 |
|
| 9834 |
pp_def("syrk", |
| 9835 |
HandleBad => 0, |
| 9836 |
Pars => 'A(m,n); int uplo(); int trans(); alpha(); beta(); [io]C(p,p)', |
| 9837 |
GenericTypes => [F,D], |
| 9838 |
Code => ' |
| 9839 |
char puplo = \'U\'; |
| 9840 |
char ptrans = \'N\'; |
| 9841 |
|
| 9842 |
extern int FORTRAN($TFD(s,d)syrk)(char *uplo, char *trans, integer *n, integer *k, |
| 9843 |
$GENERIC() *alpha, $GENERIC() *a, integer *lda, $GENERIC() *beta, |
| 9844 |
$GENERIC() *c__, integer *ldc); |
| 9845 |
integer kk = $trans() ? $SIZE(m) : $SIZE(n); |
| 9846 |
|
| 9847 |
if ($uplo()) |
| 9848 |
puplo = \'L\'; |
| 9849 |
|
| 9850 |
if ($trans()) |
| 9851 |
ptrans = \'T\'; |
| 9852 |
|
| 9853 |
|
| 9854 |
FORTRAN($TFD(s,d)syrk)( |
| 9855 |
&puplo, |
| 9856 |
&ptrans, |
| 9857 |
&(integer){$SIZE(p)}, |
| 9858 |
&kk, |
| 9859 |
$P(alpha), |
| 9860 |
$P(A), |
| 9861 |
&(integer){$SIZE(m)}, |
| 9862 |
$P(beta), |
| 9863 |
$P(C), |
| 9864 |
&(integer){$SIZE(p)}); |
| 9865 |
', |
| 9866 |
Doc => ' |
| 9867 |
|
| 9868 |
=for ref |
| 9869 |
|
| 9870 |
Performs one of the symmetric rank k operations |
| 9871 |
|
| 9872 |
C := alpha*A*A\' + beta*C, |
| 9873 |
|
| 9874 |
or |
| 9875 |
|
| 9876 |
C := alpha*A\'*A + beta*C, |
| 9877 |
|
| 9878 |
where alpha and beta are scalars, C is an n by n symmetric matrix |
| 9879 |
and A is an n by k matrix in the first case and a k by n matrix |
| 9880 |
in the second case. |
| 9881 |
|
| 9882 |
Parameters |
| 9883 |
========== |
| 9884 |
uplo: On entry, uplo specifies whether the upper or lower |
| 9885 |
triangular part of the array C is to be referenced as |
| 9886 |
follows: |
| 9887 |
uplo = 0 Only the upper triangular part of C |
| 9888 |
is to be referenced. |
| 9889 |
uplo = 1 Only the lower triangular part of C |
| 9890 |
is to be referenced. |
| 9891 |
Unchanged on exit. |
| 9892 |
|
| 9893 |
trans: On entry, trans specifies the operation to be performed as |
| 9894 |
follows: |
| 9895 |
trans = 0 C := alpha*A*A\' + beta*C. |
| 9896 |
trans = 1 C := alpha*A\'*A + beta*C. |
| 9897 |
|
| 9898 |
alpha: On entry, alpha specifies the scalar alpha. |
| 9899 |
Unchanged on exit. |
| 9900 |
|
| 9901 |
A: Before entry with trans = 0, the leading n by k |
| 9902 |
part of the array A must contain the matrix A, otherwise |
| 9903 |
the leading k by n part of the array A must contain the |
| 9904 |
matrix A. |
| 9905 |
|
| 9906 |
beta: On entry, beta specifies the scalar beta. |
| 9907 |
|
| 9908 |
C: Before entry with uplo = 0, the leading n by n |
| 9909 |
upper triangular part of the array C must contain the upper |
| 9910 |
triangular part of the symmetric matrix and the strictly |
| 9911 |
lower triangular part of C is not referenced. On exit, the |
| 9912 |
upper triangular part of the array C is overwritten by the |
| 9913 |
upper triangular part of the updated matrix. |
| 9914 |
Before entry with uplo = 1, the leading n by n |
| 9915 |
lower triangular part of the array C must contain the lower |
| 9916 |
triangular part of the symmetric matrix and the strictly |
| 9917 |
upper triangular part of C is not referenced. On exit, the |
| 9918 |
lower triangular part of the array C is overwritten by the |
| 9919 |
lower triangular part of the updated matrix. |
| 9920 |
|
| 9921 |
=for example |
| 9922 |
|
| 9923 |
$a = random(5,4); |
| 9924 |
$b = zeroes(5,5); |
| 9925 |
$alpha = 1; |
| 9926 |
$beta = 0; |
| 9927 |
syrk ($a, 1,0,$alpha, $beta , $b); |
| 9928 |
|
| 9929 |
'); |
| 9930 |
|
| 9931 |
if ($config{CBLAS}){ |
| 9932 |
pp_def("rmsyrk", |
| 9933 |
HandleBad => 0, |
| 9934 |
Pars => 'A(m,n); int uplo(); int trans(); alpha(); beta(); [io]C(p,p)', |
| 9935 |
GenericTypes => [F,D], |
| 9936 |
Code => ' |
| 9937 |
|
| 9938 |
int puplo = 121; |
| 9939 |
int ptrans = 111; |
| 9940 |
|
| 9941 |
extern void cblas_$TFD(s,d)syrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, |
| 9942 |
const enum CBLAS_TRANSPOSE Trans, const int N, const int K, |
| 9943 |
const $GENERIC() alpha, const $GENERIC() *A, const int lda, |
| 9944 |
const $GENERIC() beta, $GENERIC() *C, const int ldc); |
| 9945 |
integer kk = $trans() ? $SIZE(n) : $SIZE(m); |
| 9946 |
|
| 9947 |
if ($uplo()) |
| 9948 |
puplo = 122; |
| 9949 |
|
| 9950 |
if ($trans()) |
| 9951 |
ptrans = 112; |
| 9952 |
|
| 9953 |
|
| 9954 |
$TFD(cblas_ssyrk,cblas_dsyrk)( |
| 9955 |
101, |
| 9956 |
puplo, |
| 9957 |
ptrans, |
| 9958 |
$SIZE(p), |
| 9959 |
kk, |
| 9960 |
$alpha(), |
| 9961 |
$P(A), |
| 9962 |
$SIZE(m), |
| 9963 |
$beta(), |
| 9964 |
$P(C), |
| 9965 |
$SIZE(p)); |
| 9966 |
', |
| 9967 |
Doc => ' |
| 9968 |
|
| 9969 |
=for ref |
| 9970 |
|
| 9971 |
Row major version of syrk |
| 9972 |
|
| 9973 |
=for example |
| 9974 |
|
| 9975 |
$a = random(5,4); |
| 9976 |
$b = zeroes(4,4); |
| 9977 |
$alpha = 1; |
| 9978 |
$beta = 0; |
| 9979 |
rmsyrk ($a, 1,0,$alpha, $beta , $b); |
| 9980 |
|
| 9981 |
'); |
| 9982 |
|
| 9983 |
} |
| 9984 |
|
| 9985 |
pp_def("dot", |
| 9986 |
HandleBad => 0, |
| 9987 |
Pars => 'a(n);b(n);[o]c()', |
| 9988 |
GenericTypes => [F,D], |
| 9989 |
Code => ' |
| 9990 |
extern $GENERIC() FORTRAN($TFD(s,d)dot)(integer *n, $GENERIC() *dx, integer *incx, $GENERIC() *dy, |
| 9991 |
integer *incy); |
| 9992 |
$c() = FORTRAN($TFD(s,d)dot)( |
| 9993 |
&(integer){$SIZE(n)}, |
| 9994 |
$P(a), |
| 9995 |
&(integer){1}, |
| 9996 |
$P(b), |
| 9997 |
&(integer){1}); |
| 9998 |
', |
| 9999 |
Doc => ' |
| 10000 |
|
| 10001 |
=for ref |
| 10002 |
|
| 10003 |
Dot product of two vectors using Blas. |
| 10004 |
|
| 10005 |
=for example |
| 10006 |
|
| 10007 |
$a = random(5); |
| 10008 |
$b = random(5); |
| 10009 |
$c = dot($a, $b) |
| 10010 |
|
| 10011 |
'); |
| 10012 |
|
| 10013 |
|
| 10014 |
pp_def("axpy", |
| 10015 |
HandleBad => 0, |
| 10016 |
Pars => 'a(n); alpha();[io]b(m)', |
| 10017 |
GenericTypes => [F,D], |
| 10018 |
Code => ' |
| 10019 |
extern int FORTRAN($TFD(s,d)axpy)(integer *n, $GENERIC() *da, $GENERIC() *dx, |
| 10020 |
integer *incx, $GENERIC() *dy, integer *incy); |
| 10021 |
FORTRAN($TFD(s,d)axpy)( |
| 10022 |
&(integer){$SIZE(n)}, |
| 10023 |
$P(alpha), |
| 10024 |
$P(a), |
| 10025 |
&(integer){1}, |
| 10026 |
$P(b), |
| 10027 |
&(integer){1}); |
| 10028 |
', |
| 10029 |
Doc => ' |
| 10030 |
|
| 10031 |
=for ref |
| 10032 |
|
| 10033 |
Linear combination of vectors ax + b using Blas. |
| 10034 |
Returns result in b. |
| 10035 |
|
| 10036 |
|
| 10037 |
=for example |
| 10038 |
|
| 10039 |
$a = random(5); |
| 10040 |
$b = random(5); |
| 10041 |
axpy($a, 12, $b) |
| 10042 |
|
| 10043 |
'); |
| 10044 |
|
| 10045 |
pp_def("nrm2", |
| 10046 |
HandleBad => 0, |
| 10047 |
Pars => 'a(n);[o]b()', |
| 10048 |
GenericTypes => [F,D], |
| 10049 |
Code => ' |
| 10050 |
extern $GENERIC() FORTRAN($TFD(s,d)nrm2)(integer *n, $GENERIC() *dx, |
| 10051 |
integer *incx); |
| 10052 |
$b() = FORTRAN($TFD(s,d)nrm2)( |
| 10053 |
&(integer){$SIZE(n)}, |
| 10054 |
$P(a), |
| 10055 |
&(integer){1}); |
| 10056 |
', |
| 10057 |
Doc => ' |
| 10058 |
|
| 10059 |
=for ref |
| 10060 |
|
| 10061 |
Euclidean norm of a vector using Blas. |
| 10062 |
|
| 10063 |
=for example |
| 10064 |
|
| 10065 |
$a = random(5); |
| 10066 |
$norm2 = nrm2($a) |
| 10067 |
|
| 10068 |
'); |
| 10069 |
|
| 10070 |
pp_def("asum", |
| 10071 |
HandleBad => 0, |
| 10072 |
Pars => 'a(n);[o]b()', |
| 10073 |
GenericTypes => [F,D], |
| 10074 |
Code => ' |
| 10075 |
extern $GENERIC() FORTRAN($TFD(s,d)asum)(integer *n, $GENERIC() *dx, |
| 10076 |
integer *incx); |
| 10077 |
$b() = FORTRAN($TFD(s,d)asum)( |
| 10078 |
&(integer){$SIZE(n)}, |
| 10079 |
$P(a), |
| 10080 |
&(integer){1}); |
| 10081 |
', |
| 10082 |
Doc => ' |
| 10083 |
|
| 10084 |
=for ref |
| 10085 |
|
| 10086 |
Sum of absolute values of a vector using Blas. |
| 10087 |
|
| 10088 |
=for example |
| 10089 |
|
| 10090 |
$a = random(5); |
| 10091 |
$absum = asum($a) |
| 10092 |
|
| 10093 |
'); |
| 10094 |
|
| 10095 |
pp_def("scal", |
| 10096 |
HandleBad => 0, |
| 10097 |
Pars => '[io]a(n);scale()', |
| 10098 |
GenericTypes => [F,D], |
| 10099 |
Code => ' |
| 10100 |
extern int FORTRAN($TFD(s,d)scal)(integer *n, $GENERIC() *sa, |
| 10101 |
$GENERIC() *dx, integer *incx); |
| 10102 |
FORTRAN($TFD(s,d)scal)( |
| 10103 |
&(integer){$SIZE(n)}, |
| 10104 |
$P(scale), |
| 10105 |
$P(a), |
| 10106 |
&(integer){1}); |
| 10107 |
', |
| 10108 |
Doc => ' |
| 10109 |
|
| 10110 |
=for ref |
| 10111 |
|
| 10112 |
Scale a vector by a constant using Blas. |
| 10113 |
|
| 10114 |
=for example |
| 10115 |
|
| 10116 |
$a = random(5); |
| 10117 |
$a->scal(0.5) |
| 10118 |
|
| 10119 |
'); |
| 10120 |
|
| 10121 |
pp_def("rot", |
| 10122 |
HandleBad => 0, |
| 10123 |
Pars => '[io]a(n);c(); s();[io]b(n)', |
| 10124 |
GenericTypes => [F,D], |
| 10125 |
Code => ' |
| 10126 |
extern int FORTRAN($TFD(s,d)rot)(integer *n, $GENERIC() *dx, |
| 10127 |
integer *incx, $GENERIC() *dy, integer *incy, $GENERIC() *c, $GENERIC() *s); |
| 10128 |
FORTRAN($TFD(s,d)rot)( |
| 10129 |
&(integer){$SIZE(n)}, |
| 10130 |
$P(a), |
| 10131 |
&(integer){1}, |
| 10132 |
$P(b), |
| 10133 |
&(integer){1}, |
| 10134 |
$P(c), |
| 10135 |
$P(s) |
| 10136 |
); |
| 10137 |
', |
| 10138 |
Doc => ' |
| 10139 |
|
| 10140 |
=for ref |
| 10141 |
|
| 10142 |
Applies plane rotation using Blas. |
| 10143 |
|
| 10144 |
=for example |
| 10145 |
|
| 10146 |
$a = random(5); |
| 10147 |
$b = random(5); |
| 10148 |
rot($a, 0.5, 0.7, $b) |
| 10149 |
|
| 10150 |
'); |
| 10151 |
|
| 10152 |
pp_def("rotg", |
| 10153 |
HandleBad => 0, |
| 10154 |
Pars => '[io]a();[io]b();[o]c(); [o]s()', |
| 10155 |
GenericTypes => [F,D], |
| 10156 |
Code => ' |
| 10157 |
extern int FORTRAN($TFD(s,d)rotg)($GENERIC() *dx, |
| 10158 |
$GENERIC() *dy, $GENERIC() *c, $GENERIC() *s); |
| 10159 |
|
| 10160 |
FORTRAN($TFD(s,d)rotg)( |
| 10161 |
$P(a), |
| 10162 |
$P(b), |
| 10163 |
$P(c), |
| 10164 |
$P(s) |
| 10165 |
); |
| 10166 |
', |
| 10167 |
Doc => ' |
| 10168 |
|
| 10169 |
=for ref |
| 10170 |
|
| 10171 |
Generates plane rotation using Blas. |
| 10172 |
|
| 10173 |
=for example |
| 10174 |
|
| 10175 |
$a = sequence(4); |
| 10176 |
rotg($a(0), $a(1),$a(2),$a(3)) |
| 10177 |
|
| 10178 |
'); |
| 10179 |
|
| 10180 |
################################################################################ |
| 10181 |
# |
| 10182 |
# LAPACK AUXILIARY ROUTINES |
| 10183 |
# |
| 10184 |
################################################################################ |
| 10185 |
pp_def("lasrt", |
| 10186 |
HandleBad => 0, |
| 10187 |
Pars => '[io]d(n); int id();int [o]info()', |
| 10188 |
GenericTypes => [F,D], |
| 10189 |
Code => ' |
| 10190 |
char pwork = \'I\'; |
| 10191 |
extern int FORTRAN($TFD(s,d)lasrt)(char *id, integer *n, $GENERIC() *d__, integer * |
| 10192 |
info); |
| 10193 |
if ($id()) |
| 10194 |
pwork = \'D\'; |
| 10195 |
|
| 10196 |
FORTRAN($TFD(s,d)lasrt)( |
| 10197 |
&pwork, |
| 10198 |
&(integer){$SIZE(n)}, |
| 10199 |
$P(d), |
| 10200 |
$P(info)); |
| 10201 |
', |
| 10202 |
Doc => ' |
| 10203 |
|
| 10204 |
=for ref |
| 10205 |
|
| 10206 |
Sort the numbers in d in increasing order (if id = 0) or |
| 10207 |
in decreasing order (if id = 1 ). |
| 10208 |
|
| 10209 |
Use Quick Sort, reverting to Insertion sort on arrays of |
| 10210 |
size <= 20. Dimension of stack limits N to about 2**32. |
| 10211 |
|
| 10212 |
Arguments |
| 10213 |
========= |
| 10214 |
|
| 10215 |
id: = 0: sort d in increasing order; |
| 10216 |
= 1: sort d in decreasing order. |
| 10217 |
|
| 10218 |
d: On entry, the array to be sorted. |
| 10219 |
On exit, d has been sorted into increasing order |
| 10220 |
(d(1) <= ... <= d(N) ) or into decreasing order |
| 10221 |
(d(1) >= ... >= d(N) ), depending on id. |
| 10222 |
|
| 10223 |
info: = 0: successful exit |
| 10224 |
< 0: if info = -i, the i-th argument had an illegal value |
| 10225 |
|
| 10226 |
=for example |
| 10227 |
|
| 10228 |
$a = random(5); |
| 10229 |
lasrt ($a, 0, ($info = null)); |
| 10230 |
'); |
| 10231 |
|
| 10232 |
|
| 10233 |
|
| 10234 |
pp_def("lacpy", |
| 10235 |
HandleBad => 0, |
| 10236 |
Pars => 'A(m,n); int uplo(); [o]B(p,n)', |
| 10237 |
GenericTypes => [F,D], |
| 10238 |
Code => ' |
| 10239 |
char puplo; |
| 10240 |
extern int FORTRAN($TFD(s,d)lacpy)(char *uplo, integer *m, integer *n, $GENERIC() * |
| 10241 |
a, integer *lda, $GENERIC() *b, integer *ldb); |
| 10242 |
switch ($uplo()) |
| 10243 |
{ |
| 10244 |
case 0: puplo = \'U\'; |
| 10245 |
break; |
| 10246 |
case 1: puplo = \'L\'; |
| 10247 |
break; |
| 10248 |
default: puplo = \'A\'; |
| 10249 |
} |
| 10250 |
|
| 10251 |
FORTRAN($TFD(s,d)lacpy)( |
| 10252 |
&puplo, |
| 10253 |
&(integer){$SIZE(m)}, |
| 10254 |
&(integer){$SIZE(n)}, |
| 10255 |
$P(A), |
| 10256 |
&(integer){$SIZE(m)}, |
| 10257 |
$P(B), |
| 10258 |
&(integer){$SIZE(p)}); |
| 10259 |
', |
| 10260 |
Doc => ' |
| 10261 |
|
| 10262 |
=for ref |
| 10263 |
|
| 10264 |
Copies all or part of a two-dimensional matrix A to another |
| 10265 |
matrix B. |
| 10266 |
|
| 10267 |
Arguments |
| 10268 |
========= |
| 10269 |
|
| 10270 |
uplo: Specifies the part of the matrix A to be copied to B. |
| 10271 |
= 0: Upper triangular part |
| 10272 |
= 1: Lower triangular part |
| 10273 |
Otherwise: All of the matrix A |
| 10274 |
|
| 10275 |
A: The m by n matrix A. If uplo = 0, only the upper triangle |
| 10276 |
or trapezoid is accessed; if uplo = 1, only the lower |
| 10277 |
triangle or trapezoid is accessed. |
| 10278 |
|
| 10279 |
B: On exit, B = A in the locations specified by uplo. |
| 10280 |
|
| 10281 |
=for example |
| 10282 |
|
| 10283 |
$a = random(5,5); |
| 10284 |
$b = zeroes($a); |
| 10285 |
lacpy ($a, 0, $b); |
| 10286 |
'); |
| 10287 |
|
| 10288 |
|
| 10289 |
pp_def("laswp", |
| 10290 |
HandleBad => 0, |
| 10291 |
Pars => '[io]A(m,n);int k1();int k2(); int ipiv(p);int inc()', |
| 10292 |
GenericTypes => [F,D], |
| 10293 |
Code => ' |
| 10294 |
extern int FORTRAN($TFD(s,d)laswp)(integer *n, $GENERIC() *a, integer *lda, integer |
| 10295 |
*k1, integer *k2, integer *ipiv, integer *incx); |
| 10296 |
|
| 10297 |
FORTRAN($TFD(s,d)laswp)( |
| 10298 |
&(integer){$SIZE(n)}, |
| 10299 |
$P(A), |
| 10300 |
&(integer){$SIZE(m)}, |
| 10301 |
$P(k1), |
| 10302 |
$P(k2), |
| 10303 |
$P(ipiv), |
| 10304 |
$P(inc)); |
| 10305 |
', |
| 10306 |
Doc => ' |
| 10307 |
|
| 10308 |
=for ref |
| 10309 |
|
| 10310 |
Performs a series of row interchanges on the matrix A. |
| 10311 |
One row interchange is initiated for each of rows k1 through k2 of A. |
| 10312 |
Doesn\'t use PDL indices (start = 1). |
| 10313 |
|
| 10314 |
Arguments |
| 10315 |
========= |
| 10316 |
|
| 10317 |
A: On entry, the matrix of column dimension N to which the row |
| 10318 |
interchanges will be applied. |
| 10319 |
On exit, the permuted matrix. |
| 10320 |
|
| 10321 |
k1: The first element of ipiv for which a row interchange will |
| 10322 |
be done. |
| 10323 |
|
| 10324 |
k2: The last element of ipiv for which a row interchange will |
| 10325 |
be done. |
| 10326 |
|
| 10327 |
ipiv: The vector of pivot indices. Only the elements in positions |
| 10328 |
k1 through k2 of ipiv are accessed. |
| 10329 |
ipiv(k) = l implies rows k and l are to be interchanged. |
| 10330 |
|
| 10331 |
inc: The increment between successive values of ipiv. If ipiv |
| 10332 |
is negative, the pivots are applied in reverse order. |
| 10333 |
|
| 10334 |
=for example |
| 10335 |
|
| 10336 |
$a = random(5,5); |
| 10337 |
# reverse row (col for PDL) |
| 10338 |
$b = pdl([5,4,3,2,1]); |
| 10339 |
$a->laswp(1,2,$b,1); |
| 10340 |
'); |
| 10341 |
|
| 10342 |
pp_def("lamch", |
| 10343 |
HandleBad => 0, |
| 10344 |
Pars => 'cmach(); [o]precision()', |
| 10345 |
GenericTypes => [F,D], |
| 10346 |
Inplace => 1, |
| 10347 |
Code => ' |
| 10348 |
char pcmach; |
| 10349 |
int tmp; |
| 10350 |
extern $GENERIC() FORTRAN($TFD(s,d)lamch)(char *cmach); |
| 10351 |
|
| 10352 |
tmp = (int ) $cmach(); |
| 10353 |
switch (tmp) |
| 10354 |
{ |
| 10355 |
case 1: pcmach = \'S\'; |
| 10356 |
break; |
| 10357 |
case 2: pcmach = \'B\'; |
| 10358 |
break; |
| 10359 |
case 3: pcmach = \'P\'; |
| 10360 |
break; |
| 10361 |
case 4: pcmach = \'N\'; |
| 10362 |
break; |
| 10363 |
case 5: pcmach = \'R\'; |
| 10364 |
break; |
| 10365 |
case 6: pcmach = \'M\'; |
| 10366 |
break; |
| 10367 |
case 7: pcmach = \'U\'; |
| 10368 |
break; |
| 10369 |
case 8: pcmach = \'L\'; |
| 10370 |
break; |
| 10371 |
case 9: pcmach = \'O\'; |
| 10372 |
break; |
| 10373 |
default: pcmach = \'E\'; |
| 10374 |
} |
| 10375 |
$precision() = FORTRAN($TFD(s,d)lamch)(&pcmach); |
| 10376 |
', |
| 10377 |
Doc => ' |
| 10378 |
|
| 10379 |
=for ref |
| 10380 |
|
| 10381 |
Determines precision machine parameters. |
| 10382 |
Works inplace. |
| 10383 |
|
| 10384 |
Arguments |
| 10385 |
========= |
| 10386 |
|
| 10387 |
cmach: Specifies the value to be returned by lamch: |
| 10388 |
= 0 LAMCH := eps |
| 10389 |
= 1 LAMCH := sfmin |
| 10390 |
= 2 LAMCH := base |
| 10391 |
= 3 LAMCH := eps*base |
| 10392 |
= 4 LAMCH := t |
| 10393 |
= 5 LAMCH := rnd |
| 10394 |
= 6 LAMCH := emin |
| 10395 |
= 7 LAMCH := rmin |
| 10396 |
= 8 LAMCH := emax |
| 10397 |
= 9 LAMCH := rmax |
| 10398 |
|
| 10399 |
where |
| 10400 |
|
| 10401 |
eps = relative machine precision |
| 10402 |
sfmin = safe minimum, such that 1/sfmin does not overflow |
| 10403 |
base = base of the machine |
| 10404 |
prec = eps*base |
| 10405 |
t = number of (base) digits in the mantissa |
| 10406 |
rnd = 1.0 when rounding occurs in addition, 0.0 otherwise |
| 10407 |
emin = minimum exponent before (gradual) underflow |
| 10408 |
rmin = underflow threshold - base**(emin-1) |
| 10409 |
emax = largest exponent before overflow |
| 10410 |
rmax = overflow threshold - (base**emax)*(1-eps) |
| 10411 |
|
| 10412 |
=for example |
| 10413 |
|
| 10414 |
$a = lamch (0); |
| 10415 |
print "EPS is $a for double\n"; |
| 10416 |
'); |
| 10417 |
|
| 10418 |
pp_def("labad", |
| 10419 |
HandleBad => 0, |
| 10420 |
Pars => '[io]small(); [io]large()', |
| 10421 |
GenericTypes => [F,D], |
| 10422 |
Code => ' |
| 10423 |
|
| 10424 |
extern int FORTRAN($TFD(s,d)labad)($GENERIC() *small, $GENERIC() *large); |
| 10425 |
|
| 10426 |
FORTRAN($TFD(s,d)labad)($P(small),$P(large)); |
| 10427 |
', |
| 10428 |
Doc => ' |
| 10429 |
|
| 10430 |
=for ref |
| 10431 |
|
| 10432 |
Takes as input the values computed by C<lamch> for underflow and |
| 10433 |
overflow, and returns the square root of each of these values if the |
| 10434 |
log of large is sufficiently large. This subroutine is intended to |
| 10435 |
identify machines with a large exponent range, such as the Crays, and |
| 10436 |
redefine the underflow and overflow limits to be the square roots of |
| 10437 |
the values computed by C<lamch>. This subroutine is needed because |
| 10438 |
lamch does not compensate for poor arithmetic in the upper half of |
| 10439 |
the exponent range, as is found on a Cray. |
| 10440 |
|
| 10441 |
Arguments |
| 10442 |
========= |
| 10443 |
|
| 10444 |
small: On entry, the underflow threshold as computed by lamch. |
| 10445 |
On exit, if LOG10(large) is sufficiently large, the square |
| 10446 |
root of small, otherwise unchanged. |
| 10447 |
|
| 10448 |
large: On entry, the overflow threshold as computed by lamch. |
| 10449 |
On exit, if LOG10(large) is sufficiently large, the square |
| 10450 |
root of large, otherwise unchanged. |
| 10451 |
|
| 10452 |
=for example |
| 10453 |
|
| 10454 |
$underflow = lamch(7); |
| 10455 |
$overflow = lamch(9); |
| 10456 |
labad ($underflow, $overflow); |
| 10457 |
|
| 10458 |
'); |
| 10459 |
|
| 10460 |
pp_def( |
| 10461 |
'cplx_eigen', |
| 10462 |
Pars => 'eigreval(n);eigimval(n); eigvec(n,p);int fortran();[o]cplx_val(c=2,n);[o]cplx_vec(c=2,n,p)', |
| 10463 |
Code => ' |
| 10464 |
register PDL_Indx i; |
| 10465 |
if ($fortran() && $SIZE(n) != $SIZE(p)) |
| 10466 |
$CROAK("Fortran storage type needs square eigvec, but n=%"IND_FLAG", p=%"IND_FLAG, $SIZE(n), $SIZE(p)); |
| 10467 |
if ($fortran()) { |
| 10468 |
for(i = 0; i < $SIZE(n);i++) { |
| 10469 |
$cplx_val(c=>0,n=>i) = $eigreval(n=>i); |
| 10470 |
$cplx_val(c=>1,n=>i) = $eigimval(n=>i); |
| 10471 |
if ($eigimval(n=>i) == 0) { |
| 10472 |
loop(p) %{ |
| 10473 |
$cplx_vec(c=>0,n=>p,p=>i) = $eigvec(n=>p,p=>i); |
| 10474 |
$cplx_vec(c=>1,n=>p,p=>i) = 0; |
| 10475 |
%} |
| 10476 |
} else { |
| 10477 |
PDL_Indx index = i+1; |
| 10478 |
$cplx_val(c=>0,n=>index) = $eigreval(n=>index); |
| 10479 |
$cplx_val(c=>1,n=>index) = $eigimval(n=>index); |
| 10480 |
loop(p) %{ |
| 10481 |
$cplx_vec(c=>0,n=>p,p=>i) = $cplx_vec(c=>0,n=>p,p=>index) = $eigvec(n=>p,p=>i); |
| 10482 |
$cplx_vec(c=>1,n=>p,p=>i) = $eigvec(n=>p,p=>index); |
| 10483 |
$cplx_vec(c=>1,n=>p,p=>index) = - $eigvec(n=>p,p=>index); |
| 10484 |
%} |
| 10485 |
i = index; |
| 10486 |
} |
| 10487 |
} |
| 10488 |
} else { |
| 10489 |
for(i = 0; i < $SIZE(n);i++) { |
| 10490 |
$cplx_val(c=>0,n=>i) = $eigreval(n=>i); |
| 10491 |
$cplx_val(c=>1,n=>i) = $eigimval(n=>i); |
| 10492 |
if ($eigimval(n=>i) == 0) { |
| 10493 |
loop(p) %{ |
| 10494 |
$cplx_vec(c=>0,n=>i) = $eigvec(n=>i); |
| 10495 |
$cplx_vec(c=>1,n=>i) = 0; |
| 10496 |
%} |
| 10497 |
} else { |
| 10498 |
PDL_Indx index = i+1; |
| 10499 |
$cplx_val(c=>0,n=>index) = $eigreval(n=>index); |
| 10500 |
$cplx_val(c=>1,n=>index) = $eigimval(n=>index); |
| 10501 |
loop(p) %{ |
| 10502 |
$cplx_vec(c=>0,n=>i) = $cplx_vec(c=>0,n=>index) = $eigvec(n=>i); |
| 10503 |
$cplx_vec(c=>1,n=>i) = $eigvec(n=>index); |
| 10504 |
$cplx_vec(c=>1,n=>index) = - $eigvec(n=>index); |
| 10505 |
%} |
| 10506 |
i = index; |
| 10507 |
} |
| 10508 |
} |
| 10509 |
} |
| 10510 |
', |
| 10511 |
PMCode => <<'EOF', |
| 10512 |
sub PDL::cplx_eigen { |
| 10513 |
my ($eigre, $eigim, $eigvec, $fortran, @outs) = @_; |
| 10514 |
my ($outval, $outvec) = @outs ? @outs : (null, null); |
| 10515 |
PDL::_cplx_eigen_int($eigre, $eigim, $eigvec, $fortran, $outval, $outvec); |
| 10516 |
$_ = $_->slice('(0)')->czip($_->slice('(1)')) for $outval, $outvec; |
| 10517 |
($outval, $outvec); |
| 10518 |
} |
| 10519 |
EOF |
| 10520 |
Doc => <<EOT |
| 10521 |
=for ref |
| 10522 |
|
| 10523 |
Output complex eigen-values/vectors from eigen-values/vectors |
| 10524 |
as computed by geev or geevx. |
| 10525 |
'fortran' means fortran storage type. |
| 10526 |
EOT |
| 10527 |
); |
| 10528 |
|
| 10529 |
pp_addhdr(' |
| 10530 |
float ftrace(int n, float *mat); |
| 10531 |
double dtrace(int n, double *mat); |
| 10532 |
'); |
| 10533 |
pp_def('charpol', |
| 10534 |
Pars => 'A(n,n);[o]Y(n,n);[o]out(p=CALC($SIZE(n)+1));', |
| 10535 |
GenericTypes => [F,D], |
| 10536 |
Code => ' |
| 10537 |
int i,k; |
| 10538 |
$GENERIC() *p, b; |
| 10539 |
//$GENERIC() *tmp; |
| 10540 |
char ptrans = \'N\'; |
| 10541 |
extern int FORTRAN($TFD(s,d)gemm)(char *transa, char *transb, integer *m, integer * |
| 10542 |
n, integer *k, $GENERIC() *alpha, $GENERIC() *a, integer *lda, |
| 10543 |
$GENERIC() *b, integer *ldb, $GENERIC() *beta, $GENERIC() *c__, |
| 10544 |
integer *ldc); |
| 10545 |
$GENERIC() alpha = 1; |
| 10546 |
$GENERIC() beta = 0; |
| 10547 |
|
| 10548 |
p = ($GENERIC() * ) malloc ( $SIZE(n) * $SIZE(n) * sizeof($GENERIC())); |
| 10549 |
loop(n0,n1) %{ |
| 10550 |
$Y() = (n0 == n1) ? ($GENERIC()) 1.0 : ($GENERIC()) 0.0; |
| 10551 |
%} |
| 10552 |
$out(p=>0) = 1; |
| 10553 |
|
| 10554 |
i = 0; |
| 10555 |
for (;;) |
| 10556 |
{ |
| 10557 |
i++; |
| 10558 |
FORTRAN($TFD(s,d)gemm)(&ptrans,&ptrans,&(integer){$SIZE(n)},&(integer){$SIZE(n)}, |
| 10559 |
&(integer){$SIZE(n)},&alpha,$P(A),&(integer){$SIZE(n)}, $P(Y), &(integer){$SIZE(n)}, |
| 10560 |
&beta, p, &(integer){$SIZE(n)}); |
| 10561 |
|
| 10562 |
if (i == $SIZE(n)) break; |
| 10563 |
|
| 10564 |
//tmp = $P(Y); |
| 10565 |
//$P(Y) = p; |
| 10566 |
//p = tmp; |
| 10567 |
memmove($P(Y), p, $SIZE(n) * $SIZE(n) * sizeof($GENERIC())); |
| 10568 |
// loop(n1,n0) %{ |
| 10569 |
// $Y() = p[(n1*$SIZE(n))+n0]; |
| 10570 |
// %} |
| 10571 |
|
| 10572 |
b = $out(p=>i) = - $TFD(ftrace,dtrace)($SIZE(n), $P(Y)) / i; |
| 10573 |
loop(n0) %{ $Y(n1=>n0) += b; %} |
| 10574 |
|
| 10575 |
} |
| 10576 |
|
| 10577 |
k = $SIZE(n); |
| 10578 |
$out(p=>k) = - $TFD(ftrace,dtrace)(k, p) / k; |
| 10579 |
if ((k+1) & 1) |
| 10580 |
{ |
| 10581 |
loop(n0,n1) %{ |
| 10582 |
$Y() = -$Y(); |
| 10583 |
%} |
| 10584 |
} |
| 10585 |
free(p); |
| 10586 |
|
| 10587 |
', |
| 10588 |
Doc => 'Compute adjoint matrix and characteristic polynomial', |
| 10589 |
); |
| 10590 |
|
| 10591 |
pp_addpm({At=>'Bot'},<<'EOD'); |
| 10592 |
|
| 10593 |
=head1 AUTHOR |
| 10594 |
|
| 10595 |
Copyright (C) Grégory Vanuxem 2005-2018. |
| 10596 |
|
| 10597 |
This library is free software; you can redistribute it and/or modify |
| 10598 |
it under the terms of the Perl Artistic License as in the file Artistic_2 |
| 10599 |
in this distribution. |
| 10600 |
|
| 10601 |
=cut |
| 10602 |
|
| 10603 |
EOD |
| 10604 |
|
| 10605 |
pp_done(); # you will need this to finish pp processing |