-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (49 loc) · 1.29 KB
/
main.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
#include "./shaped/array.hpp"
#include "./thread_pool.hpp"
#include "./autograd/tensor.hpp"
using numcpp::constant;
using numcpp::with;
using numcpp::compute_running_time;
using numcpp::thread::ThreadPool;
useStdIO;
numcpp::thread::OStream acout(cout);
void test_cpp(){
acout<<1<<endl;
for(int i=0;i<100000;++i){
// acout<<'\0';
}
}
#define TEST_CPP 1
int main(){
#if !TEST_CPP
auto mat1 = numcpp::arange<int>(0, 10000, 1, {10,1000});
auto mat2 = numcpp::fill<int>(0, {1000,20});
constexpr bool output = 0;
compute_running_time(1,[&](){
mat1.matmul(mat2).print();
});
#else
// with(ThreadPool(4), [](auto &pool){
// for(int i=0;i<100;++i){
// pool.post(test_cpp);
// }
// });
// acout<<"END"<<endl;
using numcpp::Var;
auto x = Var::make(1.);
printf("x over\n");
auto y = Var::exp(x);
printf("y over\n");
auto z = Var::exp(y);
printf("z over\n");
with(std::vector<Var*>{x.get(), y.get(), z.get()}, [&](auto &&){
Var::compute_gradient(z);
printf("grad over\n");
acout << x->gradient_node << numcpp::exp(constant::e+1) << endl;
}, [](std::vector<Var*> const &var_list){
for(auto &var:var_list)
var->zero_grad();
});
#endif
return 0;
}