<commit_before>namespace ncs {

namespace sim {

template<DeviceType::Type MType>
NeuronSimulatorUpdater<MType>::NeuronSimulatorUpdater()
  : neuron_state_subscription_(nullptr),
    input_subscription_(nullptr),
    synaptic_current_subscription_(nullptr) {
}

template<DeviceType::Type MType>
bool NeuronSimulatorUpdater<MType>::
init(InputPublisher* input_publisher,
     SynapticCurrentPublisher* synaptic_current_publisher,
     const std::vector<NeuronSimulator<MType>*>& neuron_simulators,
     const std::vector<size_t>& device_id_offsets,
     size_t neuron_device_vector_size,
     size_t num_buffers) {
  num_buffers_ = num_buffers;
  neuron_simulators_ = neuron_simulators;
  device_id_offsets_ = device_id_offsets;
  neuron_device_vector_size_ = neuron_device_vector_size;
  for (size_t i = 0; i < num_buffers_; ++i) {
    auto buffer = 
      new DeviceNeuronStateBuffer<MType>(neuron_device_vector_size_);
    if (!buffer->isValid()) {
      std::cerr << "Failed to initialize DeviceNeuronStateBuffer." <<
        std::endl;
      delete buffer;
      return false;
    }
    addBlank(buffer);
  }
  input_subscription_ = input_publisher->subscribe();
  synaptic_current_subscription_ = synaptic_current_publisher->subscribe();
  neuron_state_subscription_ = this->subscribe();

  return true;
}

template<DeviceType::Type MType>
bool NeuronSimulatorUpdater<MType>::start() {
  // Initialize the first voltage vector
  auto buffer = this->getBlank();
  for (size_t i = 0; i < neuron_simulators_.size(); ++i) {
    auto simulator = neuron_simulators_[i];
    auto offset = device_id_offsets_[i];
    if (!simulator->initializeVoltages(buffer->getVoltages() + offset)) {
      std::cerr << "Failed to initialize voltages." << std::endl;
      buffer->release();
      return false;
    }
  }
  this->publish(buffer);

  struct Synchronizer : public DataBuffer {
    DeviceNeuronStateBuffer<MType>* previous_neuron_state;
    SynapticCurrentBuffer<MType>* synaptic_current;
    InputBuffer<MType>* input;
    DeviceNeuronStateBuffer<MType>* current_neuron_state;
  };<commit_msg>Initial fire vector is zeroed.<commit_after>namespace ncs {

namespace sim {

template<DeviceType::Type MType>
NeuronSimulatorUpdater<MType>::NeuronSimulatorUpdater()
  : neuron_state_subscription_(nullptr),
    input_subscription_(nullptr),
    synaptic_current_subscription_(nullptr) {
}

template<DeviceType::Type MType>
bool NeuronSimulatorUpdater<MType>::
init(InputPublisher* input_publisher,
     SynapticCurrentPublisher* synaptic_current_publisher,
     const std::vector<NeuronSimulator<MType>*>& neuron_simulators,
     const std::vector<size_t>& device_id_offsets,
     size_t neuron_device_vector_size,
     size_t num_buffers) {
  num_buffers_ = num_buffers;
  neuron_simulators_ = neuron_simulators;
  device_id_offsets_ = device_id_offsets;
  neuron_device_vector_size_ = neuron_device_vector_size;
  for (size_t i = 0; i < num_buffers_; ++i) {
    auto buffer = 
      new DeviceNeuronStateBuffer<MType>(neuron_device_vector_size_);
    if (!buffer->isValid()) {
      std::cerr << "Failed to initialize DeviceNeuronStateBuffer." <<
        std::endl;
      delete buffer;
      return false;
    }
    addBlank(buffer);
  }
  input_subscription_ = input_publisher->subscribe();
  synaptic_current_subscription_ = synaptic_current_publisher->subscribe();
  neuron_state_subscription_ = this->subscribe();

  return true;
}

template<DeviceType::Type MType>
bool NeuronSimulatorUpdater<MType>::start() {
  // Initialize the first voltage vector
  auto buffer = this->getBlank();
  if (!Memory<MType>::zero(buffer->getFireBits(),
                           Bit::num_words(buffer->getVectorSize()))) {
    std::cerr << "Failed to zero initial DeviceNeuronStateBuffer." <<
      std::endl;
    return false;
  }

  for (size_t i = 0; i < neuron_simulators_.size(); ++i) {
    auto simulator = neuron_simulators_[i];
    auto offset = device_id_offsets_[i];
    if (!simulator->initializeVoltages(buffer->getVoltages() + offset)) {
      std::cerr << "Failed to initialize voltages." << std::endl;
      buffer->release();
      return false;
    }
  }
  this->publish(buffer);

  struct Synchronizer : public DataBuffer {
    DeviceNeuronStateBuffer<MType>* previous_neuron_state;
    SynapticCurrentBuffer<MType>* synaptic_current;
    InputBuffer<MType>* input;
    DeviceNeuronStateBuffer<MType>* current_neuron_state;
  };
{'fraction_non_alphanumeric': 0.10970654627539503, 'fraction_numerical': 0.0009029345372460496, 'mean_word_length': 4.8226018396846255, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 52, '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': '3623522', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1406, 'n_words': 252}