/** ==================== Loc ============================================== Grammar: loc : id loc_1 */ static TreeLoc p_loc(void) { TreeLoc loc = 0; // set null by default TokenCode code = curr()->code; // body TreeId l0id = p_id(); TreeLoc_1 l1loc_1 = p_loc_1(); loc = t_loc_id(l0id, l1loc_1); return loc; }
/** ==================== Decl ============================================= Grammar: decl : type id ';' */ static TreeDecl p_decl(void) { TreeDecl decl = 0; // set null by default TokenCode code = curr()->code; // body TreeType l0type = p_type(); TreeId l1id = p_id(); eat(';'); decl = t_decl_type(l0type, l1id); return decl; }
interval_db* node_mgr::findIntervalDb(const string* key, int lockDB) { DBID p_id(*key); // lock intervaldb pthread_rwlock_rdlock(&interval_lock); for (uint i = 0; i < dbs.size(); i++) { if (lockDB == WRLOCK) pthread_rwlock_wrlock(&(dbs[i]->dbLock)); else pthread_rwlock_rdlock(&(dbs[i]->dbLock)); //Unlock list so others can access pthread_rwlock_unlock(&interval_lock); const DBID *d_end_id = dbs[i]->h->getEndID(); const DBID *d_start_id = dbs[i]->h->getStartID(); // ownership => (begindID + 1) to endID [both inclusive] if (between(d_start_id, d_end_id, &p_id) && dbs[i]->valid) { if (lockDB == NOLOCK) pthread_rwlock_unlock(&(dbs[i]->dbLock)); delete d_end_id; delete d_start_id; return dbs[i]; } delete d_end_id; delete d_start_id; // Release lock because you didn't find it pthread_rwlock_unlock(&(dbs[i]->dbLock)); // Acquire list lock again pthread_rwlock_rdlock(&interval_lock); } // interval_lock is locked if it gets here, so unlock pthread_rwlock_unlock(&interval_lock); return NULL; }
std::vector<Proposals> nms( const std::vector<Proposals> & proposals, const std::vector<int> & order, float max_iou ) { int N = 0; for( const Proposals & p: proposals ) N += p.p.rows(); std::vector<int> s_id( N ), p_id( N ); for( int i=0, k=0; i<proposals.size(); i++ ) for( int j=0; j<proposals[i].p.rows(); j++, k++ ) { s_id[k] = i; p_id[k] = j; } std::vector<RMatrixXs> s; std::vector<int> Ns; for( int i=0; i<proposals.size(); i++ ) { s.push_back( proposals[i].s ); Ns.push_back( proposals[i].s.maxCoeff()+1 ); } const RMatrixXi ms = mergeOverSegmentations(s); const int Nms = ms.maxCoeff()+1; VectorXu ms_area = VectorXu::Zero( Nms ); for( int j=0; j<ms.rows(); j++ ) for( int i=0; i<ms.cols(); i++ ) ms_area[ ms(j,i) ]++; std::vector<IOUSet> iou_set; std::vector<VectorXs> ids; for( int i=0; i<s.size(); i++ ) { iou_set.push_back( s[i] ); ids.push_back( map_id( ms, s[i] ) ); } std::vector<int> pb; pb.reserve( Nms ); std::vector< std::vector< VectorXb > > r( proposals.size() ); for( int i: order ) { VectorXb p = proposals[ s_id[i] ].p.row( p_id[i] ); // Run NMS if( !p.any() || iou_set[ s_id[i] ].intersects(p,max_iou) ) continue; Vector4s bbox = iou_set[ s_id[i] ].computeBBox( p ); // Project each segmentation onto the common OS pb.clear(); for( int j=0; j<Nms; j++ ) if( p[ ids[ s_id[i] ][j] ] ) pb.push_back( j ); bool intersects = false; for( int k=0; !intersects && k<iou_set.size(); k++ ) if( s_id[i] != k ){ // Reproject the common OS to the current os VectorXu p_area = VectorXu::Zero( Ns[k] ); for( int j: pb ) p_area[ ids[ k ][j] ] += ms_area[ j ]; // Run more NMS intersects = iou_set[k].intersects(p_area, bbox, max_iou); } if( !intersects ) { // Add the segment iou_set[ s_id[i] ].add( p ); r[ s_id[i] ].push_back( p ); } } std::vector<Proposals> res( proposals.size() ); for( int i=0; i<proposals.size(); i++ ) { res[i].s = proposals[i].s; res[i].p = RMatrixXb( r[i].size(), proposals[i].p.cols() ); for( int j=0; j<r[i].size(); j++ ) res[i].p.row(j) = r[i][j]; } return res; }