-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (38 loc) · 1.5 KB
/
main.cpp
File metadata and controls
46 lines (38 loc) · 1.5 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
#include <iostream>
#include <vector>
#include "Tensor.hpp"
int main() {
std::cout << "test start" << std::endl;
Tensor a = Tensor( std::vector<double>{ 1, 2, 3, 4, 5 }, true );
Tensor b = Tensor( std::vector<double>{ 2, 2, 2, 2, 2 }, true );
Tensor c = Tensor( std::vector<double>{ 5, 4, 3, 2, 1 }, true );
Tensor bb = -b;
Tensor bbb = -b;
Tensor d = a + bb;
Tensor e = bbb + c;
Tensor f = d + e;
std::cout << "to string" << std::endl;
std::cout << a.to_string() << std::endl;
std::cout << b.to_string() << std::endl;
std::cout << c.to_string() << std::endl;
std::cout << d.to_string() << std::endl;
std::cout << e.to_string() << std::endl;
std::cout << f.to_string() << std::endl;
std::cout << "backward" << std::endl;
f.backward( Tensor( std::vector<double>{ 1, 1, 1, 1 } ) );
std::cout << "getGrad" << std::endl;
std::cout << a.getGrad().to_string() << std::endl;
std::cout << b.getGrad().to_string() << std::endl;
Tensor t1{ std::vector<double>{ 1, 2, 3, 4, 5 } };
Tensor t2 = t1.transpose();
std::cout << t2.to_string() << std::endl;
t2 = t1.mm( t2 );
std::cout << t2.to_string() << std::endl;
Tensor t3{ std::vector<std::vector<double>>{ std::vector<double>{ 1, 2, 3 }, std::vector<double>{ 4, 5, 6 } } };
std::cout << t3.to_string() << std::endl;
Tensor t4{ std::vector<std::vector<double>>{ std::vector<double>{ 1, 2 }, std::vector<double>{ 3, 4 } } };
Tensor t5 = t4.mm( t4 );
std::cout << t5.to_string() << std::endl;
std::cout << t5.transpose().to_string() << std::endl;
return 0;
}