CiFEr
mat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 XLAB d.o.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CIFER_MATRIX_H
18 #define CIFER_MATRIX_H
19 
20 #include <gmp.h>
21 
22 #include "cifer/internal/errors.h"
23 #include "cifer/data/vec.h"
24 
44 typedef struct cfe_mat {
45  cfe_vec *mat;
46  size_t rows;
47  size_t cols;
48 } cfe_mat;
49 
57 void cfe_mat_init(cfe_mat *m, size_t rows, size_t cols);
58 
63 void cfe_mat_inits(size_t rows, size_t cols, cfe_mat *m, ...);
64 
71 void cfe_mat_set_const(cfe_mat *m, mpz_t c);
72 
81 void cfe_mat_copy(cfe_mat *res, cfe_mat *m);
82 
86 void cfe_mat_free(cfe_mat *m);
87 
92 void cfe_mat_frees(cfe_mat *m, ...);
93 
97 void cfe_mat_print(cfe_mat *m);
98 
102 void cfe_mat_add(cfe_mat *res, cfe_mat *m1, cfe_mat *m2);
103 
107 void cfe_mat_neg(cfe_mat *res, cfe_mat *m);
108 
112 void cfe_mat_dot(mpz_t res, cfe_mat *m1, cfe_mat *m2);
113 
117 void cfe_mat_mod(cfe_mat *res, cfe_mat *m, mpz_t modulo);
118 
122 void cfe_mat_mul_vec(cfe_vec *res, cfe_mat *m, cfe_vec *v);
123 
127 void cfe_mat_mul(cfe_mat *res, cfe_mat *m1, cfe_mat *m2);
128 
133 bool cfe_mat_check_bound(cfe_mat *m, mpz_t bound);
134 
138 void cfe_mat_get(mpz_t res, cfe_mat *m, size_t i, size_t j);
139 
143 void cfe_mat_get_col(cfe_vec *res, cfe_mat *m, size_t i);
144 
148 void cfe_mat_get_row(cfe_vec *res, cfe_mat *m, size_t i);
149 
153 cfe_vec *cfe_mat_get_row_ptr(cfe_mat *m, size_t i);
154 
158 void cfe_mat_set(cfe_mat *m, mpz_t el, size_t i, size_t j);
159 
163 void cfe_mat_set_vec(cfe_mat *m, cfe_vec *v, size_t i);
164 
169 void cfe_mat_to_vec(cfe_vec *res, cfe_mat *m);
170 
175 void cfe_mat_from_vec(cfe_mat *m, cfe_vec *v);
176 
180 void cfe_mat_transpose(cfe_mat *t, cfe_mat *m);
181 
187 void cfe_mat_extract_submatrix(cfe_mat *m, cfe_mat *min, size_t i, size_t j);
188 
192 void cfe_mat_determinant(mpz_t det, cfe_mat *m);
193 
197 cfe_error cfe_mat_inverse_mod(cfe_mat *inverse_mat, cfe_mat *m, mpz_t mod);
198 
202 void cfe_mat_mul_x_mat_y(mpz_t res, cfe_mat *mat, cfe_vec *x, cfe_vec *y);
203 
207 void cfe_mat_mul_scalar(cfe_mat *res, cfe_mat *mat, mpz_t s);
208 
217 void cfe_mat_gaussian_elimination(cfe_mat *res, cfe_mat *mat, mpz_t p);
218 
229 cfe_error cfe_mat_inverse_mod_gauss(cfe_mat *res, mpz_t det, cfe_mat *m, mpz_t p);
230 
240 void cfe_mat_determinant_gauss(mpz_t det, cfe_mat *m, mpz_t p);
241 
255 cfe_error cfe_gaussian_elimination_solver(cfe_vec *res, cfe_mat *mat, cfe_vec *vec, mpz_t p);
256 
257 #endif
cfe_mat_inits
void cfe_mat_inits(size_t rows, size_t cols, cfe_mat *m,...)
cfe_mat_mod
void cfe_mat_mod(cfe_mat *res, cfe_mat *m, mpz_t modulo)
cfe_mat_print
void cfe_mat_print(cfe_mat *m)
cfe_mat_mul_vec
void cfe_mat_mul_vec(cfe_vec *res, cfe_mat *m, cfe_vec *v)
cfe_mat_add
void cfe_mat_add(cfe_mat *res, cfe_mat *m1, cfe_mat *m2)
cfe_mat_free
void cfe_mat_free(cfe_mat *m)
cfe_mat_mul_scalar
void cfe_mat_mul_scalar(cfe_mat *res, cfe_mat *mat, mpz_t s)
cfe_vec
Definition: vec.h:41
cfe_mat_determinant_gauss
void cfe_mat_determinant_gauss(mpz_t det, cfe_mat *m, mpz_t p)
cfe_mat_extract_submatrix
void cfe_mat_extract_submatrix(cfe_mat *m, cfe_mat *min, size_t i, size_t j)
cfe_mat
struct cfe_mat cfe_mat
cfe_mat_gaussian_elimination
void cfe_mat_gaussian_elimination(cfe_mat *res, cfe_mat *mat, mpz_t p)
cfe_mat_get
void cfe_mat_get(mpz_t res, cfe_mat *m, size_t i, size_t j)
cfe_mat_frees
void cfe_mat_frees(cfe_mat *m,...)
errors.h
Error definitions.
cfe_mat::rows
size_t rows
Definition: mat.h:46
cfe_mat_mul
void cfe_mat_mul(cfe_mat *res, cfe_mat *m1, cfe_mat *m2)
cfe_mat_copy
void cfe_mat_copy(cfe_mat *res, cfe_mat *m)
cfe_mat_init
void cfe_mat_init(cfe_mat *m, size_t rows, size_t cols)
cfe_mat_inverse_mod_gauss
cfe_error cfe_mat_inverse_mod_gauss(cfe_mat *res, mpz_t det, cfe_mat *m, mpz_t p)
cfe_mat_get_row_ptr
cfe_vec * cfe_mat_get_row_ptr(cfe_mat *m, size_t i)
cfe_mat_transpose
void cfe_mat_transpose(cfe_mat *t, cfe_mat *m)
cfe_mat_check_bound
bool cfe_mat_check_bound(cfe_mat *m, mpz_t bound)
cfe_mat_neg
void cfe_mat_neg(cfe_mat *res, cfe_mat *m)
cfe_gaussian_elimination_solver
cfe_error cfe_gaussian_elimination_solver(cfe_vec *res, cfe_mat *mat, cfe_vec *vec, mpz_t p)
cfe_mat_get_col
void cfe_mat_get_col(cfe_vec *res, cfe_mat *m, size_t i)
cfe_mat_to_vec
void cfe_mat_to_vec(cfe_vec *res, cfe_mat *m)
cfe_mat_get_row
void cfe_mat_get_row(cfe_vec *res, cfe_mat *m, size_t i)
cfe_mat_from_vec
void cfe_mat_from_vec(cfe_mat *m, cfe_vec *v)
cfe_mat_set
void cfe_mat_set(cfe_mat *m, mpz_t el, size_t i, size_t j)
vec.h
Vector struct and operations.
cfe_mat_determinant
void cfe_mat_determinant(mpz_t det, cfe_mat *m)
cfe_mat_mul_x_mat_y
void cfe_mat_mul_x_mat_y(mpz_t res, cfe_mat *mat, cfe_vec *x, cfe_vec *y)
cfe_mat::cols
size_t cols
Definition: mat.h:47
cfe_mat_inverse_mod
cfe_error cfe_mat_inverse_mod(cfe_mat *inverse_mat, cfe_mat *m, mpz_t mod)
cfe_mat_dot
void cfe_mat_dot(mpz_t res, cfe_mat *m1, cfe_mat *m2)
cfe_mat_set_vec
void cfe_mat_set_vec(cfe_mat *m, cfe_vec *v, size_t i)
cfe_mat_set_const
void cfe_mat_set_const(cfe_mat *m, mpz_t c)
cfe_mat
Definition: mat.h:44