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

◆ reorder_columns()

void F4GB::reorder_columns ( )
private

Definition at line 322 of file f4.cpp.

323{
324 // Set up to sort the columns.
325 // Result is an array 0..ncols-1, giving the new order.
326 // Find the inverse of this permutation: place values into "ord" column
327 // fields.
328 // Loop through every element of the matrix, changing its comp array.
329
330 int nrows = INTSIZE(mat->rows);
331 int ncols = INTSIZE(mat->columns);
332
333 // sort the columns
334
335 int *column_order = new int[ncols];
336 int *ord = new int[ncols];
337
338 ColumnsSorter C(mMonomialInfo, mat);
339
340// Actual sort of columns /////////////////
341
342 C.reset_ncomparisons();
343
344 clock_t begin_time0 = clock();
345 for (int i = 0; i < ncols; i++)
346 {
347 column_order[i] = i;
348 }
349
350 if (M2_gbTrace >= 2) fprintf(stderr, "ncomparisons = ");
351
352 // std::cout << "-- before sort --" << std::endl;
353 // show_column_info();
354
355 std::stable_sort(column_order, column_order + ncols, C);
356
357 // std::cout << "-- after sort --" << std::endl;
358 // show_column_info();
359
360 clock_t end_time0 = clock();
361 if (M2_gbTrace >= 2) fprintf(stderr, "%ld, ", C.ncomparisons0());
362 double nsecs0 = (double)(end_time0 - begin_time0) / CLOCKS_PER_SEC;
363 clock_sort_columns += nsecs0;
364 if (M2_gbTrace >= 2) fprintf(stderr, " time = %f\n", nsecs0);
365
367
368 for (int i = 0; i < ncols; i++)
369 {
370 ord[column_order[i]] = i;
371 }
372
373 // Now move the columns into position
375 newcols.reserve(ncols);
376 for (int i = 0; i < ncols; i++)
377 {
378 long newc = column_order[i];
379 newcols.push_back(mat->columns[newc]);
380 }
381
382 // Now reset the components in each row
383 for (int r = 0; r < nrows; r++)
384 {
385 row_elem &row = mat->rows[r];
386 for (int i = 0; i < row.len; i++)
387 {
388 int oldcol = row.comps[i];
389 int newcol = ord[oldcol];
390 row.comps[i] = newcol;
391 }
392 for (int i = 1; i < row.len; i++)
393 {
394 if (row.comps[i] <= row.comps[i - 1])
395 {
396 fprintf(stderr, "Internal error: array out of order\n");
397 break;
398 }
399 }
400 }
401
402 std::swap(mat->columns, newcols);
403 delete [] column_order;
404 delete [] ord;
405 //Mem->components.deallocate(column_order);
406 //Mem->components.deallocate(ord);
407}
coefficient_matrix * mat
Definition f4.hpp:186
const MonomialInfo * mMonomialInfo
Definition f4.hpp:157
double clock_sort_columns
Definition f4.hpp:194
int M2_gbTrace
Definition m2-types.cpp:52
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition mpreal.h:3244
std::vector< column_elem > column_array
Definition f4-types.hpp:176
int * comps
Definition f4-types.hpp:163
#define INTSIZE(a)
Definition style.hpp:37

References clock_sort_columns, row_elem::comps, INTSIZE, row_elem::len, M2_gbTrace, mat, mMonomialInfo, ColumnsSorter::ncomparisons0(), ColumnsSorter::reset_ncomparisons(), and std::swap().

Referenced by make_matrix().