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

◆ kernel()

template<class RingType>
size_t DMatLinAlg< RingType >::kernel ( Mat & X)

Output: X, a matrix, columns form a basis of Ax=0 returns dim of nullspace

Definition at line 580 of file dmat-lu.hpp.

581{
582 const Mat& LU = mLUObject.LUinPlace();
583 const std::vector<size_t>& pivotColumns = mLUObject.pivotColumns();
584
585 typename RingType::Element tmp(ring()), tmp2(ring());
586
587 // First, let's set X to be the correct size:
588 X.resize(LU.numColumns(), LU.numColumns() - pivotColumns.size());
589
590 size_t col = 0;
591 size_t nextpivotidx = 0;
592 size_t nextpivotcol =
593 (pivotColumns.size() > 0 ? pivotColumns[0] : LU.numColumns());
594 size_t colX = 0;
595 while (colX < X.numColumns())
596 {
597 if (col == nextpivotcol)
598 {
599 col++;
600 nextpivotidx++;
603 : LU.numColumns());
604 continue;
605 }
606 // At this point, we are ready to create a column of X.
607 ring().set_from_long(X.entry(col, colX), -1);
608 // Now we loop through and set the elements in the rows of X = pivot
609 // columns.
610 for (long p = nextpivotidx - 1; p >= 0; p--)
611 {
612 // set X.entry(pivotColumns[p], colX)
613 ring().set(tmp, LU.entry(p, col));
614 for (size_t i = nextpivotidx - 1; i >= p + 1; i--)
615 {
616 ring().mult(tmp2,
617 LU.entry(p, pivotColumns[i]),
618 X.entry(pivotColumns[i], colX));
619 ring().subtract(tmp, tmp, tmp2);
620 }
621 ring().divide(tmp, tmp, LU.entry(p, pivotColumns[p]));
622 ring().set(X.entry(pivotColumns[p], colX), tmp);
623 }
624 colX++;
625 col++;
626 }
627 return X.numColumns();
628}
DMatLUinPlace< RingType > mLUObject
Definition dmat-lu.hpp:64
const RingType & ring() const
Definition dmat-lu.hpp:107
DMat< RingType > Mat
Definition dmat-lu.hpp:61

References DMat< ACoeffRing >::entry(), mLUObject, DMat< ACoeffRing >::numColumns(), p, DMat< ACoeffRing >::resize(), and ring().

Referenced by MatrixOps::nullSpace().