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

◆ LUincremental() [1/2]

template<typename RT>
M2_arrayintOrNull MatrixOps::LUincremental ( std::vector< size_t > & P,
DMat< RT > & LU,
const DMat< RT > & v,
int m )

Definition at line 567 of file mat-linalg.hpp.

568{
569 size_t n = LU.numRows();
570
571 // copy permuted v to m-th column of LU
572 // TODO: change to iter
573 for (size_t j = 0; j < n; j++)
574 LU.ring().set(LU.entry(j, m), v.entry(P[j], 0));
575
576 // reduce the m-th column of LU and forward solve
577 DMat<RT> x{LU.ring(), n, 1};
578 triangularSolve(LU, x, m, 1);
579 // place solution of forward solve in U
580 // TODO: change to iter
581 for (size_t i = 0; i < m; i++)
582 LU.ring().set(LU.entry(i, m), x.entry(i, 0));
583
584 // look for a pivot in L
585 int pivotPosition = -1;
586 // TODO: change to iter
587 for (size_t j = m; j < n; j++)
588 if (!LU.ring().is_zero(LU.entry(j, m)))
589 {
590 pivotPosition = j;
591 break;
592 }
593 // if no pivot found, return
594 if (pivotPosition == -1) return stdvector_to_M2_arrayint(P);
595 // otherwise swap rows and update P
596 MatElementaryOps<DMat<RT>>::interchange_rows(LU, pivotPosition, m);
597 std::swap(P[pivotPosition], P[m]);
598
599 // scale column of L
600 // TODO: change to iter
601 for (int j = m + 1; j < n; j++)
602 LU.ring().divide(LU.entry(j, m), LU.entry(j, m), LU.entry(m, m));
603
604 return stdvector_to_M2_arrayint(P);
605}
ElementType & entry(size_t row, size_t column)
Definition dmat.hpp:148
Definition dmat.hpp:62
M2_arrayintOrNull LU(const Mat &A, Mat &L, Mat &U)
void triangularSolve(Mat &Lv, Mat &x, int m, int strategy)
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition mpreal.h:3244
volatile int x
M2_arrayint stdvector_to_M2_arrayint(const std::vector< T > &v)
Definition util.hpp:79

References DMat< ACoeffRing >::entry(), LU(), stdvector_to_M2_arrayint(), std::swap(), triangularSolve(), and x.