-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_tensor.cpp
102 lines (91 loc) · 2.55 KB
/
main_tensor.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "tensor.h"
void show_help(){
printf("*** Tensors Operations ***\n");
printf("\targ 1: input file name (tensor1) \n");
printf("\targ 2: input file name (tensor2) \n");
printf("\targ 3: operazione da effettuare (+,-,d,x,convolve, concat)\n");
printf("\targ 4: output file name\n");
printf("\targ 5: parametro axis della concat\n");
printf("\n");
}
int main (int argc, char * argv[]) {
char * fn_in_1; /* file 1 */
char * fn_in_2; /* file 2 */
char * operation; /* operazione da eseguire */
char * fn_out; /* output file */
int axis = 0; /* axis for concat */
/* variabili di appoggio per le computazioni */
Tensor a,b,out;
if(argc<4){
show_help();
return 0;
}
fn_in_1 = argv[1]; /* file 1 */
fn_in_2 = argv[2]; /* file 2 */
operation = argv[3]; /* operazione da eseguire */
fn_out = argv[4]; /* output file */
if(argc>5) {
axis = atoi(argv[5]);
}
a.read_file(fn_in_1);
b.read_file(fn_in_2);
if (strcmp(operation, "+") == 0) {
out=a+b;
}else if(strcmp(operation, "-") == 0) {
out=a-b;
}else if(strcmp(operation, "x") == 0) {
out=a*b;
}else if(strcmp(operation, "convolve") == 0) {
out=a.convolve(b);
}else if(strcmp(operation, "concat") == 0) {
out=a.concat(b,axis);
}else if(strcmp(operation, "d") == 0) {
out=a/b;
}else {
throw(unknown_operation());
}
out.write_file(fn_out);
return 0; /* ciao a tutti!*/
}
/*
int main() {
Tensor scrittura(3,3,3,5);
Tensor rescale(3,3,3);
rescale.init_random(60,5);
cout<<rescale<<"\n"<<"\n";
rescale.rescale();
cout<<rescale<<"\n"<<"\n";
cout<<"inizio"<<"\n";
Tensor s1(1,1,1,10);
cout<<"fine"<<"\n";
Tensor p(3, 3, 3);
p.init_random(60,5);
cout<<p(1,2,1)<<"ELEM";
cout<<p.getMax(1)<<"MAX"<<"\n";
cout << p;
cout<<"\n"<<"somma"<<"\n";
Tensor somma=p+p;
cout<< somma;
cout<<"\n"<<"clamp"<<"\n";
somma.clamp(10,130);
cout<<somma;
cout<<"\n"<<"padding"<<"\n";
Tensor pad =somma.padding(3,2);
cout<<pad;
cout<<"\n"<<"SUBSET"<<"\n";
Tensor sub=p.subset(0,1,0,3,0,3);
cout<<sub;
scrittura.write_file("prova.txt");
Tensor r;
r.read_file("prova.txt");
cout<<"\n"<<"\n"<<"STAMPA TENSORE FILE"<<"\n";
cout<<r;
cout<<"\n"<<"CONCAT"<<"\n";
Tensor concat(90,90,3,10);
Tensor c2(90,90,3,5);
Tensor res=c2.concat(concat,0);
res.showSize();
}*/