32 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
37 if (NbRows == 0 || NbColumns == 0) {
42 q = (
Value **)malloc(NbRows *
sizeof(*q));
45 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
52 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
57 for (i = 0; i < NbRows; i++) {
88 q = (
Value **)realloc(Mat->
p, NbRows *
sizeof(*q));
90 errormsg1(
"Matrix_Extend",
"outofmem",
"out of memory space");
97 errormsg1(
"Matrix_Extend",
"outofmem",
"out of memory space");
103 for (i = Mat->
p_Init_size; i < Mat->NbColumns * NbRows; ++i)
109 for (i = 0; i < NbRows; i++) {
121 unsigned NbRows, NbColumns;
129 fprintf(Dst,
"%d %d\n", NbRows = Mat->
NbRows, NbColumns = Mat->
NbColumns);
130 if (NbColumns == 0) {
134 for (i = 0; i < NbRows; i++) {
136 for (j = 0; j < NbColumns; j++) {
164 for (i = 0; i < Mat->
NbRows; i++) {
166 c = fgets(
s, 1024, fp);
170 while (isspace(*c) && *c !=
'\n' && *c)
172 }
while (*c ==
'#' ||
175 errormsg1(
"Matrix_Read",
"baddim",
"not enough rows");
182 "Matrix_Read",
"warning",
183 "line longer than 1024 chars (ignored remaining chars till EOL)");
186 while (
n != EOF &&
n !=
'\n');
191 if (*c ==
'\n' || *c ==
'#' || *c ==
'\0') {
192 errormsg1(
"Matrix_Read",
"baddim",
"not enough columns");
196 for (z = c; *z; z++) {
197 if (*z ==
'\n' || *z ==
'#' || isspace(*z))
226 unsigned NbRows, NbColumns;
229 if (fgets(
s, 1024, fp) == NULL)
231 while ((*
s ==
'#' || *
s ==
'\n') ||
232 (sscanf(
s,
"%d %d", &NbRows, &NbColumns) < 2)) {
233 if (fgets(
s, 1024, fp) == NULL)
238 errormsg1(
"Matrix_Read",
"outofmem",
"out of memory space");
256 int nc,
nr, i, j, k, rank, reduced, pivotrow;
263 errormsg1(
"Domlib",
"nullH",
"hermite: ? Null H");
275 fprintf(stderr,
"Start -----------\n");
278 for (k = 0, rank = 0; k < nc && rank <
nr; k = k + 1) {
281 fprintf(stderr,
"Working on col %d. Rank=%d ----------\n", k + 1,
294 for (i = rank + 1; i <
nr; i++) {
303 if (pivotrow != rank) {
311 fprintf(stderr,
"Exchange rows %d and %d -----------\n", rank + 1,
319 for (j = 0; j < nc; j++)
324 for (j = 0; j <
nr; j++)
329 for (j = 0; j <
nr; j++)
334 fprintf(stderr,
"Negate row %d -----------\n", rank + 1);
344 for (i = rank + 1; i <
nr; i++) {
357 for (j = 0; j < nc; j++) {
364 for (j = 0; j <
nr; j++) {
371 for (j = 0; j <
nr; j++) {
377 fprintf(stderr,
"row %d = row %d - %d row %d -----------\n", i + 1,
392 for (i = 0; i < rank; i++) {
407 for (j = 0; j < nc; j++) {
414 for (j = 0; j <
nr; j++) {
421 for (j = 0; j <
nr; j++) {
425 fprintf(stderr,
"row %d = row %d - %d row %d -----------\n", i + 1,
461 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
474 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
479 for (i = 0; i <
nr; i++)
489 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
494 for (i = 0; i <
nr; i++)
505 for (i = 0; i <
nr; i++) {
506 for (j = i + 1; j <
nr; j++) {
539 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
543 for (i = 0; i <
nr; i++)
544 for (j = 0; j < nc; j++)
551 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
556 for (i = 0; i < nc; i++)
565 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
570 for (i = 0; i < nc; i++)
581 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
585 for (i = 0; i <
nr; i++)
586 for (j = 0; j < nc; j++)
592 for (i = 0; i < nc; i++) {
593 for (j = i + 1; j < nc; j++) {
618 fprintf(stderr,
"Trying to invert a non-square matrix !\n");
637 for (i = 0; i < k; ++i) {
643 for (i = 0; i < k; ++i) {
649 for (j = i; j < k; ++j)
669 for (c = 0; c < k; ++c) {
686 for (j = 0; j < k; ++j) {
697 for (c = ((j > i) ? i : 0); c < k; ++c) {
702 for (c = 0; c < k; ++c) {
714 for (c = 0; c < k; ++c) {
725 for (j = 0; j < k; ++j) {
752 int last_column_index = P->
NbColumns - 1;
753 Value lcm, gcd, last_column_entry, s1;
766 for (k = 1; k < P->
NbRows; ++k) {
774 for (i = 0; i < X->
NbRows; ++i)
779 for (k = 0; k < P->
NbRows; ++k) {
798 for (i = 0; i < S->
NbRows; ++i) {
822 int NbRows, NbColumns, i, j;
823 Value **cm, *q, *cp1, *cp2;
830 for (i = 0; i < NbRows; i++) {
838 for (j = 1; j < NbColumns; j++) {
854 int NbRows, NbColumns, i, j;
855 Value **cm, *cp1, *cp2;
861 for (j = 0; j < NbColumns; j++) {
867 for (i = 1; i < NbRows; i++) {
883 unsigned NbRows, NbColumns;
884 Value **q1, **q2, *p1, *p3, sum;
892 fprintf(stderr,
"? Matrix_Product : incompatible matrix dimension\n");
901 for (i = 0; i < NbRows; i++) {
902 for (j = 0; j < NbColumns; j++) {
905 for (k = 0; k < Size; k++) {
933 fprintf(stderr,
"Trying to invert a non-square matrix !\n");
952 for (i = 0; i < k; ++i) {
958 for (i = 0; i < k; ++i) {
964 for (j = i; j < k; ++j)
984 for (c = 0; c < k; ++c) {
1001 for (j = 0; j < k; ++j) {
1012 for (c = ((j > i) ? i : 0); c < k; ++c) {
1017 for (c = 0; c < k; ++c) {
1029 for (c = 0; c < k; ++c) {
1041 for (j = 0; j < k; ++j) {
1051 for (c = 0; c < k; c++)
1060 for (j = 0; j < k; ++j) {
1061 for (c = 0; c < k; c++) {
1068 for (j = 0; j < k; ++j) {
#define value_oppose(ref, val)
#define value_notzero_p(val)
#define value_divexact(ref, val1, val2)
#define value_gcd(ref, val1, val2)
#define value_notone_p(val)
#define value_absolute(ref, val)
#define value_decrement(ref, val)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_set_si(val, i)
#define value_addmul(ref, val1, val2)
#define value_read(val, str)
#define value_division(ref, val1, val2)
#define value_multiply(ref, val1, val2)
#define value_print(Dst, fmt, val)
#define value_modulus(ref, val1, val2)
#define value_subtract(ref, val1, val2)
void errormsg1(const char *f, const char *msgname, const char *msg)
static int hermite(Matrix *H, Matrix *U, Matrix *Q)
void Vector_Matrix_Product(Value *p1, Matrix *Mat, Value *p2)
void Matrix_Product(Matrix *Mat1, Matrix *Mat2, Matrix *Mat3)
void Matrix_Extend(Matrix *Mat, unsigned NbRows)
void Matrix_Vector_Product(Matrix *Mat, Value *p1, Value *p2)
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
Matrix * Matrix_Read_Input(Matrix *Mat)
int Matrix_Inverse(Matrix *Mat, Matrix *MatInv)
void right_hermite(Matrix *A, Matrix **Hp, Matrix **Up, Matrix **Qp)
Matrix * Matrix_Read(void)
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
Matrix * Matrix_Read_InputFile(Matrix *Mat, FILE *fp)
void rat_prodmat(Matrix *S, Matrix *X, Matrix *P)
void left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
int MatInverse(Matrix *Mat, Matrix *MatInv)
Matrix * Matrix_ReadFile(FILE *fp)
void Matrix_Free(Matrix *Mat)
Value * value_alloc(int want, int *got)
void Vector_Set(Value *p, int n, unsigned length)
void value_free(Value *p, int size)
void Vector_Normalize_Positive(Value *p, int length, int pos)
void Vector_Gcd(Value *p, unsigned length, Value *min)
void Vector_Exchange(Value *p1, Value *p2, unsigned length)
void Vector_Copy(Value *p1, Value *p2, unsigned length)