| 40 | |
| 41 | template <typename Dtype> |
| 42 | void ReductionLayer<Dtype>::Forward_cpu( |
| 43 | const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { |
| 44 | const Dtype* bottom_data = bottom[0]->cpu_data(); |
| 45 | const Dtype* mult_data = NULL; |
| 46 | if (sum_multiplier_.count() > 0) { |
| 47 | mult_data = sum_multiplier_.cpu_data(); |
| 48 | } |
| 49 | Dtype* top_data = top[0]->mutable_cpu_data(); |
| 50 | for (int i = 0; i < num_; ++i) { |
| 51 | switch (op_) { |
| 52 | case ReductionParameter_ReductionOp_SUM: |
| 53 | case ReductionParameter_ReductionOp_MEAN: |
| 54 | *top_data = caffe_cpu_dot(dim_, mult_data, bottom_data); |
| 55 | break; |
| 56 | case ReductionParameter_ReductionOp_ASUM: |
| 57 | *top_data = caffe_cpu_asum(dim_, bottom_data); |
| 58 | break; |
| 59 | case ReductionParameter_ReductionOp_SUMSQ: |
| 60 | *top_data = caffe_cpu_dot(dim_, bottom_data, bottom_data); |
| 61 | break; |
| 62 | default: |
| 63 | LOG(FATAL) << "Unknown reduction op: " |
| 64 | << ReductionParameter_ReductionOp_Name(op_); |
| 65 | } |
| 66 | bottom_data += dim_; |
| 67 | ++top_data; |
| 68 | } |
| 69 | if (coeff_ != Dtype(1)) { |
| 70 | // Reset the top_data pointer. |
| 71 | top_data = top[0]->mutable_cpu_data(); |
| 72 | caffe_scal(num_, coeff_, top_data); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | template <typename Dtype> |
| 77 | void ReductionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, |
nothing calls this directly
no test coverage detected