1010{
1011
1012
1013
1014
1015
1016
1017
1018 bool ret = true;
1019 int rows =
static_cast<int>(A->
numRows());
1020 int cols =
static_cast<int>(A->
numColumns());
1021 int info1 = 0, info2 = 0, info3 = 0, info4 = 0;
1022 int min = (rows <= cols) ? rows : cols;
1023
1024 if (min == 0)
1025 {
1026 ERROR(
"expected a matrix with positive dimensions");
1027 return false;
1028 }
1029
1031 std::vector<double> tau (10*min);
1032 double workspace_size[1];
1033 int work_size = -1;
1034
1035 zgeqrf_(&rows, &cols, copyA.data(), &rows, tau.data(), workspace_size, &work_size, &info1);
1036 work_size = static_cast<int>(workspace_size[0]);
1037 double *workspace = new double[20 * work_size];
1038
1039 zgeqrf_(&rows, &cols, copyA.data(), &rows, tau.data(), workspace, &work_size, &info2);
1040
1041 if (info1 < 0 or info2 < 0)
1042 {
1043 ERROR(
"argument passed to zgeqrf had an illegal value");
1044 ret = false;
1045 }
1046 if (info1 > 0 or info2 > 0)
1047 {
1048 ERROR(
"can this happen?");
1049 ret = false;
1050 }
1051
1052 if (ret)
1053 {
1054 if (return_QR)
1055 {
1059
1060
1061 int orgqr_work_size = -1;
1063 &cols,
1064 &min,
1065 copyA.data(),
1066 &rows,
1067 tau.data(),
1068 workspace_size,
1069 &orgqr_work_size,
1070 &info3);
1071 orgqr_work_size = static_cast<int>(workspace_size[0]);
1072 if (orgqr_work_size > work_size)
1073 {
1074 delete[] workspace;
1075 work_size = orgqr_work_size;
1076 workspace = new double[2 * work_size];
1077 }
1079 &cols,
1080 &min,
1081 copyA.data(),
1082 &rows,
1083 tau.data(),
1084 workspace,
1085 &work_size,
1086 &info4);
1087 if (info3 < 0 or info4 < 0)
1088 {
1089 ERROR(
"argument passed to dorgqr or dorgqr had an illegal value");
1090 ret = false;
1091 }
1092 else if (info3 > 0 or info4 > 0)
1093 {
1094 ERROR(
"can this happen?");
1095 ret = false;
1096 }
1097 else
1098 {
1100 }
1101 }
1102 else
1103 {
1104
1105
1110 }
1111 }
1112
1113 delete[] workspace;
1114 return ret;
1115}
void resize(size_t new_nrows, size_t new_ncols)
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)
void fill_from_lapack_upper(const std::vector< double > &lapack_numbers, int numrows, int numcols, DMatRR &upper)
int zgeqrf_(int *m, int *n, double *A, int *lda, double *tau, double *work, int *lwork, int *info)
int zungqr_(int *m, int *n, int *k, double *A, int *lda, double *tau, double *work, int *lwork, int *info)
const mpreal min(const mpreal &x, const mpreal &y)