-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot3d.java
66 lines (61 loc) · 1.48 KB
/
dot3d.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package tensordef;
import basicops.*;
public class dot3d extends superopdef
{
tensorgraph graph;
backpropagationstructure<dot3d> curstruct;
tensorarray3d arr1;
tensorarray3d arr2;
tensorarray3d eval;
tensorarray split1[];
tensorarray split2[];
tensorarrayops op;
dot dotops[];
tensorarray out[];
public dot3d(tensorarray3d arr1,tensorarray3d arr2,tensorgraph graph)
{
op=new tensorarrayops();
this.arr1=arr1;
this.arr2=arr2;
this.graph=graph;
if(arr1.dim1!=arr2.dim1 && arr1.dim2!=arr2.dim2 && arr1.dim3!=arr2.dim3)
{
System.out.println("dimensions should be equal");
System.exit(1);
}
else
{
out=new tensorarray[arr1.dim3];
//eval=new tensorarray3d(arr1.dim1,arr1.dim2,arr1.dim3,arr1.trainable);
split1=op.convert3dto2d(arr1);
split2=op.convert3dto2d(arr2);
dotops=new dot[arr1.dim3];
for(int i=0;i<arr1.dim3;i++)
{
dotops[i]=new dot(split1[i],split2[i],graph);
}
//System.out.println(arr1.arr[0][0][0].data);
//System.out.println(arr2.arr[0][0][0].data);
}
}
public tensorarray3d forwardconv()
{
for(int i=0;i<arr1.dim3;i++)
{
out[i]=dotops[i].forward();
}
eval=op.convert2dto3d(out);
curstruct=new backpropagationstructure<dot3d>(this,null,eval);
graph.addtolist(curstruct);
return eval;
}
public void backwardconv(tensorarray3d backflow)
{
//System.out.println(backflow.arr[0][0][0].grad);
for(int i=0;i<arr1.dim3;i++)
{
dotops[i].backward(out[i]);
}
graph.removefromlist(curstruct);
}
}