boost::math::tuple<T, T, T> operator()(const T& x) { typedef typename boost::math::lanczos::lanczos<T, Policy>::type L; T f = boost::math::detail::ibeta_imp(a, b, x, Policy(), invert, true) - target; T f1 = invert ? -boost::math::detail::ibeta_power_terms(b, a, 1 - x, x, L(), true, Policy()) : boost::math::detail::ibeta_power_terms(a, b, x, 1 - x, L(), true, Policy()); T y = 1 - x; if (y == 0) y = boost::math::tools::min_value<T>() * 8; f1 /= y * x; T f2 = f1 * (-y * a + (b - 2) * x + 1) / (y * x); if (invert) f2 = -f2; // make sure we don't have a zero derivative: if (f1 == 0) f1 = (invert ? -1 : 1) * boost::math::tools::min_value<T>() * 64; return boost::math::make_tuple(f, f1, f2); }
void Transaction::dumpPretty() const { if (!size()) return; ASTContext* C = 0; if (m_WrapperFD) C = &(m_WrapperFD->getASTContext()); if (!getFirstDecl().isNull()) C = &(getFirstDecl().getSingleDecl()->getASTContext()); PrintingPolicy Policy(C->getLangOpts()); print(llvm::errs(), Policy, /*Indent*/0, /*PrintInstantiation*/true); }
static const char *toString(clang::Stmt *stmt) { static char ret[64]; clang::LangOptions LangOpts; LangOpts.C99 = true; clang::PrintingPolicy Policy(LangOpts); std::string TypeS; llvm::raw_string_ostream s(TypeS); stmt->printPretty(s, 0, Policy); strcpy(ret, s.str().c_str()); ret[sizeof(ret) - 1] = '\0'; return (char *)ret; }
inline bool check_pos_definite(const char* function, const Eigen::Matrix<var,Eigen::Dynamic,Eigen::Dynamic>& y, const char* name, T_result* result, const Policy&) { typedef typename Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::size_type size_type; Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> y_d(y.rows(),y.cols()); for (size_type i = 0; i < y_d.rows(); i++) for (size_type j = 0; j < y_d.cols(); j++) y_d(i,j) = y(i,j).val(); return stan::math::check_pos_definite(function,y_d,name,result,Policy()); }
inline typename Dist::value_type find_scale( complemented4_type<Real1, Real2, Real3, Policy> const& c) { //cout << "cparam1 q " << c.param1 // q // << ", c.dist z " << c.dist // z // << ", c.param2 l " << c.param2 // l // << ", quantile (Dist(), c.param1 = q) " // << quantile(Dist(), c.param1) //q // << endl; #if !defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) BOOST_STATIC_ASSERT(::lslboost::math::tools::is_distribution<Dist>::value); BOOST_STATIC_ASSERT(::lslboost::math::tools::is_scaled_distribution<Dist>::value); #endif static const char* function = "lslboost::math::find_scale<Dist, Policy>(complement(%1%, %1%, %1%, Policy))"; // Checks on arguments, as not complemented version, // Explicit policy. typename Dist::value_type q = c.param1; if(!(lslboost::math::isfinite)(q) || (q < 0) || (q > 1)) { return policies::raise_domain_error<typename Dist::value_type>( function, "Probability parameter was %1%, but must be >= 0 and <= 1!", q, c.param3); } typename Dist::value_type z = c.dist; if(!(lslboost::math::isfinite)(z)) { return policies::raise_domain_error<typename Dist::value_type>( function, "find_scale z parameter was %1%, but must be finite!", z, c.param3); } typename Dist::value_type location = c.param2; if(!(lslboost::math::isfinite)(location)) { return policies::raise_domain_error<typename Dist::value_type>( function, "find_scale location parameter was %1%, but must be finite!", location, c.param3); } typename Dist::value_type result = (c.dist - c.param2) // difference between desired x and current location. / quantile(complement(Dist(), c.param1)); // ( z - location) / (quantile(complement(Dist(), q)) if (result <= 0) { // If policy isn't to throw, return the scale <= 0. policies::raise_evaluation_error<typename Dist::value_type>(function, "Computed scale (%1%) is <= 0!" " Was the complement intended?", result, Policy()); } return result; } // template <class Dist, class Policy, class Real1, class Real2, class Real3> typename Dist::value_type find_scale
inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol) { if(check_dist(function, p, result, Policy()) == false) { return false; } if(!(boost::math::isfinite)(k) || !((k == 0) || (k == 1))) { *result = policies::raise_domain_error<RealType>( function, "Number of successes argument is %1%, but must be 0 or 1 !", k, pol); return false; } return true; }
inline bool check_consistent_size(size_t max_size, const char* function, const T& x, const char* name, T_result* result, const Policy&) { size_t x_size = stan::size_of(x); if (is_vector<T>::value && x_size == max_size) return true; if (!is_vector<T>::value && x_size == 1) return true; return dom_err( function,x_size,name, " (max size) is %1%, but must be consistent, 1 or max=",max_size, result,Policy()); }
inline RealType cdf(const kolmogorov_distribution<RealType, Policy>&, const RealType& x) { static const char* function = "madlib::modules::prob::cdf(" "const kolmogorov_distribution<%1%>&, %1%)"; RealType result; if ((boost::math::isinf)(x)) { if(x < 0) return 0; // -infinity return 1; // + infinity } if (boost::math::detail::check_x(function, x, &result, Policy()) == false) return result; // FIXME: Numerically questionable if t is close to 1. return 1. - TMath::KolmogorovProb(x); }
static inline Policy apply(Geometry1 const& geometry1, Geometry2 const& geometry2) { typedef typename point_type<Geometry1>::type point_type; typedef typename geometry::coordinate_type<Geometry1>::type coordinate_type; typedef typename promote_floating_point<coordinate_type>::type factor_type; typedef model::point < typename detail::robust_type<coordinate_type>::type, geometry::dimension<point_type>::value, typename geometry::coordinate_system<point_type>::type > robust_point_type; point_type min_point; robust_point_type min_robust_point; factor_type factor; init_rescale_policy(geometry1, geometry2, min_point, min_robust_point, factor); return Policy(min_point, min_robust_point, factor); }
inline RealType cdf( const boost::math::complemented2_type< kolmogorov_distribution<RealType, Policy>, RealType >& c ) { static const char* function = "madlib::modules::prob::cdf(" "const complement(kolmogorov_distribution<%1%>&), %1%)"; RealType result; const RealType& x = c.param; if ((boost::math::isinf)(x)) { if(x < 0) return 1; // cdf complement -infinity is unity. return 0; // cdf complement +infinity is zero } if (boost::math::detail::check_x(function, x, &result, Policy()) == false) return result; return TMath::KolmogorovProb(x); }
ASTNodeInfo EvaluateTSynthesizer::VisitDeclStmt(DeclStmt* Node) { // Visit all the children, which are the contents of the DeclGroupRef for (Stmt::child_iterator I = Node->child_begin(), E = Node->child_end(); I != E; ++I) { if (*I) { Expr* E = cast_or_null<Expr>(*I); if (!E || !IsArtificiallyDependent(E)) continue; //FIXME: don't assume there is only one decl. assert(Node->isSingleDecl() && "There is more that one decl in stmt"); VarDecl* CuredDecl = cast_or_null<VarDecl>(Node->getSingleDecl()); assert(CuredDecl && "Not a variable declaration!"); QualType CuredDeclTy = CuredDecl->getType(); // check if the case is sometype * somevar = init; // or some_builtin_type somevar = init; if (CuredDecl->hasInit() && (CuredDeclTy->isAnyPointerType() || !CuredDeclTy->isRecordType())) { *I = SubstituteUnknownSymbol(CuredDeclTy, CuredDecl->getInit()); continue; } // 1. Check whether this is the case of MyClass A(dep->symbol()) // 2. Insert the RuntimeUniverse's LifetimeHandler instance // 3. Change the A's initializer to *(MyClass*)instance.getMemory() // 4. Make A reference (&A) // 5. Set the new initializer of A if (CuredDeclTy->isLValueReferenceType()) continue; // Set Sema's Current DeclContext to the one we need DeclContext* OldDC = m_Sema->CurContext; m_Sema->CurContext = CuredDecl->getDeclContext(); ASTNodeInfo NewNode; // 2.1 Get unique name for the LifetimeHandler instance and // initialize it std::string UniqueName; createUniqueName(UniqueName); IdentifierInfo& II = m_Context->Idents.get(UniqueName); // Prepare the initialization Exprs. // We want to call LifetimeHandler(DynamicExprInfo* ExprInfo, // DeclContext DC, // const char* type) // Interpreter* interp) llvm::SmallVector<Expr*, 4> Inits; // Add MyClass in LifetimeHandler unique(DynamicExprInfo* ExprInfo // DC, // "MyClass" // Interpreter* Interp) // Build Arg0 DynamicExprInfo Inits.push_back(BuildDynamicExprInfo(E)); // Build Arg1 DeclContext* DC QualType DCTy = m_Context->getTypeDeclType(m_DeclContextDecl); Inits.push_back(utils::Synthesize::CStyleCastPtrExpr(m_Sema, DCTy, (uint64_t)m_CurDeclContext) ); // Build Arg2 llvm::StringRef // Get the type of the type without specifiers PrintingPolicy Policy(m_Context->getLangOpts()); Policy.SuppressTagKeyword = 1; std::string Res; CuredDeclTy.getAsStringInternal(Res, Policy); Inits.push_back(ConstructConstCharPtrExpr(Res.c_str())); // Build Arg3 cling::Interpreter CXXScopeSpec CXXSS; DeclarationNameInfo NameInfo(m_gCling->getDeclName(), m_gCling->getLocStart()); Expr* gClingDRE = m_Sema->BuildDeclarationNameExpr(CXXSS, NameInfo ,m_gCling).take(); Inits.push_back(gClingDRE); // 2.3 Create a variable from LifetimeHandler. QualType HandlerTy = m_Context->getTypeDeclType(m_LifetimeHandlerDecl); TypeSourceInfo* TSI = m_Context->getTrivialTypeSourceInfo(HandlerTy, m_NoSLoc); VarDecl* HandlerInstance = VarDecl::Create(*m_Context, CuredDecl->getDeclContext(), m_NoSLoc, m_NoSLoc, &II, HandlerTy, TSI, SC_None); // 2.4 Call the best-match constructor. The method does overload // resolution of the constructors and then initializes the new // variable with it ExprResult InitExprResult = m_Sema->ActOnParenListExpr(m_NoSLoc, m_NoELoc, Inits); m_Sema->AddInitializerToDecl(HandlerInstance, InitExprResult.take(), /*DirectInit*/ true, /*TypeMayContainAuto*/ false); // 2.5 Register the instance in the enclosing context CuredDecl->getDeclContext()->addDecl(HandlerInstance); NewNode.addNode(new (m_Context) DeclStmt(DeclGroupRef(HandlerInstance), m_NoSLoc, m_NoELoc) ); // 3.1 Build a DeclRefExpr, which holds the object DeclRefExpr* MemberExprBase = m_Sema->BuildDeclRefExpr(HandlerInstance, HandlerTy, VK_LValue, m_NoSLoc ).takeAs<DeclRefExpr>(); // 3.2 Create a MemberExpr to getMemory from its declaration. CXXScopeSpec SS; LookupResult MemberLookup(*m_Sema, m_LHgetMemoryDecl->getDeclName(), m_NoSLoc, Sema::LookupMemberName); // Add the declaration as if doesn't exist. // TODO: Check whether this is the most appropriate variant MemberLookup.addDecl(m_LHgetMemoryDecl, AS_public); MemberLookup.resolveKind(); Expr* MemberExpr = m_Sema->BuildMemberReferenceExpr(MemberExprBase, HandlerTy, m_NoSLoc, /*IsArrow=*/false, SS, m_NoSLoc, /*FirstQualifierInScope=*/0, MemberLookup, /*TemplateArgs=*/0 ).take(); // 3.3 Build the actual call Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext); Expr* theCall = m_Sema->ActOnCallExpr(S, MemberExpr, m_NoSLoc, MultiExprArg(), m_NoELoc).take(); // Cast to the type LHS type Expr* Result = utils::Synthesize::CStyleCastPtrExpr(m_Sema, CuredDeclTy, theCall); // Cast once more (dereference the cstyle cast) Result = m_Sema->BuildUnaryOp(S, m_NoSLoc, UO_Deref, Result).take(); // 4. CuredDecl->setType(m_Context->getLValueReferenceType(CuredDeclTy)); // 5. CuredDecl->setInit(Result); NewNode.addNode(Node); // Restore Sema's original DeclContext m_Sema->CurContext = OldDC; return NewNode; } } return ASTNodeInfo(Node, 0); }
inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */) { return check_success_fraction(function, p, result, Policy()); }
inline Policy policy(LO n) { return Policy(0, static_cast<std::size_t>(n)); }
void Walker::VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) { LangOptions LangOpts; LangOpts.CPlusPlus = true; PrintingPolicy Policy(LangOpts); const Decl *D = AC->getDecl(); std::string dname = ""; if (const NamedDecl *ND = llvm::dyn_cast_or_null<NamedDecl>(D)) dname = ND->getQualifiedNameAsString(); CXXMethodDecl *MD = CE->getMethodDecl(); if (!MD) return; std::string mname = MD->getQualifiedNameAsString(); // llvm::errs()<<"Parent Decl: '"<<dname<<"'\n"; // llvm::errs()<<"Method Decl: '"<<mname<<"'\n"; // llvm::errs()<<"call expression '"; // CE->printPretty(llvm::errs(),0,Policy); // llvm::errs()<<"'\n"; // if (!MD) return; llvm::SmallString<100> buf; llvm::raw_svector_ostream os(buf); if (mname == "edm::Event::getByLabel" || mname == "edm::Event::getManyByType") { // if (const CXXRecordDecl * RD = llvm::dyn_cast_or_null<CXXMethodDecl>(D)->getParent() ) { // llvm::errs()<<"class "<<RD->getQualifiedNameAsString()<<"\n"; // llvm::errs()<<"\n"; // } os << "function '"; llvm::dyn_cast<CXXMethodDecl>(D)->getNameForDiagnostic(os, Policy, true); os << "' "; // os<<"call expression '"; // CE->printPretty(os,0,Policy); // os<<"' "; if (mname == "edm::Event::getByLabel") { os << "calls edm::Event::getByLabel with arguments '"; QualType QT; for (auto I = CE->arg_begin(), E = CE->arg_end(); I != E; ++I) { QT = (*I)->getType(); std::string qtname = QT.getCanonicalType().getAsString(); if (qtname.substr(0, 17) == "class edm::Handle") { // os<<"argument name '"; // (*I)->printPretty(os,0,Policy); // os<<"' "; const CXXRecordDecl *RD = QT->getAsCXXRecordDecl(); std::string rname = RD->getQualifiedNameAsString(); os << rname << " "; const ClassTemplateSpecializationDecl *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD); for (unsigned J = 0, F = SD->getTemplateArgs().size(); J != F; ++J) { SD->getTemplateArgs().data()[J].print(Policy, os); os << ", "; } } else { os << " " << qtname << " "; (*I)->printPretty(os, nullptr, Policy); os << ", "; } } os << "'\n"; } else { os << "calls edm::Event::getManyByType with argument '"; QualType QT = (*CE->arg_begin())->getType(); const CXXRecordDecl *RD = QT->getAsCXXRecordDecl(); os << "getManyByType , "; const ClassTemplateSpecializationDecl *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD); const TemplateArgument TA = SD->getTemplateArgs().data()[0]; const QualType AQT = TA.getAsType(); const CXXRecordDecl *SRD = AQT->getAsCXXRecordDecl(); os << SRD->getQualifiedNameAsString() << " "; const ClassTemplateSpecializationDecl *SVD = dyn_cast<ClassTemplateSpecializationDecl>(SRD); for (unsigned J = 0, F = SVD->getTemplateArgs().size(); J != F; ++J) { SVD->getTemplateArgs().data()[J].print(Policy, os); os << ", "; } } // llvm::errs()<<os.str()<<"\n"; PathDiagnosticLocation CELoc = PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC); BugType *BT = new BugType(Checker, "edm::getByLabel or edm::getManyByType called", "optional"); std::unique_ptr<BugReport> R = llvm::make_unique<BugReport>(*BT, os.str(), CELoc); R->addRange(CE->getSourceRange()); BR.emitReport(std::move(R)); } else { for (auto I = CE->arg_begin(), E = CE->arg_end(); I != E; ++I) { QualType QT = (*I)->getType(); std::string qtname = QT.getAsString(); // if (qtname.find(" edm::Event") != std::string::npos ) llvm::errs()<<"arg type '" << qtname <<"'\n"; if (qtname == "edm::Event" || qtname == "const edm::Event" || qtname == "edm::Event *" || qtname == "const edm::Event *") { std::string tname; os << "function '" << dname << "' "; os << "calls '"; MD->getNameForDiagnostic(os, Policy, true); os << "' with argument of type '" << qtname << "'\n"; // llvm::errs()<<"\n"; // llvm::errs()<<"call expression passed edm::Event "; // CE->printPretty(llvm::errs(),0,Policy); // llvm::errs()<<" argument name "; // (*I)->printPretty(llvm::errs(),0,Policy); // llvm::errs()<<" "<<qtname<<"\n"; PathDiagnosticLocation CELoc = PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC); BugType *BT = new BugType(Checker, "function call with argument of type edm::Event", "optional"); std::unique_ptr<BugReport> R = llvm::make_unique<BugReport>(*BT, os.str(), CELoc); R->addRange(CE->getSourceRange()); BR.emitReport(std::move(R)); } } } }
T t2n_asymptotic(int n) { BOOST_MATH_STD_USING // Just get B2n and convert to a Tangent number: T t2n = fabs(b2n_asymptotic<T, Policy>(2 * n)) / (2 * n); T p2 = ldexp(T(1), n); if(tools::max_value<T>() / p2 < t2n) return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", 0, T(n), Policy()); t2n *= p2; p2 -= 1; if(tools::max_value<T>() / p2 < t2n) return policies::raise_overflow_error<T>("boost::math::tangent_t2n<%1%>(std::size_t)", 0, Policy()); t2n *= p2; return t2n; }
void getParamDumper::analyzerEval(const clang::CallExpr *CE, clang::ento::CheckerContext &C) const { if ( ! C.getSourceManager().isInMainFile(CE->getExprLoc()) ) return; const FunctionDecl * FD = CE->getDirectCallee(); if (!FD) return; std::string mname = support::getQualifiedName(*FD); const char *sfile=C.getSourceManager().getPresumedLoc(CE->getExprLoc()).getFilename(); std::string sname(sfile); if ( ! support::isInterestingLocation(sname) ) return; std::string mdname; const FunctionDecl * MD = C.getCurrentAnalysisDeclContext()->getDecl()->getAsFunction(); if (!MD) return; mdname = MD->getQualifiedNameAsString(); for ( unsigned I=0, E=MD->getNumParams(); I != E; ++I) { std::string ps = "const class edm::ParameterSet "; std::string ups = "const class edm::UntrackedParameterSet "; std::string pname = MD->getParamDecl(I)->getQualifiedNameAsString(); std::string qname = MD->getParamDecl(I)->getType().getCanonicalType().getAsString(); // if (qname.substr(0,ps.length()) == ps || qname.substr(0,ups.length()) == ups) { std::string buf; llvm::raw_string_ostream os(buf); os << "in function decl '"<< mdname << "' with parameter '"<< qname << " " << pname <<"'\n"; // } } const CXXMemberCallExpr * CXE = llvm::dyn_cast_or_null<CXXMemberCallExpr>(CE); if (!CXE) return; const Expr * IOA = CXE->getImplicitObjectArgument(); std::string tname = "getparam-dumper.txt.unsorted"; std::string gp = "edm::ParameterSet::getParameter"; std::string gup = "edm::ParameterSet::getUntrackedParameter"; if (mname.substr(0,gp.length()) == gp || mname.substr(0,gup.length()) == gup ) { std::string buf; llvm::raw_string_ostream os(buf); os << "in function decl '" << mdname << "' member function call '"; clang::LangOptions LangOpts; LangOpts.CPlusPlus = true; clang::PrintingPolicy Policy(LangOpts); os << support::getQualifiedName(*(CXE->getMethodDecl())); os << "' with args '"; for ( unsigned I=0, E=CE->getNumArgs(); I != E; ++I) { if (I) os <<", "; CE->getArg(I)->printPretty(os,0,Policy); } os << "' with implicit object '"; const Expr * E = IOA->IgnoreParenNoopCasts(C.getASTContext()); QualType QE = E->getType().getCanonicalType(); os << QE.getAsString()<<" "; switch( E->getStmtClass() ) { case Stmt::MemberExprClass: os << dyn_cast<MemberExpr>(E)->getMemberDecl()->getQualifiedNameAsString(); break; case Stmt::DeclRefExprClass: os << dyn_cast<DeclRefExpr>(E)->getDecl()->getQualifiedNameAsString(); break; case Stmt::CXXOperatorCallExprClass: dyn_cast<CXXOperatorCallExpr>(E)->printPretty(os,0,Policy); break; case Stmt::CXXBindTemporaryExprClass: dyn_cast<CXXBindTemporaryExpr>(E)->printPretty(os,0,Policy); break; case Stmt::CXXMemberCallExprClass: dyn_cast<CXXMemberCallExpr>(E)->printPretty(os,0,Policy); break; case Stmt::UnaryOperatorClass: dyn_cast<UnaryOperator>(E)->printPretty(os,0,Policy); break; default: E->printPretty(os,0,Policy); os << " unhandled expr class " <<E->getStmtClassName(); } os<<"'\n"; support::writeLog(os.str(),tname); } return ; }
T operator()(T a) { return invert ? p - boost::math::ibetac(swap_ab ? b : a, swap_ab ? a : b, z, Policy()) : boost::math::ibeta(swap_ab ? b : a, swap_ab ? a : b, z, Policy()) - p; }
inline RealType quantile(const internal::levy_distribution_t<RealType, Policy>& dist, const RealType& p) { RealType v = boost::math::erfc_inv(p, Policy()); return dist.get_scale() / (2 * v * v) + dist.get_mean(); }
w += k * x * (x2 - 3) / 24 + sk * sk * x * (2 * x2 - 5) / -36; */ w = m + sigma * w; return w > tools::min_value<T>() ? w : tools::min_value<T>(); } template <class T, class Policy> T gamma_inva_imp(const T& z, const T& p, const T& q, const Policy& pol) { BOOST_MATH_STD_USING // for ADL of std lib math functions // // Special cases first: // if(p == 0) { return policies::raise_overflow_error<T>("boost::math::gamma_p_inva<%1%>(%1%, %1%)", 0, Policy()); } if(q == 0) { return tools::min_value<T>(); } // // Function object, this is the functor whose root // we have to solve: // gamma_inva_t<T, Policy> f(z, (p < q) ? p : q, (p < q) ? false : true); // // Tolerance: full precision. // tools::eps_tolerance<T> tol(policies::digits<T, Policy>()); //
void Transaction::dumpPretty() const { const ASTContext& C = getASTContext(); PrintingPolicy Policy(C.getLangOpts()); print(llvm::errs(), Policy, /*Indent*/0, /*PrintInstantiation*/true); }
void Transaction::DelayCallInfo::dump() const { PrintingPolicy Policy((LangOptions())); print(llvm::errs(), Policy, /*Indent*/0, /*PrintInstantiation*/true); }
inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */) { return check_dist(function, p, result, Policy(), typename policies::constructor_error_check<Policy>::type()); }
T operator()(T a) { return invert ? p - boost::math::gamma_q(a, z, Policy()) : boost::math::gamma_p(a, z, Policy()) - p; }
inline RealType cdf(const complemented2_type<hypergeometric_distribution<RealType, Policy>, U>& c) { BOOST_MATH_STD_USING static const char* function = "boost::math::cdf(const hypergeometric_distribution<%1%>&, const %1%&)"; RealType r = static_cast<RealType>(c.param); unsigned u = itrunc(r, typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type()); if(u != r) { return boost::math::policies::raise_domain_error<RealType>( function, "Random variable out of range: must be an integer but got %1%", r, Policy()); } return cdf(complement(c.dist, u)); }
RealType quantile_imp(const binomial_distribution<RealType, Policy>& dist, const RealType& p, const RealType& q, bool comp) { // Quantile or Percent Point Binomial function. // Return the number of expected successes k, // for a given probability p. // // Error checks: BOOST_MATH_STD_USING // ADL of std names RealType result = 0; RealType trials = dist.trials(); RealType success_fraction = dist.success_fraction(); if(false == binomial_detail::check_dist_and_prob( "boost::math::quantile(binomial_distribution<%1%> const&, %1%)", trials, success_fraction, p, &result, Policy())) { return result; } // Special cases: // if(p == 0) { // There may actually be no answer to this question, // since the probability of zero successes may be non-zero, // but zero is the best we can do: return 0; } if(p == 1) { // Probability of n or fewer successes is always one, // so n is the most sensible answer here: return trials; } if (p <= pow(1 - success_fraction, trials)) { // p <= pdf(dist, 0) == cdf(dist, 0) return 0; // So the only reasonable result is zero. } // And root finder would fail otherwise. if(success_fraction == 1) { // our formulae break down in this case: return p > 0.5f ? trials : 0; } // Solve for quantile numerically: // RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, success_fraction, p, q, Policy()); RealType factor = 8; if(trials > 100) factor = 1.01f; // guess is pretty accurate else if((trials > 10) && (trials - 1 > guess) && (guess > 3)) factor = 1.15f; // less accurate but OK. else if(trials < 10) { // pretty inaccurate guess in this area: if(guess > trials / 64) { guess = trials / 4; factor = 2; } else guess = trials / 1024; } else factor = 2; // trials largish, but in far tails. typedef typename Policy::discrete_quantile_type discrete_quantile_type; boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>(); return detail::inverse_discrete_quantile( dist, comp ? q : p, comp, guess, factor, RealType(1), discrete_quantile_type(), max_iter); } // quantile
bool check_params(const char* function, RealType* result)const { if(m_r > m_N) { *result = boost::math::policies::raise_domain_error<RealType>( function, "Parameter r out of range: must be <= N but got %1%", static_cast<RealType>(m_r), Policy()); return false; } if(m_n > m_N) { *result = boost::math::policies::raise_domain_error<RealType>( function, "Parameter n out of range: must be <= N but got %1%", static_cast<RealType>(m_n), Policy()); return false; } return true; }
void gpWalkAST::VisitCXXMemberCallExpr( clang::CXXMemberCallExpr *CE ) { const FunctionDecl * FD = CE->getMethodDecl(); if (!FD) return; std::string mname = FD->getQualifiedNameAsString(); const char *sfile=BR.getSourceManager().getPresumedLoc(CE->getExprLoc()).getFilename(); std::string sname(sfile); if ( ! support::isInterestingLocation(sname) ) return; std::string mdname = ND->getQualifiedNameAsString(); const Expr * IOA = CE->getImplicitObjectArgument(); std::string tname = "getparam-dumper.txt.unsorted"; std::string ps = "const class edm::ParameterSet "; std::string ups = "const class edm::UntrackedParameterSet "; std::string gp = "edm::ParameterSet::getParameter"; std::string gup = "edm::ParameterSet::getUntrackedParameter"; if (mname.substr(0,gp.length()) == gp || mname.substr(0,gup.length()) == gup ) { std::string buf; llvm::raw_string_ostream os(buf); const NamedDecl * nd = llvm::dyn_cast<NamedDecl>(AC->getDecl()); if ( FunctionDecl::classof(ND) ) { os << "function decl '" << nd->getQualifiedNameAsString() ; os << "' this '"<<mdname; } else { os << "constructor decl '" << nd->getQualifiedNameAsString() ; os << "' initializer for member decl '"<<mdname; } clang::LangOptions LangOpts; LangOpts.CPlusPlus = true; clang::PrintingPolicy Policy(LangOpts); os << "' with call args '"; for ( unsigned I=0, E=CE->getNumArgs(); I != E; ++I) { if (I) os <<", "; os << CE->getType().getCanonicalType().getAsString()<<" "; CE->getArg(I)->printPretty(os,0,Policy); } os << "' with implicit object '"; const Expr * E = IOA->IgnoreParenCasts(); QualType QE = E->getType().getCanonicalType(); os << QE.getAsString()<<" "; switch( E->getStmtClass() ) { case Stmt::MemberExprClass: os << dyn_cast<MemberExpr>(E)->getMemberDecl()->getQualifiedNameAsString(); break; case Stmt::DeclRefExprClass: os << dyn_cast<DeclRefExpr>(E)->getDecl()->getQualifiedNameAsString(); break; case Stmt::CXXOperatorCallExprClass: dyn_cast<CXXOperatorCallExpr>(E)->printPretty(os,0,Policy); break; case Stmt::CXXBindTemporaryExprClass: dyn_cast<CXXBindTemporaryExpr>(E)->printPretty(os,0,Policy); break; case Stmt::CXXMemberCallExprClass: dyn_cast<CXXMemberCallExpr>(E)->printPretty(os,0,Policy); break; case Stmt::UnaryOperatorClass: dyn_cast<UnaryOperator>(E)->printPretty(os,0,Policy); break; default: E->printPretty(os,0,Policy); os << " unhandled expr class " <<E->getStmtClassName(); } os<<"'\n"; support::writeLog(os.str(),tname); } return ; }
bool check_x(unsigned x, const char* function, RealType* result)const { if(x < static_cast<unsigned>((std::max)(0, (int)(m_n + m_r) - (int)(m_N)))) { *result = boost::math::policies::raise_domain_error<RealType>( function, "Random variable out of range: must be > 0 and > m + r - N but got %1%", static_cast<RealType>(x), Policy()); return false; } if(x > (std::min)(m_r, m_n)) { *result = boost::math::policies::raise_domain_error<RealType>( function, "Random variable out of range: must be less than both n and r but got %1%", static_cast<RealType>(x), Policy()); return false; } return true; }
init() { boost::math::digamma(T(1.5), Policy()); boost::math::digamma(T(500), Policy()); }
T b2n_asymptotic(int n) { BOOST_MATH_STD_USING const T nx = static_cast<T>(n); const T nx2(nx * nx); const T approximate_log_of_bernoulli_bn = ((boost::math::constants::half<T>() + nx) * log(nx)) + ((boost::math::constants::half<T>() - nx) * log(boost::math::constants::pi<T>())) + (((T(3) / 2) - nx) * boost::math::constants::ln_two<T>()) + ((nx * (T(2) - (nx2 * 7) * (1 + ((nx2 * 30) * ((nx2 * 12) - 1))))) / (((nx2 * nx2) * nx2) * 2520)); return ((n / 2) & 1 ? 1 : -1) * (approximate_log_of_bernoulli_bn > tools::log_max_value<T>() ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, nx, Policy()) : static_cast<T>(exp(approximate_log_of_bernoulli_bn))); }