30 # include <itpp/config.h>
32 # include <itpp/config_msvc.h>
35 #if defined(HAVE_LAPACK)
36 # include <itpp/base/algebra/lapack.h>
46 #if defined(HAVE_LAPACK)
48 bool lu(
const mat &X, mat &L, mat &U, ivec &p)
53 int m = X.rows(), info;
56 L.set_size(m, m,
false);
57 U.set_size(m, m,
false);
60 dgetrf_(&m, &m, A._data(), &m, p._data(), &info);
62 for (
int i = 0; i < m; i++) {
63 for (
int j = i; j < m; j++) {
69 L(i, j) = U(j, i) = 0;
82 bool lu(
const cmat &X, cmat &L, cmat &U, ivec &p)
87 int m = X.rows(), info;
90 L.set_size(m, m,
false);
91 U.set_size(m, m,
false);
94 zgetrf_(&m, &m, A._data(), &m, p._data(), &info);
96 for (
int i = 0; i < m; i++) {
97 for (
int j = i; j < m; j++) {
103 L(i, j) = U(j, i) = 0;
117 bool lu(
const mat &X, mat &L, mat &U, ivec &p)
119 it_error(
"LAPACK library is needed to use lu() function");
123 bool lu(
const cmat &X, cmat &L, cmat &U, ivec &p)
125 it_error(
"LAPACK library is needed to use lu() function");
129 #endif // HAVE_LAPACK
134 it_assert(b.size() == p.size(),
"interchange_permutations(): dimension mismatch");
137 for (
int k = 0; k < b.size(); k++) {
146 it_assert(p.size() > 0,
"permutation_matrix(): vector must have nonzero size");
153 for (k = n - 1; k >= 0; k--) {
155 row_k = identity.get_row(k);
156 row_pk = identity.get_row(p(k));
157 identity.set_row(k, row_pk);
158 identity.set_row(p(k), row_k);
168 identity.set_row(k, row_k);
169 identity.set_row(p(k), row_pk);