iscc: support application of piecewise quasipolynomial (fold) on set
[barvinok.git] / mat_util.cc
blobd341a061b89560b885f5772bc0e862685bb56655
1 #include <assert.h>
2 #include <NTL/vec_ZZ.h>
3 #include <NTL/mat_ZZ.h>
4 #include "mat_util.h"
6 int lex_cmp(const vec_ZZ& a, const vec_ZZ& b)
8 assert(a.length() == b.length());
10 for (int j = 0; j < a.length(); ++j)
11 if (a[j] != b[j])
12 return a[j] < b[j] ? -1 : 1;
13 return 0;
16 void lex_order_rows(mat_ZZ& mat)
18 for (int i = 0; i < mat.NumRows(); ++i) {
19 int m = i;
20 for (int j = i+1; j < mat.NumRows(); ++j)
21 if (lex_cmp(mat[j], mat[m]) < 0)
22 m = j;
23 if (m != i) {
24 vec_ZZ tmp = mat[m];
25 mat[m] = mat[i];
26 mat[i] = tmp;
31 int lex_cmp(const mat_ZZ& a, const mat_ZZ& b)
33 assert(a.NumCols() == b.NumCols());
34 int alen = a.NumRows();
35 int blen = b.NumRows();
36 int len = alen < blen ? alen : blen;
38 for (int i = 0; i < len; ++i) {
39 int s = lex_cmp(a[i], b[i]);
40 if (s)
41 return s;
43 return alen-blen;