| 115 | |
| 116 | template <typename Dtype> |
| 117 | void ScaleLayer<Dtype>::Forward_cpu( |
| 118 | const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { |
| 119 | const Dtype* bottom_data = bottom[0]->cpu_data(); |
| 120 | if (bottom[0] == top[0]) { |
| 121 | // In-place computation; need to store bottom data before overwriting it. |
| 122 | // Note that this is only necessary for Backward; we could skip this if not |
| 123 | // doing Backward, but Caffe currently provides no way of knowing whether |
| 124 | // we'll need to do Backward at the time of the Forward call. |
| 125 | caffe_copy(bottom[0]->count(), bottom[0]->cpu_data(), |
| 126 | temp_.mutable_cpu_data()); |
| 127 | } |
| 128 | const Dtype* scale_data = |
| 129 | ((bottom.size() > 1) ? bottom[1] : this->blobs_[0].get())->cpu_data(); |
| 130 | Dtype* top_data = top[0]->mutable_cpu_data(); |
| 131 | for (int n = 0; n < outer_dim_; ++n) { |
| 132 | for (int d = 0; d < scale_dim_; ++d) { |
| 133 | const Dtype factor = scale_data[d]; |
| 134 | caffe_cpu_scale(inner_dim_, factor, bottom_data, top_data); |
| 135 | bottom_data += inner_dim_; |
| 136 | top_data += inner_dim_; |
| 137 | } |
| 138 | } |
| 139 | if (bias_layer_) { |
| 140 | bias_layer_->Forward(bias_bottom_vec_, top); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | template <typename Dtype> |
| 145 | void ScaleLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, |
nothing calls this directly
no test coverage detected