-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
80 lines (67 loc) · 1.61 KB
/
test.cpp
File metadata and controls
80 lines (67 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <gmp.h>
#include <gmpxx.h>
#include "tools/Crypto.h"
using namespace std;
typedef struct matrix
{
int rows; //number of rows.
int cols; //number of columns
mpz_t *data = NULL;
}*Matrix;
#define mat_element(mat, row_idx, col_idx) mat->data[row_idx * (mat->cols) + col_idx]
//initialize the matrix
//initialize the matrix
Matrix mat_init(int rows, int cols)
{
if(rows <= 0 || cols <= 0)
{
return NULL;
}
Matrix A;
A = (Matrix)malloc(sizeof(Matrix) + (rows*cols)*sizeof(mpz_t));
A->cols = cols;
A->rows = rows;
A->data = (mpz_t *)malloc(rows*cols*sizeof(mpz_t));
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
mpz_init(mat_element(A, i, j));
mpz_set_si(mat_element(A, i, j), 0);
}
}
return A;
}
void set_matrix_element(Matrix A, int row_idx, int col_idx, mpz_class val)
{
if(row_idx < 0 || row_idx >= A->rows || col_idx < 0 || col_idx >= A->cols)
{
printf("Matrix index out of range\n");
return;
}
mpz_set(A->data[row_idx * (A->cols) + col_idx], val.get_mpz_t());
}
void simple_test(Matrix mat)
{
for(int i = 0; i < mat->rows ; i++)
{
for(int j = 0; j < mat->cols; j++)
cout << mat_element(mat, i, j) << " ";
cout << "\n";
}
cout << "\n";
}
int main(int argc, char const *argv[])
{
Matrix a;
a = mat_init(1, 3);
cout << "a initialized\n";
mpz_class x{1};
set_matrix_element(a, 0,0, x);
set_matrix_element(a, 0,1, x);
set_matrix_element(a, 0,2, x);
}