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

◆ labelAndSortF4Matrix()

void NCF4::labelAndSortF4Matrix ( )
private

Definition at line 837 of file NCF4.cpp.

838{
839 size_t sz = mColumnMonomials.size();
840 std::vector<int> columnIndices;
841 std::vector<Word> tempWords;
842
843 tempWords.reserve(sz);
844 columnIndices.resize(sz);
845 std::iota(columnIndices.begin(), columnIndices.end(), 0);
846
847 // store all the column monomials in a temporary to sort them
848 // and also set the reducer column for them on the same pass
849 for (auto& i : mColumnMonomials)
850 tempWords.emplace_back(i.first);
851
852 // create the monomial sorter object
853 MonomSort<std::vector<Word>> monomialSorter(&freeAlgebra().monoid(),&tempWords);
854 // stable sort was here before, but this sort is based on a total ordering
855 // with no ties so we can use an unstable (and hence parallel!) sort.
856 if (mIsParallel)
857 mtbb::parallel_sort(columnIndices.begin(),columnIndices.end(),monomialSorter);
858 else
859 std::stable_sort(columnIndices.begin(),columnIndices.end(),monomialSorter);
860
861 auto applyLabelingColumns = [&](const mtbb::blocked_range<int>& r) {
862 for (auto count = r.begin(); count != r.end(); ++count)
863 {
864 auto& val = mColumnMonomials[tempWords[columnIndices[count]]];
865 val.first = count;
866 mColumns[count].word = tempWords[columnIndices[count]];
867 mColumns[count].pivotRow = -1;
868 }
869 };
870
871 // apply the sorted labeling to the columns
872 mColumns.resize(sz);
873 if (mIsParallel)
874 mtbb::parallel_for(mtbb::blocked_range<int>{0,(int)sz}, applyLabelingColumns);
875 else
876 applyLabelingColumns(mtbb::blocked_range<int>{0,(int)sz});
877
878 auto applyLabelingRows = [&](const mtbb::blocked_range<int>& r) {
879 for (auto i = r.begin(); i != r.end(); ++i)
880 {
881 auto& comps = mRows[i].columnIndices;
882 auto& words = mRows[i].columnWords;
883 // sets the pivot row in the column if this is a reducer row
884 if (i < mFirstOverlap)
885 {
886 mColumns[mColumnMonomials[words[0]].first].pivotRow = i;
887 mColumnMonomials[words[0]].second = i;
888 }
889 for (int j = 0; j < words.size(); ++j)
890 comps[j] = mColumnMonomials[words[j]].first;
891 }
892 };
893
894 // now fix the column labels in the rows and set pivot rows in columns
895 if (mIsParallel)
896 mtbb::parallel_for(mtbb::blocked_range<int>{0,(int)mRows.size()},applyLabelingRows);
897 else
898 applyLabelingRows(mtbb::blocked_range<int>{0,(int)mRows.size()});
899}
MonomialHash mColumnMonomials
Definition NCF4.hpp:235
int mFirstOverlap
Definition NCF4.hpp:247
bool mIsParallel
Definition NCF4.hpp:253
RowsVector mRows
Definition NCF4.hpp:243
ColumnsVector mColumns
Definition NCF4.hpp:240
const FreeAlgebra & freeAlgebra() const
Definition NCF4.hpp:282

References freeAlgebra(), mColumnMonomials, mColumns, mFirstOverlap, mIsParallel, and mRows.

Referenced by process().