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

◆ solve() [1/4]

bool Lapack::solve ( const DMatCC * A,
const DMatCC * b,
DMatCC * x )
static

Definition at line 1180 of file lapack.cpp.

1181{
1182 bool ret = true;
1183 int size = static_cast<int>(A->numRows());
1184 int bsize = static_cast<int>(b->numColumns());
1185 int info;
1186
1187 /* make sure matrix is square */
1188 if (size != static_cast<int>(A->numColumns()))
1189 {
1190 ERROR("expected a square matrix");
1191 return false;
1192 }
1193
1194 /* make sure dimensions of b make sense for Ax=b */
1195 if (b->numRows() != size)
1196 {
1197 ERROR("expected matrices to have same number of rows");
1198 return false;
1199 }
1200
1201 if (size == 0)
1202 {
1203 x->resize(size, bsize);
1204 return true;
1205 }
1206
1207 int* permutation = new int[size]; // TODO: set to 0?
1208 std::vector<double> copyA = make_lapack_array(*A);
1209 std::vector<double> copyb = make_lapack_array(*b);
1210
1211 zgesv_(&size, &bsize, copyA.data(), &size, permutation, copyb.data(), &size, &info);
1212
1213 if (info > 0)
1214 {
1215 ERROR("according to zgesv, matrix is singular");
1216 ret = false;
1217 }
1218 else if (info < 0)
1219 {
1220 ERROR("argument passed to zgesv had an illegal value");
1221 ret = false;
1222 }
1223 else
1224 {
1225 x->resize(size, bsize);
1226 fill_from_lapack_array(copyb, *x);
1227 }
1228
1229 delete [] permutation;
1230 return ret;
1231}
size_t numRows() const
Definition dmat.hpp:144
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 zgesv_(int *n, int *nrhs, double *a, int *lda, int *ipiv, double *b, int *ldb, int *info)
const int ERROR
Definition m2-mem.cpp:55
volatile int x

References ERROR, fill_from_lapack_array(), make_lapack_array(), DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), x, and zgesv_().