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

◆ reorderColumns()

void F4Res::reorderColumns ( )
private

Definition at line 300 of file res-f4.cpp.

301{
302// Set up to sort the columns.
303// Result is an array 0..ncols-1, giving the new order.
304// Find the inverse of this permutation: place values into "ord" column fields.
305// Loop through every element of the matrix, changing its comp array.
306
307#if 0
308 std::cout << "-- rows --" << std::endl;
310 std::cout << "-- columns --" << std::endl;
312
313 std::cout << "reorderColumns" << std::endl;
314#endif
315 ComponentIndex ncols = static_cast<ComponentIndex>(mColumns.size());
316
317 ComponentIndex* ord = new ComponentIndex[ncols];
318
319 auto timeA = timer();
320 ResMonomialSorter sorter(ring().originalMonoid(), monoid(), frame().schreyerOrder(mThisLevel-2), mColumns);
321 auto column_order = sorter.sort();
322 auto timeB = timer();
323 double nsec_sort2 = seconds(timeB - timeA);
324 mFrame.timeSortMatrix += nsec_sort2;
325 auto ncompares = sorter.numComparisons();
326
327 if (M2_gbTrace >= 2)
328 std::cout << " #comparisons sorting " << ncols << " columns = " << ncompares << " ";
329
330 if (M2_gbTrace >= 1)
331 std::cout << " sort time: " << nsec_sort2 << std::endl;
332
333 timeA = timer();
335
336 for (ComponentIndex i = 0; i < ncols; i++)
337 {
338 ord[column_order[i]] = i;
339 }
340
341#if 0
342 std::cout << "column_order: ";
343 for (ComponentIndex i=0; i<ncols; i++) std::cout << " " << column_order[i];
344 std::cout << std::endl;
345 std::cout << "ord: ";
346 for (ComponentIndex i=0; i<ncols; i++) std::cout << " " << ord[i];
347 std::cout << std::endl;
348#endif
349 // Now move the columns into position
350 std::vector<res_packed_monomial> sortedColumnArray;
351 std::vector<Row> sortedRowArray;
352
353 sortedColumnArray.reserve(ncols);
354 sortedRowArray.reserve(ncols);
355
356 for (ComponentIndex i = 0; i < ncols; i++)
357 {
358 ComponentIndex newc = column_order[i];
359 sortedColumnArray.push_back(mColumns[newc]);
360 sortedRowArray.push_back(Row());
361 std::swap(sortedRowArray[i], mReducers[newc]);
362 }
363
364 std::swap(mColumns, sortedColumnArray);
365 std::swap(mReducers, sortedRowArray);
366
367#if 0
368 std::cout << "applying permutation to reducers" << std::endl;
369#endif
370
371 for (ComponentIndex i = 0; i < mReducers.size(); i++)
372 {
373#if 0
374 std::cout << "reducer " << i << " before:";
375 for (ComponentIndex j=0; j<mReducers[i].mComponents.size(); j++) std::cout << " " << mReducers[i].mComponents[j];
376 std::cout << std::endl;
377#endif
378 applyPermutation(ord, mReducers[i].mComponents);
379#if 0
380 std::cout << "reducer " << i << " after:";
381 for (ComponentIndex j=0; j<mReducers[i].mComponents.size(); j++) std::cout << " " << mReducers[i].mComponents[j];
382 std::cout << std::endl;
383#endif
384 }
385#if 0
386 std::cout << "applying permutation to spairs" << std::endl;
387#endif
388 for (ComponentIndex i = 0; i < mSPairs.size(); i++)
389 {
390#if 0
391 std::cout << "spair " << i << " before:";
392 for (ComponentIndex j=0; j<mSPairs[i].mComponents.size(); j++) std::cout << " " << mSPairs[i].mComponents[j];
393 std::cout << std::endl;
394#endif
395 applyPermutation(ord, mSPairs[i].mComponents);
396#if 0
397 std::cout << "spair " << i << " after:";
398 for (ComponentIndex j=0; j<mSPairs[i].mComponents.size(); j++) std::cout << " " << mSPairs[i].mComponents[j];
399 std::cout << std::endl;
400#endif
401 }
402
403 timeB = timer();
404 mFrame.timeReorderMatrix += seconds(timeB - timeA);
405 delete[] ord;
406}
void debugOutputReducers()
Definition res-f4.cpp:705
const ResPolyRing & ring() const
Definition res-f4.hpp:104
void debugOutputColumns()
Definition res-f4.cpp:715
int mThisLevel
Definition res-f4.hpp:164
const ResMonoid & monoid() const
Definition res-f4.hpp:103
std::vector< res_packed_monomial > mColumns
Definition res-f4.hpp:184
std::vector< Row > mReducers
Definition res-f4.hpp:179
SchreyerFrame & mFrame
Definition res-f4.hpp:159
SchreyerFrame & frame()
Definition res-f4.hpp:92
std::vector< Row > mSPairs
Definition res-f4.hpp:181
int M2_gbTrace
Definition m2-types.cpp:52
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition mpreal.h:3244
static void applyPermutation(ComponentIndex *permutation, std::vector< ComponentIndex > &entries)
Definition res-f4.cpp:281
int ComponentIndex
One row of the Macaulay matrix built by F4Res::construct.
Definition res-f4.hpp:119
std::chrono::steady_clock::time_point timer()
Definition timing.hpp:35
double seconds(DurationType time_diff)
Definition timing.hpp:59

References applyPermutation(), debugOutputColumns(), debugOutputReducers(), frame(), M2_gbTrace, mColumns, mFrame, monoid(), mReducers, mSPairs, mThisLevel, ring(), seconds(), std::swap(), and timer().

Referenced by makeMatrix().