void MemoryTest::update(IProgressMonitor* monitor) const { for (int i = 0; i < getIterations() && (monitor ? !monitor->getAbortRequested() : true); ++i) { #ifdef WIN32 _sleep(getDelay()); #else sleep(getDelay()); #endif if (monitor) monitor->reportProgress(100.0 * (i + 1) / getIterations()); } newState->setOutput(boost::make_shared<std::vector<double> >(getSize())); }
void Board::drawArrow(int x1, int y1, int x2, int y2) { if(trying) return; // find out number of array int num = 0; while(num < 4 && history[num].x != -2) num++; // lighten the fields // remember mark_x,mark_y int mx = mark_x, my = mark_y; mark_x = x1; mark_y = y1; updateField(x1, y1); mark_x = x2; mark_y = y2; updateField(x2, y2); // restore the mark mark_x = mx; mark_y = my; QPainter p; p.begin(this); p.setPen(QPen(QColor("red"), 6)); num = 0; while(num < 3 && history[num+1].x != -2) { p.drawLine(midCoord(history[num].x, history[num].y), midCoord(history[num+1].x, history[num+1].y)); num++; } p.flush(); p.end(); QTimer::singleShot(getDelay(), this, SLOT(undrawArrow())); }
void EventManager::check() { //_frameLimit=false; SDL_Event event; const unsigned int now=SDL_GetTicks(); const unsigned int timePast=now-_lastTime; //std::cout<<"PimePast: "<<timePast<<"["<<now<<","<<_lastTime<<"\n"; _duration=((float)(timePast))*0.001f; _lastTime=SDL_GetTicks(); if (_frameLimit)SDL_Delay(getDelay()); else time_=SDL_GetTicks(); _fullScreenToggled=false; _escTyped=false; _upTyped=false; _downTyped=false; _leftTyped=false; _rightTyped=false; _escTyped=false; _keyTyped=false; _exit=false; while(SDL_PollEvent(&event)) evaluate(event); }
void CTimerControlApp::createThread() { CTimerControlThread* thread = new CTimerControlThread; wxString address, password; unsigned int port; getGateway(address, port, password); thread->setGateway(address, port, password); wxLogInfo(wxT("Gateway set to %s:%u"), address.c_str(), port); bool delay; getDelay(delay); thread->setDelay(delay); wxLogInfo(wxT("Delay set to %d"), int(delay)); wxLogInfo(wxT("Schedule file is %s"), m_fileName.c_str()); m_frame->setFileName(m_fileName); thread->setFileName(m_fileName); thread->reload(); // Convert the worker class into a thread m_thread = new CTimerControlThreadHelper(thread); m_thread->start(); }
// // KEYBOARD // Keyboard::Keyboard() { setPos(0,0); w = 780; h = 240; kr1.setPos(0, 0); kr1.setKeys("ESC|1|2|3|4|5|6|7|8|9|0|-|BACK|"); kr2.setPos(25, 45); kr2.xpadding_small = 20; kr2.setKeys("TAB|Q|W|E|R|T|Y|U|I|O|P|( )|"); kr3.setPos(40, 90); kr3.xpadding_small = 20; kr3.setKeys("CAPS|A|S|D|F|G|H|J|K|L|;|ENTER|"); kr4.setPos(25, 135); kr4.xpadding_small = 20; kr4.setKeys("SHIFT|Z|X|C|V|B|N|M|,|.|/|SHIFT|"); space.setPos(175, 190); // Animation settings events.clear(); newEvent(0, 200, 0, 1); // intro newEvent(0, -1, 1, 1); // main currentEvent = events[0]; updateDependencyDelays(getDelay()); }
SpikeGraph::SpikeGraph() { x = 0; y = 0; w = 240; h = 105; spikeWidth = 10; scounter = 0; speed = 1 / 4.0; for (int i = 0; i < 12; i++) { newSpike(0, 1, w - (i + 1)*spikeWidth * 2); newSpike(0, -1, w - (i + 1)*spikeWidth * 2); } maskShader.load("shadersGL3/null.vert", "shadersGL3/spike.frag"); tline1 = newTickLine(0, 0, w, 40, 0, COLOR_LINE); tline2 = newTickLine(0, h + 30, w, 40, 0, COLOR_LINE); // Animation settings events.clear(); newEvent(0, 300, 0, 1); // intro newEvent(0, -1, 1, 1); // main currentEvent = events[0]; updateDependencyEvents(); updateDependencyDelays(getDelay()); }
void Player::playChain(Player* plai) { uint64_t micros = 0; auto iter = plai->first->returnNext(); while (plai->playing) { while (micros >= iter->getDelay()) { iter->doEvent(); micros -= iter->getDelay(); iter = iter->returnNext(); if (iter == nullptr) { emit plai->donePlaying(); return; } } std::this_thread::sleep_for(std::chrono::milliseconds(1)); micros += 1000; } }
int LCAConn::update_dW(int axonId) { // compute dW but don't add them to the weights yet. // That takes place in reduceKernels, so that the output is // independent of the number of processors. int nExt = preSynapticLayer()->getNumExtended(); int numKernelIndices = getNumDataPatches(); const pvdata_t * preactbuf = preSynapticLayer()->getLayerData(getDelay(axonId)); const pvdata_t * postactbuf = postSynapticLayer()->getLayerData(getDelay(axonId)); int sya = (post->getLayerLoc()->nf * (post->getLayerLoc()->nx + 2*post->getLayerLoc()->nb)); for(int kExt=0; kExt<nExt;kExt++) { PVPatch * weights = getWeights(kExt,axonId); size_t offset = getAPostOffset(kExt, axonId); pvdata_t preact = preactbuf[kExt]; int ny = weights->ny; int nk = weights->nx * nfp; const pvdata_t * postactRef = &postactbuf[offset]; pvdata_t * dwdata = get_dwData(axonId, kExt); int lineoffsetw = 0; int lineoffseta = 0; for( int y=0; y<ny; y++ ) { for( int k=0; k<nk; k++ ) { dwdata[lineoffsetw + k] += updateRule_dW(preact, postactRef[lineoffseta+k],lineoffseta+k); } lineoffsetw += syp; lineoffseta += sya; } } // Divide by (numNeurons/numKernels) int divisor = pre->getNumNeurons()/numKernelIndices; assert( divisor*numKernelIndices == pre->getNumNeurons() ); for( int kernelindex=0; kernelindex<numKernelIndices; kernelindex++ ) { int numpatchitems = nxp*nyp*nfp; pvdata_t * dwpatchdata = get_dwDataHead(axonId,kernelindex); for( int n=0; n<numpatchitems; n++ ) { dwpatchdata[n] /= divisor; } } lastUpdateTime = parent->simulationTime(); return PV_SUCCESS; }
void GossipManager_timerFired(int index) { if(GM_gossip[index].isUsed) { GM_gossip[index].msg.msgType = GOSSIP_MESSAGE; GM_gossip[index].msg.label = GM_gossip[index].label; GM_gossip[index].updater(&GM_gossip[index]); sendMessageToAllNeighbors((char*)&GM_gossip[index].msg, GM_gossip[index].messageSize+2); long newDelay = getDelay(GM_gossip[index].msDelay, GM_gossip[index].msVariance); TimerManager_setDelay(GM_gossip[index].timer, newDelay); fired++; } }
void FireworkObjectImplementation::launch(CreatureObject* player, int removeDelay) { if (player == NULL) return; if(getDelay() == 0) { completeLaunch(player, removeDelay); return; } Reference<FireworkLaunchEvent*> launchEvent = new FireworkLaunchEvent(player, _this.getReferenceUnsafeStaticCast(), removeDelay); launchEvent->schedule(delay * 1000); }
void Board::marked(int x, int y) { // make sure that the previous connection is correctly undrawn undrawConnection(); if(getField(x, y) == EMPTY) return; if(x == mark_x && y == mark_y) { // unmark the piece mark_x = -1; mark_y = -1; updateField(x, y, false); return; } if(mark_x == -1) { mark_x = x; mark_y = y; updateField(x, y, false); return; } int fld1 = getField(mark_x, mark_y); int fld2 = getField(x, y); // both field same? if(fld1 != fld2) return; // trace if(findPath(mark_x, mark_y, x, y, connection)) { madeMove(mark_x, mark_y, x, y); drawConnection(getDelay()); setField(mark_x, mark_y, EMPTY); setField(x, y, EMPTY); grav_col_1 = x; grav_col_2 = mark_x; mark_x = -1; mark_y = -1; // game is over? // Must delay until after tiles fall to make this test // See undrawConnection GP. } else { connection.clear(); } }
// // KeyRow // KeyRow::KeyRow() { setPos(0,0); setKeys("x|x|x"); xpadding_small = 30; xpadding_large = 30; // Animation settings events.clear(); newEvent(0, 300, 0, 1); // intro newEvent(0, -1, 1, 1); // main currentEvent = events[0]; updateDependencyDelays(getDelay()); }
void MosquitoNode::delaySpawn(sf::Time dt) { if (!mDelaySet) { mTotalDelayTime = sf::seconds(getDelay()); mDelaySet = true; } mUpdateDelayTime += dt; if (mUpdateDelayTime >= mTotalDelayTime) { mActive = true; } }
void Board::getHint() { int x1, y1, x2, y2; History h[4]; if(getHint_I(x1, y1, x2, y2, h)) { undrawArrow(); for(int i = 0; i < 4; i++) history[i] = h[i]; int old_delay = getDelay(); setDelay(1000); drawArrow(x1, y1, x2, y2); setDelay(old_delay); } }
void KeyRow::keysFromString(string s) { size_t pos = 0; string token; string delimiter = "|"; float xoff = 0; int i = 0; while ((pos = s.find(delimiter)) != std::string::npos) { token = s.substr(0, pos); addKey(token, xoff, 0, i); xoff += getKeyPadding(keys[keys.size()-1]); s.erase(0, pos + delimiter.length()); i++; } updateDependencyDelays(getDelay()); }
void AudioDecoder::handleDecodedFrame(AVFrame* frame) { /* compute destination number of samples */ m_outNumSamples = static_cast<int>(av_rescale_rnd(getDelay(m_resampleCtx, frame->sample_rate) + frame->nb_samples, OUT_SAMPLE_RATE, frame->sample_rate, AV_ROUND_UP)); if (m_outNumSamples > m_maxOutNumSamples) { av_freep(&m_outData[0]); auto ret = av_samples_alloc(m_outData, &m_outLinesize, OUT_NUM_CHANNELS, m_outNumSamples, OUT_SAMPLE_FORMAT, 1); if (ret < 0) { mprintf(("FFMPEG: Failed to allocate samples!!!")); return; } m_maxOutNumSamples = m_outNumSamples; } /* convert to destination format */ auto ret = resample_convert(m_resampleCtx, m_outData, 0, m_outNumSamples, (uint8_t**) frame->data, 0, frame->nb_samples); if (ret < 0) { mprintf(("FFMPEG: Error while converting audio!\n")); return; } auto outBufsize = av_samples_get_buffer_size(&m_outLinesize, OUT_NUM_CHANNELS, ret, OUT_SAMPLE_FORMAT, 1); if (outBufsize < 0) { mprintf(("FFMPEG: Could not get sample buffer size!\n")); return; } auto begin = reinterpret_cast<short*>(m_outData[0]); auto end = reinterpret_cast<short*>(m_outData[0] + outBufsize); auto size = std::distance(begin, end); auto newSize = m_audioBuffer.size() + size; if (newSize <= m_audioBuffer.capacity()) { // We haven't filled the buffer yet m_audioBuffer.insert(m_audioBuffer.end(), begin, end); } else { flushAudioBuffer(); m_audioBuffer.assign(begin, end); } }
gossip_t* GossipManager_createGossip(uint8_t label, long msDelay, long msVariance, void (handler)(char*, char, char),void (*updater)(gossip_t*)) { uint8_t i; for(i=0;i<GOSSIP_MAX;i++) { if(GM_gossip[i].isUsed != 1) { GM_gossip[i].isUsed = 1; GM_gossip[i].label = label; GM_gossip[i].handler = handler; GM_gossip[i].updater = updater; GM_gossip[i].msDelay = msDelay; GM_gossip[i].msVariance = msVariance; GM_gossip[i].timer = TimerManager_createPeriodicTimer(getDelay(msDelay, msVariance), i, GossipManager_timerFired); TimerManager_pauseTimer(GM_gossip[i].timer); return &GM_gossip[i]; } } #ifdef PRINTF ase_printf("Error: #1 in GossipManager\n"); //out of gossips, increase number of GOSSIP_MAX #endif return NULL; }
void WaveSystem::update(entityx::EntityManager &es, entityx::EventManager &events, double dt) { if(waves_.size() == 0) return; auto currentWave = waves_.begin(); auto currentCreep = currentWave->begin(); if(startNextWave_ && timer_.done()) { if(signalBegin_) { events.emit<WaveBegin>(); signalBegin_ = false; } // spawn creep auto name = currentCreep->getName(); std::size_t posLevel = name.find("-"); auto level = name.substr(posLevel+1, 1); std::size_t posColor = name.rfind("-"); auto color = name.substr(posColor+1); events.emit<WaveSpawn>(CreepInfo(creepColor(color), (CreepLevel)atoi(level.c_str())), currentCreep->getQuantity()); currentWave->erase(currentCreep); if(currentWave->size() == 0 ) // All the creeps from the current wave have been spawn { waves_.erase(currentWave); signalBegin_ = true; startNextWave_ = false; // wait untill all the creeps to be killed } else // There is still creeps to be spawn from the current wave { auto nextCreep = currentWave->begin(); timer_.reset(nextCreep->getDelay()); } } timer_.update(dt); }
/* * Function to process the subscribed messages */ int subscribeMessage(void *context, char *topicName, int topicLen, MQTTAsync_message *message) { int i; char* payloadptr; char* command; int time_delay = 0; payloadptr = message->payload; time_delay = getDelay(payloadptr); if(time_delay != -1) { sprintf(command,"sudo /sbin/shutdown -r %d", time_delay); syslog(LOG_INFO, "Received command to restart in %d minutes.",time_delay); system(command); } else syslog(LOG_ERR, "Invalid command received."); MQTTAsync_freeMessage(&message); MQTTAsync_free(topicName); return 1; }
CinqsNode *JmtNodeParser::nodeFactory(Network *network, TiXmlNode *node, const string &nodeType, const string &nodeName) { if (nodeType.compare("Queue") == 0) { if (isDelay()) { TiXmlNode *node = getLowerLevelNodeWith(baseNode, "section", "className", "Delay"); if (useOriginalCinqsDataStructures) { return new InfiniteServerNode(network, nodeName, getDelay(node)); } else { if (isResourceConsumptionLocal(node)) { return new VexLocalInfiniteServerNode(network, nodeName, getDelay(node)); } else { // cout << "PARSING DISTRIBUTION OF " << nodeName << endl; return new VexInfiniteServerNode(network, nodeName, getDelay(node)); } } } else if (isRoutingStation()) { // cout << "routing station " << nodeName << endl; JmtQueueParser parseQueue(node); // TiXmlNode *node = getLowerLevelNodeWith(baseNode, "section", "className", "Router"); // return new ResourcePool(network, nodeName, new Exp(100000000000.0), INT_MAX/2, parseQueue.getCinqsQueue()); // Use a local queue with <1ns avg service time to simulate routing stations: the local queue will not lead to any waiting return new VexLocalQueueingNode(network, nodeName, new Delay(new Normal(0.00000000001, 0.0)), INT_MAX/2, parseQueue.getCinqsQueue()); } else { // cout << "queueing node " << nodeName << endl; JmtQueueParser parseQueue(node); TiXmlNode *node = getLowerLevelNodeWith(baseNode, "section", "className", "Server"); if (useOriginalCinqsDataStructures) { return new QueueingNode(network, nodeName, getDelay(node), getServers(node), parseQueue.getCinqsQueue()); } else { if (isResourceConsumptionLocal(node)) { return new VexLocalQueueingNode(network, nodeName, getDelay(node), getServers(node), parseQueue.getCinqsQueue()); } else { return new VexQueueingNode(network, nodeName, getDelay(node), getServers(node), parseQueue.getCinqsQueue()); } } } } else if (nodeType.find("Source") != string::npos) { return new Source(network, nodeName, getServiceTimeDistribution(node)); } else if (nodeType.find("Sink") != string::npos) { return new Sink(network, nodeName); } return NULL; };
void CTimerControlApp::createThread() { m_thread = new CTimerControlThread; wxString address, password; unsigned int port; getGateway(address, port, password); m_thread->setGateway(address, port, password); wxLogInfo(wxT("Gateway set to %s:%u"), address.c_str(), port); bool delay; getDelay(delay); m_thread->setDelay(delay); wxLogInfo(wxT("Delay set to %d"), int(delay)); wxLogInfo(wxT("Schedule file is %s"), m_fileName.c_str()); m_frame->setFileName(m_fileName); m_thread->setFileName(m_fileName); m_thread->reload(); m_thread->Create(); m_thread->Run(); }
void SimpleGen::handleMessage(cMessage* msg) { if (msg == event) { // Calculate delay double delay = getDelay(); emit(eventSignal, delay); if (canSendMessage()) { // It's time to send message, so prepare new one and send send(generateMessage(), "out"); } // Send next message after delay scheduleAt(simTime() + delay, event); } else { // This should never happen, but for sure delete delete msg; } }
int main( int argc, char *argv[] ) { int db_timeout = 60000; bool end = false; int ans; //parametry uruchomienia struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; while( end==false ) { int option_index = 0; int ch=getopt_long(argc, argv, "hv", long_options, &option_index); if (ch == -1) break; switch(ch) { case 'h': print_usage(argv[0]); end = true; break; case 'v': print_version(argv[0]); end = true; break; MIN: std::cerr << "Unknown option ` " << char(ch) << " '" << std::endl; exit(1); break; } } //parametry uruchomienia -- koniec globalConfigDb=new sqlite3cc::conn(); globalConfigDb->open( std::getenv("ICD_CONFIG_DB") ); globalConfigDb->busy_timeout( db_timeout ); globalConfig=new icd::config( *globalConfigDb ); //#define FLUSH_DELAY 180 sleep( randVal()*20.0+10 ); system( "icd-transfer-data" );//first sync int timeOfNextTransfer; // int timeOfNextFlush; int timeNow; int delayNow=0; while( 1==1 ) { sleep( 30 );//sleep to avoid running loop twice in one second timeNow=time(NULL); // timeOfNextFlush=timeNow; // timeOfNextFlush/=FLUSH_DELAY; // timeOfNextFlush+=1; // timeOfNextFlush*=FLUSH_DELAY; // timeOfNextFlush+=5;//rounded to 3 min, + 5 secs if( delayNow!=getDelay() ) {//delay changed by user or transfer delayNow=getDelay(); timeOfNextTransfer=timeNow; timeOfNextTransfer/=delayNow; timeOfNextTransfer+=1; timeOfNextTransfer*=delayNow; if( delayNow > 300 ) {//rand of no more than 5 minutes timeOfNextTransfer+=(int)((double)randVal()*(double)0.1*300.0); } else { timeOfNextTransfer+=(int)((double)randVal()*(double)0.1*(double)delayNow); } timeOfNextTransfer+=30; } // if( timeOfNextTransfer<=timeOfNextFlush ) {//transfer will be faster than flush if( timeOfNextTransfer-timeNow > 0 ) { sleep( timeOfNextTransfer-timeNow ); } // system( "icd-flush-db" ); system( "icd-transfer-data" ); delayNow=0;//force get delay and calculate new time // } else {//only flush // if( timeOfNextFlush-timeNow > 0 ) { // sleep( timeOfNextFlush-timeNow ); // } // system( "icd-flush-db" ); // } }//end while( 1==1 ) return 0; }
bool CTimerControlApp::OnInit() { SetVendorName(VENDOR_NAME); if (!wxApp::OnInit()) return false; if (!m_nolog) { wxString logBaseName = LOG_BASE_NAME; if (!m_name.IsEmpty()) { logBaseName.Append(wxT("_")); logBaseName.Append(m_name); } if (m_logDir.IsEmpty()) m_logDir = wxFileName::GetHomeDir(); wxLog* log = new CLogger(m_logDir, logBaseName); wxLog::SetActiveTarget(log); } else { new wxLogNull; } #if defined(__WINDOWS__) m_config = new CTimerControlConfig(new wxConfig(APPLICATION_NAME), m_name); #else if (m_confDir.IsEmpty()) m_confDir = CONF_DIR; m_config = new CTimerControlConfig(m_confDir, m_name); #endif wxString frameName = APPLICATION_NAME + wxT(" - "); if (!m_name.IsEmpty()) { frameName.Append(m_name); frameName.Append(wxT(" - ")); } frameName.Append(VERSION); if (!m_name.IsEmpty()) { wxString fileBase = SCHEDULE_BASE_NAME; fileBase.Append(wxT("_")); fileBase.Append(m_name); fileBase.Replace(wxT(" "), wxT("_")); wxString dir = m_confDir; if (dir.IsEmpty()) dir = wxFileName::GetHomeDir(); wxFileName fileName(dir, fileBase, wxT("dat")); m_fileName = fileName.GetFullPath(); } else { wxString dir = m_confDir; if (dir.IsEmpty()) dir = wxFileName::GetHomeDir(); wxFileName fileName(dir, SCHEDULE_BASE_NAME, wxT("dat")); m_fileName = fileName.GetFullPath(); } wxPoint position = wxDefaultPosition; int x, y; getPosition(x, y); if (x >= 0 && y >= 0) position = wxPoint(x, y); bool delay; getDelay(delay); m_frame = new CTimerControlFrame(frameName, position, delay); m_frame->Show(); SetTopWindow(m_frame); wxLogInfo(wxT("Starting ") + APPLICATION_NAME + wxT(" - ") + VERSION); // Log the SVN revsion and the version of wxWidgets and the Operating System wxLogInfo(SVNREV); wxLogInfo(wxT("Using wxWidgets %d.%d.%d on %s"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, ::wxGetOsDescription().c_str()); createThread(); return wxApp::OnInit(); }
BoxVisualization::BoxVisualization() { x = 0; y = 0; w = 240; h = 11*GRID_SIZE; setDelay(0); waves = Waves(); waves.setPos(ofPoint(285,375)); tline1.w = w; tline1.duration = 40; tline1.setDelay(0); tline2.y = h; tline2.w = w; tline2.duration = 40; tline2.setDelay(0); texts.clear(); int textDelay = -55; // Top Left texts.push_back(newText("SYSTEM SUMMARY", 5, 5, 7, 10, delay+textDelay, COLOR_135, false)); // Top Right texts.push_back(newText("WAVES VISUALIZATION", 5, w-5, 7, 10, delay+textDelay-5, COLOR_55, true)); // Bottom Right texts.push_back(newText("HIGH LOAD", 5, w-5, h-18, 10, delay+textDelay-10, COLOR_55, true)); texts.push_back(newText("ALL ACTIVITY", 5, w-4, h-11, 10, delay+textDelay-10, COLOR_55, true)); // Bottom Left texts.push_back(newText("ANALYSIS OF", 5, 5,h-18, 10, delay+textDelay-15, COLOR_55, false)); texts.push_back(newText("SYSTEM UTILIZATION", 5, 5,h-11, 10, delay+textDelay-15, COLOR_55, false)); // Animation settings events.clear(); newEvent(0, 300, 0, 1); // intro newEvent(0, -1, 1, 1); // main currentEvent = events[0]; updateDependencyEvents(); updateDependencyDelays(getDelay()); }
int main(void) { // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); // Auto-configure the PIC32 for optimum performance at the specified operating frequency. SYSTEMConfigPerformance(SYS_FREQ); // osc source, PLL multipler value, PLL postscaler , RC divisor OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_1, OSC_FRC_POST_1); // Configure the PB bus to run at 1/4 the CPU frequency OSCSetPBDIV(OSC_PB_DIV_4); // Enable multi-vector interrupts INTEnableSystemMultiVectoredInt(); INTEnableInterrupts(); // Set up the UART peripheral so we can send serial data. UARTConfigure(UART_USED, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART_USED, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART_USED, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART_USED, F_PB, UART_BAUD_RATE); UARTEnable(UART_USED, UART_ENABLE | UART_TX); // And configure printf/scanf to use the correct UART. if (UART_USED == UART1) { __XC_UART = 1; } // Enable LED outputs 0-7 by setting TRISE register TRISECLR = 0x00FF; // Initialize the PORTE to 0 PORTECLR = 0x00FF; // Set the lowest bit int mask = 1; PORTESET = mask; int delay = 0xA0000; // Loop forever, it is bad to exit in an embedded processor. int count=0; // move this into the delay function while (1) { // Move this printf into your getDelay function! // printf("Hello, world! %d\n",count++); // Replace this with the getDelay function call! int delay = getDelay(); int x = PORTD; delay = x << 12; // do nothing for a lot of cycles int i=0; for(i=0;i<delay;i++) ; // shift left by 1 mask = mask << 1; // rotate around if more than 8 bits if (mask & 0x0100) mask = 1; // Set the output to the new mask PORTE=mask; // delay = 0xA0000 + 0x40000*sin((double)count/10) + 0x20000*cos((double)count/5); // // if(delay < 0) // delay *= -1; } }
int InhibSTDPConn::updateWeights(int arborID) { // Steps: // 2. Update pre_stdp_tr[arborID] // 3. Update w_ij const float dt = parent->getDeltaTime(); const float decayLTP = exp(-dt / tauLTP); //Extended Pre const int nkPre = pre->getNumExtended(); assert(nkPre == getNumWeightPatches()); //Restricted Post const pvdata_t * aPost = post->getLayerData(getDelay(arborID)); pvdata_t * post_stdp_tr_m; // Postsynaptic trace matrix; i.e. data of post_stdp_tr struct pvdata_t * post_oja_tr_m; // Postsynaptic mean trace matrix pvdata_t * ampLTD_m; // local ampLTD //Extended Pre const pvdata_t * preLayerData = pre->getLayerData(getDelay(arborID)); pvdata_t aPre; pvdata_t * pre_stdp_tr_m; // Presynaptic trace matrix pvwdata_t * W; // Weight matrix pointer //Restricted post vals const int postNx = post->getLayerLoc()->nx; const int postNy = post->getLayerLoc()->ny; const int postNf = post->getLayerLoc()->nf; const PVHalo * postHalo = &post->getLayerLoc()->halo; //stride in restricted space const int postStrideYRes = postNf * postNx; int nk, ny; #ifdef SPLIT_PRE_POST //Separate LTD and LTP calculations to take advantage of sparsity //Loop over postsynaptic neurons for post before pre (tau'') const int numPostPatch = nxpPost * nypPost * nfpPost; // Number of pre-neurons in post receptive field. Postsynaptic weights are never shrunken //Update all pre traces (all traces decay every time step) for (int kPreExt = 0; kPreExt < nkPre; kPreExt++) // Loop over all presynaptic neurons { aPre = preLayerData[kPreExt]; // Spiking activity pre_stdp_tr_m = &(pre_stdp_tr[arborID]->data[kPreExt]); // PreTrace for given presynaptic neuron kPreExt *pre_stdp_tr_m = decayLTP * ((*pre_stdp_tr_m) + aPre); //If spiked, minimum is 1. If no spike, minimum is 0. } pvwdata_t * startAdd = this->get_wDataStart(arborID); // Address of first neuron in pre layer //Loop through postsynaptic neurons (non-extended indices) for (int kPost = 0; kPost < post->getNumNeurons(); kPost++) { //Neuron indices //Post in extended space if (aPost[kPost] == 0) { //No LTP if post does not spike continue; } pvdata_t ** postData = getPostWeightsp(arborID,kPost); // Pointer array full of addresses pointing to the weights for all of the preNeurons connected to the given postNeuron's receptive field for (int kPrePatch=0; kPrePatch < numPostPatch; kPrePatch++) { // Loop through all pre-neurons connected to given post-neuron float * kPreAdd = postData[kPrePatch]; // Address of preNeuron in receptive field of postNeuron assert(kPreAdd != NULL); int kPreExt = (kPreAdd-startAdd) / (this->xPatchSize()*this->yPatchSize()*this->fPatchSize()); // Grab index based on patch size assert(kPreExt < nkPre); // Pre in extended space pre_stdp_tr_m = &(pre_stdp_tr[arborID]->data[kPreExt]); // PreTrace for given presynaptic neuron kPreExt // See STDP_LCA_Equations.pdf in documentation for description of feed-forward inhibitory weight adaptation equations. TODO: That file does not exist. //STDP Equation (*postData[kPrePatch]) -= dWMax * ampLTP * aPost[kPost] * (*pre_stdp_tr_m); (*postData[kPrePatch]) = (*postData[kPrePatch]) < wMin ? wMin : (*postData[kPrePatch]); // Stop weights from going all the way to 0 } } // Pre-synaptic neurons for Pre Before Post (tau') for (int kPreExt = 0; kPreExt < nkPre; kPreExt++) // Loop over all presynaptic neurons { //Pre in extended space aPre = preLayerData[kPreExt]; // Spiking activity if (aPre == 0) { //No LTD if pre does not spike continue; } size_t postOffsetExt = getAPostOffset(kPreExt, arborID); // Gets start index for postsynaptic vectors for given presynaptic neuron and axon // size_t postOffsetRes = postOffsetExt - (postNb * (postNx + 2*postNb) + postNb); size_t postOffsetRes = kIndexRestricted(postOffsetExt, postNx, postNy, postNf, postNb); //Post in restricted space post_stdp_tr_m = &(post_stdp_tr->data[postOffsetRes]); // Reference to STDP post trace (local) ampLTD_m = &(ampLTD[postOffsetRes]); // Points to local address W = get_wData(arborID, kPreExt); // Pointer to data of given axon & presynaptic neuron // Get weights in form of a patch (nx,ny,nf) // nk and ny are the number of neurons connected to the given presynaptic neuron in the x*nfp and y // if each of the presynaptic neurons connects to all postsynaptic than nk*ny = nkPost TODO: Is this true? Rui says yes. PVPatch * w = getWeights(kPreExt, arborID); // Get weights in form of a patch (nx,ny,nf), TODO: what's the role of the offset? nk = nfp * w->nx; // one line in x at a time ny = w->ny; // 3. Update weights for (int y = 0; y < ny; y++) { for (int kPatchLoc = 0; kPatchLoc < nk; kPatchLoc++) { //loop over all postsynaptic neurons connected to given presynaptic neuron //STDP Equation W[kPatchLoc] += dWMax * ampLTD_m[kPatchLoc] * aPre * post_stdp_tr_m[kPatchLoc]; W[kPatchLoc] = W[kPatchLoc] < wMin ? wMin : W[kPatchLoc]; // Stop weights from going all the way to 0 } // advance pointers in y W += syp; // postActivity and post trace are extended layer post_stdp_tr_m += postStrideYRes; ampLTD_m += postStrideYRes; } } #else // this stride is in extended space for post-synaptic activity and STDP decrement variable const int postStrideYExt = postNf * (postNx + postHalo->lt + postHalo->rt); for (int kPreExt = 0; kPreExt < nkPre; kPreExt++) // Loop over all presynaptic neurons { size_t postOffsetExt = getAPostOffset(kPreExt, arborID); // Gets start index for postsynaptic vectors for given presynaptic neuron and axon // size_t postOffsetRes = postOffsetExt - (postNb * (postNx + 2*postNb) + postNb); size_t postOffsetRes = kIndexRestricted(postOffsetExt, postNx, postNy, postNf, postHalo->lt, postHalo->rt, postHalo->dn, postHalo->up); //Post in extended space aPost = &post->getLayerData()[postOffsetExt]; // Gets address of postsynaptic activity //Post in restricted space post_stdp_tr_m = &(post_stdp_tr->data[postOffsetRes]); // Reference to STDP post trace (local) ampLTD_m = &(ampLTD[postOffsetRes]); // Points to local address //Pre in extended space aPre = preLayerData[kPreExt]; // Spiking activity pre_stdp_tr_m = &(pre_stdp_tr[arborID]->data[kPreExt]); // PreTrace for given presynaptic neuron kPre W = get_wData(arborID, kPreExt); // Pointer to data of given axon & presynaptic neuron // Get weights in form of a patch (nx,ny,nf) // nk and ny are the number of neurons connected to the given presynaptic neuron in the x*nfp and y // if each of the presynaptic neurons connects to all postsynaptic than nk*ny = nkPost TODO: Is this true? Rui says yes. PVPatch * w = getWeights(kPreExt, arborID); // Get weights in form of a patch (nx,ny,nf), TODO: what's the role of the offset? nk = nfp * w->nx; // one line in x at a time ny = w->ny; // 2. Updates the presynaptic trace *pre_stdp_tr_m = decayLTP * ((*pre_stdp_tr_m) + aPre); //If spiked, minimum is 1. If no spike, minimum is 0. // 3. Update weights for (int y = 0; y < ny; y++) { for (int kPatchLoc = 0; kPatchLoc < nk; kPatchLoc++) { //loop over all postsynaptic neurons connected to given presynaptic neuron // See STDP_LCA_Equations.pdf in documentation for description of feed-forward inhibitory weight adaptation equations. TODO: That file does not exist. //STDP Equation W[kPatchLoc] += dWMax * (ampLTD_m[kPatchLoc] * aPre * post_stdp_tr_m[kPatchLoc] - ampLTP * aPost[kPatchLoc] * (*pre_stdp_tr_m)); W[kPatchLoc] = W[kPatchLoc] < wMin ? wMin : W[kPatchLoc]; // Stop weights from going all the way to 0 } // advance pointers in y W += syp; // postActivity and post trace are extended layer aPost += postStrideYExt; //TODO: is this really in the extended space? post_stdp_tr_m += postStrideYRes; post_oja_tr_m += postStrideYRes; ampLTD_m += postStrideYRes; } } #endif return 0; }
int main (int argc, char *argv[]) { std::string error; std::string in="out.lev",out="out.lev"; if (argc>=2){in=std::string(argv[1]);out=std::string(argv[2]);} if(!level.load(in,error)) std::cout<<"Fehler :\""<<error<<"\"\n"; int done=0; bool _fullScreenToggled=false; std::cout<<"init: "<<init("Test01", 0, 800, 600)<<std::endl; if(!shader_per_pixel.compileAndLink() )std::cout<<("White-Shader-Error:" +shader_per_pixel.getLog() )<<"\n"; //Sound //irrklang::ISoundEngine* SoundEngine = irrklang::createIrrKlangDevice(); //irrklang::ISound* SoundEffect = SoundEngine->play2D("Sound_Water0001.wav",true,true,false,irrklang::ESM_AUTO_DETECT, true); //SoundEffect->setIsPaused(true); //Sound_Water0001.wav time_=SDL_GetTicks(); bool up_pressed=false; bool down_pressed=false; bool right_pressed=false; bool left_pressed=false; bool plus_pressed=false; bool minus_pressed=false; bool num_pressed[10]={false,false,false,false,false,false,false,false,false,false}; bool numKP_pressed[10]={false,false,false,false,false,false,false,false,false,false}; bool mousebuttondown[2]={false,false}; int mx,my; while (!done) { //SDL_Delay(50); if (frameLimit)SDL_Delay(getDelay()); else time_=SDL_GetTicks(); SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: mx=event.button.x; my=event.button.y; switch(event.button.button) { case SDL_BUTTON_LEFT: { int tr=pickTriangle(event.button.x,event.button.y); if(tr>=0)counter=tr; mousebuttondown[0]=true; } break; case SDL_BUTTON_MIDDLE: { } break; case SDL_BUTTON_RIGHT: { mousebuttondown[1]=true; } break; }break; case SDL_MOUSEBUTTONUP:switch(event.button.button) { case SDL_BUTTON_LEFT: { mousebuttondown[0]=false; } break; case SDL_BUTTON_MIDDLE: { } break; case SDL_BUTTON_RIGHT: { mousebuttondown[1]=false; } break; }break; case SDL_MOUSEMOTION: if (mousebuttondown[0]){ int tr=pickTriangle(event.motion.x,event.motion.y); if(tr>=0)counter=tr; } if (mousebuttondown[1]) { roty+=0.1*(float)(event.button.x-mx); rotx+=0.1*(float)(event.button.y-my); } mx=event.button.x; my=event.button.y; break; case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_UP: up_pressed=false; break; case SDLK_DOWN: down_pressed=false; break; case SDLK_RIGHT: right_pressed=false; break; case SDLK_LEFT: left_pressed=false; break; case SDLK_w: up_pressed=false; break; case SDLK_s: down_pressed=false; break; case SDLK_d: right_pressed=false; break; case SDLK_a: left_pressed=false; break; case SDLK_PLUS: case SDLK_KP_PLUS: plus_pressed=false; break; case SDLK_MINUS: case SDLK_KP_MINUS:minus_pressed=false; break; //case SDLK_m: SoundEffect->setIsPaused(true);break; case SDLK_ESCAPE: done=1; break; case SDLK_KP0: numKP_pressed[0]=false; break; case SDLK_KP1: numKP_pressed[1]=false; break; case SDLK_KP2: numKP_pressed[2]=false; break; case SDLK_KP3: numKP_pressed[3]=false; break; case SDLK_KP4: numKP_pressed[4]=false; break; case SDLK_KP5: numKP_pressed[5]=false; break; case SDLK_KP6: numKP_pressed[6]=false; break; case SDLK_KP7: numKP_pressed[7]=false; break; case SDLK_KP8: numKP_pressed[8]=false; break; case SDLK_KP9: numKP_pressed[9]=false; break; case SDLK_0: num_pressed[0]=false; break; case SDLK_1: num_pressed[1]=false; break; case SDLK_2: num_pressed[2]=false; break; case SDLK_3: num_pressed[3]=false; break; case SDLK_4: num_pressed[4]=false; break; case SDLK_5: num_pressed[5]=false; break; case SDLK_6: num_pressed[6]=false; break; case SDLK_7: num_pressed[7]=false; break; case SDLK_8: num_pressed[8]=false; break; case SDLK_9: num_pressed[9]=false; break; }; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_UP: up_pressed=true; break; case SDLK_DOWN: down_pressed=true; break; case SDLK_RIGHT: right_pressed=true; break; case SDLK_LEFT: left_pressed=true; break; case SDLK_w: up_pressed=true; break; case SDLK_s: down_pressed=true; break; case SDLK_d: right_pressed=true; break; case SDLK_a: left_pressed=true; break; // case SDLK_b: level[counter].blocking=!level[counter].blocking; break; case SDLK_PLUS: case SDLK_KP_PLUS: plus_pressed=true; break; case SDLK_MINUS: case SDLK_KP_MINUS:minus_pressed=true; break; //case SDLK_m: SoundEffect->setIsPaused(false);break; case SDLK_ESCAPE: done=1; break; case SDLK_l: wireframe = ! wireframe; break; case SDLK_TAB: counter=(counter+1)%80;std::cout<<"c:"<<counter<<"\n";break; //case SDLK_PAGEUP: lod++;delete tg; tg = new TriangleGraph(lod);break; //case SDLK_PAGEDOWN: lod--;if(lod<0)lod=0;delete tg; tg = new TriangleGraph(lod);break; case SDLK_KP0: numKP_pressed[0]=true; break; case SDLK_KP1: numKP_pressed[1]=true; break; case SDLK_KP2: numKP_pressed[2]=true; break; case SDLK_KP3: numKP_pressed[3]=true; break; case SDLK_KP4: numKP_pressed[4]=true; break; case SDLK_KP5: numKP_pressed[5]=true; break; case SDLK_KP6: numKP_pressed[6]=true; break; case SDLK_KP7: numKP_pressed[7]=true; break; case SDLK_KP8: numKP_pressed[8]=true; break; case SDLK_KP9: numKP_pressed[9]=true; break; case SDLK_0: num_pressed[0]=true; break; case SDLK_1: num_pressed[1]=true; break; case SDLK_2: num_pressed[2]=true; break; case SDLK_3: num_pressed[3]=true; break; case SDLK_4: num_pressed[4]=true; break; case SDLK_5: num_pressed[5]=true; break; case SDLK_6: num_pressed[6]=true; break; case SDLK_7: num_pressed[7]=true; break; case SDLK_8: num_pressed[8]=true; break; case SDLK_9: num_pressed[9]=true; break; }; break; case SDL_QUIT: done = 1; break; default: break; } } if (up_pressed )rotx+=1.1; if (down_pressed )rotx-=1.1; if (right_pressed)roty+=1.1; if (left_pressed )roty-=1.1; if (plus_pressed )level[counter].height+=0.001f;//{scale*=1.05;if (scale>1.0f)scale=1.0f;} if (minus_pressed)level[counter].height-=0.001f;//{scale/=1.05;if (scale<0.01f)scale=0.01f;} for (int i=0;i<10;i++) { if (num_pressed[i] && counter>=0 && level[counter].changeable()) setTile(i); if (numKP_pressed[i] && counter>=0 && level[counter].changeable())level[counter].height=0.85f+((float)i)*0.05; } draw (); } //if (SoundEngine) SoundEngine->drop(); level.save(out); return 0; }
int main (int argc, char *argv[]) { int done=0; bool _fullScreenToggled=false; std::cout<<"init: "<<init("Test01", 0, 800, 600)<<std::endl; if(!shader_per_pixel.compileAndLink() )std::cout<<("White-Shader-Error:" +shader_per_pixel.getLog() )<<"\n"; //Sound irrklang::ISoundEngine* SoundEngine = irrklang::createIrrKlangDevice(); irrklang::ISound* SoundEffect = SoundEngine->play2D("Sound_Water0001.wav",true,true,false,irrklang::ESM_AUTO_DETECT, true); SoundEffect->setIsPaused(true); //Sound_Water0001.wav time_=SDL_GetTicks(); bool up_pressed=false; bool down_pressed=false; bool right_pressed=false; bool left_pressed=false; bool plus_pressed=false; bool minus_pressed=false; while (!done) { //SDL_Delay(50); if (frameLimit)SDL_Delay(getDelay()); else time_=SDL_GetTicks(); SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: { int tr=pickTriangle(event.button.x,event.button.y); if(tr>=0)counter=tr; } break;/**/ /*case SDL_MOUSEMOTION: { int tr=pickTriangle(event.motion.x,event.motion.y); if(tr>=0)counter=tr; } break;*/ case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_UP: up_pressed=false; break; case SDLK_DOWN: down_pressed=false; break; case SDLK_RIGHT: right_pressed=false; break; case SDLK_LEFT: left_pressed=false; break; case SDLK_w: up_pressed=false; break; case SDLK_s: down_pressed=false; break; case SDLK_d: right_pressed=false; break; case SDLK_a: left_pressed=false; break; case SDLK_PLUS: case SDLK_KP_PLUS: plus_pressed=false; break; case SDLK_MINUS: case SDLK_KP_MINUS:minus_pressed=false; break; case SDLK_m: SoundEffect->setIsPaused(true);break; case SDLK_ESCAPE: done=1; break; }; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_UP: up_pressed=true; break; case SDLK_DOWN: down_pressed=true; break; case SDLK_RIGHT: right_pressed=true; break; case SDLK_LEFT: left_pressed=true; break; case SDLK_w: up_pressed=true; break; case SDLK_s: down_pressed=true; break; case SDLK_d: right_pressed=true; break; case SDLK_a: left_pressed=true; break; case SDLK_PLUS: case SDLK_KP_PLUS: plus_pressed=true; break; case SDLK_MINUS: case SDLK_KP_MINUS:minus_pressed=true; break; case SDLK_m: SoundEffect->setIsPaused(false);break; case SDLK_ESCAPE: done=1; break; case SDLK_l: wireframe = ! wireframe; break; case SDLK_TAB: counter=(counter+1)%80;std::cout<<"c:"<<counter<<"\n";break; case SDLK_PAGEUP: lod++;delete tg; tg = new TriangleGraph(lod);break; case SDLK_PAGEDOWN: lod--;if(lod<0)lod=0;delete tg; tg = new TriangleGraph(lod);break; }; break; case SDL_QUIT: done = 1; break; default: break; } } if (up_pressed )rotx+=1.1; if (down_pressed )rotx-=1.1; if (right_pressed)roty+=1.1; if (left_pressed )roty-=1.1; if (plus_pressed ){scale*=1.05;if (scale>1.0f)scale=1.0f;} if (minus_pressed){scale/=1.05;if (scale<0.01f)scale=0.01f;} draw (); } if (SoundEngine) SoundEngine->drop(); return 0; }
int TransposePoolingConn::deliverPresynapticPerspective(PVLayerCube const * activity, int arborID) { //Check if we need to update based on connection's channel if(getChannel() == CHANNEL_NOUPDATE){ return PV_SUCCESS; } assert(post->getChannel(getChannel())); const PVLayerLoc * preLoc = preSynapticLayer()->getLayerLoc(); const PVLayerLoc * postLoc = postSynapticLayer()->getLayerLoc(); assert(arborID >= 0); const int numExtended = activity->numItems; //Grab postIdxLayer's data int* postIdxData = NULL; if(pvpatchAccumulateType == ACCUMULATE_MAXPOOLING){ PoolingIndexLayer* postIndexLayer = originalConn->getPostIndexLayer(); assert(postIndexLayer); //Make sure this layer is an integer layer assert(postIndexLayer->getDataType() == PV_INT); DataStore * store = parent->icCommunicator()->publisherStore(postIndexLayer->getLayerId()); int delay = getDelay(arborID); //TODO this is currently a hack, need to properly implement data types. postIdxData = (int*) store->buffer(LOCAL, delay); } for(int b = 0; b < parent->getNBatch(); b++){ pvdata_t * activityBatch = activity->data + b * (preLoc->nx + preLoc->halo.rt + preLoc->halo.lt) * (preLoc->ny + preLoc->halo.up + preLoc->halo.dn) * preLoc->nf; pvdata_t * gSynPatchHeadBatch = post->getChannel(getChannel()) + b * postLoc->nx * postLoc->ny * postLoc->nf; int * postIdxDataBatch = NULL; if(pvpatchAccumulateType == ACCUMULATE_MAXPOOLING){ postIdxDataBatch = postIdxData + b * originalConn->getPostIndexLayer()->getNumExtended(); } unsigned int * activeIndicesBatch = NULL; if(activity->isSparse){ activeIndicesBatch = activity->activeIndices + b * (preLoc->nx + preLoc->halo.rt + preLoc->halo.lt) * (preLoc->ny + preLoc->halo.up + preLoc->halo.dn) * preLoc->nf; } int numLoop; if(activity->isSparse){ numLoop = activity->numActive[b]; } else{ numLoop = numExtended; } #ifdef PV_USE_OPENMP_THREADS //Clear all thread gsyn buffer if(thread_gSyn){ int numNeurons = post->getNumNeurons(); #ifdef PV_USE_OPENMP_THREADS #pragma omp parallel for #endif for(int i = 0; i < parent->getNumThreads() * numNeurons; i++){ int ti = i/numNeurons; int ni = i % numNeurons; thread_gSyn[ti][ni] = 0; } } #endif // PV_USE_OPENMP_THREADS #ifdef PV_USE_OPENMP_THREADS #pragma omp parallel for schedule(static) #endif for (int loopIndex = 0; loopIndex < numLoop; loopIndex++) { int kPreExt; if(activity->isSparse){ kPreExt = activeIndicesBatch[loopIndex]; } else{ kPreExt = loopIndex; } float a = activityBatch[kPreExt]; if (a == 0.0f) continue; //If we're using thread_gSyn, set this here pvdata_t * gSynPatchHead; #ifdef PV_USE_OPENMP_THREADS if(thread_gSyn){ int ti = omp_get_thread_num(); gSynPatchHead = thread_gSyn[ti]; } else{ gSynPatchHead = gSynPatchHeadBatch; } #else // PV_USE_OPENMP_THREADS gSynPatchHead = gSynPatchHeadBatch; #endif // PV_USE_OPENMP_THREADS const int kxPreExt = kxPos(kPreExt, preLoc->nx + preLoc->halo.lt + preLoc->halo.rt, preLoc->ny + preLoc->halo.dn + preLoc->halo.up, preLoc->nf); const int kyPreExt = kyPos(kPreExt, preLoc->nx + preLoc->halo.lt + preLoc->halo.rt, preLoc->ny + preLoc->halo.dn + preLoc->halo.up, preLoc->nf); const int kfPre = featureIndex(kPreExt, preLoc->nx + preLoc->halo.lt + preLoc->halo.rt, preLoc->ny + preLoc->halo.dn + preLoc->halo.up, preLoc->nf); if(pvpatchAccumulateType == ACCUMULATE_MAXPOOLING){ const int kxPreGlobalExt = kxPreExt + preLoc->kx0; const int kyPreGlobalExt = kyPreExt + preLoc->ky0; if(kxPreGlobalExt < preLoc->halo.lt || kxPreGlobalExt >= preLoc->nxGlobal + preLoc->halo.lt || kyPreGlobalExt < preLoc->halo.up || kyPreGlobalExt >= preLoc->nyGlobal + preLoc->halo.up){ continue; } //Convert stored global extended index into local extended index int postGlobalExtIdx = postIdxDataBatch[kPreExt]; // If all inputs are zero and input layer is sparse, postGlobalExtIdx will still be -1. if(postGlobalExtIdx == -1) { continue; } //Make sure the index is in bounds assert(postGlobalExtIdx >= 0 && postGlobalExtIdx < (postLoc->nxGlobal + postLoc->halo.lt + postLoc->halo.rt) * (postLoc->nyGlobal + postLoc->halo.up + postLoc->halo.dn) * postLoc->nf); const int kxPostGlobalExt = kxPos(postGlobalExtIdx, postLoc->nxGlobal + postLoc->halo.lt + postLoc->halo.rt, postLoc->nyGlobal + postLoc->halo.dn + postLoc->halo.up, postLoc->nf); const int kyPostGlobalExt = kyPos(postGlobalExtIdx, postLoc->nxGlobal + postLoc->halo.lt + postLoc->halo.rt, postLoc->nyGlobal + postLoc->halo.dn + postLoc->halo.up, postLoc->nf); const int kfPost = featureIndex(postGlobalExtIdx, postLoc->nxGlobal + postLoc->halo.lt + postLoc->halo.rt, postLoc->nyGlobal + postLoc->halo.dn + postLoc->halo.up, postLoc->nf); const int kxPostLocalRes = kxPostGlobalExt - postLoc->kx0 - postLoc->halo.lt; const int kyPostLocalRes = kyPostGlobalExt - postLoc->ky0 - postLoc->halo.up; if(kxPostLocalRes < 0 || kxPostLocalRes >= postLoc->nx|| kyPostLocalRes < 0 || kyPostLocalRes >= postLoc->ny){ continue; } const int kPostLocalRes = kIndex(kxPostLocalRes, kyPostLocalRes, kfPost, postLoc->nx, postLoc->ny, postLoc->nf); gSynPatchHeadBatch[kPostLocalRes] = a; } else{ PVPatch * weights = getWeights(kPreExt, arborID); const int nk = weights->nx * fPatchSize(); const int ny = weights->ny; pvgsyndata_t * postPatchStart = gSynPatchHead + getGSynPatchStart(kPreExt, arborID); const int sy = getPostNonextStrides()->sy; // stride in layer int offset = kfPre; int sf = fPatchSize(); pvwdata_t w = 1.0; if(getPvpatchAccumulateType() == ACCUMULATE_SUMPOOLING){ float relative_XScale = pow(2, (post->getXScale() - pre->getXScale())); float relative_YScale = pow(2, (post->getYScale() - pre->getYScale())); w = 1.0/(nxp*nyp*relative_XScale*relative_YScale); } void* auxPtr = NULL; for (int y = 0; y < ny; y++) { (accumulateFunctionPointer)(0, nk, postPatchStart + y*sy + offset, a, &w, auxPtr, sf); } } } #ifdef PV_USE_OPENMP_THREADS //Set back into gSyn if(thread_gSyn){ pvdata_t * gSynPatchHead = gSynPatchHeadBatch; int numNeurons = post->getNumNeurons(); //Looping over neurons first to be thread safe #pragma omp parallel for for(int ni = 0; ni < numNeurons; ni++){ for(int ti = 0; ti < parent->getNumThreads(); ti++){ if(pvpatchAccumulateType == ACCUMULATE_MAXPOOLING){ if(gSynPatchHead[ni] < fabs(thread_gSyn[ti][ni])){ gSynPatchHead[ni] = thread_gSyn[ti][ni]; } } else{ gSynPatchHead[ni] += thread_gSyn[ti][ni]; } } } } #endif } return PV_SUCCESS; }