@Override
 public synchronized EventPacket<?> filterPacket(EventPacket<?> in) {
   checkOutputPacketEventType(in);
   checkNeuronAllocation();
   OutputEventIterator outItr = out.outputIterator();
   for (Object o : in) {
     TypedEvent e = (TypedEvent) o;
     if (neurons.stimulate(e)) {
       TypedEvent oe = (TypedEvent) outItr.nextOutput();
       oe.copyFrom(e);
     }
   }
   return out;
 }
Ejemplo n.º 2
0
    /**
     * extracts the meaning of the raw events.
     *
     * @param in the raw events, can be null
     * @return out the processed events. these are partially processed in-place. empty packet is
     *     returned if null is supplied as in.
     */
    @Override
    public synchronized EventPacket extractPacket(AEPacketRaw in) {
      if (out == null) {
        out = new EventPacket<PolarityEvent>(chip.getEventClass());
      } else {
        out.clear();
      }
      if (in == null) {
        return out;
      }
      int n = in.getNumEvents(); // addresses.length;

      int skipBy = 1;
      if (isSubSamplingEnabled()) {
        while (n / skipBy > getSubsampleThresholdEventCount()) {
          skipBy++;
        }
      }
      int[] a = in.getAddresses();
      int[] timestamps = in.getTimestamps();
      OutputEventIterator outItr = out.outputIterator();
      for (int i = 0; i < n; i += skipBy) { // bug here
        int addr = a[i];
        PolarityEvent e = (PolarityEvent) outItr.nextOutput();
        e.address = addr;
        e.timestamp = (timestamps[i]);
        e.x = (short) (((addr & XMASK) >>> XSHIFT));
        e.y = (short) ((addr & YMASK) >>> YSHIFT);
        e.type = (byte) (addr & 1);
        e.polarity = e.type == 1 ? PolarityEvent.Polarity.Off : PolarityEvent.Polarity.On;
        if (e.x < 0 || e.x >= sizeX || e.y < 0 || e.y >= sizeY) {
          log.warning(
              e.toString()
                  + " is outside size of chip"); // TODO should remove for speed once problems with
                                                 // y address outside legal range are sorted out
        }
      }
      return out;
    }