void test_airy(T, const char* name) { std::cout << "Testing type " << name << std::endl; static const boost::array<boost::array<T, 5>, 8> data = {{ // Values are x, Ai, Bi, Ai', Bi'. // Calculated from functions.wolfram.com. {{ 0, static_cast<T>(0.355028053887817239260063186004183176397979174199177240583327L), static_cast<T>(0.614926627446000735150922369093613553594728188648596505040879L), static_cast<T>(-0.258819403792806798405183560189203963479091138354934582210002L), static_cast<T>(0.448288357353826357914823710398828390866226799212262061082809L) }}, {{ 2, static_cast<T>(0.0349241304232743791353220807918076097610602138975832071886699L), static_cast<T>(3.29809499997821471028060442522345242200397596340362078768292L), static_cast<T>(-0.0530903844336536317039991858787034912485609900458779926304030L), static_cast<T>(4.10068204993288988938203407917793529439024461377513711983771L) }}, {{ 3.5, static_cast<T>(0.00258409878698963496327714478330027845019631096464789073425468L), static_cast<T>(33.0555067546114794142573129819217946861266278143724855010951L), static_cast<T>(-0.00500441396795258283203024967883836790716278377542974739809987L), static_cast<T>(59.1643195813609870345742121795224602529063343063320217229383L) }}, {{ 30.5, static_cast<T>(2.04253461666926015963302258449952681287194929082634196439857e-50L), static_cast<T>(1.41092256201712698413071856671990267572381736486242769613348e48L), static_cast<T>(-1.12969466271996376602221721397236452019046628449363103927812e-49L), static_cast<T>(7.78046629440950280615411694840600772185863288897663300007879e48L) }}, {{ -2, static_cast<T>(0.227407428201685575991924436037873799460772225417096716495790L), static_cast<T>(-0.412302587956398488083234054611461042034534834472404728823877L), static_cast<T>(0.618259020741691041406264291332475282915777945124146942159898L), static_cast<T>(0.278795166921169522685097569410983241403000593451631000239732L) }}, {{ -3.5, static_cast<T>(-0.375533823140431911934396951580170239543268576378264063902563L), static_cast<T>(0.168939837481058611843442769540943269911562243926304070915824L), static_cast<T>(-0.343443433454048146287937374098698857094194220958713294264017L), static_cast<T>(-0.693116284907288801752443612670580462699702668014978495343697L) }}, {{ -30.25, static_cast<T>(-0.236900428491559731119806902381433570300271552218956227857722L), static_cast<T>(0.0418614989839147441219283537268101850442118139150748075124111L), static_cast<T>(-0.232197332372689274917364138870840123428255785603863926579897L), static_cast<T>(-1.30261375952554697768880873095691151213006925411329957440342L) }}, {{ -300.5, static_cast<T>(-0.117584304761702008955433457721670950077867326839023449546057L), static_cast<T>(0.0673518035440918806545676478730240310819758211028871823560384), static_cast<T>(-1.16763702262473888724431076711846459336993902544926162874376L), static_cast<T>(-2.03826035550300900666977975504950803669545593208969273694133L) }}, }}; T tol = boost::math::tools::epsilon<T>() * 800; for(unsigned i = 0; i < data.size(); ++i) { BOOST_CHECK_CLOSE_FRACTION(data[i][1], boost::math::airy_ai(data[i][0]), tol); if(boost::math::isfinite(data[i][2])) BOOST_CHECK_CLOSE_FRACTION(data[i][2], boost::math::airy_bi(data[i][0]), tol); BOOST_CHECK_CLOSE_FRACTION(data[i][3], boost::math::airy_ai_prime(data[i][0]), tol); if(boost::math::isfinite(data[i][4])) BOOST_CHECK_CLOSE_FRACTION(data[i][4], boost::math::airy_bi_prime(data[i][0]), tol); } }
void test_complex_spherical_harmonic(const T& data, const char* /* name */, boost::mpl::true_ const &) { typedef typename T::value_type row_type; typedef typename row_type::value_type value_type; for(unsigned i = 0; i < sizeof(data) / sizeof(data[0]); ++i) { // // Sanity check that the complex version does the same thing as the real // and imaginary versions: // std::complex<value_type> r = boost::math::spherical_harmonic( boost::math::tools::real_cast<unsigned>(data[i][0]), boost::math::tools::real_cast<unsigned>(data[i][1]), data[i][2], data[i][3]); value_type re = boost::math::spherical_harmonic_r( boost::math::tools::real_cast<unsigned>(data[i][0]), boost::math::tools::real_cast<unsigned>(data[i][1]), data[i][2], data[i][3]); value_type im = boost::math::spherical_harmonic_i( boost::math::tools::real_cast<unsigned>(data[i][0]), boost::math::tools::real_cast<unsigned>(data[i][1]), data[i][2], data[i][3]); BOOST_CHECK_CLOSE_FRACTION(std::real(r), re, value_type(5)); BOOST_CHECK_CLOSE_FRACTION(std::imag(r), im, value_type(5)); } }
void check_time(char const* format, char const* sDate, int year, int month, int day, int hour, int min, int sec, double fsec) { // std::cout << "Test " << sDate << " against " << format << std::endl; const ossimDate d = ossimplugins::time::details::strptime(format, sDate); BOOST_CHECK_EQUAL(d.getYear(), year); BOOST_CHECK_EQUAL(d.getMonth(), month); BOOST_CHECK_EQUAL(d.getDay(), day); BOOST_CHECK_EQUAL(d.getHour(), hour); BOOST_CHECK_EQUAL(d.getMin(), min); BOOST_CHECK_EQUAL(d.getSec(), sec); BOOST_CHECK_EQUAL(d.getFractionalSecond(), fsec); // Reference ossimLocalTm iso; iso.setIso8601(sDate); BOOST_CHECK_EQUAL(d.getModifiedJulian(), iso.getModifiedJulian()); // Is ossimDate |--> MJD bijective ? const double dMJD = d.getModifiedJulian(); ossimDate d2; d2.setDateFromModifiedJulian(dMJD); BOOST_CHECK_EQUAL(d2.getYear(), year); BOOST_CHECK_EQUAL(d2.getMonth(), month); BOOST_CHECK_EQUAL(d2.getDay(), day); BOOST_CHECK_EQUAL(d2.getHour(), hour); BOOST_CHECK_EQUAL(d2.getMin(), min); BOOST_CHECK_CLOSE_FRACTION(d2.getSec()+d2.getFractionalSecond(), sec+fsec, 1e-6); // Alternative implementation BOOST_CHECK_CLOSE_FRACTION(d.getModifiedJulian(), getModifiedJulianDate(sDate), 1e-12); // Check string conversion // Yes, this is likelly to fail du to double imprecisions // - official ossimDate string conversion ossimplugins::time::ModifiedJulianDate mjd = ossimplugins::time::toModifiedJulianDate(sDate); // std::cout << "MJD("<<sDate<<"): " << mjd.as_day_frac() << std::endl; BOOST_CHECK_CLOSE_FRACTION(d.getModifiedJulian(), mjd.as_day_frac(), 1e-12); std::ostringstream oss; oss << d.getYear() << '-' << std::setw(2) << std::setfill('0') << d.getMonth() << '-' << d.getDay() << 'T'; d.printTime(oss); if (d.getFractionalSecond() > 0) { oss << '.' << std::setw(6) << (d.getFractionalSecond() * 1000*1000); } BOOST_CHECK_EQUAL(oss.str(), sDate); // - our string conversion // std::cout << std::setprecision(20) ; // std::cout << mjd.as_day_frac() << " -> " << to_simple_string(mjd) << " / " << d.getModifiedJulian() << "\n"; // std::cout << oss.str() << "\n"; // We know this test will fail because of float rounding => just display std::cout.precision(16); std::cout << mjd << " as a simple string (" << ossimplugins::time::to_simple_string(mjd) << ") is expected to differ from " << sDate << "\n"; // BOOST_CHECK_EQUAL(to_simple_string(mjd), sDate); }
void test_cbrt(const int fuzzy_bits) { // Use at least 6 resolution bits. // Use at least 8 range bits. BOOST_STATIC_ASSERT(-FixedPointType::resolution >= 6); BOOST_STATIC_ASSERT( FixedPointType::range >= 8); const FixedPointType a1 ( 2L ); const FloatPointType b1( 2L ); const FixedPointType a2 ( 3L ); const FloatPointType b2( 3L ); const FixedPointType a3 ( 8.375L); const FloatPointType b3( 8.375L); const FixedPointType a4 ( 64.125L); const FloatPointType b4( 64.125L); const FixedPointType a5 (100.875L); const FloatPointType b5(100.875L); const FixedPointType a6 (FixedPointType( 1) / 3); const FloatPointType b6(FloatPointType( 1) / 3); const FixedPointType a7 (FixedPointType( 12) / 10); const FloatPointType b7(FloatPointType( 12) / 10); const FixedPointType a8 (FixedPointType(111) / 10); const FloatPointType b8(FloatPointType(111) / 10); const FixedPointType a9 (boost::math::constants::phi<FixedPointType>()); const FloatPointType b9(boost::math::constants::phi<FloatPointType>()); // Use boost::math::cbrt for fixed-point negatable because cbrt(negatable) is not yet implemented. // Do not use a using directive for boost::math::cbrt() until cbrt is implemented for fixed-point negatable. BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a1), FixedPointType(boost::math::cbrt(b1)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a2), FixedPointType(boost::math::cbrt(b2)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a3), FixedPointType(boost::math::cbrt(b3)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a4), FixedPointType(boost::math::cbrt(b4)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a5), FixedPointType(boost::math::cbrt(b5)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a6), FixedPointType(boost::math::cbrt(b6)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a7), FixedPointType(boost::math::cbrt(b7)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a8), FixedPointType(boost::math::cbrt(b8)), tolerance_maker<FixedPointType>(fuzzy_bits)); BOOST_CHECK_CLOSE_FRACTION(boost::math::cbrt(a9), FixedPointType(boost::math::cbrt(b9)), tolerance_maker<FixedPointType>(fuzzy_bits)); }
/** * @test perturbation looks quit random * - no two adjanced equal values * - all values are equally distributed. */ BOOST_FIXTURE_TEST_CASE( perturbation_looks_quit_random, advertising ) { std::map< bluetoe::link_layer::delta_time, unsigned > perturbations; bluetoe::link_layer::delta_time last_perturbation = bluetoe::link_layer::delta_time::now(); all_data( filter_channel_37, [&]( const test::schedule_data& a, const test::schedule_data& b ) { const auto current_perturbation = b.on_air_time - a.on_air_time - bluetoe::link_layer::delta_time::msec( 100 ); if ( !perturbations.empty() ) { BOOST_CHECK_NE( last_perturbation, current_perturbation ); } ++perturbations[ current_perturbation ]; last_perturbation = current_perturbation; } ); double average = 0.0; unsigned count = 0; for ( auto p : perturbations ) { average += p.first.usec() * p.second; count += p.second; } BOOST_CHECK_CLOSE_FRACTION( ( average / count ), 5.0 * 1000, 0.2 ); }
void test_smooth_r4<float_type>::test() { // place particles along the x-axis within one half of the box, // put every second particle at the origin unsigned int npart = particle->nparticle(); vector_type dx(0); dx[0] = box->edges()(0, 0) / npart / 2; std::vector<vector_type> r_list(particle->nparticle()); std::vector<unsigned int> species(particle->nparticle()); for (unsigned int k = 0; k < r_list.size(); ++k) { r_list[k] = (k % 2) ? k * dx : vector_type(0); species[k] = (k < npart_list[0]) ? 0U : 1U; // set particle type for a binary mixture } BOOST_CHECK( set_position(*particle, r_list.begin()) == r_list.end() ); BOOST_CHECK( set_species(*particle, species.begin()) == species.end() ); // read forces and other stuff from device std::vector<float> en_pot(particle->nparticle()); BOOST_CHECK( get_potential_energy(*particle, en_pot.begin()) == en_pot.end() ); std::vector<vector_type> f_list(particle->nparticle()); BOOST_CHECK( get_force(*particle, f_list.begin()) == f_list.end() ); float const eps = std::numeric_limits<float>::epsilon(); for (unsigned int i = 0; i < npart; ++i) { unsigned int type1 = species[i]; unsigned int type2 = species[(i + 1) % npart]; vector_type r = r_list[i] - r_list[(i + 1) % npart]; vector_type f = f_list[i]; // reference values from host module host_float_type fval, en_pot_; host_float_type rr = inner_prod(r, r); std::tie(fval, en_pot_) = (*host_potential)(rr, type1, type2); if (rr < host_potential->rr_cut(type1, type2)) { double rcut = host_potential->r_cut(type1, type2); // the GPU force module stores only a fraction of these values en_pot_ /= 2; // the first term is from the smoothing, the second from the potential // (see lennard_jones.cpp from unit tests) float const tolerance = 8 * eps * (1 + rcut/(rcut - std::sqrt(rr))) + 10 * eps; BOOST_CHECK_SMALL(norm_inf(fval * r - f), std::max(norm_inf(fval * r), 1.f) * tolerance * 2); BOOST_CHECK_CLOSE_FRACTION(en_pot_, en_pot[i], 2 * tolerance); } else { // when the distance is greater than the cutoff // set the force and the pair potential to zero fval = en_pot_ = 0; BOOST_CHECK_SMALL(norm_inf(f), eps); BOOST_CHECK_SMALL(en_pot[i], eps); } } }
void test_big_sqrt_pi(const int fuzzy_bits) { // Limit the precision of the fixed-point type in order to remain // within the precision of the string-literal value of pi above. BOOST_STATIC_ASSERT(FixedPointType::range - FixedPointType::resolution < int((3000LL * 1000LL) / 301LL)); const FixedPointType a(boost::math::constants::pi<FixedPointType>()); static const FloatPointType b(str_pi_reference().c_str()); BOOST_CHECK_CLOSE_FRACTION(sqrt(a), FixedPointType(sqrt(b)), tolerance_maker<FixedPointType>(fuzzy_bits)); }
BOOST_FIXTURE_TEST_CASE(test_bow, test::Peppers) { VocabularyPtr vocabulary(test::load<vis::Vocabulary>(VOCABULARY_FILE)); BowHog extractor(*vocabulary); arma::fvec descriptors = extractor.extract(image); float sum = arma::sum(descriptors); printmat(descriptors); printvar(sum); BOOST_CHECK_EQUAL(extractor.numWords(), descriptors.size()); BOOST_CHECK_CLOSE_FRACTION(sum, 1., 0.1); }
void test_real_concept_extra() { boost::math::concepts::real_concept tol = boost::math::tools::epsilon<boost::math::concepts::real_concept>() * 20; for(unsigned i = 0; i <= boost::math::max_bernoulli_b2n<long double>::value; ++i) { BOOST_CHECK_CLOSE_FRACTION(static_cast<boost::math::concepts::real_concept>(boost::math::bernoulli_b2n<long double>(i)), boost::math::bernoulli_b2n<boost::math::concepts::real_concept>(i), tol); } for(unsigned i = 1; i < 500; ++i) { boost::math::concepts::real_concept r = boost::math::bernoulli_b2n<long double>(i + boost::math::max_bernoulli_b2n<long double>::value); if((i + boost::math::max_bernoulli_b2n<long double>::value) & 1) { BOOST_CHECK(r >= boost::math::tools::max_value<boost::math::concepts::real_concept>()); } else { BOOST_CHECK(r <= -boost::math::tools::max_value<boost::math::concepts::real_concept>()); } } }
//! Use integrateTo() to integrate one step forward in time. void executeOneIntegrateToStep( const Eigen::MatrixXd benchmarkData, const double singleStepTestTolerance, const numerical_integrators::NumericalIntegratorXdPointer integrator ) { // Use integrateTo() to integrate one step forward in time and check results against benchmark // data. // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); // Use integrateTo() to integrate one step. integrator->integrateTo( benchmarkData( SECOND_ROW, TIME_COLUMN_INDEX ), benchmarkData( SECOND_ROW, TIME_COLUMN_INDEX ) - benchmarkData( FIRST_ROW, TIME_COLUMN_INDEX ) ); // Check if the expected time at the end of the integration step matches the required // time. This test should be exact. BOOST_CHECK_EQUAL( benchmarkData( SECOND_ROW, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ) ); // Check if expected state at end of integration step matches required state. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( SECOND_ROW, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), singleStepTestTolerance ); // Roll back to the previous step. This should be possible since the integrateTo() function // was called above. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that the rolled back time is as required. This test should be exact. BOOST_CHECK_EQUAL( benchmarkData( FIRST_ROW, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ) ); // Check that the rolled back state is as required. This test should be exact. BOOST_CHECK_EQUAL( benchmarkData( FIRST_ROW, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
//! Use integrateTo() to integrate to specified time in one step. void executeIntegrateToToSpecifiedTime( const Eigen::MatrixXd benchmarkData, const double fullIntegrationTestTolerance, const numerical_integrators::NumericalIntegratorXdPointer integrator, const double specifiedTime ) { // Use integrateTo() to integrate to specified time and and check results against benchmark // data. // Set index of last row of matrix containing benchmark data. const int indexLastRowBenchmarkData = benchmarkData.rows( ) - 1; // Use integrateTo() to integrate to final time. integrator->integrateTo( specifiedTime, benchmarkData( SECOND_ROW, TIME_COLUMN_INDEX ) - benchmarkData( FIRST_ROW, TIME_COLUMN_INDEX ) ); // Check if the expected time at the end of the integration step matches the required // time. This test should be exact. BOOST_CHECK_EQUAL( benchmarkData( indexLastRowBenchmarkData, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ) ); // Check if expected state at end of integration step matches required state. // The reason this test has a different, higher tolerance than for a single integration // step is because the acummulated error builds up, since this test is based off of // a time-series. The individual steps are accurate to the tolerance used in // Case 1. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( indexLastRowBenchmarkData, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), fullIntegrationTestTolerance ); // Roll back to the previous step. This should be possible since the integrateTo() function // was called above. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
void test_spots(T, const char* t) { std::cout << "Testing basic sanity checks for type " << t << std::endl; // // basic sanity checks, tolerance is 100 epsilon: // These spots were generated by MathCAD, precision is // 14-16 digits. // T tolerance = (std::max)(boost::math::tools::epsilon<T>() * 100, static_cast<T>(1e-14)); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(0, static_cast<T>(1)), static_cast<T>(1.L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1)), static_cast<T>(2.L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(2)), static_cast<T>(4.L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(10)), static_cast<T>(20), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(100)), static_cast<T>(200), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e6)), static_cast<T>(2e6), tolerance); if(std::numeric_limits<T>::max_exponent >= std::numeric_limits<double>::max_exponent) { BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e307)), static_cast<T>(2e307), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(99, static_cast<T>(100)), static_cast<T>(4.967223743011310E+227L), tolerance); } BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(30)), static_cast<T>(5.896624628001300E+17L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(1000)), static_cast<T>(1.023976960161280E+33L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(10)), static_cast<T>(8.093278209760000E+12L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(-10)), static_cast<T>(8.093278209760000E+12L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-10)), static_cast<T>(-7.880000000000000E+3L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000)), static_cast<T>(-7.999988000000000E+9L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000000)), static_cast<T>(-7.999999999988000E+18L), tolerance); }
void test_spots(T, const char* t) { std::cout << "Testing basic sanity checks for type " << t << std::endl; // // basic sanity checks, tolerance is 100 epsilon: // T tolerance = boost::math::tools::epsilon<T>() * 100; BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-1, static_cast<T>(0.5L)), static_cast<T>(1L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, static_cast<T>(0.5L)), static_cast<T>(-0.2890625000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, static_cast<T>(0.5L)), static_cast<T>(-0.4375000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, static_cast<T>(0.5L)), static_cast<T>(0.2231445312500000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, static_cast<T>(0.5L)), static_cast<T>(0.3232421875000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, static_cast<T>(0.5L)), static_cast<T>(-0.09542943523261546936538467572384923220258L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, static_cast<T>(0.5L)), static_cast<T>(-0.1316993126940266257030910566308990611306L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(0.5L)), static_cast<T>(5.625000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance); if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent) { BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance); } BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(0.5L)), static_cast<T>(4.966634149702370788037088925152355134665e30L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, 2, static_cast<T>(-0.5L)), static_cast<T>(4.218750000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(-0.5L)), static_cast<T>(-5.625000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(-0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(-0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance); if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent) { BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(-0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance); } BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, 20, static_cast<T>(-0.5L)), static_cast<T>(-4.966634149702370788037088925152355134665e30L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(4, -2, static_cast<T>(0.5L)), static_cast<T>(0.01171875000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, -2, static_cast<T>(0.5L)), static_cast<T>(0.04687500000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, -5, static_cast<T>(0.5L)), static_cast<T>(0.00002378609812640364935569308025139290054701L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, -4, static_cast<T>(0.5L)), static_cast<T>(0.0002563476562500000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, -30, static_cast<T>(0.5L)), static_cast<T>(-2.379819988646847616996471299410611801239e-48L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-40, -20, static_cast<T>(0.5L)), static_cast<T>(4.356454600748202401657099008867502679122e-33L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(1, static_cast<T>(0.5L)), static_cast<T>(-0.7253469278329725771511886907693685738381L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(4, static_cast<T>(0.5L)), static_cast<T>(0.4401745259867706044988642951843745400835L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(7, static_cast<T>(0.5L)), static_cast<T>(-0.3439152932669753451878700644212067616780L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_q(40, static_cast<T>(0.5L)), static_cast<T>(0.1493671665503550095010454949479907886011L), tolerance); }
void test_spots(T, const char* t) { std::cout << "Testing basic sanity checks for type " << t << std::endl; // // basic sanity checks, tolerance is 100 epsilon: // T tolerance = boost::math::tools::epsilon<T>() * 100; BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(0.5L)), static_cast<T>(0.5L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(0.5L)), static_cast<T>(-0.3307291666666666666666666666666666666667L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(0.5L)), static_cast<T>(-0.5183392237103174603174603174603174603175L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(0.5L)), static_cast<T>(0.3120174870800154148915399248893113634676L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(0.5L)), static_cast<T>(-0.3181388060269979064951118308575628226834L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(-0.5L)), static_cast<T>(1.5L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(-0.5L)), static_cast<T>(3.835937500000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(-0.5L)), static_cast<T>(7.950934709821428571428571428571428571429L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(-0.5L)), static_cast<T>(76.12915699869631476833699787070874048223L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(-0.5L)), static_cast<T>(2307.428631277506570629232863491518399720L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(1, static_cast<T>(4.5L)), static_cast<T>(-3.500000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, static_cast<T>(4.5L)), static_cast<T>(0.08593750000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(7, static_cast<T>(4.5L)), static_cast<T>(-1.036928013392857142857142857142857142857L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(20, static_cast<T>(4.5L)), static_cast<T>(1.437239150257817378525582974722170737587L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, static_cast<T>(4.5L)), static_cast<T>(-0.7795068145562651416494321484050019245248L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(4, 5, static_cast<T>(0.5L)), static_cast<T>(88.31510416666666666666666666666666666667L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 0, static_cast<T>(2.5L)), static_cast<T>(-0.8802526766660982969576719576719576719577L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 1, static_cast<T>(4.5L)), static_cast<T>(1.564311458042689732142857142857142857143L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 6, static_cast<T>(8.5L)), static_cast<T>(20.51596541066649098875661375661375661376L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(10, 12, static_cast<T>(12.5L)), static_cast<T>(-199.5560968456234671241181657848324514991L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::laguerre(50, 40, static_cast<T>(12.5L)), static_cast<T>(-4.996769495006119488583146995907246595400e16L), tolerance); }
void check_close(const std::complex<T>& a, const std::complex<T>& b) { T tol = boost::math::tools::epsilon<T>() * 3000; BOOST_CHECK_CLOSE_FRACTION(a.real(), b.real(), tol); BOOST_CHECK_CLOSE_FRACTION(a.imag(), b.imag(), tol); }
void phase_space<modules_type>::test() { float_type const epsilon = std::numeric_limits<float_type>::epsilon(); auto& input_position = input_position_sample->data(); auto& input_velocity = input_velocity_sample->data(); auto& input_species = input_species_sample->data(); // prepare input sample BOOST_CHECK_EQUAL(input_position.size(), accumulate(npart.begin(), npart.end(), 0u)); BOOST_CHECK_EQUAL(input_velocity.size(), accumulate(npart.begin(), npart.end(), 0u)); for (unsigned int i = 0, n = 0; i < npart.size(); ++i) { // iterate over particle species for (unsigned int j = 0; j < npart[i]; ++n, ++j) { // iterate over particles vector_type& r = input_position[n]; vector_type& v = input_velocity[n]; unsigned int& type = input_species[n]; r[0] = float_type(j) + float_type(1) / (i + 1); //< a large, non-integer value r[1] = 0; r[dimension - 1] = - static_cast<float_type>(j); v[0] = static_cast<float_type>(i); v[1] = 0; v[dimension - 1] = float_type(1) / (j + 1); type = i; } } // copy input sample to particle std::shared_ptr<particle_group_type> particle_group = std::make_shared<particle_group_type>(particle); { auto phase_space = phase_space_type(particle, particle_group, box); phase_space.set("position", input_position_sample); phase_space.set("velocity", input_velocity_sample); phase_space.set("species", input_species_sample); phase_space.set("mass", input_mass_sample); } // randomly permute particles in memory, do it three times since permutations are // not commutative shuffle(particle, random); shuffle(particle, random); shuffle(particle, random); // compare output and input, copy GPU sample to host before typename modules_type::samples_type result(phase_space_type(particle, particle_group, box)); auto const& result_position = result.position->data(); auto const& result_velocity = result.velocity->data(); auto const& result_species = result.species->data(); BOOST_CHECK_EQUAL(result_position.size(), accumulate(npart.begin(), npart.end(), 0u)); for (unsigned int i = 0, n = 0; i < npart.size(); ++i) { // iterate over particle species for (unsigned int j = 0; j < npart[i]; ++n, ++j) { // iterate over particles // compare positions with a tolerance due to mapping to and from the periodic box for (unsigned int k = 0; k < dimension; ++k) { BOOST_CHECK_CLOSE_FRACTION(result_position[n][k], input_position[n][k], 10 * epsilon); } } } // compare velocities directly as they should not have been modified BOOST_CHECK_EQUAL_COLLECTIONS( result_velocity.begin(), result_velocity.end() , input_velocity.begin(), input_velocity.end() ); // compare particle species BOOST_CHECK_EQUAL_COLLECTIONS( result_species.begin(), result_species.end() , input_species.begin(), input_species.end() ); }
void test_spots(T, const char*) { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4127 4756) #endif // // A few special spot tests: // BOOST_MATH_STD_USING T tol = boost::math::tools::epsilon<T>() * 20; if(std::numeric_limits<T>::max_exponent > 200) { BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -500)), T(180.25)), T(8.0113754557649679470816892372669519037339812035512e-178L), 3 * tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -525)), T(192.25)), T(1.5966560279353205461166489184101261541784867035063e-197L), 3 * tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(182.25), T(ldexp(T(1), -500))), T(4.077990437521002194346763299159975185747917450788e+181L), 3 * tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), T(ldexp(T(1), -525))), T(1.2040790040958522422697601672703926839178050326148e+199L), 3 * tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(193.25), T(194.75)), T(0.00037151765099653237632823607820104961270831942138159L), 3 * tol); } BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(T(0), T(2)), std::domain_error); BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(T(2), T(0)), std::domain_error); BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(T(-1), T(2)), std::domain_error); BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(T(2), T(-1)), std::domain_error); if(std::numeric_limits<T>::has_infinity) { BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(std::numeric_limits<T>::infinity(), T(2)), std::domain_error); BOOST_MATH_CHECK_THROW(boost::math::tgamma_ratio(T(2), std::numeric_limits<T>::infinity()), std::domain_error); } // // Some bug cases from Rocco Romeo: // if(std::numeric_limits<T>::min_exponent < -1020) { BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(100)), T(1.20390418056093374068585549133304106854441830616070800417660e151L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(150)), T(2.94980580122226729924781231239336413648584663386992050529324e46L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(180)), T(1.00669209319561468911303652019446665496398881230516805140750e-20L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(220)), T(1.08230263539550701700187215488533416834407799907721731317227e-112L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(260)), T(7.62689807594728483940172477902929825624752380292252137809206e-208L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1020)), T(290)), T(5.40206998243175672775582485422795773284966068149812072521290e-281L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_delta_ratio(T(ldexp(T(1), -1020)), T(ldexp(T(1), -1020))), T(2), tol); if(0 != ldexp(T(1), -1074)) { // This is denorm_min at double precision: BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(ldexp(T(1), -1074)), T(200)), T(5.13282785052571536804189023927976812551830809667482691717029e-50), tol * 50); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_ratio(T(200), T(ldexp(T(1), -1074))), T(1.94824379293682687942882944294875087145333536754699303593931e49), tol * 10); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_delta_ratio(T(ldexp(T(1), -1074)), T(200)), T(5.13282785052571536804189023927976812551830809667482691717029e-50), tol * 10); BOOST_CHECK_CLOSE_FRACTION(boost::math::tgamma_delta_ratio(T(200), T(ldexp(T(1), -1074))), T(1), tol); } } }
void test_spots(T, const char* t) { std::cout << "Testing basic sanity checks for type " << t << std::endl; // // basic sanity checks, tolerance is 100 epsilon: // T tolerance = boost::math::tools::epsilon<T>() * 100; BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(3, 2, static_cast<T>(0.5), static_cast<T>(0)), static_cast<T>(0.2061460599687871330692286791802688341213L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 10, static_cast<T>(0.75), static_cast<T>(-0.25)), static_cast<T>(0.06197787102219208244041677775577045124092L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 10, static_cast<T>(0.75), static_cast<T>(-0.25)), static_cast<T>(0.04629885158895932341185988759669916977920L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(-0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, 15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, 15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, 15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, 15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, 15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(-0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, 15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(-0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(39, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.1757594233240278196989039119899901986211L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(39, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(-0.1837126108841860058078729532035715580790L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(39, 15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.1757594233240278196989039119899901986211L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(39, 15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.1837126108841860058078729532035715580790L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(39, 15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.1757594233240278196989039119899901986211L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(39, 15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.1837126108841860058078729532035715580790L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(39, 15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(-0.1757594233240278196989039119899901986211L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(39, 15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.1837126108841860058078729532035715580790L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(19, 14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.2341701030303444033808969389588343934828L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(19, 14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.0197340092863212879172432610952871202640L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(19, 14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.2341701030303444033808969389588343934828L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(19, 14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(-0.0197340092863212879172432610952871202640L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(19, 14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(0.2341701030303444033808969389588343934828L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(19, 14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.0197340092863212879172432610952871202640L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(19, 14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.2341701030303444033808969389588343934828L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(19, 14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.0197340092863212879172432610952871202640L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, -15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(-0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, -15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(-0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, -15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(-0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, -15, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, -15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, -15, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(-0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(40, -15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.2806904825045745687343492963236868973484L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(40, -15, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.2933918444656603582282372590387544902135L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, -14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, -14, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(-0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, -14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, -14, static_cast<T>(-0.75), static_cast<T>(-2.25)), static_cast<T>(0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, -14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, -14, static_cast<T>(0.75), static_cast<T>(-2.25)), static_cast<T>(0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, -14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(0.3479218186133435466692822481919867452442L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, -14, static_cast<T>(0.75), static_cast<T>(2.25)), static_cast<T>(-0.0293201066685263879566422194539567289974L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(-4), static_cast<T>(2.25)), static_cast<T>(0.5253373768014719124617844890495875474590L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(-4), static_cast<T>(2.25)), static_cast<T>(0.0442712905622650144694916590407495495699L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(-4), static_cast<T>(-2.25)), static_cast<T>(0.5253373768014719124617844890495875474590L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(-4), static_cast<T>(-2.25)), static_cast<T>(-0.0442712905622650144694916590407495495699L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(4), static_cast<T>(-2.25)), static_cast<T>(0.5253373768014719124617844890495875474590L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(4), static_cast<T>(-2.25)), static_cast<T>(-0.0442712905622650144694916590407495495699L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 14, static_cast<T>(4), static_cast<T>(2.25)), static_cast<T>(0.5253373768014719124617844890495875474590L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 14, static_cast<T>(4), static_cast<T>(2.25)), static_cast<T>(0.0442712905622650144694916590407495495699L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 15, static_cast<T>(-4), static_cast<T>(2.25)), static_cast<T>(-0.2991140325667575801827063718821420263438L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 15, static_cast<T>(-4), static_cast<T>(2.25)), static_cast<T>(0.3126490678888350710506307405826667514065L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 15, static_cast<T>(-4), static_cast<T>(-2.25)), static_cast<T>(-0.2991140325667575801827063718821420263438L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 15, static_cast<T>(-4), static_cast<T>(-2.25)), static_cast<T>(-0.3126490678888350710506307405826667514065L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 15, static_cast<T>(4), static_cast<T>(-2.25)), static_cast<T>(0.2991140325667575801827063718821420263438L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 15, static_cast<T>(4), static_cast<T>(-2.25)), static_cast<T>(0.3126490678888350710506307405826667514065L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(20, 15, static_cast<T>(4), static_cast<T>(2.25)), static_cast<T>(0.2991140325667575801827063718821420263438L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(20, 15, static_cast<T>(4), static_cast<T>(2.25)), static_cast<T>(-0.3126490678888350710506307405826667514065L), tolerance); BOOST_CHECK_EQUAL(::boost::math::spherical_harmonic_r(10, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0)); BOOST_CHECK_EQUAL(::boost::math::spherical_harmonic_i(10, 15, static_cast<T>(-0.75), static_cast<T>(2.25)), static_cast<T>(0)); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_r(53, 42, static_cast<T>(-8.75), static_cast<T>(-2.25)), static_cast<T>(-0.0008147976618889536159592309471859037113647L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::spherical_harmonic_i(53, 42, static_cast<T>(-8.75), static_cast<T>(-2.25)), static_cast<T>(0.0002099802242493057018193798824353982612756L), tolerance); }
//! Use performIntegrationStep() to integrate to specified time in multiple steps. void performIntegrationStepToSpecifiedTime( const Eigen::MatrixXd benchmarkData, const double singleStepTestTolerance, const double fullIntegrationTestTolerance, const numerical_integrators::NumericalIntegratorXdPointer integrator ) { // Use performIntegrationstep() to integrate to specified time in multiple steps and check // results against benchmark data. // Declare last time and state. double lastTime = TUDAT_NAN; Eigen::VectorXd lastState = Eigen::VectorXd::Zero( 1 ); // Loop through all the integration steps in the benchmark data. for ( int i = 1; i < benchmarkData.rows( ); i++ ) { // Set the step size based on the benchmark data. double stepSize = benchmarkData( i, TIME_COLUMN_INDEX ) - benchmarkData( i - 1, TIME_COLUMN_INDEX ); // Store last time and state. lastTime = integrator->getCurrentIndependentVariable( ); lastState = integrator->getCurrentState( ); // Perform the integration step. integrator->performIntegrationStep( stepSize ); // Check if the expected time at the end of the integration step matches the required // time. This test should be accurate to effectively machine precision. if ( std::fabs( integrator->getCurrentIndependentVariable( ) ) < std::numeric_limits< double >::epsilon( ) ) { BOOST_CHECK_SMALL( benchmarkData( i, TIME_COLUMN_INDEX ), singleStepTestTolerance ); } else { BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ), singleStepTestTolerance ); } // Check if expected state at end of integration step matches required state. // The reason this test has a different, higher tolerance than for a single integration // step is because the acummulated error builds up, since this test is based off of // a time-series. The individual steps are accurate to singleStepTestTolerance. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), fullIntegrationTestTolerance ); } // Roll back to the previous step. This should be possible since the // performIntegrationStep() function was called above. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that the rolled back time is as required. This test should be exact. BOOST_CHECK_EQUAL( lastTime, integrator->getCurrentIndependentVariable( ) ); // Check that the rolled back state is as required. This test should be exact. BOOST_CHECK_EQUAL( lastState( 0 ), integrator->getCurrentState( )( 0 ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
void test_spots(T, const char* type_name) { BOOST_MATH_STD_USING // Function values calculated on http://functions.wolfram.com/ // Note that Mathematica's Sn/Cn/Dn accepts k^2 as the second parameter. // Arguments here are theta, k, sn, cn, dn static const boost::array<boost::array<T, 5>, 36> data1 = {{ {{ SC_(0.0), SC_(0.0), SC_(0.0), SC_(1.0), SC_(1.0) }}, {{ ldexp(T(1), -25), ldexp(T(1), -25), SC_(2.98023223876953080883700663838486782870427050521881839342311e-8), SC_(0.99999999999999955591079014993741669975171697261290223678373), SC_(0.99999999999999999999999999999960556954738949421406900774443) }}, {{ -ldexp(T(1), -25), ldexp(T(1), -25), SC_(-2.98023223876953080883700663838486782870427050521881839342311e-8), SC_(0.99999999999999955591079014993741669975171697261290223678373), SC_(0.99999999999999999999999999999960556954738949421406900774443) }}, {{ SC_(0.25), ldexp(T(1), -25), SC_(0.247403959254522927383635623557663763268693729825996390997241), SC_(0.968912421710644784709721529742747886950140086772629513814665), SC_(0.99999999999999997281786831901333837240938011109848356555885) }}, {{ SC_(-0.25), ldexp(T(1), -25), SC_(-0.247403959254522927383635623557663763268693729825996390997241), SC_(0.968912421710644784709721529742747886950140086772629513814665), SC_(0.99999999999999997281786831901333837240938011109848356555885) }}, {{ SC_(1.25), ldexp(T(1), -25), SC_(0.948984619355586147780156037971989352776684194861616269831136), SC_(0.315322362395268865789580233344649598639316847638615703458263), SC_(0.99999999999999960006577747263860127231780811081154547949983) }}, {{ SC_(-1.25), ldexp(T(1), -25), SC_(-0.948984619355586147780156037971989352776684194861616269831136), SC_(0.315322362395268865789580233344649598639316847638615703458263), SC_(0.99999999999999960006577747263860127231780811081154547949983) }}, {{ SC_(25.0), ldexp(T(1), -25), SC_(-0.132351750097778560056127137329035522219365438979106560464704), SC_(0.991202811863472859528158119981178957382802975691690722810123), SC_(0.99999999999999999222089563757583834413059580275315226870704) }}, {{ SC_(-25.0), ldexp(T(1), -25), SC_(0.132351750097778560056127137329035522219365438979106560464704), SC_(0.991202811863472859528158119981178957382802975691690722810123), SC_(0.99999999999999999222089563757583834413059580275315226870704) }}, {{ ldexp(T(1), -25), SC_(0.5), SC_(2.98023223876953058825550995757802173334628440851964836958219e-8), SC_(0.99999999999999955591079014993744956895610118130967536624417), SC_(0.99999999999999988897769753748438088116649141278818704012037) }}, {{ -ldexp(T(1), -25), SC_(0.5), SC_(-2.98023223876953058825550995757802173334628440851964836958219e-8), SC_(0.99999999999999955591079014993744956895610118130967536624417), SC_(0.99999999999999988897769753748438088116649141278818704012037) }}, {{ SC_(0.25), SC_(0.5), SC_(0.246781405136141600483623741101255389743847413013817188632739), SC_(0.969071172865559727608777289021929824625726812182428398055476), SC_(0.992358168465276394946615469032829292963938826683866720698130) }}, {{ SC_(-0.25), SC_(0.5), SC_(-0.246781405136141600483623741101255389743847413013817188632739), SC_(0.969071172865559727608777289021929824625726812182428398055476), SC_(0.992358168465276394946615469032829292963938826683866720698130) }}, {{ SC_(1.25), SC_(0.5), SC_(0.928561236426319775700204388269999130782711902203415239399579), SC_(0.371179242693370810357222594552131893184749696381729988511999), SC_(0.885688154799196841458565445994481097477880319663264816077719) }}, {{ SC_(-1.25), SC_(0.5), SC_(-0.928561236426319775700204388269999130782711902203415239399579), SC_(0.371179242693370810357222594552131893184749696381729988511999), SC_(0.885688154799196841458565445994481097477880319663264816077719) }}, {{ SC_(25.0), SC_(0.5), SC_(-0.969223071486651608400225080456020493867827336842041561445359), SC_(-0.246184154035106463351874891855925292474628176040625311168501), SC_(0.874729477852721764836147376110255133761608728373832418508248) }}, {{ SC_(-25.0), SC_(0.5), SC_(0.969223071486651608400225080456020493867827336842041561445359), SC_(-0.246184154035106463351874891855925292474628176040625311168501), SC_(0.874729477852721764836147376110255133761608728373832418508248) }}, {{ ldexp(T(1), -25), 1 - ldexp(T(1), -9), SC_(2.98023223876953036939562331632512854347569015560128614888589e-8), SC_(0.99999999999999955591079014993754766348947956082687878223721), SC_(0.99999999999999955764381956001984590118394542979655101564079) }}, {{ -ldexp(T(1), -25), 1 - ldexp(T(1), -9), SC_(-2.98023223876953036939562331632512854347569015560128614888589e-8), SC_(0.99999999999999955591079014993754766348947956082687878223721), SC_(0.99999999999999955764381956001984590118394542979655101564079) }}, {{ SC_(0.25), 1 - ldexp(T(1), -9), SC_(0.244928335616519632082236089277654937383208524525331032303082), SC_(0.969541185516180906431546524888118346090913555188425579774305), SC_(0.969661908643964623248878987955178702010392829596222190545649) }}, {{ SC_(-0.25), 1 - ldexp(T(1), -9), SC_(-0.244928335616519632082236089277654937383208524525331032303082), SC_(0.969541185516180906431546524888118346090913555188425579774305), SC_(0.969661908643964623248878987955178702010392829596222190545649) }}, {{ SC_(1.25), 1 - ldexp(T(1), -9), SC_(0.848768940045053312079390719205939167551169094157365783446523), SC_(0.528763923140371497228677918580246099580380684604621321430057), SC_(0.531415689278260818860813380561526095359692710060403584603095) }}, {{ SC_(-1.25), 1 - ldexp(T(1), -9), SC_(-0.848768940045053312079390719205939167551169094157365783446523), SC_(0.528763923140371497228677918580246099580380684604621321430057), SC_(0.531415689278260818860813380561526095359692710060403584603095) }}, {{ SC_(25.0), 1 - ldexp(T(1), -9), SC_(-0.0252326124525503880903568715488227138184083895871544015366337), SC_(-0.999681606947341709011836635135181960590782564534371631099332), SC_(0.999682849652724146508471774051629114156076052044812654903417) }}, {{ SC_(-25.0), 1 - ldexp(T(1), -9), SC_(0.0252326124525503880903568715488227138184083895871544015366337), SC_(-0.999681606947341709011836635135181960590782564534371631099332), SC_(0.999682849652724146508471774051629114156076052044812654903417) }}, // Try modulus > 1 {{ ldexp(T(1), -25), SC_(1.5), SC_(2.98023223876952981622027157475276613133414644789222481971590e-8), SC_(0.999999999999999555910790149937712522591174851747994454928040), SC_(0.999999999999999000799277837359575841918151654603571877092161) }}, {{ -ldexp(T(1), -25), SC_(1.5), SC_(-2.98023223876952981622027157475276613133414644789222481971590e-8), SC_(0.999999999999999555910790149937712522591174851747994454928040), SC_(0.999999999999999000799277837359575841918151654603571877092161) }}, {{ SC_(0.25), SC_(1.5), SC_(0.241830488135945315134822478837394038661484435596992059686086), SC_(0.970318512143270619246031961334217540099946232418710982266812), SC_(0.931888155181641649031244632258710371461078255228024421800363) }}, {{ SC_(-0.25), SC_(1.5), SC_(-0.241830488135945315134822478837394038661484435596992059686086), SC_(0.970318512143270619246031961334217540099946232418710982266812), SC_(0.931888155181641649031244632258710371461078255228024421800363) }}, {{ SC_(1.25), SC_(1.5), SC_(0.665875890711922169121186264316618499018039094009893317545462), SC_(0.746062529663971452521312655373498959968622875614588791642250), SC_(-0.0486921028438866868299166778939466685768843580182675008164949) }}, {{ SC_(-1.25), SC_(1.5), SC_(-0.665875890711922169121186264316618499018039094009893317545462), SC_(0.746062529663971452521312655373498959968622875614588791642250), SC_(-0.0486921028438866868299166778939466685768843580182675008164949) }}, {{ SC_(25.0), SC_(1.5), SC_(0.618665338981368217712277210270169521641154921220796362724248), SC_(0.785654630447163313102421517325310755764805805534154371583941), SC_(0.372585153048138377269609818284480926623056458773704266654150) }}, {{ SC_(-25.0), SC_(1.5), SC_(-0.618665338981368217712277210270169521641154921220796362724248), SC_(0.785654630447163313102421517325310755764805805534154371583941), SC_(0.372585153048138377269609818284480926623056458773704266654150) }}, // Special Values: {{ SC_(0.0), SC_(0.5), SC_(0.0), SC_(1.0), SC_(1.0) }}, {{ SC_(5.0), SC_(0.0), SC_(-0.958924274663138468893154406155993973352461543964601778131672), SC_(0.283662185463226264466639171513557308334422592252215944930359), SC_(1.0) }}, {{ SC_(5.0), SC_(1.0), SC_(0.999909204262595131210990447534473021089812615990547862736429), SC_(0.0134752822213045573055191382448821552908373539417006868332819), SC_(0.0134752822213045573055191382448821552908373539417006868332819) }}, }}; do_test_sn<T>(data1, type_name, "Jacobi Elliptic: Mathworld Data"); #include "jacobi_elliptic.ipp" do_test_sn<T>(jacobi_elliptic, type_name, "Jacobi Elliptic: Random Data"); #include "jacobi_elliptic_small.ipp" do_test_sn<T>(jacobi_elliptic_small, type_name, "Jacobi Elliptic: Random Small Values"); #include "jacobi_near_1.ipp" do_test_sn<T>(jacobi_near_1, type_name, "Jacobi Elliptic: Modulus near 1"); #include "jacobi_large_phi.ipp" do_test_sn<T>(jacobi_large_phi, type_name, "Jacobi Elliptic: Large Phi"); // // Sanity checks for all the various derived functions - these are all // trivial wrappers around the main three that are tested above - so just // use a simple sanity check for each one. // Test values are from functions.wolfram.com: // T tol = boost::math::tools::epsilon<T>() * 100; boost::math::policies::policy<> pol; BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cd(T(0.5), T(0.5)), static_cast<T>(0.905869360370352996327275878479104183407762212476128499788493L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cd(T(0.5), T(0.5), pol), static_cast<T>(0.905869360370352996327275878479104183407762212476128499788493L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cn(T(0.5), T(0.5)), static_cast<T>(0.879941022963758342138211939938800035594045353539382810624647L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cn(T(0.5), T(0.5), pol), static_cast<T>(0.879941022963758342138211939938800035594045353539382810624647L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cs(T(0.5), T(0.5)), static_cast<T>(1.85218402142505803268146025319200184620073865036147924150565L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_cs(T(0.5), T(0.5), pol), static_cast<T>(1.85218402142505803268146025319200184620073865036147924150565L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_dc(T(0.5), T(0.5)), static_cast<T>(1.10391193669599654696698383614539220889596741980833071370343L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_dc(T(0.5), T(0.5), pol), static_cast<T>(1.10391193669599654696698383614539220889596741980833071370343L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_dn(T(0.5), T(0.5)), static_cast<T>(0.971377398838178842823315157470233933307542433588855341182382L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_dn(T(0.5), T(0.5), pol), static_cast<T>(0.971377398838178842823315157470233933307542433588855341182382L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_ds(T(0.5), T(0.5)), static_cast<T>(2.04464805020871497502900445828888632133468724223115900866414L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_ds(T(0.5), T(0.5), pol), static_cast<T>(2.04464805020871497502900445828888632133468724223115900866414L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_nc(T(0.5), T(0.5)), static_cast<T>(1.13643979983097851593855424992691981204889859711476187519109L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_nc(T(0.5), T(0.5), pol), static_cast<T>(1.13643979983097851593855424992691981204889859711476187519109L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_nd(T(0.5), T(0.5)), static_cast<T>(1.02946599457230050141998045852435702297405263760707971258676L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_nd(T(0.5), T(0.5), pol), static_cast<T>(1.02946599457230050141998045852435702297405263760707971258676L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_ns(T(0.5), T(0.5)), static_cast<T>(2.10489563855842977359275221390569031239706339764770047142101L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_ns(T(0.5), T(0.5), pol), static_cast<T>(2.10489563855842977359275221390569031239706339764770047142101L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sc(T(0.5), T(0.5)), static_cast<T>(0.539903156723383602910722041849329275299051877814755451255071L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sc(T(0.5), T(0.5), pol), static_cast<T>(0.539903156723383602910722041849329275299051877814755451255071L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sd(T(0.5), T(0.5)), static_cast<T>(0.489081727242945953222289853693492188561192086497066116267160L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sd(T(0.5), T(0.5), pol), static_cast<T>(0.489081727242945953222289853693492188561192086497066116267160L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sn(T(0.5), T(0.5)), static_cast<T>(0.475082936028536510082218324703870258745078171807428948028252L), tol); BOOST_CHECK_CLOSE_FRACTION(boost::math::jacobi_sn(T(0.5), T(0.5), pol), static_cast<T>(0.475082936028536510082218324703870258745078171807428948028252L), tol); }
//! Use performIntegrationStep() to integrate to specified time in multiple steps, including //! discrete events. void performIntegrationStepToSpecifiedTimeWithEvents( const Eigen::MatrixXd benchmarkData, const double singleStepTestTolerance, const double fullIntegrationTestTolerance, const numerical_integrators::ReinitializableNumericalIntegratorXdPointer integrator ) { // Use performIntegrationstep() to integrate to specified time in multiple steps, including // discrete events and check results against benchmark data. The discrete events are enabled // by modifying the state instantaneously. These discrete events cannot be rolled back. // Declare last time and state. double lastTime = TUDAT_NAN; Eigen::VectorXd lastState = Eigen::VectorXd::Zero( 1 ); // Loop through all the integration steps in the benchmark data. for ( int i = 1; i < benchmarkData.rows( ); i++ ) { // Set the step size based on the benchmark data generated. const double stepSize = benchmarkData( i, TIME_COLUMN_INDEX ) - benchmarkData( i - 1, TIME_COLUMN_INDEX ); // Store last time and state. lastTime = integrator->getCurrentIndependentVariable( ); lastState = integrator->getCurrentState( ); // Perform the integration step. integrator->performIntegrationStep( stepSize ); // Check if the expected time at the end of the integration step matches the required // time. This test should be accurate to effectively machine precision. if ( std::fabs( benchmarkData( i, TIME_COLUMN_INDEX ) ) < std::numeric_limits< double >::min( ) ) { BOOST_CHECK_SMALL( integrator->getCurrentIndependentVariable( ), std::numeric_limits< double >::epsilon( ) ); } else { BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ), singleStepTestTolerance ); } // Check if expected state at end of integration step matches required state. // The reason this test has a different, higher tolerance than for a single integration // step is because the acummulated error builds up, since this test is based off of // a time-series. The individual steps are accurate to the tolerance used in // Case 1. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), fullIntegrationTestTolerance ); // Check if a discrete event is schedule to take place, and execute discrete event // if so. if ( i < benchmarkData.rows( ) - 1 && std::fabs( benchmarkData( i + 1, TIME_COLUMN_INDEX ) - benchmarkData( i, TIME_COLUMN_INDEX ) ) < std::numeric_limits< double >::epsilon( ) ) { // Increment loop to next row in matrix, which contains the discrete event that // affects the state. i++; // Modify the current state based on the discrete event integrator->modifyCurrentState( Eigen::VectorXd::Constant( 1, benchmarkData( i, STATE_COLUMN_INDEX ) ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); } } // Check that it is possible to roll back to the previous step. This is allowable, because // the last action performed by the integrator is the performIntegrationStep() function. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that the rolled back time is as required. This test should be exact. BOOST_CHECK_EQUAL( lastTime, integrator->getCurrentIndependentVariable( ) ); // Check that the rolled back state is as required. This test should be exact. BOOST_CHECK_EQUAL( lastState( 0 ), integrator->getCurrentState( )( 0 ) ); // Check that it is now not possible to roll back to the previous step. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
void test(const char* name) { std::cout << "Testing type " << name << ":\n"; static const typename table_type<T>::type data[] = { /* First 50 from 2 to 100 inclusive: */ /* TABLE[N[BernoulliB[n], 200], {n,2,100,2}] */ SC_(0.1666666666666666666666666666666666666666), SC_(-0.0333333333333333333333333333333333333333), SC_(0.0238095238095238095238095238095238095238), SC_(-0.0333333333333333333333333333333333333333), SC_(0.0757575757575757575757575757575757575757), SC_(-0.2531135531135531135531135531135531135531), SC_(1.1666666666666666666666666666666666666666), SC_(-7.0921568627450980392156862745098039215686), SC_(54.9711779448621553884711779448621553884711), SC_(-529.1242424242424242424242424242424242424242), SC_(6192.1231884057971014492753623188405797101449), SC_(-86580.2531135531135531135531135531135531135531), SC_(1.4255171666666666666666666666666666666666e6), SC_(-2.7298231067816091954022988505747126436781e7), SC_(6.0158087390064236838430386817483591677140e8), SC_(-1.5116315767092156862745098039215686274509e10), SC_(4.2961464306116666666666666666666666666666e11), SC_(-1.3711655205088332772159087948561632772159e13), SC_(4.8833231897359316666666666666666666666666e14), SC_(-1.9296579341940068148632668144863266814486e16), SC_(8.4169304757368261500055370985603543743078e17), SC_(-4.0338071854059455413076811594202898550724e19), SC_(2.1150748638081991605601453900709219858156e21), SC_(-1.2086626522296525934602731193708252531781e23), SC_(7.5008667460769643668557200757575757575757e24), SC_(-5.0387781014810689141378930305220125786163e26), SC_(3.6528776484818123335110430842971177944862e28), SC_(-2.8498769302450882226269146432910678160919e30), SC_(2.3865427499683627644645981919219214971751e32), SC_(-2.1399949257225333665810744765191097392674e34), SC_(2.0500975723478097569921733095672310251666e36), SC_(-2.0938005911346378409095185290027970184709e38), SC_(2.2752696488463515559649260352769264581469e40), SC_(-2.6257710286239576047303049736158202081449e42), SC_(3.2125082102718032518204792304264985243521e44), SC_(-4.1598278166794710913917074495262358936689e46), SC_(5.6920695482035280023883456219121058644480e48), SC_(-8.2183629419784575692290653468617333014550e50), SC_(1.2502904327166993016732339829702895524177e53), SC_(-2.0015583233248370274925329198813298768724e55), SC_(3.3674982915364374233396676903338753016219e57), SC_(-5.9470970503135447718660496844051540840579e59), SC_(1.1011910323627977559564130790437691604630e62), SC_(-2.1355259545253501188658385019041065678973e64), SC_(4.3328896986641192419616613059379206218451e66), SC_(-9.1885528241669328226200555215501897138960e68), SC_(2.0346896776329074493455027990220020065975e71), SC_(-4.7003833958035731078575255535006060654596e73), SC_(1.1318043445484249270675186257733934267890e76), SC_(-2.8382249570693706959264156336481764738284e78), /* next 50 from 102 to 200: */ /* TABLE[N[BernoulliB[n], 200], {n,102,200,2}] */ SC_(7.4064248979678850629750827140920984176879e80), SC_(-2.0096454802756604483465619672715363186867e83), SC_(5.6657170050805941445719346030519356961419e85), SC_(-1.6584511154136216915823713374319912301494e88), SC_(5.0368859950492377419289421915180154812442e90), SC_(-1.5861468237658186369363401572966438782740e93), SC_(5.1756743617545626984073240682507122561240e95), SC_(-1.7488921840217117339690025877618159145141e98), SC_(6.1160519994952185255824525264264167780767e100), SC_(-2.2122776912707834942288323456712932445573e103), SC_(8.2722776798770969854221062459984595731204e105), SC_(-3.1958925111415709583591634369180814873526e108), SC_(1.2750082223387792982310024302926679866957e111), SC_(-5.2500923086774133899402824624565175446919e113), SC_(2.2301817894241625209869298198838728143738e116), SC_(-9.7684521930955204438633513398980239301166e118), SC_(4.4098361978452954272272622874813169191875e121), SC_(-2.0508570886464088839729337727583015486456e124), SC_(9.8214433279791277107572969602097521041491e126), SC_(-4.8412600798208880508789196709963412761130e129), SC_(2.4553088801480982609783467404088690399673e132), SC_(-1.2806926804084747548782513278601785721811e135), SC_(6.8676167104668581192101888598464400436092e137), SC_(-3.7846468581969104694978995416379556814489e140), SC_(2.1426101250665291550871323135148272096660e143), SC_(-1.2456727137183695007019642961637607219458e146), SC_(7.4345787551000152543679668394052061311780e148), SC_(-4.5535795304641704894063333223321274876772e151), SC_(2.8612112816858868345363847251017232522918e154), SC_(-1.8437723552033869727688202653628785487541e157), SC_(1.2181154536221046699501316506599521355817e160), SC_(-8.2482187185314121548481845729689344730141e162), SC_(5.7225877937832943329651649814297861591868e165), SC_(-4.0668530525059104726767969383115865560219e168), SC_(2.9596092064642050062875269581585187042637e171), SC_(-2.2049522565189457509031175227344598483637e174), SC_(1.6812597072889599805831152515136066575446e177), SC_(-1.3116736213556957648645280635581715300443e180), SC_(1.0467894009478038082183285392982308964382e183), SC_(-8.5432893578833707718598254629908277459327e185), SC_(7.1287821322486542352288406677143822472124e188), SC_(-6.0802931455535899300084711868647745846198e191), SC_(5.2996776424849923930094291004324726622848e194), SC_(-4.7194259168745862644364622901337991110376e197), SC_(4.2928413791402981089416829654107466904552e200), SC_(-3.9876744968232207443447765554293879510665e203), SC_(3.7819780419358882713894418116139332789822e206), SC_(-3.6614233683681191243685808215119734875519e209), SC_(3.6176090272372862348855460929891408947754e212), SC_(-3.6470772645191354362138308865549944904868e215), }; T tol = boost::math::tools::epsilon<T>() * 20; for(unsigned i = 1; i <= 100; ++i) { T b2n = boost::math::bernoulli_b2n<T>(i); T t2n = boost::math::tangent_t2n<T>(i); if((boost::math::isinf)(b2n)) { if(!(boost::math::isinf)(data[i - 1])) { std::cout << "When calculating B2N(" << i << ")\n"; BOOST_ERROR("Got an infinity when one wasn't expected"); } else if((b2n > 0) != (data[i - 1] > 0)) { std::cout << "When calculating B2N(" << i << ")\n"; BOOST_ERROR("Sign of infinity was incorrect"); } } else if((boost::math::isnan)(b2n)) { std::cout << "When calculating B2N(" << i << ")\n"; BOOST_ERROR("Result of B2n was a NaN, and that should never happen!"); } else { BOOST_CHECK_CLOSE_FRACTION(b2n, data[i - 1], tol); } if(i <= boost::math::max_bernoulli_b2n<T>::value) { BOOST_CHECK_EQUAL(b2n, boost::math::unchecked_bernoulli_b2n<T>(i)); } if((boost::math::isfinite)(t2n) && (t2n < boost::math::tools::max_value<T>())) { T p = ldexp(T(1), 2 * i); int s = i & 1 ? 1 : -1; p = t2n / (s * p * (p - 1)); p *= 2 * i; BOOST_CHECK_CLOSE_FRACTION(p, b2n, tol); } } // // Test consistency of array interface: // T bn[boost::math::max_bernoulli_b2n<T>::value + 20]; boost::math::bernoulli_b2n<T>(0, boost::math::max_bernoulli_b2n<T>::value + 20, bn); for(unsigned i = 0; i < boost::math::max_bernoulli_b2n<T>::value + 20; ++i) { BOOST_CHECK_EQUAL(bn[i], boost::math::bernoulli_b2n<T>(i)); } boost::math::tangent_t2n<T>(0, boost::math::max_bernoulli_b2n<T>::value + 20, bn); for(unsigned i = 0; i < boost::math::max_bernoulli_b2n<T>::value + 20; ++i) { BOOST_CHECK_EQUAL(bn[i], boost::math::tangent_t2n<T>(i)); } // // Some spot tests for things that should throw exceptions: // static unsigned overflow_index = boost::is_same<T, boost::math::concepts::real_concept>::value ? boost::math::max_bernoulli_b2n<long double>::value + 5 : boost::math::max_bernoulli_b2n<T>::value + 5; BOOST_CHECK_THROW(boost::math::bernoulli_b2n<T>(overflow_index, boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::throw_on_error>())), std::overflow_error); BOOST_CHECK_THROW(boost::math::tangent_t2n<T>(overflow_index, boost::math::policies::make_policy(boost::math::policies::overflow_error<boost::math::policies::throw_on_error>())), std::overflow_error); }