PIPS
matrix.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "linear_assert.h"
#include "boolean.h"
#include "arithmetique.h"
#include "matrix.h"
+ Include dependency graph for matrix.c:

Go to the source code of this file.

Functions

Valuematrix_elem_ref (Pmatrix M, int r, int c)
 package matrix More...
 
Value matrix_elem (Pmatrix M, int r, int c)
 
void matrix_transpose (const Pmatrix A, Pmatrix At)
 void matrix_transpose(Pmatrix a, Pmatrix a_t): transpose an (nxm) rational matrix a into a (mxn) rational matrix a_t More...
 
void matrix_multiply (const Pmatrix a, const Pmatrix b, Pmatrix c)
 void matrix_multiply(Pmatrix a, Pmatrix b, Pmatrix c): multiply rational matrix a by rational matrix b and store result in matrix c More...
 
void matrix_normalize (Pmatrix a)
 void matrix_normalize(Pmatrix a) More...
 
void matrix_normalizec (Pmatrix MAT)
 void matrix_normalizec(Pmatrix MAT): Normalisation des coefficients de la matrice MAT, i.e. More...
 
void matrix_swap_columns (Pmatrix A, int c1, int c2)
 void matrix_swap_columns(Pmatrix a, int c1, int c2): exchange columns c1,c2 of an (nxm) rational matrix More...
 
void matrix_swap_rows (Pmatrix A, int r1, int r2)
 void matrix_swap_rows(Pmatrix a, int r1, int r2): exchange rows r1 and r2 of an (nxm) rational matrix a More...
 
void matrix_assign (Pmatrix A, Pmatrix B)
 void matrix_assign(Pmatrix A, Pmatrix B) Copie de la matrice A dans la matrice B More...
 
bool matrix_equality (Pmatrix A, Pmatrix B)
 bool matrix_equality(Pmatrix A, Pmatrix B) test de l'egalite de deux matrices A et B; elles doivent avoir ete normalisees au prealable pour que le test soit mathematiquement exact More...
 
void matrix_nulle (Pmatrix Z)
 void matrix_nulle(Pmatrix Z): Initialisation de la matrice Z a la valeur matrice nulle More...
 
bool matrix_nulle_p (Pmatrix Z)
 bool matrix_nulle_p(Pmatrix Z): test de nullite de la matrice Z More...
 
bool matrix_diagonal_p (Pmatrix Z)
 bool matrix_diagonal_p(Pmatrix Z): test de nullite de la matrice Z More...
 
bool matrix_triangular_p (Pmatrix Z, bool inferieure)
 bool matrix_triangular_p(Pmatrix Z, bool inferieure): test de triangularite de la matrice Z More...
 
bool matrix_triangular_unimodular_p (Pmatrix Z, bool inferieure)
 bool matrix_triangular_unimodular_p(Pmatrix Z, bool inferieure) test de la triangulaire et unimodulaire de la matrice Z. More...
 
void matrix_substract (Pmatrix a, Pmatrix b, Pmatrix c)
 void matrix_substract(Pmatrix a, Pmatrix b, Pmatrix c): substract rational matrix c from rational matrix b and store result in matrix a More...
 
void matrix_add (Pmatrix a, Pmatrix b, Pmatrix c)
 a = b + c More...
 
void matrix_subtraction_column (Pmatrix MAT, int c1, int c2, Value x)
 void matrix_subtraction_column(Pmatrix MAT,int c1,int c2,int x): Soustrait x fois la colonne c2 de la colonne c1 Precondition: n > 0; m > 0; 0 < c1, c2 < m; Effet: c1[0..n-1] = c1[0..n-1] - x*c2[0..n-1]. More...
 
void matrix_subtraction_line (Pmatrix MAT, int r1, int r2, Value x)
 void matrix_subtraction_line(Pmatrix MAT,int r1,int r2,int x): Soustrait x fois la ligne r2 de la ligne r1 Precondition: n > 0; m > 0; 0 < r1, r2 < n; Effet: r1[0..m-1] = r1[0..m-1] - x*r2[0..m-1] More...
 
void matrix_uminus (Pmatrix A, Pmatrix mA)
 void matrix_uminus(A, mA) More...
 

Function Documentation

◆ matrix_add()

void matrix_add ( Pmatrix  a,
Pmatrix  b,
Pmatrix  c 
)

