MCPcopy Create free account
hub / github.com/BVLC/caffe / Forward_cpu

Method Forward_cpu

src/caffe/layers/lstm_unit_layer.cpp:41–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40template <typename Dtype>
41void LSTMUnitLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
42 const vector<Blob<Dtype>*>& top) {
43 const int num = bottom[0]->shape(1);
44 const int x_dim = hidden_dim_ * 4;
45 const Dtype* C_prev = bottom[0]->cpu_data();
46 const Dtype* X = bottom[1]->cpu_data();
47 const Dtype* cont = bottom[2]->cpu_data();
48 Dtype* C = top[0]->mutable_cpu_data();
49 Dtype* H = top[1]->mutable_cpu_data();
50 for (int n = 0; n < num; ++n) {
51 for (int d = 0; d < hidden_dim_; ++d) {
52 const Dtype i = sigmoid(X[d]);
53 const Dtype f = (*cont == 0) ? 0 :
54 (*cont * sigmoid(X[1 * hidden_dim_ + d]));
55 const Dtype o = sigmoid(X[2 * hidden_dim_ + d]);
56 const Dtype g = tanh(X[3 * hidden_dim_ + d]);
57 const Dtype c_prev = C_prev[d];
58 const Dtype c = f * c_prev + i * g;
59 C[d] = c;
60 const Dtype tanh_c = tanh(c);
61 H[d] = o * tanh_c;
62 }
63 C_prev += hidden_dim_;
64 X += x_dim;
65 C += hidden_dim_;
66 H += hidden_dim_;
67 ++cont;
68 }
69}
70
71template <typename Dtype>
72void LSTMUnitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,

Callers

nothing calls this directly

Calls 5

tanhFunction · 0.85
shapeMethod · 0.80
sigmoidFunction · 0.70
cpu_dataMethod · 0.45
mutable_cpu_dataMethod · 0.45

Tested by

no test coverage detected