void TestDetSet::inserting() { DSTV detsets(2); unsigned int ntot=0; for (unsigned int n=1;n<5;++n) { ntot+=n; unsigned int id=20+n; DST df = detsets.insert(id,n); CPPUNIT_ASSERT(detsets.size()==n); CPPUNIT_ASSERT(detsets.dataSize()==ntot); CPPUNIT_ASSERT(detsets.detsetSize(n-1)==n); CPPUNIT_ASSERT(df.size()==n); CPPUNIT_ASSERT(df.id()==id); std::copy(sv.begin(),sv.begin()+n,df.begin()); std::vector<DST::data_type> v1(n); std::vector<DST::data_type> v2(n); std::copy(detsets.m_data.begin()+ntot-n,detsets.m_data.begin()+ntot,v2.begin()); std::copy(sv.begin(),sv.begin()+n,v1.begin()); CPPUNIT_ASSERT(v1==v2); } // test error conditions try { detsets.insert(22,6); CPPUNIT_ASSERT("insert did not throw"==0); } catch (edm::Exception const & err) { CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference); } }
void down_sample( const SRC& src_view , const DST& dst_view ) { assert( src_view.dimensions() == dst_view.dimensions() ); // @todo Take care of signed images. Bransform them into unsigned images // by adding half the value range to the channels. typedef SRC::value_type src_pixel_t; typedef DST::value_type dst_pixel_t; typedef channel_type<dst_pixel_t>::type dst_channel_t; boost::fusion::vector<src_pixel_t,src_pixel_t> minmax = minmax_channel_values<src_pixel_t>( src_view ); const src_pixel_t& min = at_c<0>( minmax ); const src_pixel_t& max = at_c<1>( minmax ); // calculate the diff src_pixel_t diff; static_for_each( diff, min, max, calc_diff() ); // sample down dst_channel_t dst_max = channel_traits< dst_channel_t >::max_value(); for ( int y=0; y < src_view.height(); ++y ) { SRC::x_iterator src_it = src_view.row_begin( y ); DST::x_iterator dst_it = dst_view.row_begin( y ); for ( int x = 0; x < src_view.width(); ++x ) { typename src_pixel_t::const_reference src = src_it[x]; typename dst_pixel_t::reference dst = dst_it[x]; for ( int i = 0; i < num_channels<src_pixel_t>::type::value; ++i ) { if ( dynamic_at_c( diff, i ) == 0 ) { dynamic_at_c( dst, i ) = 0; } else { dynamic_at_c( dst, i ) = static_cast<dst_channel_t>( dst_max * ( static_cast<float>( dynamic_at_c( src, i ) - dynamic_at_c( min, i )) / static_cast<float>( dynamic_at_c( diff, i )))); } // else } //for } //for } // for }
void TestDetSet::toRangeMap() { DSTV detsets(2); for (unsigned int n=1;n<5;++n) { unsigned int id=20+n; FF ff(detsets,id); ff.resize(n); std::copy(sv.begin(),sv.begin()+n,ff.begin()); } { FF ff(detsets,31); ff.resize(2); std::copy(sv.begin(),sv.begin()+2,ff.begin()); } { FF ff(detsets,11); ff.resize(2); std::copy(sv.begin(),sv.begin()+2,ff.begin()); } { FF ff(detsets,34); ff.resize(4); std::copy(sv.begin(),sv.begin()+4,ff.begin()); } typedef edm::RangeMap<det_id_type, edm::OwnVector<B> > RM; edm::RangeMap<det_id_type, edm::OwnVector<B> > rm; try { edmNew::copy(detsets,rm); rm.post_insert(); std::vector<det_id_type> ids = rm.ids(); CPPUNIT_ASSERT(ids.size()==detsets.size()); CPPUNIT_ASSERT(rm.size()==detsets.dataSize()); for (int i=0; i<int(ids.size()); i++) { RM::range r = rm.get(ids[i]); DST df = *detsets.find(ids[i]); // DST df = *detsets.find(ids[i],true); CPPUNIT_ASSERT(static_cast<unsigned long>(r.second-r.first)==df.size()); CPPUNIT_ASSERT(std::equal(r.first,r.second,df.begin())); } } catch (edm::Exception const & err) { std::cout << err.what() << std::endl; CPPUNIT_ASSERT(err.what()==0); } }
bool RegionInfo::isRegion(BasicBlock *entry, BasicBlock *exit) const { assert(entry && exit && "entry and exit must not be null!"); typedef DominanceFrontier::DomSetType DST; DST *entrySuccs = &DF->find(entry)->second; // Exit is the header of a loop that contains the entry. In this case, // the dominance frontier must only contain the exit. if (!DT->dominates(entry, exit)) { for (DST::iterator SI = entrySuccs->begin(), SE = entrySuccs->end(); SI != SE; ++SI) if (*SI != exit && *SI != entry) return false; return true; } DST *exitSuccs = &DF->find(exit)->second; // Do not allow edges leaving the region. for (DST::iterator SI = entrySuccs->begin(), SE = entrySuccs->end(); SI != SE; ++SI) { if (*SI == exit || *SI == entry) continue; if (exitSuccs->find(*SI) == exitSuccs->end()) return false; if (!isCommonDomFrontier(*SI, entry, exit)) return false; } // Do not allow edges pointing into the region. for (DST::iterator SI = exitSuccs->begin(), SE = exitSuccs->end(); SI != SE; ++SI) if (DT->properlyDominates(entry, *SI) && *SI != exit) return false; return true; }
void TestDetSet::onDemand() { auto pg = std::make_shared<Getter>(this); Getter & g = *pg; assert(!g.aborted); std::vector<unsigned int> v; v+= 21,23,25,27,1020; DSTV detsets(pg,v,2); CPPUNIT_ASSERT(g.ntot==0); CPPUNIT_ASSERT(detsets.onDemand()); try { { CPPUNIT_ASSERT(detsets.exists(21)); CPPUNIT_ASSERT(!detsets.exists(22)); CPPUNIT_ASSERT(!detsets.isValid(21)); CPPUNIT_ASSERT(!detsets.isValid(22)); // DST df = *detsets.find(21); detsets.reserve(5,100); DST df = *detsets.find(21,true); CPPUNIT_ASSERT(df.id()==21); CPPUNIT_ASSERT(df.size()==1); CPPUNIT_ASSERT(detsets.isValid(21)); CPPUNIT_ASSERT(!detsets.isValid(23)); CPPUNIT_ASSERT(g.ntot==1); assert(!g.aborted); } { DST df = detsets[25]; CPPUNIT_ASSERT(df.id()==25); CPPUNIT_ASSERT(df.size()==5); CPPUNIT_ASSERT(g.ntot==1+5); assert(!g.aborted); } { DST df = detsets[1020]; CPPUNIT_ASSERT(df.id()==1020); CPPUNIT_ASSERT(df.size()==0); CPPUNIT_ASSERT(g.ntot==1+5); assert(g.aborted); } } catch (edm::Exception const &) { CPPUNIT_ASSERT("DetSetVector threw when not expected"==0); } // no onDemand! int i=0; // for (auto di = detsets.begin(false); di!=detsets.end(false); ++di) { for (auto di = detsets.begin(); di!=detsets.end(); ++di) { ++i; auto ds = *di; auto id = ds.id(); CPPUNIT_ASSERT(id==1020 || (id>20&&id<28&& id%2==1)); if (1020==id || 21==id || 25==id) CPPUNIT_ASSERT(ds.isValid()); else CPPUNIT_ASSERT(!ds.isValid()); } CPPUNIT_ASSERT(5==i); CPPUNIT_ASSERT(g.ntot==1+5); // CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this,1,2)).n==9); CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this,1,2)).n==9); // CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this,1,2)).n==9); CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this,1,2)).n==9); CPPUNIT_ASSERT(g.ntot==1+3+5+7); try{ DSTV::const_iterator p = detsets.find(22); CPPUNIT_ASSERT(p==detsets.end()); } catch (edm::Exception const &) { CPPUNIT_ASSERT("find thrown edm exception when not expected"==0); } try{ detsets[22]; CPPUNIT_ASSERT("[] did not throw"==0); } catch (edm::Exception const & err) { CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference); } DSTV detsets2; detsets2.swap(detsets); CPPUNIT_ASSERT(detsets2.onDemand()); DSTV detsets3; detsets3 = std::move(detsets2); CPPUNIT_ASSERT(detsets3.onDemand()); DSTV detsets5(std::move(detsets3)); CPPUNIT_ASSERT(detsets5.onDemand()); DSTV detsets4(detsets5); CPPUNIT_ASSERT(detsets4.onDemand()); }
void TestDetSet::iterator() { DSTV detsets(2); for (unsigned int n=1;n<5;++n) { unsigned int id=20+n; FF ff(detsets,id); ff.resize(n); std::copy(sv.begin(),sv.begin()+n,ff.begin()); } // CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this)).n==5); CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this)).n==5); { FF ff(detsets,31); ff.resize(2); std::copy(sv.begin(),sv.begin()+2,ff.begin()); } { FF ff(detsets,11); ff.resize(2); std::copy(sv.begin(),sv.begin()+2,ff.begin()); } { FF ff(detsets,34); ff.resize(4); std::copy(sv.begin(),sv.begin()+4,ff.begin()); } DSTV::Range r = detsets.equal_range(30,cmp10()); CPPUNIT_ASSERT(r.second-r.first==2); r = detsets.equal_range(40,cmp10()); CPPUNIT_ASSERT(r.second-r.first==0); try { { CPPUNIT_ASSERT(detsets.exists(22)); CPPUNIT_ASSERT(!detsets.exists(44)); DST df = *detsets.find(22); // DST df = *detsets.find(22,true); CPPUNIT_ASSERT(df.id()==22); CPPUNIT_ASSERT(df.size()==2); } { DST df = detsets[22]; CPPUNIT_ASSERT(df.id()==22); CPPUNIT_ASSERT(df.size()==2); } } catch (edm::Exception const &) { CPPUNIT_ASSERT("DetSetVector threw when not expected"==0); } try{ DSTV::const_iterator p = detsets.find(44); // DSTV::const_iterator p = detsets.find(44,true); CPPUNIT_ASSERT(p==detsets.end()); // CPPUNIT_ASSERT(p==detsets.end(true)); } catch (edm::Exception const &) { CPPUNIT_ASSERT("find thrown edm exception when not expected"==0); } try{ detsets[44]; CPPUNIT_ASSERT("[] did not throw"==0); } catch (edm::Exception const & err) { CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference); } }