mirror of
https://github.com/marian-nmt/marian.git
synced 2024-09-11 06:15:56 +03:00
more loops
This commit is contained in:
parent
9bf70850cf
commit
c084ecd76c
24
src/test.cpp
24
src/test.cpp
@ -3,14 +3,16 @@
|
|||||||
|
|
||||||
#include "marian.h"
|
#include "marian.h"
|
||||||
|
|
||||||
marian::Var layer(size_t max) {
|
using namespace marian;
|
||||||
|
|
||||||
using namespace marian;
|
Var layer(size_t max, std::vector<Var>& x) {
|
||||||
|
|
||||||
Var x0 = 1, x1 = 2, x2 = 3;
|
Var x0 = 1, x1 = 2, x2 = 3;
|
||||||
|
x = { x0, x1, x2 };
|
||||||
|
|
||||||
Var y = 0.0;
|
Var y = 0.0;
|
||||||
for(int i = 0; i < max; i++) {
|
for(int i = 0; i < max; i++) {
|
||||||
Var xi = i;
|
Var xi = i;
|
||||||
|
x.push_back(xi);
|
||||||
y = y + x0 + log(x2) + x1;
|
y = y + x0 + log(x2) + x1;
|
||||||
for(int j = 0; j < i; ++j) {
|
for(int j = 0; j < i; ++j) {
|
||||||
y = y + xi;
|
y = y + xi;
|
||||||
@ -22,11 +24,10 @@ marian::Var layer(size_t max) {
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
using namespace marian;
|
std::vector<Var> x1, x2;
|
||||||
|
Var y1 = layer(10, x1);
|
||||||
Var y1 = layer(10);
|
Var y2 = layer(rand() % 20 + 1, x2);
|
||||||
Var y2 = layer(rand() % 20 + 1);
|
|
||||||
|
|
||||||
Var y = y1 + log(y2);
|
Var y = y1 + log(y2);
|
||||||
|
|
||||||
@ -40,4 +41,9 @@ int main(int argc, char** argv) {
|
|||||||
std::cerr << "dy/dy1 = " << y1.grad() << std::endl;
|
std::cerr << "dy/dy1 = " << y1.grad() << std::endl;
|
||||||
std::cerr << "dy/dy2 = " << y2.grad() << std::endl;
|
std::cerr << "dy/dy2 = " << y2.grad() << std::endl;
|
||||||
|
|
||||||
|
for(size_t i = 0; i < x1.size(); ++i)
|
||||||
|
std::cerr << "dy/dx1_" << i << " = " << x1[i].grad() << std::endl;
|
||||||
|
for(size_t i = 0; i < x2.size(); ++i)
|
||||||
|
std::cerr << "dy/dx2_" << i << " = " << x2[i].grad() << std::endl;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user