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

◆ LU() [3/4]

M2_arrayintOrNull Lapack::LU ( const DMatRR * A,
DMatRR * L,
DMatRR * U )
static

Definition at line 195 of file lapack.cpp.

196{
197 int rows = static_cast<int>(A->numRows());
198 int cols = static_cast<int>(A->numColumns());
199 int info;
200 int min = (rows <= cols) ? rows : cols;
201 M2_arrayint result = M2_makearrayint(rows);
202
203 L->resize(rows, min);
204 U->resize(min, cols);
205
206 if (min == 0)
207 {
208 if (rows > 0)
209 for (int i = 0; i < rows; i++) result->array[i] = i;
210 return result;
211 }
212
213 int* perm = new int[min];
214 std::vector<double> copyA = make_lapack_array(*A);
215
216 dgetrf_(&rows, &cols, copyA.data(), &rows, perm, &info);
217
218 fill_lower_and_upper(copyA, *L, *U);
219
220 for (int i = 0; i < rows; i++) result->array[i] = i;
221 for (int i = 0; i < min; i++)
222 {
223 int thisloc = perm[i] - 1;
224 int tmp = result->array[thisloc];
225 result->array[thisloc] = result->array[i];
226 result->array[i] = tmp;
227 }
228
229 delete [] perm;
230
231 if (info < 0)
232 {
233 ERROR("argument passed to dgetrf had an illegal value");
234 return nullptr;
235 }
236
237 return result;
238}
size_t numRows() const
Definition dmat.hpp:144
void resize(size_t new_nrows, size_t new_ncols)
Definition dmat.hpp:157
size_t numColumns() const
Definition dmat.hpp:145
std::vector< double > make_lapack_array(const DMatRR &mat)
Definition lapack.cpp:20
void fill_lower_and_upper(const std::vector< double > &lapack_numbers, DMatRR &lower, DMatRR &upper)
Definition lapack.cpp:126
void dgetrf_(const int *rows, const int *cols, double *A, const int *ld, int *ipiv, int *info)
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_makearrayint(int n)
Definition m2-types.cpp:6
const mpreal min(const mpreal &x, const mpreal &y)
Definition mpreal.h:2792

References dgetrf_(), ERROR, fill_lower_and_upper(), M2_makearrayint(), make_lapack_array(), DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), DMat< ACoeffRing >::resize(), and result().