| 20 | |
| 21 | template <typename Dtype> |
| 22 | void TanHLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, |
| 23 | const vector<bool>& propagate_down, |
| 24 | const vector<Blob<Dtype>*>& bottom) { |
| 25 | if (propagate_down[0]) { |
| 26 | const Dtype* top_data = top[0]->cpu_data(); |
| 27 | const Dtype* top_diff = top[0]->cpu_diff(); |
| 28 | Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); |
| 29 | const int count = bottom[0]->count(); |
| 30 | Dtype tanhx; |
| 31 | for (int i = 0; i < count; ++i) { |
| 32 | tanhx = top_data[i]; |
| 33 | bottom_diff[i] = top_diff[i] * (1 - tanhx * tanhx); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #ifdef CPU_ONLY |
| 39 | STUB_GPU(TanHLayer); |
nothing calls this directly
no test coverage detected