<commit_before>// Copyright 2014 <NAME>

#include <vector>

#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template <typename Dtype>
void SplitLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  CHECK_EQ(bottom.size(), 1) << "Split Layer takes a single blob as input.";
  CHECK_GE(top->size(), 1) << "Split Layer takes at least one blob as output.";
  count_ = bottom[0]->count();
  for (int i = 0; i < top->size(); ++i) {
    (*top)[i]->Reshape(bottom[0]->num(), bottom[0]->channels(),
                       bottom[0]->height(), bottom[0]->width());
    CHECK_EQ(count_, (*top)[i]->count());
  }
};

template <typename Dtype>
void SplitLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  const Dtype* bottom_data = bottom[0]->cpu_data();
  for (int i = 0; i < top->size(); ++i) {
    Dtype* top_data = (*top)[i]->mutable_cpu_data();
    caffe_copy(count_, bottom_data, top_data);
  }
}

template <typename Dtype>
void SplitLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  const Dtype* bottom_data = bottom[0]->gpu_data();
  for (int i = 0; i < top->size(); ++i) {
    Dtype* top_data = (*top)[i]->mutable_gpu_data();
    caffe_gpu_copy(count_, bottom_data, top_data);
  }
}

template <typename Dtype>
Dtype SplitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
      const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
  const Dtype* top_diff = top[0]->cpu_diff();
  Dtype* bottom_diff = (*bottom)[0]->mutable_cpu_diff();
  caffe_copy(count_, top_diff, bottom_diff);
  for (int i = 1; i < top.size(); ++i) {
    top_diff = top[i]->cpu_diff();
    caffe_axpy(count_, Dtype(1.), top_diff, bottom_diff);
  }
  return Dtype(0.);
}


template <typename Dtype>
Dtype SplitLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
      const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
  const Dtype* top_diff = top[0]->gpu_diff();
  Dtype* bottom_diff = (*bottom)[0]->mutable_gpu_diff();
  caffe_gpu_copy(count_, top_diff, bottom_diff);
  for (int i = 1; i < top.size(); ++i) {
    top_diff = top[i]->gpu_diff();
    caffe_gpu_axpy(count_, Dtype(1.), top_diff, bottom_diff);
  }
  return Dtype(0.);
}

INSTANTIATE_CLASS(SplitLayer);

}  // namespace caffe<commit_msg>make split_layer backward obey propagate_down<commit_after>// Copyright 2014 <NAME>

#include <vector>

#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template <typename Dtype>
void SplitLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  CHECK_EQ(bottom.size(), 1) << "Split Layer takes a single blob as input.";
  CHECK_GE(top->size(), 1) << "Split Layer takes at least one blob as output.";
  count_ = bottom[0]->count();
  for (int i = 0; i < top->size(); ++i) {
    (*top)[i]->Reshape(bottom[0]->num(), bottom[0]->channels(),
                       bottom[0]->height(), bottom[0]->width());
    CHECK_EQ(count_, (*top)[i]->count());
  }
};

template <typename Dtype>
void SplitLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  const Dtype* bottom_data = bottom[0]->cpu_data();
  for (int i = 0; i < top->size(); ++i) {
    Dtype* top_data = (*top)[i]->mutable_cpu_data();
    caffe_copy(count_, bottom_data, top_data);
  }
}

template <typename Dtype>
void SplitLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
      vector<Blob<Dtype>*>* top) {
  const Dtype* bottom_data = bottom[0]->gpu_data();
  for (int i = 0; i < top->size(); ++i) {
    Dtype* top_data = (*top)[i]->mutable_gpu_data();
    caffe_gpu_copy(count_, bottom_data, top_data);
  }
}

template <typename Dtype>
Dtype SplitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
      const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
  if (propagate_down) {
    const Dtype* top_diff = top[0]->cpu_diff();
    Dtype* bottom_diff = (*bottom)[0]->mutable_cpu_diff();
    caffe_copy(count_, top_diff, bottom_diff);
    for (int i = 1; i < top.size(); ++i) {
      top_diff = top[i]->cpu_diff();
      caffe_axpy(count_, Dtype(1.), top_diff, bottom_diff);
    }
  }
  return Dtype(0.);
}


template <typename Dtype>
Dtype SplitLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
      const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
  if (propagate_down) {
    const Dtype* top_diff = top[0]->gpu_diff();
    Dtype* bottom_diff = (*bottom)[0]->mutable_gpu_diff();
    caffe_gpu_copy(count_, top_diff, bottom_diff);
    for (int i = 1; i < top.size(); ++i) {
      top_diff = top[i]->gpu_diff();
      caffe_gpu_axpy(count_, Dtype(1.), top_diff, bottom_diff);
    }
  }
  return Dtype(0.);
}

INSTANTIATE_CLASS(SplitLayer);

}  // namespace caffe
{'fraction_non_alphanumeric': 0.18336713995943205, 'fraction_numerical': 0.010547667342799188, 'mean_word_length': 4.484983314794216, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1342926', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1794, 'n_words': 383}