1731{
1732 bool ret = true;
1733 int rows =
static_cast<int>(A->
numRows());
1734 int cols =
static_cast<int>(A->
numColumns());
1735 int brows =
static_cast<int>(b->
numRows());
1736 int bcols =
static_cast<int>(b->
numColumns());
1737 double rcond = -1.0;
1739 int min = (rows < cols) ? rows : cols;
1740 int max = (rows > cols) ? rows : cols;
1741 int wsize = 2 *
min + ((bcols >
max) ? bcols :
max);
1742
1743 if (brows != rows)
1744 {
1745 ERROR(
"expected compatible right hand side");
1746 return false;
1747 }
1748
1749 if (min == 0 || bcols == 0)
1750 {
1751 x->resize(cols, bcols);
1752 return true;
1753 }
1754
1757 double *workspace = new double[2 * wsize];
1758 double *sing =
new double[
min];
1759 double *rwork =
new double[5 *
min];
1760
1761 if (rows < cols)
1762 {
1763
1764
1765 std::vector<double> copyb2(2 * cols * bcols);
1766 for (auto& a : copyb2) a = 0;
1767 int bloc = 0;
1768 int copyloc = 0;
1769 for (int j = 0; j < bcols; j++)
1770 {
1771 copyloc = 2 * j * cols;
1772 for (int i = 0; i < 2 * brows; i++)
1773 {
1774 copyb2[copyloc++] = copyb[bloc++];
1775 }
1776 }
1778 }
1779
1781 &cols,
1782 &bcols,
1783 copyA.data(),
1784 &rows,
1785 copyb.data(),
1787 sing,
1788 &rcond,
1789 &rank,
1790 workspace,
1791 &wsize,
1792 rwork,
1793 &info);
1794
1795 if (info != 0)
1796 {
1797 ERROR(
"argument passed to zgelss had an illegal value");
1798 ret = false;
1799 }
1800 else
1801 {
1802 x->resize(cols, bcols);
1803 if (rows > cols)
1804 {
1805
1806 int copyloc = 0;
1807 for (int j = 0; j < bcols; j++)
1808 {
1809 copyloc = 2 * j * rows;
1810 for (int i = 0; i < cols; i++)
1811 {
1812 double re = copyb[copyloc++];
1813 double im = copyb[copyloc++];
1814 x->ring().set_from_doubles(
x->entry(i,j), re, im);
1815 }
1816 }
1817 }
1818 else
1819 {
1821 }
1822 }
1823
1824 delete[] workspace;
1825 delete[] sing;
1826 delete[] rwork;
1827
1828 return ret;
1829}
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 zgelss_(int *rows, int *cols, int *nhrs, double *A, int *ldA, double *b, int *ldb, double *Sigma, double *rcond, int *rank, double *work, int *lwork, double *rwork, 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)