a = b + c

precondition

Definition at line 471 of file matrix.c.

472 {
473  /* precondition */
474  int m = MATRIX_NB_LINES(a);
475  int n = MATRIX_NB_COLUMNS(a);
476  assert(n>0 && m>0);
479 
480  Value d1 = MATRIX_DENOMINATOR(b);
481  Value d2 = MATRIX_DENOMINATOR(c);
482  if (value_eq(d1,d2)){
483  int i, j;
484  for (i=1; i<=m; i++)
485  for (j=1; j<=n; j++)
486  MATRIX_ELEM(a,i,j) =
487  value_plus(MATRIX_ELEM(b,i,j),MATRIX_ELEM(c,i,j));
488  MATRIX_DENOMINATOR(a) = d1;
489  }
490  else{
491  Value lcm = ppcm(d1, d2);
492  d1 = value_div(lcm,d1);
493  d2 = value_div(lcm,d2);
494  int i, j;
495  for (i=1; i<=m; i++) {
496  for (j=1; j<=n; j++) {
497  Value t1 = value_mult(MATRIX_ELEM(b,i,j),d1);
498  Value t2 = value_mult(MATRIX_ELEM(c,i,j),d2);
499  MATRIX_ELEM(a,i,j) = value_plus(t1,t2);
500  }
501  }
502  MATRIX_DENOMINATOR(a) = lcm;
503  }
504 }
#define value_pos_p(val)
int Value
#define value_eq(v1, v2)
bool operators on values
#define value_plus(v1, v2)
binary operators on values
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
#define value_div(v1, v2)
Value ppcm(Value, Value)
ppcm.c
Definition: ppcm.c:42
#define MATRIX_NB_LINES(matrix)
Definition: matrix-local.h:87
#define MATRIX_NB_COLUMNS(matrix)
Definition: matrix-local.h:88
#define MATRIX_DENOMINATOR(matrix)
int MATRIX_DENONIMATOR(matrix): acces au denominateur global d'une matrice matrix
Definition: matrix-local.h:86
#define MATRIX_ELEM(matrix, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrix-local.h:80
#define assert(ex)
Definition: newgen_assert.h:41

References assert, MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, ppcm(), value_div, value_eq, value_mult, value_plus, and value_pos_p.

Referenced by make_reindex(), and prepare_reindexing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrix_assign()

void matrix_assign ( Pmatrix  A,
Pmatrix  B 
)

void matrix_assign(Pmatrix A, Pmatrix B) Copie de la matrice A dans la matrice B

Les parametres de la fonction :

int A[] : matrice !int B[] : matrice int n : nombre de lignes de la matrice int m : nombre de colonnes de la matrice

Ancien nom: matrix_dup

Definition at line 259 of file matrix.c.

260 {
261  int m = MATRIX_NB_LINES(A);
262  int n = MATRIX_NB_COLUMNS(A);
263  int i;
264  for (i=0 ; i<m*n; i++)
265  B->coefficients[i] = A->coefficients[i];
266 }
#define B(A)
Definition: iabrev.h:61
Definition: pip__tab.h:25

References B, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by matrix_hermite(), matrix_smith(), sc_resol_smith(), and smith_int().

+ Here is the caller graph for this function:

◆ matrix_diagonal_p()

bool matrix_diagonal_p ( Pmatrix  Z)

bool matrix_diagonal_p(Pmatrix Z): test de nullite de la matrice Z

QQ i dans [1..n] QQ j dans [1..n] Z(i,j) == 0 && i != j || i == j

Les parametres de la fonction :

int Z[] : matrice int n : nombre de lignes de la matrice int m : nombre de colonnes de la matrice

Definition at line 336 of file matrix.c.

337 {
338  int i,j;
339  int m = MATRIX_NB_LINES(Z);
340  int n = MATRIX_NB_COLUMNS(Z);
341  for (i=1;i<=m;i++)
342  for (j=1;j<=n;j++)
343  if(i!=j && MATRIX_ELEM(Z,i,j)!=0)
344  return false;
345  return true;
346 }

References MATRIX_ELEM, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by extract_lattice(), and matrix_diagonal_inversion().

+ Here is the caller graph for this function:

◆ matrix_elem()

Value matrix_elem ( Pmatrix  M,
int  r,
int  c 
)

