TaPAS  0.2
matrix.h
Go to the documentation of this file.
1 /*
2  * matrix.h -- Matrices of rationals
3  *
4  * This file is a part of the Talence Linear Algebra Library.
5  *
6  * Copyright (C) 2010 CNRS UMR 5800 & Université Bordeaux I (see AUTHORS file).
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
29 #ifndef __MATRIX_H__
30 # define __MATRIX_H__
31 
32 # include <talalib/common.h>
33 # include <talalib/vec.h>
34 
35 BEGIN_C_DECLS
36 
37 typedef struct tla_matrix_st {
38  int m;
39  int n;
40  tla_vec_t coefs;
41 } tla_matrix_t[1];
42 
43  /* --------------- */
44 
45 extern void
46 tla_matrix_init (tla_matrix_t M, int m, int n);
47 
48 extern void
49 tla_matrix_init_set (tla_matrix_t M, const tla_matrix_t N);
50 
51 extern void
52 tla_matrix_init_with_vec (tla_matrix_t M, const tla_vec_t v, int iscol);
53 
54 # define tla_matrix_init_with_vec_column(M, v) \
55  tla_matrix_init_with_vec (M, v, 1)
56 # define tla_matrix_init_with_vec_line(M, v) \
57  tla_matrix_init_with_vec (M, v, 0)
58 
59 /*
60  * Accessor to the coefficient at line _i and column _j. _i and _j belong to
61  * the range, respectively [1, m] and [1, n] where m is the number of lines
62  * of the matrix _M and n it number of columns.
63  */
64 # define TLA_M_NUM(_M, _i, _j) \
65  (ccl_assert((((_M)->n)*((_i)-1)+((_j)-1))<(((_M)->m)*((_M)->n))), \
66  ((_M)->coefs->num[((_M)->n)*((_i)-1)+((_j)-1)]))
67 
68 # define TLA_M_DEN(_M) (_M)->coefs->den
69 
70 extern void
71 tla_matrix_remove_last_line (tla_matrix_t R, tla_matrix_t M);
72 
73 extern void
74 tla_matrix_resize (tla_matrix_t M, int m, int n);
75 
76 extern void
77 tla_matrix_clear (tla_matrix_t M);
78 
79 extern void
80 tla_matrix_canonicalize (tla_matrix_t M);
81 
82 #define tla_matrix_get_nb_lines(M) ((M)->m)
83 #define tla_matrix_get_nb_columns(M) ((M)->n)
84 
85 extern void
86 tla_matrix_get_line (tla_matrix_t M, int i, tla_vec_t R);
87 
88 extern void
89 tla_matrix_get_column (tla_matrix_t M, int j, tla_vec_t R);
90 
91 /*
92  * \pre v->size == n && R->size == m
93  */
94 extern void
95 tla_matrix_mul_vector (tla_vec_t R, const tla_matrix_t M, const tla_vec_t v);
96 
97 void
98 tla_matrix_mul_matrix (tla_matrix_t R, const tla_matrix_t M,
99  const tla_matrix_t N);
100 
101 extern void
102 tla_matrix_set (tla_matrix_t M, const tla_matrix_t N);
103 
104 extern void
105 tla_matrix_z_mul (tla_matrix_t R, const mpz_t z, const tla_matrix_t M);
106 
107 extern void
108 tla_matrix_set_identity (tla_matrix_t M);
109 
110 extern void
111 tla_matrix_set_zero (tla_matrix_t M);
112 
113 extern int
114 tla_matrix_are_equal (const tla_matrix_t M1, const tla_matrix_t M2);
115 
116 extern unsigned int
117 tla_matrix_hash (const tla_matrix_t M);
118 
119 extern int
120 tla_matrix_Z_solution (const tla_matrix_t M, tla_vec_t x, const tla_vec_t v);
121 
126 extern void
127 tla_matrix_compute_snf (tla_matrix_t A, tla_matrix_t H, int *dim,
128  tla_matrix_t X, tla_matrix_t Y, tla_matrix_t U,
129  tla_matrix_t V);
130 
135 extern void
136 tla_matrix_compute_hnf (const tla_matrix_t A, tla_matrix_t H, int *dim,
137  tla_matrix_t U, tla_matrix_t V);
138 
139 
140 extern void
141 tla_matrix_swap_lines (tla_matrix_t A, int i1, int i2);
142 
143 extern void
144 tla_matrix_swap_columns (tla_matrix_t A, int j1, int j2);
145 
146 extern void
147 tla_matrix_neg_line (tla_matrix_t A, int i);
148 
149 extern void
150 tla_matrix_neg_column (tla_matrix_t A, int j);
151 
152 extern void
153 tla_matrix_submul_column (tla_matrix_t A, int j, int jpivot, mpz_t x);
154 
155 extern void
156 tla_matrix_sub_column (tla_matrix_t A, int j, int jpivot);
157 
158 extern void
159 tla_matrix_addmul_column (tla_matrix_t A, int j, int jpivot, mpz_t x);
160 
161 extern void
162 tla_matrix_submul_line (tla_matrix_t A, int i, int ipivot, mpz_t x);
163 
164 extern void
165 tla_matrix_addmul_line (tla_matrix_t A, int i, int ipivot, mpz_t x);
166 
167 extern void
168 tla_matrix_add_line (tla_matrix_t A, int i, int ipivot);
169 
170 extern int
171 tla_matrix_least_in_line (tla_matrix_t H, int i, int jmin);
172 
173 extern int
174 tla_matrix_is_identity (tla_matrix_t M);
175 
176 END_C_DECLS
177 
178 #endif /* ! __MATRIX_H__ */
void tla_matrix_compute_hnf(const tla_matrix_t A, tla_matrix_t H, int *dim, tla_matrix_t U, tla_matrix_t V)
void tla_matrix_compute_snf(tla_matrix_t A, tla_matrix_t H, int *dim, tla_matrix_t X, tla_matrix_t Y, tla_matrix_t U, tla_matrix_t V)