NEST  2.6.0,not_revisioned_source_dir@0
slice_ring_buffer.h
Go to the documentation of this file.
1 /*
2  * slice_ring_buffer.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SLICE_RING_BUFFER_H
24 #define SLICE_RING_BUFFER_H
25 
26 #include "config.h"
27 
28 #include <algorithm>
29 #include <functional>
30 #include <vector>
31 
32 #include "nest.h"
33 #include "scheduler.h"
34 
35 namespace nest
36 {
57  public:
58 
60 
68  void add_spike(const delay rel_delivery, const long_t stamp,
69  const double ps_offset, const double weight);
70 
77  void add_refractory(const long_t stamp, const double_t ps_offset);
78 
82  void prepare_delivery();
83 
87  void discard_events();
88 
105  bool get_next_spike(const long_t req_stamp,
106  double_t& ps_offset, double_t& weight,
107  bool& end_of_refract);
108 
112  void clear();
113 
117  void resize();
118 
119  private:
120 
124  struct SpikeInfo {
125  SpikeInfo(long_t stamp, double_t ps_offset, double_t weight);
126 
127  bool operator< (const SpikeInfo& b) const;
128  bool operator<=(const SpikeInfo& b) const;
129  bool operator> (const SpikeInfo& b) const;
130 
131  // data elements must not be const, since heap implementation
132  // in DEC STL uses operator=().
133  long_t stamp_; //<! spike's time stamp
134  double_t ps_offset_; //<! spike offset is PS sense
135  double_t weight_; //<! spike weight
136  };
137 
139  std::vector<std::vector<SpikeInfo> > queue_;
140 
142  std::vector<SpikeInfo> * deliver_;
143 
145 
146  };
147 
148  inline
149  void SliceRingBuffer::add_spike(const delay rel_delivery, const long_t stamp,
150  const double ps_offset, const double weight)
151  {
152  const delay idx = Scheduler::get_slice_modulo(rel_delivery);
153  assert((size_t) idx < queue_.size());
154  assert(ps_offset >= 0);
155 
156  queue_[idx].push_back(SpikeInfo(stamp, ps_offset, weight));
157  }
158 
159  inline
160  void SliceRingBuffer::add_refractory(const long_t stamp, const double_t ps_offset)
161  {
162  // We require that only one refractory-return pseudo-event is stored per
163  // time step. We guard against violation using assert(): refract_.stamp_ must
164  // be equal to the marker value for non-refractoriness. All else would mean
165  // that a refractory neuron fired.
167 
168  refract_.stamp_ = stamp;
169  refract_.ps_offset_= ps_offset;
170  }
171 
172  inline
174  double_t& ps_offset, double_t& weight,
175  bool& end_of_refract)
176  {
177  end_of_refract = false;
178  if ( deliver_->empty() || refract_ <= deliver_->back() )
179  if ( refract_.stamp_ == req_stamp )
180  { // if relies on stamp_==long_t::max() if not refractory
181  // return from refractoriness
182  ps_offset = refract_.ps_offset_;
183  weight = 0;
184  end_of_refract = true;
185 
186  // mark as non-refractory
188  return true;
189  }
190  else
191  return false;
192  else if ( deliver_->back().stamp_ == req_stamp )
193  {
194  // we have an event to deliver, register its offset
195  ps_offset = deliver_->back().ps_offset_;
196 
197  // accumulate weights of all spikes with same stamp
198  // AND offset
199  weight = 0.0; // accumulate weights of all
200  while ( !deliver_->empty()
201  && deliver_->back().ps_offset_ == ps_offset
202  && deliver_->back().stamp_ == req_stamp )
203  {
204  weight += deliver_->back().weight_;
205  deliver_->pop_back();
206  }
207 
208  return true;
209  }
210  else
211  {
212  // ensure that we are not blocked by spike from the past, cf #404
213  assert( deliver_->back().stamp_ > req_stamp );
214  return false;
215  }
216  }
217 
218  inline
220  double_t weight) :
221  stamp_(stamp),
222  ps_offset_(ps_offset),
223  weight_(weight)
224  {}
225 
226  inline
228  {
229  return stamp_ == b.stamp_ ? ps_offset_ > b.ps_offset_ : stamp_ < b.stamp_;
230  }
231 
232  inline
234  {
235  return !(*this > b);
236  }
237 
238  inline
240  {
241  return stamp_ == b.stamp_ ? ps_offset_ < b.ps_offset_ : stamp_ > b.stamp_;
242  }
243 
244 }
245 
246 #endif
std::vector< std::vector< SpikeInfo > > queue_
entire queue, one slot per min_delay block within max_delay
Definition: slice_ring_buffer.h:139
double_t weight
Weight of a connection.
Definition: nest.h:170
void clear()
Clear buffer.
Definition: slice_ring_buffer.cpp:52
double_t ps_offset_
Definition: slice_ring_buffer.h:134
static delay get_slice_modulo(delay d)
Index to slice-based buffer.
Definition: scheduler.h:795
void discard_events()
Discard all events in current slice.
Definition: slice_ring_buffer.cpp:67
SpikeInfo(long_t stamp, double_t ps_offset, double_t weight)
Definition: slice_ring_buffer.h:219
long_t stamp_
Definition: slice_ring_buffer.h:133
Queue for all spikes arriving into a neuron.
Definition: slice_ring_buffer.h:56
double_t weight_
Definition: slice_ring_buffer.h:135
assert(pNet!=0)
std::vector< SpikeInfo > * deliver_
slot to deliver from
Definition: slice_ring_buffer.h:142
SliceRingBuffer()
Definition: slice_ring_buffer.cpp:28
bool operator<(const SpikeInfo &b) const
Definition: slice_ring_buffer.h:227
Information about spike.
Definition: slice_ring_buffer.h:124
void resize()
Resize the buffer according to min_delay and max_delay.
Definition: slice_ring_buffer.cpp:34
void add_spike(const delay rel_delivery, const long_t stamp, const double ps_offset, const double weight)
Add spike to queue.
Definition: slice_ring_buffer.h:149
double double_t
Double precision floating point numbers.
Definition: nest.h:93
const Name b("b")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:58
const Name max("max")
Definition: topology_names.h:75
bool operator>(const SpikeInfo &b) const
Definition: slice_ring_buffer.h:239
long_t delay
Delay of a connection.
Definition: nest.h:178
Default types used by the NEST kernel.
SpikeInfo refract_
pseudo-event for return from refractoriness
Definition: slice_ring_buffer.h:144
bool operator<=(const SpikeInfo &b) const
Definition: slice_ring_buffer.h:233
bool get_next_spike(const long_t req_stamp, double_t &ps_offset, double_t &weight, bool &end_of_refract)
Return next spike.
Definition: slice_ring_buffer.h:173
void prepare_delivery()
Prepare for spike delivery in current slice by sorting.
Definition: slice_ring_buffer.cpp:58
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
void add_refractory(const long_t stamp, const double_t ps_offset)
Add refractory event to queue.
Definition: slice_ring_buffer.h:160