Definition at line 49 of file matrix.c.

50 {
51  assert(M != NULL && M->coefficients != NULL);
52  assert(1 <= r && r <= M->number_of_lines);
53  assert(1 <= c && c <= M->number_of_columns);
54  // return M->coefficients[(c-1) * M->number_of_lines + r - 1];
55  return MATRIX_ELEM(M, r, c);
56 }
Value * coefficients
Definition: matrix-local.h:67

References assert, Pmatrix::coefficients, and MATRIX_ELEM.

◆ matrix_elem_ref()

Value* matrix_elem_ref ( Pmatrix  M,
int  r,
int  c 
)

package matrix

matrix.c

Definition at line 41 of file matrix.c.

42 {
43  assert(M != NULL && M->coefficients != NULL);
44  assert(1 <= r && r <= M->number_of_lines);
45  assert(1 <= c && c <= M->number_of_columns);
46  return &(MATRIX_ELEM(M, r, c));
47 }

References assert, Pmatrix::coefficients, and MATRIX_ELEM.

◆ matrix_equality()

bool matrix_equality ( Pmatrix  A,
Pmatrix  B 
)

bool matrix_equality(Pmatrix A, Pmatrix B) test de l'egalite de deux matrices A et B; elles doivent avoir ete normalisees au prealable pour que le test soit mathematiquement exact

Definition at line 273 of file matrix.c.

274 {
275  int m = MATRIX_NB_LINES(A);
276  int n = MATRIX_NB_COLUMNS(A);
277  int i;
278  for (i = 0 ; i < m*n; i++)
279  if (B->coefficients[i] != A->coefficients[i])
280  return false;
281  return true;
282 }

References B, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

◆ matrix_multiply()

void matrix_multiply ( const Pmatrix  a,
const Pmatrix  b,
Pmatrix  c 
)

void matrix_multiply(Pmatrix a, Pmatrix b, Pmatrix c): multiply rational matrix a by rational matrix b and store result in matrix c

 a is a (pxq) matrix, b a (qxr) and c a (pxr)

 c := a x b ;

Algorithm used is directly from definition, and space has to be provided for output matrix c by caller. Matrix c is not necessarily normalized: its denominator may divide all its elements (see matrix_normalize()).

Precondition: p > 0; q > 0; r > 0; c != a; c != b; – aliasing between c and a or b – is not supported

validate dimensions

simplified aliasing test

set denominator

use ordinary school book algorithm

Definition at line 95 of file matrix.c.

96 {
97  /* validate dimensions */
98  int p = MATRIX_NB_LINES(a);
99  int q = MATRIX_NB_COLUMNS(a);
100  int r = MATRIX_NB_COLUMNS(b);
101  // should check that all dimensions are compatible & well allocated?!
102 
103  assert(p > 0 && q > 0 && r > 0);
104  /* simplified aliasing test */
105  assert(c != a && c != b);
106 
107  /* set denominator */
108  MATRIX_DENOMINATOR(c) =
110 
111  /* use ordinary school book algorithm */
112  int i, j, k;
113  for(i=1; i<=p; i++) {
114  for(j=1; j<=r; j++) {
115  Value v = VALUE_ZERO;
116  for(k=1; k<=q; k++) {
117  Value va = MATRIX_ELEM(a, i, k);
118  Value vb = MATRIX_ELEM(b, k, j);
119  value_addto(v, value_mult(va, vb));
120  }
121  MATRIX_ELEM(c, i, j) = v;
122  }
123  }
124 }
#define VALUE_ZERO
#define value_addto(ref, val)

References assert, MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, value_addto, value_mult, and VALUE_ZERO.

Referenced by extract_lattice(), fusion_buffer(), make_reindex(), matrices_to_1D_lattice(), matrix_general_inversion(), matrix_unimodular_inversion(), prepare_reindexing(), region_sc_minimal(), sc_resol_smith(), smith_int(), and Tiling_buffer_allocation().

+ Here is the caller graph for this function:

◆ matrix_normalize()

void matrix_normalize ( Pmatrix  a)

void matrix_normalize(Pmatrix a)

 A rational matrix is stored as an integer one with one extra
 integer, the denominator for all the elements. To normalise the
 matrix in this sense means to reduce this denominator to the
 smallest positive number possible. All elements are also reduced
 to their smallest possible value.

