| 70 | |
| 71 | template <typename Dtype> |
| 72 | void CropLayer<Dtype>::crop_copy(const vector<Blob<Dtype>*>& bottom, |
| 73 | const vector<Blob<Dtype>*>& top, |
| 74 | const vector<int>& offsets, |
| 75 | vector<int> indices, |
| 76 | int cur_dim, |
| 77 | const Dtype* src_data, |
| 78 | Dtype* dest_data, |
| 79 | bool is_forward) { |
| 80 | if (cur_dim + 1 < top[0]->num_axes()) { |
| 81 | // We are not yet at the final dimension, call copy recursively |
| 82 | for (int i = 0; i < top[0]->shape(cur_dim); ++i) { |
| 83 | indices[cur_dim] = i; |
| 84 | crop_copy(bottom, top, offsets, indices, cur_dim+1, |
| 85 | src_data, dest_data, is_forward); |
| 86 | } |
| 87 | } else { |
| 88 | // We are at the last dimensions, which is stored continously in memory |
| 89 | for (int i = 0; i < top[0]->shape(cur_dim); ++i) { |
| 90 | // prepare index vector reduced(red) and with offsets(off) |
| 91 | std::vector<int> ind_red(cur_dim, 0); |
| 92 | std::vector<int> ind_off(cur_dim+1, 0); |
| 93 | for (int j = 0; j < cur_dim; ++j) { |
| 94 | ind_red[j] = indices[j]; |
| 95 | ind_off[j] = indices[j] + offsets[j]; |
| 96 | } |
| 97 | ind_off[cur_dim] = offsets[cur_dim]; |
| 98 | // do the copy |
| 99 | if (is_forward) { |
| 100 | caffe_copy(top[0]->shape(cur_dim), |
| 101 | src_data + bottom[0]->offset(ind_off), |
| 102 | dest_data + top[0]->offset(ind_red)); |
| 103 | } else { |
| 104 | // in the backwards pass the src_data is top_diff |
| 105 | // and the dest_data is bottom_diff |
| 106 | caffe_copy(top[0]->shape(cur_dim), |
| 107 | src_data + top[0]->offset(ind_red), |
| 108 | dest_data + bottom[0]->offset(ind_off)); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | template <typename Dtype> |
| 115 | void CropLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, |
nothing calls this directly
no test coverage detected