double TD_VonMises::getNormalization(const double kappa, const double period) const { // std::vector<double> centers(1); centers[0] = 0.0; std::vector<double> kappas(1); kappas[0] = kappa; std::vector<double> periods(1); periods[0] = period; std::vector<double> norm(1); norm[0] = 1.0; // const unsigned int nbins = 1001; std::vector<double> points; std::vector<double> weights; double min = 0.0; double max = period; GridIntegrationWeights::getOneDimensionalIntegrationPointsAndWeights(points,weights,nbins,min,max); // double sum = 0.0; for(unsigned int l=0; l<nbins; l++) { std::vector<double> arg(1); arg[0]= points[l]; sum += weights[l] * VonMisesDiagonal(arg,centers,kappas,periods,norm); } return 1.0/sum; }
void populatePeriodMenu() { if (_periodMenu) return; _periodMenu = new QMenu(q); if (_trContext.isEmpty()) _periodMenu->setTitle(_trTitle); else _periodMenu->setTitle(QApplication::translate(_trContext.toUtf8(), _trTitle.toUtf8())); for(int i = _startPeriod; i < periods().count(); ++i) { QAction *a = _periodMenu->addMenu(valueMenu(_periodMenu, i)); a->setText(Utils::firstLetterUpperCase(periods().at(i))); a->setData(i); // store the period id } q->setMenu(_periodMenu); }
int main( int argc, char** argv ) { int numtasks = 0; MPI_( MPI_Init( &argc, &argv ) ); MPI_( MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN ) ); MPI_( MPI_Comm_size( MPI_COMM_WORLD, &numtasks ) ); const int DIM = int( std::sqrt( double( numtasks ) ) ); std::vector< int > dims( 2, DIM ); std::vector< int > periods( 2, 0 ); //periodic - false -> non-periodic const int reorder = 0; //false - no reorder MPI_Comm cartcomm; MPI_( MPI_Cart_create( MPI_COMM_WORLD, 2, &dims[ 0 ], &periods[ 0 ], reorder, &cartcomm ) ); int task = -1; MPI_( MPI_Comm_rank( cartcomm, &task ) ); std::vector< int > coords( 2, -1 ); MPI_( MPI_Cart_coords( cartcomm, task, 2, &coords[ 0 ] ) ); std::vector< int > neighbors( 4, -1 ); enum { UP = 0, DOWN, LEFT, RIGHT }; // compute the shifted source and destination ranks, given a shift direction and amount //MPI_Cart_shift is uses to find two "nearby" neighbors of the calling process //along a specified direction of an N-dimensional grid //The direction and offset are specified as a signed integer //If the sign of the displacement is positive the "source" rank is lower //than the destination rank; if it's negative the opposite is true MPI_( MPI_Cart_shift( cartcomm, 0, 1, &neighbors[ UP ], &neighbors[ DOWN ] ) ); MPI_( MPI_Cart_shift( cartcomm, 1, 1, &neighbors[ LEFT ], &neighbors[ RIGHT ] ) ); int sendbuf = task; const int tag = 0x01; std::vector< int > recvbuf( 4, MPI_PROC_NULL ); std::vector< MPI_Request > reqs( 2 * 4 ); for( int i = 0; i != 4; ++i ) { int dest = neighbors[ i ]; int src = neighbors[ i ]; MPI_( MPI_Isend( &sendbuf, 1, MPI_INT, dest, tag, MPI_COMM_WORLD, &reqs[ i ] ) ); MPI_( MPI_Irecv( &recvbuf[ i ], 1, MPI_INT, src, tag, MPI_COMM_WORLD, &reqs[ i + 4 ] ) ); } std::vector< MPI_Status > status( 2 * 4 ); MPI_( MPI_Waitall( 8, &reqs[ 0 ], &status[ 0 ] ) ); std::ostringstream os; os << "rank= " << task << " coords= " << coords[ 0 ] << ',' << coords[ 1 ] << " neighbors= " << neighbors[ UP ] << ',' << neighbors[ DOWN ] << ',' << neighbors[ LEFT ] << ',' << neighbors[ RIGHT ] << '\n'; std::cout << os.str(); os.flush(); MPI_( MPI_Finalize() ); return 0; }
TEST_F(CachingWordShaperTest, GlyphBoundsWithSpaces) { CachingWordShaper shaper(cache.get()); TextRun periods(reinterpret_cast<const LChar*>(".........."), 10); FloatRect periodsGlyphBounds; float periodsWidth = shaper.width(&font, periods, nullptr, &periodsGlyphBounds); TextRun periodsAndSpaces(reinterpret_cast<const LChar*>(". . . . . . . . . ."), 19); FloatRect periodsAndSpacesGlyphBounds; float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr, &periodsAndSpacesGlyphBounds); // The total width of periods and spaces should be longer than the width of periods alone. ASSERT_GT(periodsAndSpacesWidth, periodsWidth); // The glyph bounds of periods and spaces should be longer than the glyph bounds of periods alone. ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); }
TEST_F(PeriodicActionTest, General) { const unsigned n = 5; std::vector<int> x(n, 0); boost::ptr_vector<std::atomic<uint64_t> > periods(n); periods.reserve(n); std::vector<std::unique_ptr<PeriodicAction>> acts; acts.reserve(n); bpt::ptime start = bpt::second_clock::universal_time(); for (unsigned i = 0; i < n; i++) { periods.push_back(new std::atomic<uint64_t>(i + 1)); acts.emplace_back(new PeriodicAction(std::string("incrementer ") + boost::lexical_cast<std::string>(i), [&x, i] { ++x[i]; std::this_thread::sleep_for(std::chrono::seconds(duration(i))); }, periods[i])); } const int slp = 7; sleep(slp); for (unsigned i = 0; i < n; i++) { const bpt::time_duration d = bpt::microsec_clock::universal_time() - start; acts[i].reset(); const int expected = floor(d.total_milliseconds() / 1000.0) / std::max(periods[i].load(), duration(i)); EXPECT_NEAR(x[i], expected, 1.1); } }