Precondition: MATRIX_DENOMINATOR(a)!=0

we must find the GCD of all elements of matrix

factor out

ensure denominator is positive

FI: this code is useless because pgcd()always return a positive integer, even if a is the null matrix; its denominator CANNOT be 0

Definition at line 136 of file matrix.c.

137 {
138  int m = MATRIX_NB_LINES(a);
139  int n = MATRIX_NB_COLUMNS(a);
140  assert(MATRIX_DENOMINATOR(a) != 0);
141 
142  /* we must find the GCD of all elements of matrix */
143  Value factor = MATRIX_DENOMINATOR(a);
144 
145  int i, j;
146  for(i=1; i<=m; i++)
147  for(j=1; j<=n; j++)
148  factor = pgcd(factor, MATRIX_ELEM(a,i,j));
149 
150  /* factor out */
151  if (value_notone_p(factor)) {
152  for(i=1; i<=m; i++)
153  for(j=1; j<=n; j++)
154  value_division(MATRIX_ELEM(a,i,j), factor);
156  }
157 
158  /* ensure denominator is positive */
159  /* FI: this code is useless because pgcd()always return a positive integer,
160  even if a is the null matrix; its denominator CANNOT be 0 */
162 
163 /*
164  if(MATRIX_DENOMINATOR(a) < 0) {
165  MATRIX_DENOMINATOR(a) = MATRIX_DENOMINATOR(a)*-1;
166  for(loop1=1; loop1<=n; loop1++)
167  for(loop2=1; loop2<=m; loop2++)
168  MATRIX_ELEM(a,loop1,loop2) =
169  -1 * MATRIX_ELEM(a,loop1,loop2);
170  }*/
171 }
#define pgcd(a, b)
Pour la recherche de performance, selection d'une implementation particuliere des fonctions.
#define value_notone_p(val)
#define value_division(ref, val)

References assert, MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, pgcd, value_division, value_notone_p, and value_pos_p.

Referenced by make_reindex(), and prepare_reindexing().

+ Here is the caller graph for this function:

◆ matrix_normalizec()

void matrix_normalizec ( Pmatrix  MAT)

void matrix_normalizec(Pmatrix MAT): Normalisation des coefficients de la matrice MAT, i.e.

division des coefficients de la matrice MAT et de son denominateur par leur pgcd

La matrice est modifiee.

Les parametres de la fonction :

!int MAT[] : matrice de dimension (n,m) int n : nombre de lignes de la matrice int m : nombre de colonnes de la matrice

??? matrix is supposed to be positive?

Parameters
MATAT

Definition at line 187 of file matrix.c.

188 {
189  int m = MATRIX_NB_LINES(MAT);
190  int n = MATRIX_NB_COLUMNS(MAT);
191  assert( n>0 && m>0);
192 
193  Value a = MATRIX_DENOMINATOR(MAT);
194  int i;
195  for (i = 0; i<m*n && value_gt(a, VALUE_ONE); i++)
196  a = pgcd(a, MAT->coefficients[i]);
197 
198  if (value_gt(a,VALUE_ONE)) {
199  for (i = 0; i<m*n; i++)
200  value_division(MAT->coefficients[i],a);
201  }
202 }
#define value_gt(v1, v2)
#define VALUE_ONE

References assert, Pmatrix::coefficients, MATRIX_DENOMINATOR, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, pgcd, value_division, value_gt, and VALUE_ONE.

Referenced by sc_resol_smith(), and smith_int().

+ Here is the caller graph for this function:

◆ matrix_nulle()

void matrix_nulle ( Pmatrix  Z)

void matrix_nulle(Pmatrix Z): Initialisation de la matrice Z a la valeur matrice nulle

Post-condition:

QQ i dans [1..n] QQ j dans [1..n] Z(i,j) == 0

Definition at line 293 of file matrix.c.

294 {
295  int m = MATRIX_NB_LINES(Z);
296  int n = MATRIX_NB_COLUMNS(Z);
297  int i,j;
298  for (i=1; i<=m; i++)
299  for (j=1; j<=n; j++)
300  MATRIX_ELEM(Z,i,j) = VALUE_ZERO;
302 }

References MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, VALUE_ONE, and VALUE_ZERO.

