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

◆ SVD_divide_conquer() [1/4]

bool Lapack::SVD_divide_conquer ( const DMatCC * A,
DMatRR * Sigma,
DMatCC * U,
DMatCC * VT )
static

Definition at line 1561 of file lapack.cpp.

1565{
1566 bool ret = true;
1567 char doit = 'A'; // other options are 'S' and 'O' for singular vectors only
1568 int rows = static_cast<int>(A->numRows());
1569 int cols = static_cast<int>(A->numColumns());
1570 int info;
1571 int min = (rows <= cols) ? rows : cols;
1572
1573 if (min == 0)
1574 {
1575 ERROR("expected a matrix with positive dimensions");
1576 return false;
1577 }
1578
1579 int max = (rows >= cols) ? rows : cols;
1580 int wsize = min * min + 2 * min + max;
1581
1582 double *workspace = new double[2 * wsize];
1583 int *iworkspace = new int[8 * min];
1584 double *rwork = new double[5 * min * min + 7 * min]; // documentation not clear
1585
1586 std::vector<double> copyA = make_lapack_array(*A);
1587 std::vector<double> u(2 * rows * rows);
1588 std::vector<double> vt(2 * cols * cols);
1589 std::vector<double> sigma(2 * min);
1590
1591 zgesdd_(&doit,
1592 &rows,
1593 &cols,
1594 copyA.data(),
1595 &rows,
1596 sigma.data(),
1597 u.data(),
1598 &rows,
1599 vt.data(),
1600 &cols,
1601 workspace,
1602 &wsize,
1603 rwork,
1604 iworkspace,
1605 &info);
1606
1607 if (info < 0)
1608 {
1609 ERROR("argument passed to zgesdd had an illegal value");
1610 ret = false;
1611 }
1612 else if (info > 0)
1613 {
1614 ERROR("zgesdd did not converge");
1615 ret = false;
1616 }
1617 else
1618 {
1619 U->resize(rows, rows);
1621 VT->resize(cols, cols);
1622 fill_from_lapack_array(vt, *VT);
1623 Sigma->resize(min, 1);
1624 fill_from_lapack_array(sigma, *Sigma);
1625 }
1626
1627 delete[] workspace;
1628 delete[] iworkspace;
1629 delete[] rwork;
1630
1631 return ret;
1632}
size_t numRows() const
Definition dmat.hpp:144
void resize(size_t new_nrows, size_t new_ncols)
Definition dmat.hpp:157
size_t numColumns() const
Definition dmat.hpp:145
std::vector< double > make_lapack_array(const DMatRR &mat)
Definition lapack.cpp:20
void fill_from_lapack_array(const std::vector< double > &doubles, DMatRR &mat)
Definition lapack.cpp:45
int zgesdd_(char *jobU, 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 *iwork, int *info)
const int ERROR
Definition m2-mem.cpp:55
const mpreal min(const mpreal &x, const mpreal &y)
Definition mpreal.h:2792
#define max(a, b)
Definition polyroots.cpp:52

References ERROR, fill_from_lapack_array(), make_lapack_array(), max, DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), DMat< ACoeffRing >::resize(), and zgesdd_().