42# include "matrix_utilities.hpp"
43# include "multiplication.hpp"
44# include "system_solvers_small.hpp"
46# include "bitpit_private_lapacke.hpp"
50namespace linearalgebra{
54const int ROW_MAJOR = LAPACK_ROW_MAJOR;
55const int COL_MAJOR = LAPACK_COL_MAJOR;
81 std::vector<std::vector<double>> &A,
82 std::vector<std::vector<double>> &L,
83 std::vector<std::vector<double>> &U,
84 std::vector<std::vector<double>> *P
92double toll_pivot = 1.0e-8;
97double pivot, pivot_trial;
98std::vector<std::vector<double>> AA;
107if (m == 0) {
return(3); };
132for (k = 0; k < n; k++) {
137 pivot = std::abs(AA[k][k]);
138 for (i = k+1; i < n; i++) {
139 pivot_trial = std::abs(AA[i][k]);
140 if (pivot_trial > pivot) {
147 if (pivot_row == k) {
148 if (pivot < 1.0e-14) {
152 else if ((pivot >= 1.0e-14) && (pivot < toll_pivot)) {
157 swap(AA[k], AA[pivot_row]);
159 swap((*P)[k], (*P)[pivot_row]);
164 for (i = k+1; i < n; i++) {
165 L[i][k] = AA[i][k]/AA[k][k] ;
166 for (j = k+1; j < n; j++) {
167 AA[i][j] = AA[i][j] - L[i][k]*AA[k][j];
171 for (j = k; j < n; j++) {
187 std::vector<std::vector<double>> &A,
188 std::vector<double> &B,
189 std::vector<double> &x
207if (m == 0) {
return; };
213if (l == 0) {
return; };
222for (i = 0; i < n; i++) {
225if (std::abs(d) < 1.0e-14) {
237for (i = n-1; i >= 0; i--) {
239 for(p = n-1; p > i; p--) {
242 x[i] = (B[i] -
sum)/A[i][i];
256 std::vector<std::vector<double>> &A,
257 std::vector<double> &B,
258 std::vector<double> &x
277if (m == 0) {
return; };
283if (l == 0) {
return; };
292for (i = 0; i < n; i++) {
295if (std::abs(d) < 1.0e-14) {
307for(i = 0; i < n; i++) {
309 for(p = 0; p < i; p++) {
310 sum += A[i][p] * x[p];
312 x[i] = (B[i] -
sum)/A[i][i];
327 std::vector<std::vector<double>> &A,
328 std::vector<double> &B,
329 std::vector<double> &x
338std::vector<std::vector<double>> L, U, P, *P_ = &P;
339std::vector<double> z, C;
348if ((info == 2) || (info == 3)) {
387 std::vector<double> &A,
388 std::vector<double> &B
391 std::vector<int> ipiv(B.size());
392 int info =
solveLU(layout, B.size(), A.data(), B.data(),ipiv.data());
425 int ldb = (layout == constants::ROW_MAJOR ? 1 : matrixOrder);
426 int info = LAPACKE_dgesv(layout, matrixOrder, 1, A, matrixOrder, ipiv, B, ldb);
void sum(const std::array< T, d > &x, T1 &s)
void matmul(T, const std::vector< std::vector< T > > &, std::vector< std::vector< T > > &)
void zeros(std::vector< std::vector< T > > &, int, int)
void eye(std::vector< std::vector< T > > &, int, int)
void forwardSubstitution(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)
void backwardSubstitution(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)
unsigned int factorizeLU(std::vector< std::vector< double > > &A, std::vector< std::vector< double > > &L, std::vector< std::vector< double > > &U, std::vector< std::vector< double > > *P)
void solveLU(std::vector< std::vector< double > > &A, std::vector< double > &B, std::vector< double > &x)