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

◆ LU() [1/4]

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

Definition at line 1117 of file lapack.cpp.

1118{
1119 int rows = static_cast<int>(A->numRows());
1120 int cols = static_cast<int>(A->numColumns());
1121 int info;
1122 int min = (rows <= cols) ? rows : cols;
1123 M2_arrayint result = M2_makearrayint(rows);
1124
1125 L->resize(rows, min);
1126 U->resize(min, cols);
1127
1128 if (min == 0)
1129 {
1130 if (rows > 0)
1131 for (int i = 0; i < rows; i++) result->array[i] = i;
1132 return result;
1133 }
1134
1135 int* perm = new int[min];
1136 std::vector<double> copyA = make_lapack_array(*A);
1137
1138 zgetrf_(&rows, &cols, copyA.data(), &rows, perm, &info);
1139
1140 if (info < 0)
1141 {
1142 ERROR("argument passed to zgetrf had an illegal value");
1143 result = nullptr;
1144 }
1145 else
1146 {
1147 fill_lower_and_upper(copyA, *L, *U);
1148
1149 for (int i = 0; i < rows; i++) result->array[i] = i;
1150 for (int i = 0; i < min; i++)
1151 {
1152 int thisloc = perm[i] - 1;
1153 int tmp = result->array[thisloc];
1154 result->array[thisloc] = result->array[i];
1155 result->array[i] = tmp;
1156 }
1157
1158// TODO: What is this block? Remove it?
1159#if 0
1160 /* set the permutation array */
1161 for (int row=1; row<=min; row++) {
1162 int targ = row;
1163 for (int i=1; i<=min; i++) {
1164 if (i == targ)
1165 targ = perm[i-1];
1166 else if (perm[i-1] == targ)
1167 targ = i;
1168 }
1169 result->array[row-1] = targ-1;
1170 }
1171 for (int i=min; i<rows; i++)
1172 result->array[i] = i;
1173#endif
1174 }
1175
1176 delete[] perm;
1177 return result;
1178}
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
int zgetrf_(int *rows, int *cols, double *M, 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 ERROR, fill_lower_and_upper(), M2_makearrayint(), make_lapack_array(), DMat< ACoeffRing >::numColumns(), DMat< ACoeffRing >::numRows(), DMat< ACoeffRing >::resize(), result(), and zgetrf_().