1635{
1636 bool ret = true;
1637 char job = 'N';
1638 int info;
1639 int rows =
static_cast<int>(A->
numRows());
1640 int cols =
static_cast<int>(A->
numColumns());
1641 int brows =
static_cast<int>(b->
numRows());
1642 int bcols =
static_cast<int>(b->
numColumns());
1643 int min = (rows <= cols) ? rows : cols;
1644 int max = (rows >= cols) ? rows : cols;
1645 int wsize =
min + ((bcols >=
max) ? bcols :
max);
1646
1647 if (brows != rows)
1648 {
1649 ERROR(
"expected compatible right hand side");
1650 return false;
1651 }
1652
1653 if (min == 0 || bcols == 0)
1654 {
1655 x->resize(cols, bcols);
1656 return true;
1657 }
1658
1661 double *workspace = new double[2 * wsize];
1662
1663 if (rows < cols)
1664 {
1665
1666
1667 std::vector<double> copyb2(2 * cols * bcols);
1668 for (auto& a : copyb2) a = 0;
1669 int bloc = 0;
1670 int copyloc = 0;
1671 for (int j = 0; j < bcols; j++)
1672 {
1673 copyloc = 2 * j * cols;
1674 for (int i = 0; i < 2 * brows; i++)
1675 {
1676 copyb2[copyloc++] = copyb[bloc++];
1677 }
1678 }
1680 }
1681
1683 &rows,
1684 &cols,
1685 &bcols,
1686 copyA.data(),
1687 &rows,
1688 copyb.data(),
1690 workspace,
1691 &wsize,
1692 &info);
1693
1694 if (info != 0)
1695 {
1696 ERROR(
"argument passed to zgels had an illegal value");
1697 ret = false;
1698 }
1699 else
1700 {
1701 x->resize(cols, bcols);
1702 if (rows > cols)
1703 {
1704
1705 int copyloc = 0;
1706 for (int j = 0; j < bcols; j++)
1707 {
1708 copyloc = 2 * j * rows;
1709 for (int i = 0; i < cols; i++)
1710 {
1711 double re = copyb[copyloc++];
1712 double im = copyb[copyloc++];
1713 x->ring().set_from_doubles(
x->entry(i,j), re, im);
1714 }
1715 }
1716 }
1717 else
1718 {
1720 }
1721 }
1722
1723 delete[] workspace;
1724
1725 return ret;
1726}
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 zgels_(char *job, int *rows, int *cols, int *nhrs, double *A, int *ldA, double *b, int *ldb, double *work, int *lwork, int *info)
const mpreal min(const mpreal &x, const mpreal &y)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)