802{
803 bool ret = true;
804 int rows =
static_cast<int>(A->
numRows());
806 int brows =
static_cast<int>(b->
numRows());
807 int bcols =
static_cast<int>(b->
numColumns());
808 double rcond = -1.0;
810 int min = (rows < cols) ? rows : cols;
811 int max = (rows > cols) ? rows : cols;
813 int wsize = 3 *
min + ((tempmax > bcols) ? tempmax : bcols);
814
815 if (brows != rows)
816 {
817 ERROR(
"expected compatible right hand side");
818 return false;
819 }
820
821 if (min == 0 || bcols == 0)
822 {
823 x->resize(cols, bcols);
824 return true;
825 }
826
829 double *workspace = new double[wsize];
830 double *sing =
new double[
min];
831
832 if (rows < cols)
833 {
834
835
836 std::vector<double> copyb2(cols * bcols);
837 for (auto&a : copyb2) a = 0;
838 int bloc = 0;
839 int copyloc = 0;
840 for (int j = 0; j < bcols; j++)
841 {
842 copyloc = j * cols;
843 for (int i = 0; i < brows; i++)
844 {
845 copyb2[copyloc++] = copyb[bloc++];
846 }
847 }
849 }
850
852 &cols,
853 &bcols,
854 copyA.data(),
855 &rows,
856 copyb.data(),
858 sing,
859 &rcond,
860 &rank,
861 workspace,
862 &wsize,
863 &info);
864
865 if (info != 0)
866 {
867 ERROR(
"argument passed to dgelss had an illegal value");
868 ret = false;
869 }
870 else
871 {
872 x->resize(cols, bcols);
873 if (rows > cols)
874 {
875
876 int copyloc = 0;
877 for (int j = 0; j < bcols; j++)
878 {
879 copyloc = j * rows;
880 for (int i = 0; i < cols; i++)
881 {
882 x->entry(i,j) = copyb[copyloc++];
883 }
884 }
885 }
886 else
887 {
889 }
890 }
891
892 delete [] workspace;
893 delete [] sing;
894
895 return ret;
896}
size_t numColumns() const
std::vector< double > make_lapack_array(const DMatRR &mat)
void fill_from_lapack_array(const std::vector< double > &doubles, DMatRR &mat)
int dgelss_(int *rows, int *cols, int *nhrs, double *A, int *ldA, double *b, int *ldb, double *Sigma, double *rcond, int *rank, double *work, int *lwork, int *info)
size_t rank(const DMatZZpFFPACK &A)
const mpreal min(const mpreal &x, const mpreal &y)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)