-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegate_tensorarray.java
More file actions
50 lines (49 loc) · 1.02 KB
/
negate_tensorarray.java
File metadata and controls
50 lines (49 loc) · 1.02 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
package tensordef;
import basicops.*;
import java.util.*;
public class negate_tensorarray extends superopdef
{
tensorarray arr;
tensorarray eval;
backpropagationstructure<negate_tensorarray> curstruct;
negate ops[][];
tensorgraph graph;
public negate_tensorarray(tensorarray arr,tensorgraph graph)
{
this.arr=arr;
this.graph=graph;
eval=new tensorarray(arr.dim1,arr.dim2,arr.trainable);
curstruct=new backpropagationstructure<>(this,eval,null);
graph.addtolist(curstruct);
ops=new negate[arr.dim1][arr.dim2];
for(int i=0;i<arr.dim1;i++)
{
for(int j=0;j<arr.dim2;j++)
{
ops[i][j]=new negate(arr.arr[i][j]);
}
}
}
public tensorarray forward()
{
for(int i=0;i<arr.dim1;i++)
{
for(int j=0;j<arr.dim2;j++)
{
eval.arr[i][j].data=ops[i][j].forward().data;
}
}
return eval;
}
public void backward(tensorarray backward)
{
for(int i=0;i<arr.dim1;i++)
{
for(int j=0;j<arr.dim2;j++)
{
ops[i][j].backward(backward.arr[i][j]);
}
}
graph.removefromlist(curstruct);
}
}