Macaulay2 Engine
Loading...
Searching...
No Matches

◆ norm_of_inverse_via_svd()

bool norm_of_inverse_via_svd ( int size,
complex * A,
double & norm )

Definition at line 1339 of file NAG.cpp.

1340{
1341 bool ret = true;
1342 char doit = 'A'; // other options are 'S' and 'O' for singular vectors only
1343 int rows = size;
1344 int cols = size;
1345 int info;
1346 int min = (rows <= cols) ? rows : cols;
1347
1348 if (min == 0)
1349 {
1350 ERROR("expected a matrix with positive dimensions");
1351 return false;
1352 }
1353
1354 int max = (rows >= cols) ? rows : cols;
1355 int wsize = 4 * min + 2 * max;
1356 double* workspace = newarray_atomic(double, 2 * wsize);
1357 double* rwork = newarray_atomic(double, 5 * max);
1358
1359 double* copyA = (double*)A;
1360 double* u = newarray_atomic(double, 2 * rows * rows);
1361 double* vt = newarray_atomic(double, 2 * cols * cols);
1362 double* sigma = newarray_atomic(double, 2 * min);
1363
1364 zgesvd_(&doit,
1365 &doit,
1366 &rows,
1367 &cols,
1368 copyA,
1369 &rows,
1370 sigma,
1371 u,
1372 &rows,
1373 vt,
1374 &cols,
1375 workspace,
1376 &wsize,
1377 rwork,
1378 &info);
1379
1380 if (info < 0)
1381 {
1382 ERROR("argument passed to zgesvd had an illegal value");
1383 ret = false;
1384 }
1385 else if (info > 0)
1386 {
1387 ERROR("zgesvd did not converge");
1388 ret = false;
1389 }
1390 else
1391 {
1392 if (sigma[size - 1] == 0)
1393 {
1394 ERROR("invertible matrix expected");
1395 ret = false;
1396 }
1397 norm = 1 / sigma[size - 1];
1398 }
1399
1400 freemem(workspace);
1401 freemem(rwork);
1402 // freemem(copyA);
1403 freemem(u);
1404 freemem(vt);
1405 freemem(sigma);
1406
1407 return ret;
1408}
int zgesvd_(char *jobU, char *jobV, int *rows, int *cols, double *A, int *ldA, double *Sigma, double *U, int *ldU, double *VT, int *ldVT, double *w, int *lwork, double *rwork, int *info)
void freemem(void *s)
Definition m2-mem.cpp:103
const int ERROR
Definition m2-mem.cpp:55
const mpreal min(const mpreal &x, const mpreal &y)
Definition mpreal.h:2792
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
#define max(a, b)
Definition polyroots.cpp:52

References ERROR, freemem(), max, newarray_atomic, and zgesvd_().

Referenced by PathTracker::track().