-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThirdSpanLayer.cpp
More file actions
56 lines (53 loc) · 1.94 KB
/
Copy pathThirdSpanLayer.cpp
File metadata and controls
56 lines (53 loc) · 1.94 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
#include "DeepLearning.h"
ThirdSpanLayer::ThirdSpanLayer(int d,int h,int w){
depth = d;
height = h;
width = w;
for(int i = 0;i < batchSize;i++){
ThirdArray tmp(depth,height,width);
error.push_back(tmp);
}
for(int i = 0;i < batchSize;i++){
Array tmp(depth*height*width,1);
output.push_back(tmp);
}
}
void ThirdSpanLayer::forward(const vector<ThirdArray>& inp){
for(int n = 0;n < batchSize;n++){
if(inp[n].depth != depth || inp[n].width != width || inp[n].height != height){
printf("Error : Unable to compute ThirdSpan Forward\n");
fprintf(fpDebug, "Error : Unable to compute ThirdSpan Forward\n");
fprintf(fpDebug, "depth = %d\n",depth);
fprintf(fpDebug, "input->depth = %d\n",inp[n].depth);
fprintf(fpDebug, "height = %d\n",height);
fprintf(fpDebug, "input->height = %d\n",inp[n].height);
fprintf(fpDebug, "width = %d\n",width);
fprintf(fpDebug, "input->width = %d\n",inp[n].width);
exit(0);
}
for(int i = 0;i < depth;i++){
for(int j = 0;j < height;j++){
for(int k = 0;k < width;k++){
output[n].arr[i * height * width + j * width + k][0] = inp[n].thiArr[i].arr[j][k];
}
}
}
}
return;
}
void ThirdSpanLayer::backward(const vector<Array>& err){
for(int n = 0;n < batchSize;n++){
if(err[n].width != 1 || err[n].height != depth * width * height){
printf("Error : Unable to compute Span backward\n");
exit(0);
}
for(int i = 0;i < depth;i++){
for(int j = 0;j < height;j++){
for(int k = 0;k < width;k++){
error[n].thiArr[i].arr[j][k] = err[n].arr[i * height * width + j * width + k][0];
}
}
}
}
return;
}