CiFEr
|
Matrix struct and operations. More...
Go to the source code of this file.
Data Structures | |
struct | cfe_mat |
Typedefs | |
typedef struct cfe_mat | cfe_mat |
Matrix struct and operations.
As in GMP library, all functions except initialization functions presume that all of the parameters are properly initialized.
All functions (unless otherwise specified) store their results (either a GMP integer, a vector or a matrix) to a parameter and do not modify the original matrix. Thus, the "result" passed as a parameter must also be properly initialized.
Matrix of arbitrary precision (GMP) integers. It represents a row-major matrix. A matrix of dimensions i, j consists of i vectors, each consisting of j elements.
void cfe_mat_init | ( | cfe_mat * | m, |
size_t | rows, | ||
size_t | cols | ||
) |
Initializes a matrix.
m | A pointer to the uninitialized matrix |
rows | The number of rows |
cols | The number of columns |
void cfe_mat_inits | ( | size_t | rows, |
size_t | cols, | ||
cfe_mat * | m, | ||
... | |||
) |
Variadic version of cfe_mat_init. Initializes a NULL-terminated list of matrices.
void cfe_mat_set_const | ( | cfe_mat * | m, |
mpz_t | c | ||
) |
Sets all the entries of a matrix to equal the given constant.
m | A pointer to an initialized matrix |
c | The constant that the entries equal to |
Copies all the entries of a matrix to another matrix. The matrices must have equal dimensions.
res | A pointer to an initialized matrix, matrix will be copied here |
m | A pointer to the matrix that will be copied |
void cfe_mat_free | ( | cfe_mat * | m | ) |
Frees the memory occupied by the contents of the matrix.
void cfe_mat_frees | ( | cfe_mat * | m, |
... | |||
) |
Variadic version of cfe_mat_free. Frees a NULL-terminated list of matrices.
void cfe_mat_print | ( | cfe_mat * | m | ) |
Prints a matrix to standard output.
Calculates the dot (inner) product of matrices.
Multiplication of a matrix by a vector.
bool cfe_mat_check_bound | ( | cfe_mat * | m, |
mpz_t | bound | ||
) |
Checks if all elements are < bound.
void cfe_mat_get | ( | mpz_t | res, |
cfe_mat * | m, | ||
size_t | i, | ||
size_t | j | ||
) |
Sets res to the j-th element of the i-th row of the matrix.
Sets res to the i-th column of the matrix.
Sets res to the i-th row of the matrix.
Returs the pointer to the i-th row of the matrix.
void cfe_mat_set | ( | cfe_mat * | m, |
mpz_t | el, | ||
size_t | i, | ||
size_t | j | ||
) |
Sets the j-th element of the i-th row of the matrix to el.
Creates a vector from matrix elements by concatenating rows into a single vector.
Constructs a matrix of dimensions rows * cols from v. The vector must hold exactly rows * cols elements.
Returns a matrix obtained from m by removing row i and column j. It returns an error if i >= number of rows of m, or if j >= number of columns of m.
void cfe_mat_determinant | ( | mpz_t | det, |
cfe_mat * | m | ||
) |
Determinant of a square matrix.
Inverse of a matrix over a modular field Z_mod.
Calcualtes x^T * mat * y, for x, y vectors and mat a matrix.
Multiplication of a matrix mat and a scalar s.
cfe_gaussian_elimination transforms a matrix to an equivalent upper triangular matrix over field Z_p, where p should be a prime number.
res | A pointer to an initialized matrix where the result will be saved |
mat | A pointer to a matrix to be transformed |
p | Modulus for the computations |
cfe_mat_inverse_mod_gauss calculates the inverse of a matrix over field Z_p, using Gaussian elimination. The latter is faster than the naive (analytic) algorithm. Additionally the determinant of the matrix is returned.
res | A pointer to an initialized matrix where the result will be saved |
det | Determinant will be saved here; if not needed this should be NULL |
m | A pointer to a matrix |
p | Modulus for the computations |
void cfe_mat_determinant_gauss | ( | mpz_t | det, |
cfe_mat * | m, | ||
mpz_t | p | ||
) |
cfe_mat_determinant_gauss calculates the determinant of a matrix over field Z_p, using Gaussian elimination. The latter is faster than the naive (analytic) algorithm.
det | The result will be saved |
m | A pointer to a matrix |
p | Modulus for the computations |
cfe_gaussian_elimination_solver solves a matrix vector equation mat * x = v and finds vector x, using Gaussian elimination. Arithmetic operations are considered to be over Z_p, where p should be a prime number. If such x does not exist, then the function returns an 1, else 0.
res | A pointer to an uninitialized vector where the result will be saved |
mat | A pointer to the matrix for the equation |
vec | A pointer to the right-hand side vector in the equation |
p | Modulus for the computations |