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

◆ SVD_divide_conquer() [3/4]

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

Definition at line 636 of file lapack.cpp.

640{
641 bool ret = true;
642 char doit = 'A'; // other options are 'S' and 'O' for singular vectors only
643 int rows = static_cast<int>(A->numRows());
644 int cols = static_cast<int>(A->numColumns());
645 int info;
646 int min = (rows <= cols) ? rows : cols;
647
648 if (min == 0)
649 {
650 ERROR("expected a matrix with positive dimensions");
651 return false;
652 }
653
654 int max = (rows >= cols) ? rows : cols;
655 int wsize = 4 * min * min + max + 9 * min;
656
657 double *workspace = new double[wsize];
658 int* iworkspace = new int[8 * min];
659
660 std::vector<double> copyA = make_lapack_array(*A);
661 std::vector<double> u(rows * rows);
662 std::vector<double> vt(cols * cols);
663 std::vector<double> sigma(min);
664
665 dgesdd_(&doit,
666 &rows,
667 &cols,
668 copyA.data(),
669 &rows,
670 sigma.data(),
671 u.data(),
672 &rows,
673 vt.data(),
674 &cols,
675 workspace,
676 &wsize,
677 iworkspace,
678 &info);
679
680 if (info < 0)
681 {
682 ERROR("argument passed to dgesdd had an illegal value");
683 ret = false;
684 }
685 else if (info > 0)
686 {
687 ERROR("dgesdd did not converge");
688 ret = false;
689 }
690 else
691 {
692 U->resize(rows, rows);
693 VT->resize(cols, cols);
694 Sigma->resize(min, 1);
696 fill_from_lapack_array(vt, *VT);
697 fill_from_lapack_array(sigma, *Sigma);
698 }
699
700 delete [] workspace;
701 delete [] iworkspace;
702
703 return ret;
704}
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 dgesdd_(char *jobU, int *rows, int *cols, double *A, int *ldA, double *Sigma, double *U, int *ldU, double *VT, int *ldVT, double *work, int *lwork, 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 dgesdd_(), ERROR, fill_from_lapack_array(), make_lapack_array(), max, DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), and DMat< ACoeffRing >::resize().