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

Method Backward_cpu

src/caffe/layers/batch_reindex_layer.cpp:52–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51template<typename Dtype>
52void BatchReindexLayer<Dtype>::Backward_cpu(
53 const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,
54 const vector<Blob<Dtype>*>& bottom) {
55 CHECK(!propagate_down[1]) << "Cannot backprop to index.";
56 if (!propagate_down[0]) {
57 return;
58 }
59 int inner_dim = bottom[0]->count() / bottom[0]->shape(0);
60 Dtype* bot_diff = bottom[0]->mutable_cpu_diff();
61 const Dtype* permut = bottom[1]->cpu_data();
62 const Dtype* top_diff = top[0]->cpu_diff();
63 caffe_set(bottom[0]->count(), Dtype(0), bot_diff);
64 for (int index = 0; index < top[0]->count(); ++index) {
65 int n = index / (inner_dim);
66 int in_n = static_cast<int>(permut[n]);
67 bot_diff[in_n * (inner_dim) + index % (inner_dim)] += top_diff[index];
68 }
69}
70
71#ifdef CPU_ONLY
72STUB_GPU(BatchReindexLayer);

Callers

nothing calls this directly

Calls 6

caffe_setFunction · 0.85
countMethod · 0.80
shapeMethod · 0.80
mutable_cpu_diffMethod · 0.80
cpu_diffMethod · 0.80
cpu_dataMethod · 0.45

Tested by

no test coverage detected