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