-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp_tensorarray.java
52 lines (51 loc) · 1.1 KB
/
exp_tensorarray.java
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
package tensordef;
import basicops.*;
import java.math.*;
import java.util.*;
public class exp_tensorarray extends superopdef
{
tensorarray arr1;
exp expops[][];
tensorarray eval;
tensorgraph graph;
backpropagationstructure<exp_tensorarray> curstruct;
public exp_tensorarray(tensorarray t1,tensorgraph graph)
{
arr1=t1;
this.graph=graph;
eval=new tensorarray(arr1.dim1,arr1.dim2,false);
expops=new exp[arr1.dim1][arr1.dim2];
curstruct=new backpropagationstructure<exp_tensorarray>(this,eval,null);
graph.addtolist(curstruct);
for(int i=0;i<arr1.dim1;i++)
{
for(int j=0;j<arr1.dim2;j++)
{
expops[i][j]=new exp(arr1.arr[i][j]);
}
}
}
public tensorarray forward()
{
for(int i=0;i<arr1.dim1;i++)
{
for(int j=0;j<arr1.dim2;j++)
{
eval.arr[i][j].data=expops[i][j].forward().data;
}
}
return eval;
}
public void backward(tensorarray backflow)
{
//System.out.println(backflow.arr[0][0].grad);
for(int i=0;i<arr1.dim1;i++)
{
for(int j=0;j<arr1.dim2;j++)
{
expops[i][j].backward(backflow.arr[i][j]);
}
}
graph.removefromlist(curstruct);
}
}