Macaulay2 Engine
Loading...
Searching...
No Matches
matrix-sort.cpp File Reference

MatrixSorter — compute the column permutation that sorts a Matrix by degree / leading term. More...

#include "matrix.hpp"

Go to the source code of this file.

Classes

class  MatrixSorter
 Helper that computes a column permutation for an engine Matrix by degree-then-monomial-order sort. More...

Detailed Description

MatrixSorter — compute the column permutation that sorts a Matrix by degree / leading term.

Note
AI-generated documentation. Verify against the source before relying on it.

Defines MatrixSorter, the helper that the engine-level Matrix::sort(degorder, ringorder) (defined at the bottom of this file — the only external entry point) hands off to. It carries parallel per-column arrays (sort_vals, sort_vecs, sort_degs) plus the deg_ascending and ringorder_ascending flags from the constructor, which flip the sign of the degree comparison and the ring-order comparison respectively. The comparator walks degrees first (skipped entirely when deg_ascending == 0), then leading monomials via R->compare_vecs, returning the standard -1 / 0 / 1 comparator triple. A hand-rolled sort_partition / sort_range quicksort drives the permutation; null vectors sort to the end. The sorter does not mutate the input matrix — it computes a permutation M2_arrayint result and hands that back via MatrixSorter::value(), so the same permutation can be applied uniformly to a basis, its change-of-basis matrix, and its syzygies in lockstep.

The class is file-local: no other engine translation unit references MatrixSorter directly; everyone goes through Matrix::sort.

See also
matrix.hpp
style.hpp

Definition in file matrix-sort.cpp.