Referenced by build_contraction_matrices(), compute_delay_merged_nest(), compute_delay_tiled_nest(), constraints_to_matrices(), constraints_with_sym_cst_to_matrices(), egalites_to_matrice(), matrix_diagonal_inversion(), matrix_hermite(), matrix_perm_col(), matrix_perm_line(), matrix_triangular_inversion(), my_constraints_with_sym_cst_to_matrices(), sc_resol_smith(), smith_int(), and sys_mat_conv().

+ Here is the caller graph for this function:

◆ matrix_nulle_p()

bool matrix_nulle_p ( Pmatrix  Z)

bool matrix_nulle_p(Pmatrix Z): test de nullite de la matrice Z

QQ i dans [1..n] QQ j dans [1..n] Z(i,j) == 0

Definition at line 311 of file matrix.c.

312 {
313  int m = MATRIX_NB_LINES(Z);
314  int n = MATRIX_NB_COLUMNS(Z);
315  int i, j;
316  for (i=1; i<=m; i++)
317  for (j=1; j<=n; j++)
318  if (MATRIX_ELEM(Z,i,j) != VALUE_ZERO)
319  return false;
320  return true;
321 }

References MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, and VALUE_ZERO.

◆ matrix_substract()

void matrix_substract ( Pmatrix  a,
Pmatrix  b,
Pmatrix  c 
)

void matrix_substract(Pmatrix a, Pmatrix b, Pmatrix c): substract rational matrix c from rational matrix b and store result in matrix a

 a is a (nxm) matrix, b a (nxm) and c a (nxm)

 a = b - c ;

Algorithm used is directly from definition, and space has to be provided for output matrix a by caller. Matrix a is not necessarily normalized: its denominator may divide all its elements (see matrix_normalize()).

Precondition: n > 0; m > 0; Note: aliasing between a and b or c is supported

denominators of b, c

ppcm of b,c

precondition

Definition at line 435 of file matrix.c.

436 {
437  Value d1,d2; /* denominators of b, c */
438  Value lcm; /* ppcm of b,c */
439  int i,j;
440 
441  /* precondition */
442  int m = MATRIX_NB_LINES(a);
443  int n = MATRIX_NB_COLUMNS(a);
444  assert(n>0 && m>0);
447 
448  d1 = MATRIX_DENOMINATOR(b);
449  d2 = MATRIX_DENOMINATOR(c);
450  if (value_eq(d1,d2)){
451  for (i=1; i<=m; i++)
452  for (j=1; j<=n; j++)
453  MATRIX_ELEM(a,i,j) =
454  value_minus(MATRIX_ELEM(b,i,j),MATRIX_ELEM(c,i,j));
455  MATRIX_DENOMINATOR(a) = d1;
456  }
457  else {
458  lcm = ppcm(d1,d2);
459  d1 = value_div(lcm,d1);
460  d2 = value_div(lcm,d2);
461  for (i=1; i<=m; i++)
462  for (j=1; j<=n; j++)
463  MATRIX_ELEM(a,i,j) =
465  value_mult(MATRIX_ELEM(c,i,j),d2));
466  MATRIX_DENOMINATOR(a) = lcm;
467  }
468 }
#define value_minus(v1, v2)

References assert, MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, ppcm(), value_div, value_eq, value_minus, value_mult, and value_pos_p.

Referenced by compute_delay_merged_nest(), compute_delay_tiled_nest(), fusion_buffer(), and Tiling_buffer_allocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrix_subtraction_column()

void matrix_subtraction_column ( Pmatrix  MAT,
int  c1,
int  c2,
Value  x 
)

void matrix_subtraction_column(Pmatrix MAT,int c1,int c2,int x): Soustrait x fois la colonne c2 de la colonne c1 Precondition: n > 0; m > 0; 0 < c1, c2 < m; Effet: c1[0..n-1] = c1[0..n-1] - x*c2[0..n-1].

Les parametres de la fonction :

int MAT[] : matrice int c1 : numero du colonne int c2 : numero du colonne int x :

Parameters
MATAT
c11
c22

Definition at line 518 of file matrix.c.

519 {
520  int m = MATRIX_NB_LINES(MAT);
521  int i;
522  for (i=1; i<=m; i++)
523  value_substract(MATRIX_ELEM(MAT,i,c1),
524  value_mult(x, MATRIX_ELEM(MAT,i,c2)));
525 }
#define value_substract(ref, val)
static char * x
Definition: split_file.c:159

