-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pad.c
64 lines (58 loc) · 1.71 KB
/
test_pad.c
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
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include <string.h>
// #include "SimpleMatrixMultiplication.h"
#include "matrix/matrix.h"
// #include "CacheObliviousMatrixMultiplication.h"
// #include "StrassenMatrixMultiplication.h"
#include "util.h"
const unsigned int M_default = 2;
const unsigned int N_default = 2;
int main(int argc, char** argv) {
int M, N, new_M, new_N;
if (argc < 5) {
fprintf(stderr, "M, N not given, use the default values\n");
M = M_default;
N = N_default;
new_M = M*2;
new_N = N*2;
}
else{
M = atoi(argv[1]);
N = atoi(argv[2]);
new_M = atoi(argv[3]);
new_N = atoi(argv[4]);
}
fprintf(stderr, "the values are: M(%d); N(%d); new_M(%d); new_N(%d)", M, N, new_M, new_N);
int incRowA = N;
Dtype* A = (Dtype*)malloc(sizeof(int)*M*incRowA);
// initialize the original matrix to all 1s
for(int i = 0; i < M; i++){
for(int j = 0; j < N; j++){
A[i*incRowA+j] = j;
}
}
// print the initial matrix
fprintf(stderr, "printing the original matrix \n");
for(int i = 0; i < M; i++){
for(int j = 0; j < N; j++){
fprintf(stderr, "%d", (int)A[i*N]);
}
fprintf(stderr, "\n");
}
Dtype* new_A = padMatrixToPowerSquareMatrix(A, M, N, incRowA);
int longer_side = max(M, N);
new_M = new_N = getNumberLargerThanXAndIsPowerOfTwo(longer_side);
fprintf(stderr, "print the new matrix after zero padding \n");
for(int i = 0; i < new_M; i++){
for(int j = 0; j < new_N; j++){
fprintf(stderr, "%d", (int)(new_A[i*new_N + j]));
}
fprintf(stderr, "\n");
}
}