-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorgraph.java
More file actions
63 lines (58 loc) · 1.22 KB
/
tensorgraph.java
File metadata and controls
63 lines (58 loc) · 1.22 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package tensordef;
import basicops.*;
//import tensordef.*;
import java.util.*;
public class tensorgraph
{
ArrayList<backpropagationstructure<?>> oplist;
public tensorgraph()
{
oplist=new ArrayList<backpropagationstructure<?>>();
}
public <T extends superopdef>void addtolist(backpropagationstructure<T> ob)
{
oplist.add(ob);
}
public <T extends superopdef> void removefromlist(backpropagationstructure<T> ob)
{
oplist.remove(ob);
}
public void backward()
{
backpropagationstructure<?> temp=oplist.get(oplist.size()-1);
if(temp.ans!=null)
{
for(int i=0;i<temp.ans.dim1;i++)
{
for(int j=0;j<temp.ans.dim2;j++)
{
temp.ans.arr[i][j].grad=1;
}
}
}else
{
for(int i=0;i<temp.ans1.dim1;i++)
{
for(int j=0;j<temp.ans1.dim2;j++)
{
for(int k=0;k<temp.ans1.dim3;k++)
{
temp.ans1.arr[i][j][k].grad=1;
}
}
}
}
while(!oplist.isEmpty())
{
backpropagationstructure<?> curobjectref=oplist.get(oplist.size()-1);
//System.out.println(curobjectref);
if(curobjectref.ans!=null)
curobjectref.ob.backward(curobjectref.ans);
else
{
//System.out.println(curobjectref.ob);
curobjectref.ob.backwardconv(curobjectref.ans1);
}
}
}
}