References MATRIX_ELEM, MATRIX_NB_LINES, value_mult, value_substract, and x.

Referenced by matrix_hermite(), matrix_smith(), and matrix_unimodular_triangular_inversion().

+ Here is the caller graph for this function:

◆ matrix_subtraction_line()

void matrix_subtraction_line ( Pmatrix  MAT,
int  r1,
int  r2,
Value  x 
)

void matrix_subtraction_line(Pmatrix MAT,int r1,int r2,int x): Soustrait x fois la ligne r2 de la ligne r1 Precondition: n > 0; m > 0; 0 < r1, r2 < n; Effet: r1[0..m-1] = r1[0..m-1] - x*r2[0..m-1]

Les parametres de la fonction :

int MAT[] : matrice int n : nombre de lignes de la matrice int m : nombre de colonnes de la matrice int r1 : numero du ligne int r2 : numero du ligne int x :

Parameters
MATAT
r11
r22

Definition at line 541 of file matrix.c.

542 {
543  int n = MATRIX_NB_COLUMNS(MAT);
544  int i;
545  for (i=1; i<=n; i++)
546  value_substract(MATRIX_ELEM(MAT,r1,i),
547  value_mult(x,MATRIX_ELEM(MAT,r2,i)));
548 }

References MATRIX_ELEM, MATRIX_NB_COLUMNS, value_mult, value_substract, and x.

Referenced by matrix_smith().

+ Here is the caller graph for this function:

◆ matrix_swap_columns()

void matrix_swap_columns ( Pmatrix  A,
int  c1,
int  c2 
)

void matrix_swap_columns(Pmatrix a, int c1, int c2): exchange columns c1,c2 of an (nxm) rational matrix

 Precondition:      n > 0; m > 0; 0 < c1 <= m; 0 < c2 <= m;
Parameters
c11
c22

Definition at line 209 of file matrix.c.

210 {
211  int m = MATRIX_NB_LINES(A);
212  int n = MATRIX_NB_COLUMNS(A);
213  assert(n > 0 && m > 0);
214  assert(0 < c1 && c1 <= n);
215  assert(0 < c2 && c2 <= n);
216 
217  int i;
218  for(i=1; i<=m; i++) {
219  Value temp = MATRIX_ELEM(A,i,c1);
220  MATRIX_ELEM(A,i,c1) = MATRIX_ELEM(A,i,c2);
221  MATRIX_ELEM(A,i,c2) = temp;
222  }
223 }

References assert, MATRIX_ELEM, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by matrix_hermite(), and matrix_smith().

+ Here is the caller graph for this function:

◆ matrix_swap_rows()

void matrix_swap_rows ( Pmatrix  A,
int  r1,
int  r2 
)

void matrix_swap_rows(Pmatrix a, int r1, int r2): exchange rows r1 and r2 of an (nxm) rational matrix a

Precondition: n > 0; m > 0; 1 <= r1 <= n; 1 <= r2 <= n

Parameters
r11
r22

Definition at line 230 of file matrix.c.

231 {
232  int m = MATRIX_NB_LINES(A);
233  int n = MATRIX_NB_COLUMNS(A);
234  assert(n > 0);
235  assert(m > 0);
236  assert(0 < r1 && r1 <= m);
237  assert(0 < r2 && r2 <= m);
238 
239  int i;
240  for(i=1; i<=n; i++) {
241  Value temp = MATRIX_ELEM(A,r1,i);
242  MATRIX_ELEM(A,r1,i) = MATRIX_ELEM(A,r2,i);
243  MATRIX_ELEM(A,r2,i) = temp;
244  }
245 }

References assert, MATRIX_ELEM, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by matrix_hermite(), and matrix_smith().

+ Here is the caller graph for this function:

◆ matrix_transpose()

void matrix_transpose ( const Pmatrix  A,
Pmatrix  At 
)

void matrix_transpose(Pmatrix a, Pmatrix a_t): transpose an (nxm) rational matrix a into a (mxn) rational matrix a_t

   t

At := A ;

verification step

copy from a to a_t

Parameters
Att

Definition at line 64 of file matrix.c.

65 {
66  /* verification step */
67  int m = MATRIX_NB_LINES(A);
68  int n = MATRIX_NB_COLUMNS(A);
69  assert(n >= 0 && m >= 0);
70 
71  /* copy from a to a_t */
73  int i, j;
74  for(i=1; i<=m; i++)
75  for(j=1; j<=n; j++)
76  MATRIX_ELEM(At,j,i) = MATRIX_ELEM(A,i,j);
77 }

References assert, MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by region_sc_minimal().

+ Here is the caller graph for this function:

◆ matrix_triangular_p()

bool matrix_triangular_p ( Pmatrix  Z,
bool  inferieure 
)

bool matrix_triangular_p(Pmatrix Z, bool inferieure): test de triangularite de la matrice Z

si inferieure == true QQ i dans [1..n] QQ j dans [i+1..m] Z(i,j) == 0

si inferieure == false (triangulaire superieure) QQ i dans [1..n] QQ j dans [1..i-1] Z(i,j) == 0

Les parametres de la fonction :

int Z[] : matrice int n : nombre de lignes de la matrice int m : nombre de colonnes de la matrice

Parameters
inferieurenferieure

Definition at line 367 of file matrix.c.

368 {
369  int m = MATRIX_NB_LINES(Z);
370  int n = MATRIX_NB_COLUMNS(Z);
371  int i,j;
372  for (i=1; i<=m; i++)
373  if(inferieure) {
374  for (j=i+1; j<=n; j++)
375  if(MATRIX_ELEM(Z,i,j)!=0)
376  return false;
377  }
378  else
379  for (j=1; j<=i-1; j++)
380  if(MATRIX_ELEM(Z,i,j)!=0)
381  return false;
382  return true;
383 }

References MATRIX_ELEM, MATRIX_NB_COLUMNS, and MATRIX_NB_LINES.

Referenced by matrix_triangular_inversion(), and matrix_triangular_unimodular_p().

+ Here is the caller graph for this function:

◆ matrix_triangular_unimodular_p()

bool matrix_triangular_unimodular_p ( Pmatrix  Z,
bool  inferieure 
)

bool matrix_triangular_unimodular_p(Pmatrix Z, bool inferieure) test de la triangulaire et unimodulaire de la matrice Z.

si inferieure == true QQ i dans [1..n] QQ j dans [i+1..n] Z(i,j) == 0 i dans [1..n] Z(i,i) == 1

si inferieure == false (triangulaire superieure) QQ i dans [1..n] QQ j dans [1..i-1] Z(i,j) == 0 i dans [1..n] Z(i,i) == 1 les parametres de la fonction : matrice Z : la matrice entre

Parameters
inferieurenferieure

Definition at line 403 of file matrix.c.

404 {
405  int m = MATRIX_NB_LINES(Z);
406  assert(MATRIX_NB_COLUMNS(Z) == m);
407  bool triangulaire = matrix_triangular_p(Z,inferieure);
408  if (triangulaire) {
409  int i;
410  for(i=1; i<=m; i++)
411  if (value_notone_p(MATRIX_ELEM(Z,i,i)))
412  return false;
413  return true;
414  }
415  else
416  return false;
417 }
bool matrix_triangular_p(Pmatrix Z, bool inferieure)
bool matrix_triangular_p(Pmatrix Z, bool inferieure): test de triangularite de la matrice Z
Definition: matrix.c:367

References assert, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, matrix_triangular_p(), and value_notone_p.

Referenced by extract_lattice(), matrix_unimodular_inversion(), and matrix_unimodular_triangular_inversion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrix_uminus()

void matrix_uminus ( Pmatrix  A,
Pmatrix  mA 
)

void matrix_uminus(A, mA)

computes mA = - A

input: A, larger allocated mA output: none modifies: mA

Parameters
mAA

Definition at line 558 of file matrix.c.

559 {
562 
563  int i,j;
564  for (i=1; i<=MATRIX_NB_LINES(A); i++)
565  for (j=1; j<=MATRIX_NB_COLUMNS(A); j++)
566  MATRIX_ELEM(mA, i, j) = value_uminus(MATRIX_ELEM(A, i, j));
567 }
#define value_uminus(val)
unary operators on values

References assert, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, and value_uminus.

Referenced by extract_lattice().

+ Here is the caller graph for this function: