diff --git a/stan/math/fwd/fun/Phi.hpp b/stan/math/fwd/fun/Phi.hpp index 5fe92943ef1..70c1c38249e 100644 --- a/stan/math/fwd/fun/Phi.hpp +++ b/stan/math/fwd/fun/Phi.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -12,8 +14,6 @@ namespace math { template inline fvar Phi(const fvar& x) { - using std::exp; - using std::sqrt; T xv = x.val_; return fvar(Phi(xv), x.d_ * exp(xv * xv / -2.0) * INV_SQRT_TWO_PI); } diff --git a/stan/math/fwd/fun/Phi_approx.hpp b/stan/math/fwd/fun/Phi_approx.hpp index 582a9113d3a..2509a44348a 100644 --- a/stan/math/fwd/fun/Phi_approx.hpp +++ b/stan/math/fwd/fun/Phi_approx.hpp @@ -3,7 +3,9 @@ #include #include -#include +#include +#include +#include #include namespace stan { @@ -21,7 +23,6 @@ namespace math { */ template inline fvar Phi_approx(const fvar& x) { - using std::pow; return inv_logit(0.07056 * pow(x, 3.0) + 1.5976 * x); } diff --git a/stan/math/fwd/fun/abs.hpp b/stan/math/fwd/fun/abs.hpp index 1f50b149fd6..27305d4e053 100644 --- a/stan/math/fwd/fun/abs.hpp +++ b/stan/math/fwd/fun/abs.hpp @@ -3,9 +3,9 @@ #include #include -#include +#include #include -#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/acos.hpp b/stan/math/fwd/fun/acos.hpp index 75f0561578c..e92b5525b79 100644 --- a/stan/math/fwd/fun/acos.hpp +++ b/stan/math/fwd/fun/acos.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include #include #include #include @@ -13,8 +14,6 @@ namespace math { template inline fvar acos(const fvar& x) { - using std::acos; - using std::sqrt; return fvar(acos(x.val_), x.d_ / -sqrt(1 - square(x.val_))); } diff --git a/stan/math/fwd/fun/acosh.hpp b/stan/math/fwd/fun/acosh.hpp index 376daa568aa..fccf9a0b51f 100644 --- a/stan/math/fwd/fun/acosh.hpp +++ b/stan/math/fwd/fun/acosh.hpp @@ -3,9 +3,9 @@ #include #include +#include +#include #include -#include -#include #include #include @@ -14,7 +14,6 @@ namespace math { template inline fvar acosh(const fvar& x) { - using std::sqrt; return fvar(acosh(x.val_), x.d_ / sqrt(square(x.val_) - 1)); } diff --git a/stan/math/fwd/fun/asin.hpp b/stan/math/fwd/fun/asin.hpp index 0ce1b593342..ecf7fa26918 100644 --- a/stan/math/fwd/fun/asin.hpp +++ b/stan/math/fwd/fun/asin.hpp @@ -3,8 +3,9 @@ #include #include +#include +#include #include -#include #include #include @@ -13,8 +14,6 @@ namespace math { template inline fvar asin(const fvar& x) { - using std::asin; - using std::sqrt; return fvar(asin(x.val_), x.d_ / sqrt(1 - square(x.val_))); } diff --git a/stan/math/fwd/fun/asinh.hpp b/stan/math/fwd/fun/asinh.hpp index 4e430514ec4..bdd74be74d3 100644 --- a/stan/math/fwd/fun/asinh.hpp +++ b/stan/math/fwd/fun/asinh.hpp @@ -3,8 +3,9 @@ #include #include +#include +#include #include -#include #include #include @@ -13,7 +14,6 @@ namespace math { template inline fvar asinh(const fvar& x) { - using std::sqrt; return fvar(asinh(x.val_), x.d_ / sqrt(square(x.val_) + 1)); } diff --git a/stan/math/fwd/fun/atan.hpp b/stan/math/fwd/fun/atan.hpp index a16f6ef8792..2e42c89dfb8 100644 --- a/stan/math/fwd/fun/atan.hpp +++ b/stan/math/fwd/fun/atan.hpp @@ -3,8 +3,9 @@ #include #include +#include +#include #include -#include #include #include @@ -13,7 +14,6 @@ namespace math { template inline fvar atan(const fvar& x) { - using std::atan; return fvar(atan(x.val_), x.d_ / (1 + square(x.val_))); } diff --git a/stan/math/fwd/fun/atan2.hpp b/stan/math/fwd/fun/atan2.hpp index 9af5e37ca68..94bee5b263a 100644 --- a/stan/math/fwd/fun/atan2.hpp +++ b/stan/math/fwd/fun/atan2.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include #include namespace stan { @@ -11,7 +12,6 @@ namespace math { template inline fvar atan2(const fvar& x1, const fvar& x2) { - using std::atan2; return fvar(atan2(x1.val_, x2.val_), (x1.d_ * x2.val_ - x1.val_ * x2.d_) / (square(x2.val_) + square(x1.val_))); @@ -19,14 +19,12 @@ inline fvar atan2(const fvar& x1, const fvar& x2) { template inline fvar atan2(double x1, const fvar& x2) { - using std::atan2; return fvar(atan2(x1, x2.val_), (-x1 * x2.d_) / (square(x1) + square(x2.val_))); } template inline fvar atan2(const fvar& x1, double x2) { - using std::atan2; return fvar(atan2(x1.val_, x2), (x1.d_ * x2) / (square(x2) + square(x1.val_))); } diff --git a/stan/math/fwd/fun/atanh.hpp b/stan/math/fwd/fun/atanh.hpp index ded211fd2d4..04b95144eac 100644 --- a/stan/math/fwd/fun/atanh.hpp +++ b/stan/math/fwd/fun/atanh.hpp @@ -3,8 +3,10 @@ #include #include +#include +#include +#include #include -#include #include #include diff --git a/stan/math/fwd/fun/beta.hpp b/stan/math/fwd/fun/beta.hpp index b8ba5e7d10c..a4c8b782052 100644 --- a/stan/math/fwd/fun/beta.hpp +++ b/stan/math/fwd/fun/beta.hpp @@ -3,8 +3,8 @@ #include #include +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/cbrt.hpp b/stan/math/fwd/fun/cbrt.hpp index a584eb8a710..bfdec65d9c9 100644 --- a/stan/math/fwd/fun/cbrt.hpp +++ b/stan/math/fwd/fun/cbrt.hpp @@ -3,8 +3,8 @@ #include #include +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/ceil.hpp b/stan/math/fwd/fun/ceil.hpp index cc322cfaac8..3fca1ef6c77 100644 --- a/stan/math/fwd/fun/ceil.hpp +++ b/stan/math/fwd/fun/ceil.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace stan { @@ -10,7 +11,6 @@ namespace math { template inline fvar ceil(const fvar& x) { - using std::ceil; return fvar(ceil(x.val_), 0); } diff --git a/stan/math/fwd/fun/conj.hpp b/stan/math/fwd/fun/conj.hpp index 706d97d2678..38be744e31a 100644 --- a/stan/math/fwd/fun/conj.hpp +++ b/stan/math/fwd/fun/conj.hpp @@ -5,22 +5,4 @@ #include #include -namespace stan { -namespace math { - -/** - * Return the phase angle of the complex argument. - * - * @tparam T value type of autodiff variable - * @param[in] z argument - * @return phase angle of the argument - */ -template -inline std::complex> conj(const std::complex>& z) { - return internal::complex_conj(z); -} - -} // namespace math -} // namespace stan - #endif diff --git a/stan/math/fwd/fun/cos.hpp b/stan/math/fwd/fun/cos.hpp index 0cfe38166b8..19be59e91de 100644 --- a/stan/math/fwd/fun/cos.hpp +++ b/stan/math/fwd/fun/cos.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -12,8 +14,6 @@ namespace math { template inline fvar cos(const fvar& x) { - using std::cos; - using std::sin; return fvar(cos(x.val_), x.d_ * -sin(x.val_)); } diff --git a/stan/math/fwd/fun/cosh.hpp b/stan/math/fwd/fun/cosh.hpp index d1194cf54ed..c96e0c6789d 100644 --- a/stan/math/fwd/fun/cosh.hpp +++ b/stan/math/fwd/fun/cosh.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13,8 +14,6 @@ namespace math { template inline fvar cosh(const fvar& x) { - using std::cosh; - using std::sinh; return fvar(cosh(x.val_), x.d_ * sinh(x.val_)); } diff --git a/stan/math/fwd/fun/determinant.hpp b/stan/math/fwd/fun/determinant.hpp index e3fee48d829..ac6cfa12e57 100644 --- a/stan/math/fwd/fun/determinant.hpp +++ b/stan/math/fwd/fun/determinant.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_DETERMINANT_HPP #define STAN_MATH_FWD_FUN_DETERMINANT_HPP +#include +#include #include #include -#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/digamma.hpp b/stan/math/fwd/fun/digamma.hpp index 3ab0cbb5fb8..ede447b685a 100644 --- a/stan/math/fwd/fun/digamma.hpp +++ b/stan/math/fwd/fun/digamma.hpp @@ -3,9 +3,9 @@ #include #include +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/erf.hpp b/stan/math/fwd/fun/erf.hpp index 6e88c092c0a..2ed906da5f8 100644 --- a/stan/math/fwd/fun/erf.hpp +++ b/stan/math/fwd/fun/erf.hpp @@ -3,9 +3,10 @@ #include #include +#include +#include #include #include -#include #include namespace stan { @@ -13,7 +14,6 @@ namespace math { template inline fvar erf(const fvar& x) { - using std::exp; return fvar(erf(x.val_), x.d_ * exp(-square(x.val_)) * TWO_OVER_SQRT_PI); } diff --git a/stan/math/fwd/fun/erfc.hpp b/stan/math/fwd/fun/erfc.hpp index 458013f5a7b..b3c222561ee 100644 --- a/stan/math/fwd/fun/erfc.hpp +++ b/stan/math/fwd/fun/erfc.hpp @@ -3,9 +3,10 @@ #include #include +#include +#include #include #include -#include #include namespace stan { @@ -13,7 +14,6 @@ namespace math { template inline fvar erfc(const fvar& x) { - using std::exp; return fvar(erfc(x.val_), -x.d_ * exp(-square(x.val_)) * TWO_OVER_SQRT_PI); } diff --git a/stan/math/fwd/fun/exp.hpp b/stan/math/fwd/fun/exp.hpp index d0690fd803d..d24e35e06eb 100644 --- a/stan/math/fwd/fun/exp.hpp +++ b/stan/math/fwd/fun/exp.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -11,7 +13,6 @@ namespace stan { namespace math { template inline fvar exp(const fvar& x) { - using std::exp; return fvar(exp(x.val_), x.d_ * exp(x.val_)); } diff --git a/stan/math/fwd/fun/exp2.hpp b/stan/math/fwd/fun/exp2.hpp index 52e6ed65c44..cda233bfad0 100644 --- a/stan/math/fwd/fun/exp2.hpp +++ b/stan/math/fwd/fun/exp2.hpp @@ -3,8 +3,8 @@ #include #include -#include #include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/expm1.hpp b/stan/math/fwd/fun/expm1.hpp index 72c388fadfb..86a0b146f1d 100644 --- a/stan/math/fwd/fun/expm1.hpp +++ b/stan/math/fwd/fun/expm1.hpp @@ -1,9 +1,10 @@ #ifndef STAN_MATH_FWD_FUN_EXPM1_HPP #define STAN_MATH_FWD_FUN_EXPM1_HPP -#include #include #include +#include +#include #include namespace stan { @@ -11,7 +12,6 @@ namespace math { template inline fvar expm1(const fvar& x) { - using std::exp; return fvar(expm1(x.val_), x.d_ * exp(x.val_)); } diff --git a/stan/math/fwd/fun/fabs.hpp b/stan/math/fwd/fun/fabs.hpp index 47af374b153..dff73342478 100644 --- a/stan/math/fwd/fun/fabs.hpp +++ b/stan/math/fwd/fun/fabs.hpp @@ -3,9 +3,10 @@ #include #include +#include +#include #include -#include -#include +#include #include namespace stan { @@ -13,8 +14,6 @@ namespace math { template inline fvar fabs(const fvar& x) { - using std::fabs; - if (unlikely(is_nan(value_of(x.val_)))) { return fvar(fabs(x.val_), NOT_A_NUMBER); } else if (x.val_ > 0.0) { diff --git a/stan/math/fwd/fun/falling_factorial.hpp b/stan/math/fwd/fun/falling_factorial.hpp index e62796c7a1a..930bf911aa7 100644 --- a/stan/math/fwd/fun/falling_factorial.hpp +++ b/stan/math/fwd/fun/falling_factorial.hpp @@ -3,9 +3,8 @@ #include #include - +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/floor.hpp b/stan/math/fwd/fun/floor.hpp index bdd12a10b93..d68164c0159 100644 --- a/stan/math/fwd/fun/floor.hpp +++ b/stan/math/fwd/fun/floor.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace stan { @@ -10,7 +11,6 @@ namespace math { template inline fvar floor(const fvar& x) { - using std::floor; return fvar(floor(x.val_), 0); } diff --git a/stan/math/fwd/fun/fmax.hpp b/stan/math/fwd/fun/fmax.hpp index b5227d31adb..3919b6a64d6 100644 --- a/stan/math/fwd/fun/fmax.hpp +++ b/stan/math/fwd/fun/fmax.hpp @@ -3,9 +3,9 @@ #include #include +#include #include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/fmin.hpp b/stan/math/fwd/fun/fmin.hpp index e906df91f36..df5f6a66c71 100644 --- a/stan/math/fwd/fun/fmin.hpp +++ b/stan/math/fwd/fun/fmin.hpp @@ -4,8 +4,8 @@ #include #include #include -#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/fmod.hpp b/stan/math/fwd/fun/fmod.hpp index 2cbed3e8c09..0642c5add99 100644 --- a/stan/math/fwd/fun/fmod.hpp +++ b/stan/math/fwd/fun/fmod.hpp @@ -3,9 +3,11 @@ #include #include +#include +#include #include #include -#include +#include #include namespace stan { @@ -13,15 +15,12 @@ namespace math { template inline fvar fmod(const fvar& x1, const fvar& x2) { - using std::fmod; - using std::trunc; return fvar(fmod(x1.val_, x2.val_), x1.d_ - x2.d_ * trunc(x1.val_ / x2.val_)); } template inline fvar fmod(const fvar& x1, double x2) { - using std::fmod; if (unlikely(is_any_nan(value_of(x1.val_), x2))) { return fvar(fmod(x1.val_, x2), NOT_A_NUMBER); } else { @@ -31,8 +30,6 @@ inline fvar fmod(const fvar& x1, double x2) { template inline fvar fmod(double x1, const fvar& x2) { - using std::fmod; - using std::trunc; return fvar(fmod(x1, x2.val_), -x2.d_ * trunc(x1 / x2.val_)); } diff --git a/stan/math/fwd/fun/gamma_p.hpp b/stan/math/fwd/fun/gamma_p.hpp index f3f84cc7b04..20c1d25016c 100644 --- a/stan/math/fwd/fun/gamma_p.hpp +++ b/stan/math/fwd/fun/gamma_p.hpp @@ -3,10 +3,12 @@ #include #include +#include +#include +#include #include -#include #include -#include +#include #include namespace stan { @@ -14,9 +16,6 @@ namespace math { template inline fvar gamma_p(const fvar &x1, const fvar &x2) { - using std::exp; - using std::log; - T u = gamma_p(x1.val_, x2.val_); if (is_inf(x1.val_)) { return fvar(u, NOT_A_NUMBER); @@ -48,9 +47,6 @@ inline fvar gamma_p(const fvar &x1, double x2) { template inline fvar gamma_p(double x1, const fvar &x2) { - using std::exp; - using std::log; - T u = gamma_p(x1, x2.val_); if (is_inf(x1)) { return fvar(u, NOT_A_NUMBER); diff --git a/stan/math/fwd/fun/gamma_q.hpp b/stan/math/fwd/fun/gamma_q.hpp index b2ba8d41255..2e1951bcd82 100644 --- a/stan/math/fwd/fun/gamma_q.hpp +++ b/stan/math/fwd/fun/gamma_q.hpp @@ -3,7 +3,12 @@ #include #include -#include +#include +#include +#include +#include +#include +#include #include #include @@ -12,12 +17,6 @@ namespace math { template inline fvar gamma_q(const fvar& x1, const fvar& x2) { - using boost::math::digamma; - using std::exp; - using std::fabs; - using std::log; - using std::pow; - T u = gamma_q(x1.val_, x2.val_); T S = 0; @@ -44,14 +43,7 @@ inline fvar gamma_q(const fvar& x1, const fvar& x2) { template inline fvar gamma_q(const fvar& x1, double x2) { - using boost::math::digamma; - using std::exp; - using std::fabs; - using std::log; - using std::pow; - T u = gamma_q(x1.val_, x2); - T S = 0; double s = 1; double l = log(x2); @@ -75,15 +67,9 @@ inline fvar gamma_q(const fvar& x1, double x2) { template inline fvar gamma_q(double x1, const fvar& x2) { - using std::exp; - using std::pow; - T u = gamma_q(x1, x2.val_); - double g = tgamma(x1); - T der2 = -exp(-x2.val_) * pow(x2.val_, x1 - 1.0) / g; - return fvar(u, x2.d_ * der2); } } // namespace math diff --git a/stan/math/fwd/fun/grad_inc_beta.hpp b/stan/math/fwd/fun/grad_inc_beta.hpp index 70e0453c674..6c8c6e88486 100644 --- a/stan/math/fwd/fun/grad_inc_beta.hpp +++ b/stan/math/fwd/fun/grad_inc_beta.hpp @@ -1,8 +1,6 @@ #ifndef STAN_MATH_FWD_FUN_GRAD_INC_BETA_HPP #define STAN_MATH_FWD_FUN_GRAD_INC_BETA_HPP -#include -#include #include #include #include @@ -11,6 +9,8 @@ #include #include #include +#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/hypergeometric_1F0.hpp b/stan/math/fwd/fun/hypergeometric_1F0.hpp index 8448b6cc3a4..b304d5c8381 100644 --- a/stan/math/fwd/fun/hypergeometric_1F0.hpp +++ b/stan/math/fwd/fun/hypergeometric_1F0.hpp @@ -1,9 +1,12 @@ #ifndef STAN_MATH_FWD_FUN_HYPERGEOMETRIC_1F0_HPP #define STAN_MATH_FWD_FUN_HYPERGEOMETRIC_1F0_HPP -#include -#include #include +#include +#include +#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/hypergeometric_2F1.hpp b/stan/math/fwd/fun/hypergeometric_2F1.hpp index 993825bd51d..9e450cda01f 100644 --- a/stan/math/fwd/fun/hypergeometric_2F1.hpp +++ b/stan/math/fwd/fun/hypergeometric_2F1.hpp @@ -3,8 +3,9 @@ #include #include -#include +#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/hypergeometric_pFq.hpp b/stan/math/fwd/fun/hypergeometric_pFq.hpp index cec91aaa90b..3165878ffcf 100644 --- a/stan/math/fwd/fun/hypergeometric_pFq.hpp +++ b/stan/math/fwd/fun/hypergeometric_pFq.hpp @@ -3,8 +3,10 @@ #include #include -#include +#include +#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/hypot.hpp b/stan/math/fwd/fun/hypot.hpp index 07def1797e4..09d186d6009 100644 --- a/stan/math/fwd/fun/hypot.hpp +++ b/stan/math/fwd/fun/hypot.hpp @@ -24,7 +24,6 @@ namespace math { */ template inline fvar hypot(const fvar& x1, const fvar& x2) { - using std::sqrt; T u = hypot(x1.val_, x2.val_); return fvar(u, (x1.d_ * x1.val_ + x2.d_ * x2.val_) / u); } @@ -44,7 +43,6 @@ inline fvar hypot(const fvar& x1, const fvar& x2) { */ template inline fvar hypot(const fvar& x1, double x2) { - using std::sqrt; T u = hypot(x1.val_, x2); return fvar(u, (x1.d_ * x1.val_) / u); } @@ -64,7 +62,6 @@ inline fvar hypot(const fvar& x1, double x2) { */ template inline fvar hypot(double x1, const fvar& x2) { - using std::sqrt; T u = hypot(x1, x2.val_); return fvar(u, (x2.d_ * x2.val_) / u); } diff --git a/stan/math/fwd/fun/inc_beta.hpp b/stan/math/fwd/fun/inc_beta.hpp index 8f964d365ea..d0b89e35e06 100644 --- a/stan/math/fwd/fun/inc_beta.hpp +++ b/stan/math/fwd/fun/inc_beta.hpp @@ -1,15 +1,15 @@ #ifndef STAN_MATH_FWD_FUN_INC_BETA_HPP #define STAN_MATH_FWD_FUN_INC_BETA_HPP -#include -#include -#include #include #include #include #include #include +#include #include +#include +#include #include namespace stan { @@ -17,7 +17,6 @@ namespace math { template inline fvar inc_beta(const fvar& a, const fvar& b, const fvar& x) { - using std::pow; T d_a; T d_b; const T beta_ab = beta(a.val_, b.val_); diff --git a/stan/math/fwd/fun/inv.hpp b/stan/math/fwd/fun/inv.hpp index b5b2531f4fe..3d0cd3108a5 100644 --- a/stan/math/fwd/fun/inv.hpp +++ b/stan/math/fwd/fun/inv.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/inv_Phi.hpp b/stan/math/fwd/fun/inv_Phi.hpp index bfff53da0e2..5424f484f74 100644 --- a/stan/math/fwd/fun/inv_Phi.hpp +++ b/stan/math/fwd/fun/inv_Phi.hpp @@ -3,9 +3,10 @@ #include #include +#include +#include #include #include -#include #include namespace stan { @@ -13,7 +14,6 @@ namespace math { template inline fvar inv_Phi(const fvar& p) { - using std::exp; T xv = inv_Phi(p.val_); return fvar(xv, p.d_ / exp(-0.5 * square(xv)) * SQRT_TWO_PI); } diff --git a/stan/math/fwd/fun/inv_cloglog.hpp b/stan/math/fwd/fun/inv_cloglog.hpp index d0e7a0f4c34..73767500376 100644 --- a/stan/math/fwd/fun/inv_cloglog.hpp +++ b/stan/math/fwd/fun/inv_cloglog.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,7 +12,6 @@ namespace math { template inline fvar inv_cloglog(const fvar& x) { - using std::exp; return fvar(inv_cloglog(x.val_), x.d_ * exp(x.val_ - exp(x.val_))); } } // namespace math diff --git a/stan/math/fwd/fun/inv_erfc.hpp b/stan/math/fwd/fun/inv_erfc.hpp index c2b5852b958..f9628d013e0 100644 --- a/stan/math/fwd/fun/inv_erfc.hpp +++ b/stan/math/fwd/fun/inv_erfc.hpp @@ -3,10 +3,10 @@ #include #include +#include +#include #include #include -#include -#include #include namespace stan { diff --git a/stan/math/fwd/fun/inv_inc_beta.hpp b/stan/math/fwd/fun/inv_inc_beta.hpp index ab095c557db..23ce0d583ed 100644 --- a/stan/math/fwd/fun/inv_inc_beta.hpp +++ b/stan/math/fwd/fun/inv_inc_beta.hpp @@ -3,15 +3,18 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/inv_logit.hpp b/stan/math/fwd/fun/inv_logit.hpp index 8a6bd96d438..7becb85444a 100644 --- a/stan/math/fwd/fun/inv_logit.hpp +++ b/stan/math/fwd/fun/inv_logit.hpp @@ -18,8 +18,6 @@ namespace math { */ template inline fvar inv_logit(const fvar& x) { - using std::exp; - using std::pow; return fvar(inv_logit(x.val_), x.d_ * inv_logit(x.val_) * (1 - inv_logit(x.val_))); } diff --git a/stan/math/fwd/fun/inv_sqrt.hpp b/stan/math/fwd/fun/inv_sqrt.hpp index 40625094d37..eefe580c075 100644 --- a/stan/math/fwd/fun/inv_sqrt.hpp +++ b/stan/math/fwd/fun/inv_sqrt.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include namespace stan { @@ -10,9 +12,8 @@ namespace math { template inline fvar inv_sqrt(const fvar& x) { - using std::sqrt; T sqrt_x(sqrt(x.val_)); - return fvar(1 / sqrt_x, -0.5 * x.d_ / (x.val_ * sqrt_x)); + return fvar(1.0 / sqrt_x, -0.5 * x.d_ / (x.val_ * sqrt_x)); } } // namespace math } // namespace stan diff --git a/stan/math/fwd/fun/inv_square.hpp b/stan/math/fwd/fun/inv_square.hpp index 016ed9e9294..d1f41d48f30 100644 --- a/stan/math/fwd/fun/inv_square.hpp +++ b/stan/math/fwd/fun/inv_square.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/inverse.hpp b/stan/math/fwd/fun/inverse.hpp index 36f8da0b4c1..82e817b2dc9 100644 --- a/stan/math/fwd/fun/inverse.hpp +++ b/stan/math/fwd/fun/inverse.hpp @@ -1,14 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_INVERSE_HPP #define STAN_MATH_FWD_FUN_INVERSE_HPP -#include -#include #include -#include -#include #include #include #include +#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/lambert_w.hpp b/stan/math/fwd/fun/lambert_w.hpp index 622dff79612..45968e8722f 100644 --- a/stan/math/fwd/fun/lambert_w.hpp +++ b/stan/math/fwd/fun/lambert_w.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/stan/math/fwd/fun/lbeta.hpp b/stan/math/fwd/fun/lbeta.hpp index b1f55bc483d..eb2c05b4c1a 100644 --- a/stan/math/fwd/fun/lbeta.hpp +++ b/stan/math/fwd/fun/lbeta.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/lgamma.hpp b/stan/math/fwd/fun/lgamma.hpp index 864d6dda152..780dc896bcb 100644 --- a/stan/math/fwd/fun/lgamma.hpp +++ b/stan/math/fwd/fun/lgamma.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/lmgamma.hpp b/stan/math/fwd/fun/lmgamma.hpp index 7281086cce7..77698007cc8 100644 --- a/stan/math/fwd/fun/lmgamma.hpp +++ b/stan/math/fwd/fun/lmgamma.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -12,7 +12,6 @@ namespace math { template inline fvar> lmgamma(int x1, const fvar& x2) { - using std::log; T deriv = 0; for (int count = 1; count < x1 + 1; count++) { deriv += x2.d_ * digamma(x2.val_ + (1.0 - count) / 2.0); diff --git a/stan/math/fwd/fun/lmultiply.hpp b/stan/math/fwd/fun/lmultiply.hpp index 7df57e26d23..4af4aaf27c4 100644 --- a/stan/math/fwd/fun/lmultiply.hpp +++ b/stan/math/fwd/fun/lmultiply.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,20 +12,17 @@ namespace math { template inline fvar lmultiply(const fvar& x1, const fvar& x2) { - using std::log; return fvar(lmultiply(x1.val_, x2.val_), x1.d_ * log(x2.val_) + x1.val_ * x2.d_ / x2.val_); } template inline fvar lmultiply(double x1, const fvar& x2) { - using std::log; return fvar(lmultiply(x1, x2.val_), x1 * x2.d_ / x2.val_); } template inline fvar lmultiply(const fvar& x1, double x2) { - using std::log; return fvar(lmultiply(x1.val_, x2), x1.d_ * log(x2)); } } // namespace math diff --git a/stan/math/fwd/fun/log.hpp b/stan/math/fwd/fun/log.hpp index d7ce96f0bfa..d3270d2b833 100644 --- a/stan/math/fwd/fun/log.hpp +++ b/stan/math/fwd/fun/log.hpp @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include #include #include @@ -13,7 +16,6 @@ namespace math { template inline fvar log(const fvar& x) { - using std::log; if (x.val_ < 0.0) { return fvar(NOT_A_NUMBER, NOT_A_NUMBER); } else { diff --git a/stan/math/fwd/fun/log10.hpp b/stan/math/fwd/fun/log10.hpp index f418eeb4b37..a28bef26a61 100644 --- a/stan/math/fwd/fun/log10.hpp +++ b/stan/math/fwd/fun/log10.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -13,8 +14,6 @@ namespace math { template inline fvar log10(const fvar& x) { - using std::log; - using std::log10; if (x.val_ < 0.0) { return fvar(NOT_A_NUMBER, NOT_A_NUMBER); } else { diff --git a/stan/math/fwd/fun/log1m_exp.hpp b/stan/math/fwd/fun/log1m_exp.hpp index 9ce2211d07d..9f1b1e7a9d6 100644 --- a/stan/math/fwd/fun/log1m_exp.hpp +++ b/stan/math/fwd/fun/log1m_exp.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include namespace stan { diff --git a/stan/math/fwd/fun/log1m_inv_logit.hpp b/stan/math/fwd/fun/log1m_inv_logit.hpp index edf27198399..6251e7e8b11 100644 --- a/stan/math/fwd/fun/log1m_inv_logit.hpp +++ b/stan/math/fwd/fun/log1m_inv_logit.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -19,7 +20,6 @@ namespace math { */ template inline fvar log1m_inv_logit(const fvar& x) { - using std::exp; return fvar(log1m_inv_logit(x.val_), -x.d_ * inv_logit(x.val_)); } diff --git a/stan/math/fwd/fun/log1p_exp.hpp b/stan/math/fwd/fun/log1p_exp.hpp index ca7d82661fb..7b5d689ccf1 100644 --- a/stan/math/fwd/fun/log1p_exp.hpp +++ b/stan/math/fwd/fun/log1p_exp.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,7 +12,6 @@ namespace math { template inline fvar log1p_exp(const fvar& x) { - using std::exp; return fvar(log1p_exp(x.val_), x.d_ * inv_logit(x.val_)); } diff --git a/stan/math/fwd/fun/log_determinant.hpp b/stan/math/fwd/fun/log_determinant.hpp index 2270718ee43..78405cdc88f 100644 --- a/stan/math/fwd/fun/log_determinant.hpp +++ b/stan/math/fwd/fun/log_determinant.hpp @@ -1,13 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_LOG_DETERMINANT_HPP #define STAN_MATH_FWD_FUN_LOG_DETERMINANT_HPP -#include -#include #include #include #include #include #include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/log_diff_exp.hpp b/stan/math/fwd/fun/log_diff_exp.hpp index 1ee40481ec7..036cc04884b 100644 --- a/stan/math/fwd/fun/log_diff_exp.hpp +++ b/stan/math/fwd/fun/log_diff_exp.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/log_falling_factorial.hpp b/stan/math/fwd/fun/log_falling_factorial.hpp index 4a879b02649..636b823f3ef 100644 --- a/stan/math/fwd/fun/log_falling_factorial.hpp +++ b/stan/math/fwd/fun/log_falling_factorial.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include namespace stan { diff --git a/stan/math/fwd/fun/log_inv_logit.hpp b/stan/math/fwd/fun/log_inv_logit.hpp index d0139d30278..c1ca6eaefbd 100644 --- a/stan/math/fwd/fun/log_inv_logit.hpp +++ b/stan/math/fwd/fun/log_inv_logit.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -12,7 +12,6 @@ namespace math { template inline fvar log_inv_logit(const fvar& x) { - using std::exp; return fvar(log_inv_logit(x.val_), x.d_ * inv_logit(-x.val_)); } } // namespace math diff --git a/stan/math/fwd/fun/log_inv_logit_diff.hpp b/stan/math/fwd/fun/log_inv_logit_diff.hpp index 05df12dd376..e31f166d040 100644 --- a/stan/math/fwd/fun/log_inv_logit_diff.hpp +++ b/stan/math/fwd/fun/log_inv_logit_diff.hpp @@ -3,10 +3,10 @@ #include #include +#include +#include +#include #include -#include -#include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/log_mix.hpp b/stan/math/fwd/fun/log_mix.hpp index 0477b398865..3da901d67d6 100644 --- a/stan/math/fwd/fun/log_mix.hpp +++ b/stan/math/fwd/fun/log_mix.hpp @@ -3,7 +3,8 @@ #include #include -#include +#include +#include #include #include #include @@ -28,7 +29,6 @@ template inline void log_mix_partial_helper( const T_theta& theta, const T_lambda1& lambda1, const T_lambda2& lambda2, promote_args_t (&partials_array)[N]) { - using std::exp; using partial_return_type = promote_args_t; auto lam2_m_lam1 = lambda2 - lambda1; auto exp_lam2_m_lam1 = exp(lam2_m_lam1); diff --git a/stan/math/fwd/fun/log_rising_factorial.hpp b/stan/math/fwd/fun/log_rising_factorial.hpp index 399f13d1cb3..89e2f4bcc1e 100644 --- a/stan/math/fwd/fun/log_rising_factorial.hpp +++ b/stan/math/fwd/fun/log_rising_factorial.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/log_softmax.hpp b/stan/math/fwd/fun/log_softmax.hpp index 7cd5f1dc684..82d1f7b0204 100644 --- a/stan/math/fwd/fun/log_softmax.hpp +++ b/stan/math/fwd/fun/log_softmax.hpp @@ -1,12 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_LOG_SOFTMAX_HPP #define STAN_MATH_FWD_FUN_LOG_SOFTMAX_HPP +#include #include +#include #include -#include -#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/log_sum_exp.hpp b/stan/math/fwd/fun/log_sum_exp.hpp index beb34551160..30795b8f99b 100644 --- a/stan/math/fwd/fun/log_sum_exp.hpp +++ b/stan/math/fwd/fun/log_sum_exp.hpp @@ -1,13 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_LOG_SUM_EXP_HPP #define STAN_MATH_FWD_FUN_LOG_SUM_EXP_HPP +#include #include #include -#include -#include +#include #include -#include #include +#include #include #include @@ -16,7 +16,6 @@ namespace math { template inline fvar log_sum_exp(const fvar& x1, const fvar& x2) { - using std::exp; return fvar(log_sum_exp(x1.val_, x2.val_), x1.d_ * inv_logit(-(x2.val_ - x1.val_)) + x2.d_ * inv_logit(-(x1.val_ - x2.val_))); @@ -24,7 +23,6 @@ inline fvar log_sum_exp(const fvar& x1, const fvar& x2) { template inline fvar log_sum_exp(double x1, const fvar& x2) { - using std::exp; if (x1 == NEGATIVE_INFTY) { return fvar(x2.val_, x2.d_); } diff --git a/stan/math/fwd/fun/logit.hpp b/stan/math/fwd/fun/logit.hpp index c5572814bf5..472329d4fa1 100644 --- a/stan/math/fwd/fun/logit.hpp +++ b/stan/math/fwd/fun/logit.hpp @@ -3,9 +3,9 @@ #include #include -#include -#include +#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/mdivide_left.hpp b/stan/math/fwd/fun/mdivide_left.hpp index 7fd7c6a1e5e..654b017afc6 100644 --- a/stan/math/fwd/fun/mdivide_left.hpp +++ b/stan/math/fwd/fun/mdivide_left.hpp @@ -1,13 +1,12 @@ #ifndef STAN_MATH_FWD_FUN_MDIVIDE_LEFT_HPP #define STAN_MATH_FWD_FUN_MDIVIDE_LEFT_HPP -#include #include -#include -#include #include #include #include +#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/mdivide_left_ldlt.hpp b/stan/math/fwd/fun/mdivide_left_ldlt.hpp index 69db8bd1d8e..7400873dbd4 100644 --- a/stan/math/fwd/fun/mdivide_left_ldlt.hpp +++ b/stan/math/fwd/fun/mdivide_left_ldlt.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_MDIVIDE_LEFT_LDLT_HPP #define STAN_MATH_FWD_FUN_MDIVIDE_LEFT_LDLT_HPP -#include #include +#include +#include #include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/mdivide_left_tri_low.hpp b/stan/math/fwd/fun/mdivide_left_tri_low.hpp index 67be26be5d1..5aedc86dcfa 100644 --- a/stan/math/fwd/fun/mdivide_left_tri_low.hpp +++ b/stan/math/fwd/fun/mdivide_left_tri_low.hpp @@ -1,13 +1,14 @@ #ifndef STAN_MATH_FWD_FUN_MDIVIDE_LEFT_TRI_LOW_HPP #define STAN_MATH_FWD_FUN_MDIVIDE_LEFT_TRI_LOW_HPP -#include #include -#include -#include +#include +#include #include +#include #include -#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/mdivide_right.hpp b/stan/math/fwd/fun/mdivide_right.hpp index b87cbcb102e..a2421931918 100644 --- a/stan/math/fwd/fun/mdivide_right.hpp +++ b/stan/math/fwd/fun/mdivide_right.hpp @@ -1,13 +1,12 @@ #ifndef STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_HPP #define STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_HPP -#include #include -#include -#include #include #include #include +#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/mdivide_right_tri_low.hpp b/stan/math/fwd/fun/mdivide_right_tri_low.hpp index a5fe504a146..039dc7dd57c 100644 --- a/stan/math/fwd/fun/mdivide_right_tri_low.hpp +++ b/stan/math/fwd/fun/mdivide_right_tri_low.hpp @@ -1,12 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_TRI_LOW_HPP #define STAN_MATH_FWD_FUN_MDIVIDE_RIGHT_TRI_LOW_HPP -#include #include -#include -#include -#include #include +#include +#include +#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/multiply.hpp b/stan/math/fwd/fun/multiply.hpp index 3e5d94ab199..cbe365b2860 100644 --- a/stan/math/fwd/fun/multiply.hpp +++ b/stan/math/fwd/fun/multiply.hpp @@ -1,12 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_MULTIPLY_HPP #define STAN_MATH_FWD_FUN_MULTIPLY_HPP -#include -#include #include -#include #include +#include #include +#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/multiply_log.hpp b/stan/math/fwd/fun/multiply_log.hpp index 32eea41173f..3df40b33268 100644 --- a/stan/math/fwd/fun/multiply_log.hpp +++ b/stan/math/fwd/fun/multiply_log.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,20 +12,17 @@ namespace math { template inline fvar multiply_log(const fvar& x1, const fvar& x2) { - using std::log; return fvar(multiply_log(x1.val_, x2.val_), x1.d_ * log(x2.val_) + x1.val_ * x2.d_ / x2.val_); } template inline fvar multiply_log(double x1, const fvar& x2) { - using std::log; return fvar(multiply_log(x1, x2.val_), x1 * x2.d_ / x2.val_); } template inline fvar multiply_log(const fvar& x1, double x2) { - using std::log; return fvar(multiply_log(x1.val_, x2), x1.d_ * log(x2)); } } // namespace math diff --git a/stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp b/stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp index 93923da0f1e..c9ca25018b5 100644 --- a/stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp +++ b/stan/math/fwd/fun/multiply_lower_tri_self_transpose.hpp @@ -2,8 +2,9 @@ #define STAN_MATH_FWD_FUN_MULTIPLY_LOWER_TRI_SELF_TRANSPOSE_HPP #include -#include #include +#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/norm.hpp b/stan/math/fwd/fun/norm.hpp index 1de3e640223..6a087506c0a 100644 --- a/stan/math/fwd/fun/norm.hpp +++ b/stan/math/fwd/fun/norm.hpp @@ -2,6 +2,7 @@ #define STAN_MATH_FWD_FUN_NORM_HPP #include +#include #include #include diff --git a/stan/math/fwd/fun/norm1.hpp b/stan/math/fwd/fun/norm1.hpp index a4c35dcddd7..151216f2f12 100644 --- a/stan/math/fwd/fun/norm1.hpp +++ b/stan/math/fwd/fun/norm1.hpp @@ -1,14 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_NORM1_HPP #define STAN_MATH_FWD_FUN_NORM1_HPP +#include #include #include -#include -#include #include -#include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/norm2.hpp b/stan/math/fwd/fun/norm2.hpp index 7d78d7b7ce7..3ba8200363a 100644 --- a/stan/math/fwd/fun/norm2.hpp +++ b/stan/math/fwd/fun/norm2.hpp @@ -1,12 +1,12 @@ #ifndef STAN_MATH_FWD_FUN_NORM2_HPP #define STAN_MATH_FWD_FUN_NORM2_HPP +#include #include #include #include -#include -#include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/owens_t.hpp b/stan/math/fwd/fun/owens_t.hpp index 42c5898ed15..3793697dbd9 100644 --- a/stan/math/fwd/fun/owens_t.hpp +++ b/stan/math/fwd/fun/owens_t.hpp @@ -3,10 +3,11 @@ #include #include +#include +#include +#include #include -#include #include -#include #include namespace stan { @@ -23,8 +24,6 @@ namespace math { */ template inline fvar owens_t(const fvar& x1, const fvar& x2) { - using std::exp; - T neg_x1_sq_div_2 = -square(x1.val_) * 0.5; T one_p_x2_sq = 1.0 + square(x2.val_); return fvar(owens_t(x1.val_, x2.val_), @@ -45,8 +44,6 @@ inline fvar owens_t(const fvar& x1, const fvar& x2) { */ template inline fvar owens_t(double x1, const fvar& x2) { - using std::exp; - T neg_x1_sq_div_2 = -square(x1) * 0.5; T one_p_x2_sq = 1.0 + square(x2.val_); return fvar( @@ -64,8 +61,6 @@ inline fvar owens_t(double x1, const fvar& x2) { */ template inline fvar owens_t(const fvar& x1, double x2) { - using std::exp; - T neg_x1_sq_div_2 = -square(x1.val_) * 0.5; return fvar(owens_t(x1.val_, x2), -x1.d_ diff --git a/stan/math/fwd/fun/polar.hpp b/stan/math/fwd/fun/polar.hpp index 891c2f0d500..2728e6ded8d 100644 --- a/stan/math/fwd/fun/polar.hpp +++ b/stan/math/fwd/fun/polar.hpp @@ -3,6 +3,9 @@ #include #include +#include +#include +#include #include #include #include diff --git a/stan/math/fwd/fun/pow.hpp b/stan/math/fwd/fun/pow.hpp index c2056c9f5cf..12337c3d3ba 100644 --- a/stan/math/fwd/fun/pow.hpp +++ b/stan/math/fwd/fun/pow.hpp @@ -30,8 +30,6 @@ template , base_type_t>* = nullptr, require_all_stan_scalar_t* = nullptr> inline auto pow(const T1& x1, const T2& x2) { - using std::log; - using std::pow; if constexpr (is_complex::value || is_complex::value) { return internal::complex_pow(x1, x2); } else if constexpr (is_fvar::value && is_fvar::value) { @@ -43,23 +41,17 @@ inline auto pow(const T1& x1, const T2& x2) { auto u = stan::math::pow(x1, x2.val_); return T2(u, x2.d_ * stan::math::log(x1) * u); } else { - using std::sqrt; if (x2 == -2) { return stan::math::inv_square(x1); - } - if (x2 == -1) { + } else if (x2 == -1) { return stan::math::inv(x1); - } - if (x2 == -0.5) { + } else if (x2 == -0.5) { return stan::math::inv_sqrt(x1); - } - if (x2 == 0.5) { + } else if (x2 == 0.5) { return stan::math::sqrt(x1); - } - if (x2 == 1.0) { + } else if (x2 == 1.0) { return x1; - } - if (x2 == 2.0) { + } else if (x2 == 2.0) { return stan::math::square(x1); } return T1(stan::math::pow(x1.val_, x2), diff --git a/stan/math/fwd/fun/proj.hpp b/stan/math/fwd/fun/proj.hpp index 931d2dc4b72..d07ee0aa004 100644 --- a/stan/math/fwd/fun/proj.hpp +++ b/stan/math/fwd/fun/proj.hpp @@ -2,6 +2,7 @@ #define STAN_MATH_FWD_FUN_PROJ_HPP #include +#include #include #include diff --git a/stan/math/fwd/fun/rising_factorial.hpp b/stan/math/fwd/fun/rising_factorial.hpp index 461665edce1..f816c0b53cb 100644 --- a/stan/math/fwd/fun/rising_factorial.hpp +++ b/stan/math/fwd/fun/rising_factorial.hpp @@ -3,8 +3,8 @@ #include #include +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/round.hpp b/stan/math/fwd/fun/round.hpp index 31d0108263e..35f31fdbc56 100644 --- a/stan/math/fwd/fun/round.hpp +++ b/stan/math/fwd/fun/round.hpp @@ -3,8 +3,8 @@ #include #include +#include #include -#include #include namespace stan { diff --git a/stan/math/fwd/fun/sin.hpp b/stan/math/fwd/fun/sin.hpp index c938cf4948d..a208ff190be 100644 --- a/stan/math/fwd/fun/sin.hpp +++ b/stan/math/fwd/fun/sin.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -12,8 +14,6 @@ namespace math { template inline fvar sin(const fvar& x) { - using std::cos; - using std::sin; return fvar(sin(x.val_), x.d_ * cos(x.val_)); } diff --git a/stan/math/fwd/fun/sinh.hpp b/stan/math/fwd/fun/sinh.hpp index 0a7e6d4343a..15c114ec7ab 100644 --- a/stan/math/fwd/fun/sinh.hpp +++ b/stan/math/fwd/fun/sinh.hpp @@ -1,9 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_SINH_HPP #define STAN_MATH_FWD_FUN_SINH_HPP -#include #include #include +#include +#include +#include #include namespace stan { @@ -11,8 +13,6 @@ namespace math { template inline fvar sinh(const fvar& x) { - using std::cosh; - using std::sinh; return fvar(sinh(x.val_), x.d_ * cosh(x.val_)); } diff --git a/stan/math/fwd/fun/softmax.hpp b/stan/math/fwd/fun/softmax.hpp index 3e1f4c93ef5..3625332ddf2 100644 --- a/stan/math/fwd/fun/softmax.hpp +++ b/stan/math/fwd/fun/softmax.hpp @@ -1,12 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_SOFTMAX_HPP #define STAN_MATH_FWD_FUN_SOFTMAX_HPP +#include #include #include -#include -#include #include -#include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/sqrt.hpp b/stan/math/fwd/fun/sqrt.hpp index aa8fa0abc5c..81d0f187423 100644 --- a/stan/math/fwd/fun/sqrt.hpp +++ b/stan/math/fwd/fun/sqrt.hpp @@ -3,10 +3,11 @@ #include #include -#include -#include +#include #include -#include +#include +#include +#include #include #include @@ -15,7 +16,6 @@ namespace math { template inline fvar sqrt(const fvar& x) { - using std::sqrt; if (value_of_rec(x.val_) == 0.0) { return fvar(sqrt(x.val_), 0.0 * x.d_); } diff --git a/stan/math/fwd/fun/sum.hpp b/stan/math/fwd/fun/sum.hpp index 36eef6ad687..ad587cdb91e 100644 --- a/stan/math/fwd/fun/sum.hpp +++ b/stan/math/fwd/fun/sum.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_FWD_FUN_SUM_HPP #define STAN_MATH_FWD_FUN_SUM_HPP +#include #include #include #include -#include #include #include diff --git a/stan/math/fwd/fun/tan.hpp b/stan/math/fwd/fun/tan.hpp index 503ca10e2ef..b19cd576969 100644 --- a/stan/math/fwd/fun/tan.hpp +++ b/stan/math/fwd/fun/tan.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -12,8 +14,6 @@ namespace math { template inline fvar tan(const fvar& x) { - using std::cos; - using std::tan; return fvar(tan(x.val_), x.d_ / (cos(x.val_) * cos(x.val_))); } diff --git a/stan/math/fwd/fun/tanh.hpp b/stan/math/fwd/fun/tanh.hpp index 9bb120ba4e3..9699163b226 100644 --- a/stan/math/fwd/fun/tanh.hpp +++ b/stan/math/fwd/fun/tanh.hpp @@ -13,7 +13,6 @@ namespace math { template inline fvar tanh(const fvar& x) { - using std::tanh; T u = tanh(x.val_); return fvar(u, x.d_ * (1 - u * u)); } diff --git a/stan/math/fwd/fun/tcrossprod.hpp b/stan/math/fwd/fun/tcrossprod.hpp index f25b4036576..c5fdb3e66b0 100644 --- a/stan/math/fwd/fun/tcrossprod.hpp +++ b/stan/math/fwd/fun/tcrossprod.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_FWD_FUN_TCROSSPROD_HPP #define STAN_MATH_FWD_FUN_TCROSSPROD_HPP -#include #include +#include +#include #include #include -#include namespace stan { namespace math { @@ -18,7 +18,13 @@ tcrossprod(const EigMat& m) { return {}; } const auto& m_ref = to_ref(m); - return m_ref * m_ref.transpose(); + auto ret = multiply(m_ref, m_ref.transpose()); + if constexpr (is_stan_scalar::value) { + return Eigen::Matrix, EigMat::RowsAtCompileTime, + EigMat::RowsAtCompileTime>{{ret}}; + } else { + return ret; + } } } // namespace math diff --git a/stan/math/fwd/fun/tgamma.hpp b/stan/math/fwd/fun/tgamma.hpp index ef9d2f0b173..0f89977edcd 100644 --- a/stan/math/fwd/fun/tgamma.hpp +++ b/stan/math/fwd/fun/tgamma.hpp @@ -3,8 +3,8 @@ #include #include +#include #include -#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/to_fvar.hpp b/stan/math/fwd/fun/to_fvar.hpp index 103936b148b..3c4c9226e09 100644 --- a/stan/math/fwd/fun/to_fvar.hpp +++ b/stan/math/fwd/fun/to_fvar.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_FWD_FUN_TO_FVAR_HPP #define STAN_MATH_FWD_FUN_TO_FVAR_HPP -#include #include #include #include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/trace_quad_form.hpp b/stan/math/fwd/fun/trace_quad_form.hpp index 5720ddc6734..f10a0dbc1c4 100644 --- a/stan/math/fwd/fun/trace_quad_form.hpp +++ b/stan/math/fwd/fun/trace_quad_form.hpp @@ -1,13 +1,13 @@ #ifndef STAN_MATH_FWD_FUN_TRACE_QUAD_FORM_HPP #define STAN_MATH_FWD_FUN_TRACE_QUAD_FORM_HPP -#include +#include #include -#include +#include +#include #include #include #include -#include namespace stan { namespace math { @@ -20,7 +20,7 @@ inline return_type_t trace_quad_form(const EigMat1& A, check_square("trace_quad_form", "A", A); check_multiplicable("trace_quad_form", "A", A, "B", B); const auto& B_ref = to_ref(B); - return B_ref.cwiseProduct(multiply(A, B_ref)).sum(); + return sum(B_ref.cwiseProduct(multiply(A, B_ref))); } } // namespace math diff --git a/stan/math/fwd/fun/trigamma.hpp b/stan/math/fwd/fun/trigamma.hpp index 3f60c14a9f5..b1a4f6dea2d 100644 --- a/stan/math/fwd/fun/trigamma.hpp +++ b/stan/math/fwd/fun/trigamma.hpp @@ -3,6 +3,10 @@ #include #include +#include +#include +#include +#include #include namespace stan { diff --git a/stan/math/fwd/fun/value_of.hpp b/stan/math/fwd/fun/value_of.hpp index e8ad84e0f67..ad3b68f19dc 100644 --- a/stan/math/fwd/fun/value_of.hpp +++ b/stan/math/fwd/fun/value_of.hpp @@ -3,7 +3,7 @@ #include #include - +#include namespace stan { namespace math { diff --git a/stan/math/fwd/fun/value_of_rec.hpp b/stan/math/fwd/fun/value_of_rec.hpp index 811836c57ff..27c297b8fa7 100644 --- a/stan/math/fwd/fun/value_of_rec.hpp +++ b/stan/math/fwd/fun/value_of_rec.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_FWD_FUN_VALUE_OF_REC_HPP #define STAN_MATH_FWD_FUN_VALUE_OF_REC_HPP -#include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/mix/fun/typedefs.hpp b/stan/math/mix/fun/typedefs.hpp index ddf7ea5d793..a03fd87f3eb 100644 --- a/stan/math/mix/fun/typedefs.hpp +++ b/stan/math/mix/fun/typedefs.hpp @@ -2,8 +2,8 @@ #define STAN_MATH_MIX_MAT_FUN_TYPEDEFS_HPP #include -#include #include +#include #include namespace stan { diff --git a/stan/math/mix/functor/derivative.hpp b/stan/math/mix/functor/derivative.hpp index 868d1591716..478063fe82b 100644 --- a/stan/math/mix/functor/derivative.hpp +++ b/stan/math/mix/functor/derivative.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP #define STAN_MATH_MIX_FUNCTOR_DERIVATIVE_HPP +#include #include #include -#include #include namespace stan { diff --git a/stan/math/mix/functor/finite_diff_grad_hessian_auto.hpp b/stan/math/mix/functor/finite_diff_grad_hessian_auto.hpp index 108b059149c..8c38ed5477f 100644 --- a/stan/math/mix/functor/finite_diff_grad_hessian_auto.hpp +++ b/stan/math/mix/functor/finite_diff_grad_hessian_auto.hpp @@ -2,9 +2,9 @@ #define STAN_MATH_MIX_FUNCTOR_FINITE_DIFF_GRAD_HESSIAN_AUTO_HPP #include -#include #include #include +#include #include namespace stan { diff --git a/stan/math/mix/functor/grad_hessian.hpp b/stan/math/mix/functor/grad_hessian.hpp index 9fcf47ba1f6..d8abb272feb 100644 --- a/stan/math/mix/functor/grad_hessian.hpp +++ b/stan/math/mix/functor/grad_hessian.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_GRAD_HESSIAN_HPP #define STAN_MATH_MIX_FUNCTOR_GRAD_HESSIAN_HPP +#include #include #include -#include #include #include diff --git a/stan/math/mix/functor/grad_tr_mat_times_hessian.hpp b/stan/math/mix/functor/grad_tr_mat_times_hessian.hpp index 1463a21e150..c8f72b98a00 100644 --- a/stan/math/mix/functor/grad_tr_mat_times_hessian.hpp +++ b/stan/math/mix/functor/grad_tr_mat_times_hessian.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_MIX_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP #define STAN_MATH_MIX_FUNCTOR_GRAD_TR_MAT_TIMES_HESSIAN_HPP +#include +#include #include #include -#include -#include #include #include diff --git a/stan/math/mix/functor/gradient_dot_vector.hpp b/stan/math/mix/functor/gradient_dot_vector.hpp index 99124607053..b664effd19b 100644 --- a/stan/math/mix/functor/gradient_dot_vector.hpp +++ b/stan/math/mix/functor/gradient_dot_vector.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_GRADIENT_DOT_VECTOR_HPP #define STAN_MATH_MIX_FUNCTOR_GRADIENT_DOT_VECTOR_HPP +#include #include #include -#include #include namespace stan { diff --git a/stan/math/mix/functor/hessian.hpp b/stan/math/mix/functor/hessian.hpp index d885d49e224..601444384ea 100644 --- a/stan/math/mix/functor/hessian.hpp +++ b/stan/math/mix/functor/hessian.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_HESSIAN_HPP #define STAN_MATH_MIX_FUNCTOR_HESSIAN_HPP +#include #include #include -#include #include namespace stan { diff --git a/stan/math/mix/functor/hessian_times_vector.hpp b/stan/math/mix/functor/hessian_times_vector.hpp index ebcc0f3933f..5d3bf9fb567 100644 --- a/stan/math/mix/functor/hessian_times_vector.hpp +++ b/stan/math/mix/functor/hessian_times_vector.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP #define STAN_MATH_MIX_FUNCTOR_HESSIAN_TIMES_VECTOR_HPP +#include #include #include -#include #include #include diff --git a/stan/math/mix/functor/partial_derivative.hpp b/stan/math/mix/functor/partial_derivative.hpp index 8cec018dca3..dfa428c2185 100644 --- a/stan/math/mix/functor/partial_derivative.hpp +++ b/stan/math/mix/functor/partial_derivative.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_MIX_FUNCTOR_PARTIAL_DERIVATIVE_HPP #define STAN_MATH_MIX_FUNCTOR_PARTIAL_DERIVATIVE_HPP +#include #include #include -#include #include namespace stan { diff --git a/stan/math/mix/meta.hpp b/stan/math/mix/meta.hpp index 3ca1e63ce70..f0622433c71 100644 --- a/stan/math/mix/meta.hpp +++ b/stan/math/mix/meta.hpp @@ -3,16 +3,16 @@ #include -#include -#include -#include - #include #include #include +#include + +#include +#include +#include #include -#include #include #endif diff --git a/stan/math/prim/fun/abs.hpp b/stan/math/prim/fun/abs.hpp index 317fd6a846d..fca073133ec 100644 --- a/stan/math/prim/fun/abs.hpp +++ b/stan/math/prim/fun/abs.hpp @@ -34,9 +34,9 @@ inline T abs(T x) { * @param x argument * @return absolute value of argument (a real number) */ -template * = nullptr> +template * = nullptr> inline auto abs(T x) { - return hypot(x.real(), x.imag()); + return std::hypot(x.real(), x.imag()); } /** @@ -62,10 +62,7 @@ struct abs_fun { * @param x argument * @return Absolute value of each variable in the container. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_not_stan_scalar_t* = nullptr> +template * = nullptr> inline auto abs(const Container& x) { return apply_scalar_unary::apply(x); } @@ -79,7 +76,7 @@ inline auto abs(const Container& x) { * @return Absolute value of each variable in the container. */ template * = nullptr> + require_container_bt* = nullptr> inline auto abs(const Container& x) { return apply_vector_unary::apply( x, [&](const auto& v) { return v.array().abs(); }); diff --git a/stan/math/prim/fun/acos.hpp b/stan/math/prim/fun/acos.hpp index 1dd3c348b84..1efa76b5174 100644 --- a/stan/math/prim/fun/acos.hpp +++ b/stan/math/prim/fun/acos.hpp @@ -18,6 +18,30 @@ namespace stan { namespace math { +/** + * Return the arc cosine of the arithmetic argument. + * + * @tparam V An `Arithmetic` argument + * @param[in] x argument + * @return arc cosine of the argument + */ +template * = nullptr> +inline auto acos(const T x) { + return std::acos(x); +} + +/** + * Return the arc cosine of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return arc cosine of the argument + */ +template * = nullptr> +inline auto acos(const T x) { + return std::acos(x); +} + /** * Structure to wrap `acos()` so it can be vectorized. * @@ -28,7 +52,6 @@ namespace math { struct acos_fun { template static inline auto fun(const T& x) { - using std::acos; return acos(x); } }; @@ -41,11 +64,7 @@ struct acos_fun { * @param x argument * @return Arc cosine of each variable in the container, in radians. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto acos(const Container& x) { return apply_scalar_unary::apply(x); } @@ -59,7 +78,7 @@ inline auto acos(const Container& x) { * @return Arc cosine of each variable in the container, in radians. */ template * = nullptr> + require_container_bt* = nullptr> inline auto acos(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().acos(); }); diff --git a/stan/math/prim/fun/acosh.hpp b/stan/math/prim/fun/acosh.hpp index 2869fc842b7..5580e9e1e73 100644 --- a/stan/math/prim/fun/acosh.hpp +++ b/stan/math/prim/fun/acosh.hpp @@ -19,11 +19,12 @@ namespace math { * Return the inverse hyperbolic cosine of the specified value. * Returns nan for nan argument. * - * @param[in] x Argument. + * @param[in] x `Arithmetic` Argument. * @return Inverse hyperbolic cosine of the argument. * @throw std::domain_error If argument is less than 1. */ -inline double acosh(double x) { +template * = nullptr> +inline double acosh(const T x) { if (is_nan(x)) { return x; } else { @@ -37,23 +38,16 @@ inline double acosh(double x) { } /** - * Integer version of acosh. + * Return the inverse hyperbolic cosine of the specified value. + * Returns nan for nan argument. * - * @param[in] x Argument. + * @param[in] x `complex` Argument. * @return Inverse hyperbolic cosine of the argument. * @throw std::domain_error If argument is less than 1. */ -inline double acosh(int x) { - if (is_nan(x)) { - return x; - } else { - check_greater_or_equal("acosh", "x", x, 1); -#ifdef _WIN32 - if (is_inf(x)) - return x; -#endif - return std::acosh(x); - } +template * = nullptr> +inline auto acosh(const T x) { + return std::acosh(x); } /** @@ -83,13 +77,27 @@ struct acosh_fun { * @param x container * @return Elementwise acosh of members of container. */ -template < - typename T, require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto acosh(const T& x) { return apply_scalar_unary::apply(x); } +/** + * Return the elementwise application of acosh() to + * specified argument container. The return type promotes the + * underlying scalar argument type to double if it is an integer, + * and otherwise is the argument type. + * + * @tparam T type of container + * @param x container + * @return Elementwise acosh of members of container. + */ +template * = nullptr> +inline auto acosh(const Container& x) { + return apply_scalar_unary::apply(x); +} + namespace internal { /** diff --git a/stan/math/prim/fun/arg.hpp b/stan/math/prim/fun/arg.hpp index 718aa48ee10..cf0e79fa12b 100644 --- a/stan/math/prim/fun/arg.hpp +++ b/stan/math/prim/fun/arg.hpp @@ -1,6 +1,7 @@ #ifndef STAN_MATH_PRIM_FUN_ARG_HPP #define STAN_MATH_PRIM_FUN_ARG_HPP +#include #include #include @@ -13,7 +14,7 @@ namespace math { * @param[in] z argument * @return phase angle of the argument */ -template +template * = nullptr> inline V arg(const std::complex& z) { return std::arg(z); } @@ -28,7 +29,6 @@ namespace internal { */ template inline V complex_arg(const std::complex& z) { - using std::atan2; return atan2(z.imag(), z.real()); } } // namespace internal diff --git a/stan/math/prim/fun/asin.hpp b/stan/math/prim/fun/asin.hpp index e34afb1f1c0..f620a24d2af 100644 --- a/stan/math/prim/fun/asin.hpp +++ b/stan/math/prim/fun/asin.hpp @@ -16,6 +16,30 @@ namespace stan { namespace math { +/** + * Return the arc sine of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return arc sine of the argument + */ +template * = nullptr> +inline auto asin(const T x) { + return std::asin(x); +} + +/** + * Return the arc sine of the complex argument. + * + * @tparam V `complex argument + * @param[in] x argument + * @return arc sine of the argument + */ +template * = nullptr> +inline auto asin(const T x) { + return std::asin(x); +} + /** * Structure to wrap `asin()` so it can be vectorized. * @@ -26,7 +50,6 @@ namespace math { struct asin_fun { template static inline auto fun(const T& x) { - using std::asin; return asin(x); } }; @@ -39,11 +62,7 @@ struct asin_fun { * @param x container * @return Arcsine of each variable in the container, in radians. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto asin(const Container& x) { return apply_scalar_unary::apply(x); } @@ -57,7 +76,7 @@ inline auto asin(const Container& x) { * @return Arcsine of each variable in the container, in radians. */ template * = nullptr> + require_container_bt* = nullptr> inline auto asin(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().asin(); }); diff --git a/stan/math/prim/fun/asinh.hpp b/stan/math/prim/fun/asinh.hpp index cc8d0d02543..ab72065efae 100644 --- a/stan/math/prim/fun/asinh.hpp +++ b/stan/math/prim/fun/asinh.hpp @@ -19,6 +19,29 @@ namespace stan { namespace math { +/** + * Return the hyperbolic arc sine of the arithmetic argument. + * + * @tparam V An arithmetic type + * @param[in] x argument + * @return hyperbolic arc sine of the argument + */ +template * = nullptr> +inline auto asinh(const T x) { + return std::asinh(x); +} + +/** + * Return the hyperbolic arc sine of the complex argument. + * + * @tparam V a complex type with inner arithmetic type. + * @param[in] x argument + * @return hyperbolic arc sine of the argument + */ +template * = nullptr> +inline auto asinh(const T x) { + return std::asinh(x); +} /** * Structure to wrap `asinh()` so it can be vectorized. @@ -30,7 +53,6 @@ namespace math { struct asinh_fun { template static inline auto fun(const T& x) { - using std::asinh; return asinh(x); } }; @@ -43,13 +65,25 @@ struct asinh_fun { * @param x container * @return Inverse hyperbolic sine of each value in the container. */ -template < - typename T, require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto asinh(const T& x) { return apply_scalar_unary::apply(x); } +/** + * Returns the elementwise `asinh()` of the input, + * which may be a scalar or any Stan container of numeric scalars. + * + * @tparam T type of container + * @param x container + * @return Inverse hyperbolic sine of each value in the container. + */ +template * = nullptr> +inline auto asinh(const Container& x) { + return apply_scalar_unary::apply(x); +} + namespace internal { /** * Return the hyperbolic arc sine of the complex argument. diff --git a/stan/math/prim/fun/atan.hpp b/stan/math/prim/fun/atan.hpp index 3adc5cb14c8..9e7099b7d43 100644 --- a/stan/math/prim/fun/atan.hpp +++ b/stan/math/prim/fun/atan.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_PRIM_FUN_ATAN_HPP #define STAN_MATH_PRIM_FUN_ATAN_HPP +#include #include #include #include -#include #include #include #include @@ -14,6 +14,30 @@ namespace stan { namespace math { +/** + * Return the arc tangent of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return arc tangent of the argument + */ +template * = nullptr> +inline auto atan(const T x) { + return std::atan(x); +} + +/** + * Return the arc tangent of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return arc tangent of the argument + */ +template * = nullptr> +inline auto atan(const T x) { + return std::atan(x); +} + /** * Structure to wrap \c atan() so it can be vectorized. * @@ -24,7 +48,6 @@ namespace math { struct atan_fun { template static inline auto fun(const T& x) { - using std::atan; return atan(x); } }; @@ -37,11 +60,7 @@ struct atan_fun { * @param x container * @return Arctan of each value in x, in radians. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto atan(const Container& x) { return apply_scalar_unary::apply(x); } @@ -55,7 +74,7 @@ inline auto atan(const Container& x) { * @return Elementwise atan of members of container. */ template * = nullptr> + require_container_bt* = nullptr> inline auto atan(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().atan(); }); diff --git a/stan/math/prim/fun/atanh.hpp b/stan/math/prim/fun/atanh.hpp index 0aad7199435..fdf6c4df9b5 100644 --- a/stan/math/prim/fun/atanh.hpp +++ b/stan/math/prim/fun/atanh.hpp @@ -20,11 +20,12 @@ namespace math { * returns infinity. * Returns nan for nan argument. * - * @param[in] x Argument. + * @param[in] x `Arithmetic` Argument. * @return Inverse hyperbolic tangent of the argument. * @throw std::domain_error If argument is not in [-1, 1]. */ -inline double atanh(double x) { +template * = nullptr> +inline double atanh(const T x) { if (is_nan(x)) { return x; } else { @@ -34,14 +35,17 @@ inline double atanh(double x) { } /** - * Integer version of atanh. + * Return the inverse hyperbolic tangent of the specified value. + * An argument of -1 returns negative infinity and an argument of 1 + * returns infinity. + * Returns nan for nan argument. * - * @param[in] x Argument. + * @param[in] x `complex` Argument. * @return Inverse hyperbolic tangent of the argument. - * @throw std::domain_error If argument is less than 1. + * @throw std::domain_error If argument is not in [-1, 1]. */ -inline double atanh(int x) { - check_bounded("atanh", "x", x, -1, 1); +template * = nullptr> +inline auto atanh(const T x) { return std::atanh(x); } @@ -72,13 +76,27 @@ struct atanh_fun { * @param x container * @return Elementwise atanh of members of container. */ -template < - typename T, require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto atanh(const T& x) { return apply_scalar_unary::apply(x); } +/** + * Return the elementwise application of atanh() to + * specified argument container. The return type promotes the + * underlying scalar argument type to double if it is an integer, + * and otherwise is the argument type. + * + * @tparam T type of container + * @param x container + * @return Elementwise atanh of members of container. + */ +template * = nullptr> +inline auto atanh(const Container& x) { + return apply_scalar_unary::apply(x); +} + namespace internal { /** * Return the hyperbolic arc tangent of the complex argument. diff --git a/stan/math/prim/fun/conj.hpp b/stan/math/prim/fun/conj.hpp index 49a569e757c..ebb9ac28222 100644 --- a/stan/math/prim/fun/conj.hpp +++ b/stan/math/prim/fun/conj.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_FUN_CONJ_HPP #define STAN_MATH_PRIM_FUN_CONJ_HPP -#include #include +#include namespace stan { namespace math { @@ -14,21 +14,38 @@ namespace math { * @param[in] z argument * @return complex conjugate of the argument */ -template -inline std::complex conj(const std::complex& z) { +template * = nullptr> +inline auto conj(const V& z) { return std::conj(z); } +/** + * Return the complex conjugate the complex argument. + * + * @tparam V value type of argument + * @param[in] z argument + * @return complex conjugate of the argument + */ +template * = nullptr> +inline V conj(const V& z) { + return {z.real(), -z.imag()}; +} + /** * Return the complex conjugate the Eigen object. * - * @tparam Eig A type derived from `Eigen::EigenBase` + * @tparam Eig A type derived from `Eigen::EigenBase` with an inner complex + * autodiff type. * @param[in] z argument * @return complex conjugate of the argument */ template * = nullptr> -inline auto conj(const Eig& z) { - return z.conjugate(); +inline auto conj(Eig&& z) { + return make_holder( + [](auto&& z_inner) { + return z_inner.unaryExpr([](auto&& z_i) { return conj(z_i); }); + }, + std::forward(z)); } /** @@ -40,25 +57,14 @@ inline auto conj(const Eig& z) { */ template * = nullptr> inline auto conj(const StdVec& z) { - promote_scalar_t, StdVec> result(z.size()); - std::transform(z.begin(), z.end(), result.begin(), - [](auto&& x) { return stan::math::conj(x); }); + const auto z_size = z.size(); + promote_scalar_t, StdVec> result(z_size); + for (std::size_t i = 0; i < z_size; ++i) { + result[i] = conj(z[i]); + } return result; } -namespace internal { -/** - * Return the complex conjugate the complex argument. - * - * @tparam V value type of argument - * @param[in] z argument - * @return complex conjugate of the argument - */ -template -inline std::complex complex_conj(const std::complex& z) { - return {z.real(), -z.imag()}; -} -} // namespace internal } // namespace math } // namespace stan diff --git a/stan/math/prim/fun/cos.hpp b/stan/math/prim/fun/cos.hpp index 33046c6d180..0a3b044ccdc 100644 --- a/stan/math/prim/fun/cos.hpp +++ b/stan/math/prim/fun/cos.hpp @@ -13,6 +13,30 @@ namespace stan { namespace math { +/** + * Return the cosine of the arithmetic argument. + * + * @tparam T An arithmetic argument + * @param[in] x argument + * @return cosine of the argument + */ +template * = nullptr> +inline auto cos(const T x) { + return std::cos(x); +} + +/** + * Return the cosine of the complex argument. + * + * @tparam T `complex` argument + * @param[in] x argument + * @return cosine of the argument + */ +template * = nullptr> +inline auto cos(const T x) { + return std::cos(x); +} + /** * Structure to wrap `cos()` so it can be vectorized. * @@ -23,7 +47,6 @@ namespace math { struct cos_fun { template static inline auto fun(const T& x) { - using std::cos; return cos(x); } }; @@ -36,11 +59,7 @@ struct cos_fun { * @param x angles in radians * @return Cosine of each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto cos(const Container& x) { return apply_scalar_unary::apply(x); } @@ -54,7 +73,7 @@ inline auto cos(const Container& x) { * @return Cosine of each value in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto cos(const Container& x) { return apply_vector_unary::apply( x, [&](const auto& v) { return v.array().cos(); }); diff --git a/stan/math/prim/fun/cosh.hpp b/stan/math/prim/fun/cosh.hpp index 62f76a21fbc..ae60c233a68 100644 --- a/stan/math/prim/fun/cosh.hpp +++ b/stan/math/prim/fun/cosh.hpp @@ -12,6 +12,30 @@ namespace stan { namespace math { +/** + * Return the hyperbolic cosine of the arithmetic argument. + * + * @tparam V An arithmetic type + * @param[in] x argument + * @return hyperbolic cosine of the argument + */ +template * = nullptr> +inline auto cosh(const T x) { + return std::cosh(x); +} + +/** + * Return the hyperbolic cosine of the complex argument. + * + * @tparam V `complex` type of argument + * @param[in] x argument + * @return hyperbolic cosine of the argument + */ +template * = nullptr> +inline auto cosh(const T x) { + return std::cosh(x); +} + /** * Structure to wrap `cosh()` so it can be vectorized. * @@ -22,7 +46,6 @@ namespace math { struct cosh_fun { template static inline auto fun(const T& x) { - using std::cosh; return cosh(x); } }; @@ -35,11 +58,7 @@ struct cosh_fun { * @param x angles in radians * @return Hyberbolic cosine of x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto cosh(const Container& x) { return apply_scalar_unary::apply(x); } @@ -53,7 +72,7 @@ inline auto cosh(const Container& x) { * @return Hyberbolic cosine of x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto cosh(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().cosh(); }); diff --git a/stan/math/prim/fun/exp.hpp b/stan/math/prim/fun/exp.hpp index eed21f36914..d12d82cb556 100644 --- a/stan/math/prim/fun/exp.hpp +++ b/stan/math/prim/fun/exp.hpp @@ -11,6 +11,35 @@ namespace stan { namespace math { + +/** + * Return the natural (base e) exponentiation of the specified + * complex argument. + * + * @tparam V `Arithmetic` type + * @param x input + * @return natural exponentiation of specified number + */ +template * = nullptr> +inline auto exp(const T x) { + return std::exp(x); +} + +/** + * Return the natural (base e) complex exponentiation of the specified + * complex argument. + * + * @tparam V `complex` type + * @param x complex number + * @return natural exponentiation of specified complex number + * @see documentation for `std::complex` for boundary condition and + * branch cut details + */ +template * = nullptr> +inline auto exp(const T x) { + return std::exp(x); +} + /** * Structure to wrap `exp()` so that it can be * vectorized. @@ -25,7 +54,6 @@ struct exp_fun { */ template static inline auto fun(const T& x) { - using std::exp; return exp(x); } }; @@ -39,11 +67,7 @@ struct exp_fun { * @param[in] x container * @return Elementwise application of exponentiation to the argument. */ -template < - typename Container, - require_not_container_st* = nullptr, - require_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, - require_not_var_matrix_t* = nullptr> +template * = nullptr> inline auto exp(const Container& x) { return apply_scalar_unary::apply(x); } @@ -57,7 +81,7 @@ inline auto exp(const Container& x) { * @return Elementwise application of exponentiation to the argument. */ template * = nullptr> + require_container_bt* = nullptr> inline auto exp(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().exp(); }); diff --git a/stan/math/prim/fun/floor.hpp b/stan/math/prim/fun/floor.hpp index 6fd4cccc01c..3845bee34b2 100644 --- a/stan/math/prim/fun/floor.hpp +++ b/stan/math/prim/fun/floor.hpp @@ -10,6 +10,15 @@ namespace stan { namespace math { +template * = nullptr> +inline auto floor(const T x) { + return std::floor(x); +} + +template * = nullptr> +inline auto floor(const T x) { + return std::floor(x); +} /** * Structure to wrap `floor()` so that it can be vectorized. * @@ -20,7 +29,6 @@ namespace math { struct floor_fun { template static inline auto fun(const T& x) { - using std::floor; return floor(x); } }; @@ -33,11 +41,7 @@ struct floor_fun { * @param x container * @return Greatest integer <= each value in x. */ -template * = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr, - require_not_var_matrix_t* = nullptr> +template * = nullptr> inline auto floor(const Container& x) { return apply_scalar_unary::apply(x); } @@ -51,7 +55,7 @@ inline auto floor(const Container& x) { * @return Greatest integer <= each value in x. */ template * = nullptr, + require_container_bt* = nullptr, require_not_var_matrix_t* = nullptr> inline auto floor(const Container& x) { return apply_vector_unary::apply( diff --git a/stan/math/prim/fun/generalized_inverse.hpp b/stan/math/prim/fun/generalized_inverse.hpp index 9a4ef5a4447..fd03af80007 100644 --- a/stan/math/prim/fun/generalized_inverse.hpp +++ b/stan/math/prim/fun/generalized_inverse.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/prim/fun/gp_periodic_cov.hpp b/stan/math/prim/fun/gp_periodic_cov.hpp index c2dc72745d6..c0be5931535 100644 --- a/stan/math/prim/fun/gp_periodic_cov.hpp +++ b/stan/math/prim/fun/gp_periodic_cov.hpp @@ -46,8 +46,6 @@ inline typename Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> gp_periodic_cov(const std::vector &x, const T_sigma &sigma, const T_l &l, const T_p &p) { - using std::exp; - using std::sin; const char *fun = "gp_periodic_cov"; check_positive(fun, "signal standard deviation", sigma); check_positive(fun, "length-scale", l); @@ -126,8 +124,6 @@ inline typename Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> gp_periodic_cov(const std::vector &x1, const std::vector &x2, const T_sigma &sigma, const T_l &l, const T_p &p) { - using std::exp; - using std::sin; const char *fun = "gp_periodic_cov"; check_positive(fun, "signal standard deviation", sigma); check_positive(fun, "length-scale", l); diff --git a/stan/math/prim/fun/inv_cloglog.hpp b/stan/math/prim/fun/inv_cloglog.hpp index 669c2c41ef0..f197d49c24e 100644 --- a/stan/math/prim/fun/inv_cloglog.hpp +++ b/stan/math/prim/fun/inv_cloglog.hpp @@ -45,8 +45,26 @@ namespace math { * @param x Argument. * @return Inverse complementary log-log of the argument. */ -inline double inv_cloglog(double x) { - using std::exp; +template * = nullptr> +inline auto inv_cloglog(const T x) { + return 1. - std::exp(-std::exp(x)); +} + +/** + * The inverse complementary log-log function. + * + * The function is defined by + * + * inv_cloglog(x) = 1 - exp(-exp(x)). + * + * This function can be used to implement the inverse link + * function for complementary-log-log regression. + * + * @param x Argument. + * @return Inverse complementary log-log of the argument. + */ +template * = nullptr> +inline auto inv_cloglog(const T& x) { return 1. - exp(-exp(x)); } @@ -71,11 +89,7 @@ struct inv_cloglog_fun { * @param x container * @return 1 - exp(-exp()) applied to each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto inv_cloglog(const Container& x) { return apply_scalar_unary::apply(x); } @@ -89,7 +103,7 @@ inline auto inv_cloglog(const Container& x) { * @return 1 - exp(-exp()) applied to each value in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto inv_cloglog(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return 1 - (-v.array().exp()).exp(); }); diff --git a/stan/math/prim/fun/inv_sqrt.hpp b/stan/math/prim/fun/inv_sqrt.hpp index c4e58fcbedb..00fa616a45f 100644 --- a/stan/math/prim/fun/inv_sqrt.hpp +++ b/stan/math/prim/fun/inv_sqrt.hpp @@ -12,11 +12,16 @@ namespace stan { namespace math { -template * = nullptr> -inline auto inv_sqrt(T x) { - using std::sqrt; +template * = nullptr> +inline auto inv_sqrt(const T x) { + return inv(std::sqrt(x)); +} + +template * = nullptr> +inline auto inv_sqrt(const T x) { return inv(sqrt(x)); } + /** * Structure to wrap `1 / sqrt(x)` so that it can be vectorized. * @@ -39,12 +44,7 @@ struct inv_sqrt_fun { * @param x container * @return inverse square root of each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_not_stan_scalar_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto inv_sqrt(const Container& x) { return apply_scalar_unary::apply(x); } @@ -58,7 +58,7 @@ inline auto inv_sqrt(const Container& x) { * @return inverse square root each variable in the container. */ template * = nullptr, - require_container_st* = nullptr> + require_container_bt* = nullptr> inline auto inv_sqrt(const Container& x) { // Eigen 3.4.0 has precision issues on ARM64 with vectorised rsqrt // Resolved in current master branch, below can be removed on next release diff --git a/stan/math/prim/fun/log.hpp b/stan/math/prim/fun/log.hpp index 75a2dcd00b9..8216cee2aa6 100644 --- a/stan/math/prim/fun/log.hpp +++ b/stan/math/prim/fun/log.hpp @@ -16,6 +16,30 @@ namespace stan { namespace math { +/** + * Return the natural logarithm of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return natural logarithm of the argument + */ +template * = nullptr> +inline auto log(const T x) { + return std::log(x); +} + +/** + * Return the natural logarithm of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return natural logarithm of the argument + */ +template * = nullptr> +inline auto log(const T x) { + return std::log(x); +} + /** * Structure to wrap `log()` so that it can be vectorized. */ @@ -29,7 +53,6 @@ struct log_fun { */ template static inline auto fun(const T& x) { - using std::log; return log(x); } }; @@ -43,11 +66,7 @@ struct log_fun { * @param[in] x container * @return Elementwise application of natural log to the argument. */ -template < - typename Container, - require_not_container_st* = nullptr, - require_not_var_matrix_t* = nullptr, - require_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto log(const Container& x) { return apply_scalar_unary::apply(x); } @@ -61,7 +80,7 @@ inline auto log(const Container& x) { * @return Natural log of each variable in the container. */ template * = nullptr> + require_container_bt* = nullptr> inline auto log(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().log(); }); diff --git a/stan/math/prim/fun/log10.hpp b/stan/math/prim/fun/log10.hpp index 02e60664a29..f7d81343ea5 100644 --- a/stan/math/prim/fun/log10.hpp +++ b/stan/math/prim/fun/log10.hpp @@ -12,6 +12,30 @@ namespace stan { namespace math { +/** + * Return the base 10 logarithm of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return base 10 logarithm of the argument + */ +template * = nullptr> +inline auto log10(const T x) { + return std::log10(x); +} + +/** + * Return the base 10 logarithm of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return base 10 logarithm of the argument + */ +template * = nullptr> +inline auto log10(const T x) { + return std::log10(x); +} + /** * Structure to wrap log10() so it can be vectorized. * @@ -22,7 +46,6 @@ namespace math { struct log10_fun { template static inline auto fun(const T& x) { - using std::log10; return log10(x); } }; @@ -34,10 +57,7 @@ struct log10_fun { * @param x container * @return Log base-10 applied to each value in x. */ -template < - typename Container, require_not_var_matrix_t* = nullptr, - require_not_container_st* = nullptr, - require_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto log10(const Container& x) { return apply_scalar_unary::apply(x); } @@ -51,7 +71,7 @@ inline auto log10(const Container& x) { * @return Log base-10 of each variable in the container. */ template * = nullptr> + require_container_bt* = nullptr> inline auto log10(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().log10(); }); diff --git a/stan/math/prim/fun/logit.hpp b/stan/math/prim/fun/logit.hpp index e0b9715adf5..3f6f7ce7a8c 100644 --- a/stan/math/prim/fun/logit.hpp +++ b/stan/math/prim/fun/logit.hpp @@ -43,9 +43,9 @@ namespace math { * @param u argument * @return log odds of argument */ -inline double logit(double u) { - using std::log; - return log(u / (1 - u)); +template * = nullptr> +inline double logit(const T u) { + return std::log(u / (1 - u)); } /** @@ -54,7 +54,10 @@ inline double logit(double u) { * @param u argument * @return log odds of argument */ -inline double logit(int u) { return logit(static_cast(u)); } +template * = nullptr> +inline double logit(const T u) { + return logit(static_cast(u)); +} /** * Structure to wrap logit() so it can be vectorized. @@ -83,11 +86,7 @@ struct logit_fun { * @param x container * @return elementwise logit of container elements */ -template < - typename Container, - require_not_container_st* = nullptr, - require_not_var_matrix_t* = nullptr, - require_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto logit(const Container& x) { return apply_scalar_unary::apply(x); } @@ -104,7 +103,7 @@ inline auto logit(const Container& x) { * of scope */ template * = nullptr> + require_container_bt* = nullptr> inline auto logit(const Container& x) { return make_holder( [](const auto& v_ref) { diff --git a/stan/math/prim/fun/matrix_exp_2x2.hpp b/stan/math/prim/fun/matrix_exp_2x2.hpp index 7a2c0fd472b..8f020bf71c3 100644 --- a/stan/math/prim/fun/matrix_exp_2x2.hpp +++ b/stan/math/prim/fun/matrix_exp_2x2.hpp @@ -24,11 +24,6 @@ namespace math { template * = nullptr> Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> matrix_exp_2x2(const EigMat& A) { - using std::cosh; - using std::exp; - using std::sinh; - using std::sqrt; - using T = value_type_t; T a = A(0, 0), b = A(0, 1), c = A(1, 0), d = A(1, 1), delta; delta = sqrt(square(a - d) + 4 * b * c); diff --git a/stan/math/prim/fun/norm.hpp b/stan/math/prim/fun/norm.hpp index ba2afb2d71e..b006bf1ad4c 100644 --- a/stan/math/prim/fun/norm.hpp +++ b/stan/math/prim/fun/norm.hpp @@ -14,7 +14,7 @@ namespace math { * @param[in] z argument * @return squared magnitude of the argument */ -template +template * = nullptr> inline V norm(const std::complex& z) { return std::norm(z); } diff --git a/stan/math/prim/fun/polar.hpp b/stan/math/prim/fun/polar.hpp index 9ba15ee3aae..e894cc9d203 100644 --- a/stan/math/prim/fun/polar.hpp +++ b/stan/math/prim/fun/polar.hpp @@ -1,9 +1,10 @@ #ifndef STAN_MATH_PRIM_FUN_POLAR_HPP #define STAN_MATH_PRIM_FUN_POLAR_HPP +#include #include #include -#include +#include #include #include #include @@ -20,8 +21,6 @@ namespace internal { */ template inline complex_return_t complex_polar(const U& r, const V& theta) { - using std::cos; - using std::sin; if (!(r >= 0) || is_inf(theta)) { return {std::numeric_limits::quiet_NaN()}; } @@ -36,16 +35,8 @@ inline complex_return_t complex_polar(const U& r, const V& theta) { * @param[in] theta phase angle * @return complex number with magnitude and phase angle */ -inline std::complex polar(double r, double theta) { - return internal::complex_polar(r, theta); -} -inline std::complex polar(double r, int theta) { - return internal::complex_polar(r, static_cast(theta)); -} -inline std::complex polar(int r, double theta) { - return internal::complex_polar(static_cast(r), theta); -} -inline std::complex polar(int r, int theta) { +template * = nullptr> +inline std::complex polar(U r, V theta) { return internal::complex_polar(static_cast(r), static_cast(theta)); } diff --git a/stan/math/prim/fun/pow.hpp b/stan/math/prim/fun/pow.hpp index 95809bd8830..2cb708c7f5c 100644 --- a/stan/math/prim/fun/pow.hpp +++ b/stan/math/prim/fun/pow.hpp @@ -33,42 +33,73 @@ inline complex_return_t complex_pow(const U& x, const V& y) { * Return the first argument raised to the power of the second * argument. * - * @tparam T1 type of first argument - * @tparam T2 type of second argument + * @tparam T1 `complex` type + * @tparam T2 `complex` type * @param a first argument * @param b second argument * @return the first argument raised to the power of the second * argument. */ -template * = nullptr, - require_arithmetic_t* = nullptr> +template * = nullptr> inline auto pow(const std::complex& a, const std::complex& b) { return std::pow(a, b); } -template * = nullptr, - require_arithmetic_t* = nullptr> +/** + * Return the first argument raised to the power of the second + * argument. + * + * @tparam T1 `Arithmetic` type + * @tparam T2 `complex` type + * @param a first argument + * @param b second argument + * @return the first argument raised to the power of the second + * argument. + */ +template * = nullptr> inline auto pow(const T1& a, const std::complex& b) { return std::pow(a, b); } -template * = nullptr, - require_arithmetic_t* = nullptr> +/** + * Return the first argument raised to the power of the second + * argument. + * + * @tparam T1 `complex` type + * @tparam T2 `Arithmetic` type + * @param a first argument + * @param b second argument + * @return the first argument raised to the power of the second + * argument. + */ +template * = nullptr> inline auto pow(const std::complex& a, const T2& b) { return std::pow(a, b); } -template * = nullptr, - require_arithmetic_t* = nullptr> +/** + * Return the first argument raised to the power of the second + * argument. + * + * @tparam T1 `Arithmetic` type + * @tparam T2 `Arithmetic` type + * @param a first argument + * @param b second argument + * @return the first argument raised to the power of the second + * argument. + */ +template * = nullptr> inline auto pow(const T1& a, const T2& b) { return std::pow(a, b); } /** * Returns the elementwise raising of the first argument to the power of the - * second argument. + * second argument. One type must be a `Container` type. * - * @tparam T1 type of first argument - * @tparam T2 type of second argument + * @tparam T1 A `Container` type with a @ref base_type that is `Arithmetic` or + * an `Arithmetic` + * @tparam T1 A `Container` type with a @ref base_type that is `Arithmetic` or + * an `Arithmetic` * @param a first argument * @param b second argument * @return the elementwise raising of the first argument to the power of the @@ -79,6 +110,7 @@ template * = nullptr, require_all_arithmetic_t, base_type_t>* = nullptr> inline auto pow(const T1& a, const T2& b) { return apply_scalar_binary( + // Qualified pow since only Arithmetic types are accepted here a, b, [](const auto& c, const auto& d) { return stan::math::pow(c, d); }); } } // namespace math diff --git a/stan/math/prim/fun/proj.hpp b/stan/math/prim/fun/proj.hpp index 52c5dce6299..f731830edd5 100644 --- a/stan/math/prim/fun/proj.hpp +++ b/stan/math/prim/fun/proj.hpp @@ -15,7 +15,7 @@ namespace math { * @param[in] z argument * @return projection of the argument onto the Riemann sphere */ -template +template * = nullptr> inline std::complex proj(const std::complex& z) { return std::proj(z); } diff --git a/stan/math/prim/fun/sin.hpp b/stan/math/prim/fun/sin.hpp index b4b92206da9..a0145dd4c6b 100644 --- a/stan/math/prim/fun/sin.hpp +++ b/stan/math/prim/fun/sin.hpp @@ -13,6 +13,30 @@ namespace stan { namespace math { +/** + * Return the sine of the complex argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return sine of the argument + */ +template * = nullptr> +inline auto sin(const T x) { + return std::sin(x); +} + +/** + * Return the sine of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return sine of the argument + */ +template * = nullptr> +inline auto sin(const T x) { + return std::sin(x); +} + /** * Structure to wrap sin() so it can be vectorized. * @@ -23,7 +47,6 @@ namespace math { struct sin_fun { template static inline auto fun(const T& x) { - using std::sin; return sin(x); } }; @@ -35,10 +58,7 @@ struct sin_fun { * @param x angles in radians * @return Sine of each value in x. */ -template < - typename T, require_not_container_st* = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto sin(const T& x) { return apply_scalar_unary::apply(x); } @@ -52,7 +72,7 @@ inline auto sin(const T& x) { * @return Sine of each value in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto sin(const Container& x) { return apply_vector_unary::apply( x, [&](const auto& v) { return v.array().sin(); }); @@ -68,6 +88,7 @@ namespace internal { */ template inline std::complex complex_sin(const std::complex& z) { + using namespace stan::math; return neg_i_times(sinh(i_times(z))); } } // namespace internal diff --git a/stan/math/prim/fun/sinh.hpp b/stan/math/prim/fun/sinh.hpp index 35d917fdd8d..e3e55fa7477 100644 --- a/stan/math/prim/fun/sinh.hpp +++ b/stan/math/prim/fun/sinh.hpp @@ -11,6 +11,30 @@ namespace stan { namespace math { +/** + * Return the hyperbolic sine of the arithmetic argument. + * + * @tparam V An arithmetic argument + * @param[in] x argument + * @return hyperbolic sine of the argument + */ +template * = nullptr> +inline auto sinh(const T x) { + return std::sinh(x); +} + +/** + * Return the hyperbolic sine of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return hyperbolic sine of the argument + */ +template * = nullptr> +inline auto sinh(const T x) { + return std::sinh(x); +} + /** * Structure to wrap sinh() so that it can be vectorized. * @@ -21,7 +45,6 @@ namespace math { struct sinh_fun { template static inline auto fun(const T& x) { - using std::sinh; return sinh(x); } }; @@ -33,11 +56,7 @@ struct sinh_fun { * @param x container * @return Hyperbolic sine of each variable in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto sinh(const Container& x) { return apply_scalar_unary::apply(x); } @@ -51,7 +70,7 @@ inline auto sinh(const Container& x) { * @return Hyperbolic sine of each variable in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto sinh(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().sinh(); }); diff --git a/stan/math/prim/fun/sqrt.hpp b/stan/math/prim/fun/sqrt.hpp index 79c2f07aea0..3e1620d2a61 100644 --- a/stan/math/prim/fun/sqrt.hpp +++ b/stan/math/prim/fun/sqrt.hpp @@ -11,6 +11,30 @@ namespace stan { namespace math { +/** + * Return the square root of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return square root of the argument + */ +template * = nullptr> +inline auto sqrt(const T x) { + return std::sqrt(x); +} + +/** + * Return the square root of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return square root of the argument + */ +template * = nullptr> +inline auto sqrt(const T x) { + return std::sqrt(x); +} + /** * Structure to wrap `sqrt()` so that it can be vectorized. * @@ -21,7 +45,6 @@ namespace math { struct sqrt_fun { template static inline auto fun(const T& x) { - using std::sqrt; return sqrt(x); } }; @@ -33,11 +56,7 @@ struct sqrt_fun { * @param x container * @return Square root of each value in x. */ -template * = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr, - require_not_var_matrix_t* = nullptr> +template * = nullptr> inline auto sqrt(const Container& x) { return apply_scalar_unary::apply(x); } @@ -51,7 +70,7 @@ inline auto sqrt(const Container& x) { * @return Square root of each value in x. */ template * = nullptr, + require_container_bt* = nullptr, require_not_var_matrix_t* = nullptr> inline auto sqrt(const Container& x) { return apply_vector_unary::apply( diff --git a/stan/math/prim/fun/square.hpp b/stan/math/prim/fun/square.hpp index 2ac0105266c..cb14bd77c8b 100644 --- a/stan/math/prim/fun/square.hpp +++ b/stan/math/prim/fun/square.hpp @@ -23,7 +23,10 @@ namespace math { * @param x Input to square. * @return Square of input. */ -inline double square(double x) { return std::pow(x, 2); } +template * = nullptr> +inline double square(const T x) { + return std::pow(x, 2); +} /** * Structure to wrap square() so that it can be vectorized. @@ -46,11 +49,7 @@ struct square_fun { * @param x container * @return Each value in x squared. */ -template < - typename Container, require_not_stan_scalar_t* = nullptr, - require_not_container_st* = nullptr, - require_not_var_matrix_t* = nullptr, - require_not_nonscalar_prim_or_rev_kernel_expression_t* = nullptr> +template * = nullptr> inline auto square(const Container& x) { return apply_scalar_unary::apply(x); } @@ -64,7 +63,7 @@ inline auto square(const Container& x) { * @return Each value in x squared. */ template * = nullptr> + require_container_bt* = nullptr> inline auto square(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().square(); }); diff --git a/stan/math/prim/fun/tan.hpp b/stan/math/prim/fun/tan.hpp index a0f63790105..373672eb0c8 100644 --- a/stan/math/prim/fun/tan.hpp +++ b/stan/math/prim/fun/tan.hpp @@ -13,6 +13,30 @@ namespace stan { namespace math { +/** + * Return the tangent of the arithmetic argument. + * + * @tparam V value type of argument + * @param[in] x argument + * @return tangent of the argument + */ +template * = nullptr> +inline auto tan(const T x) { + return std::tan(x); +} + +/** + * Return the tangent of the complex argument. + * + * @tparam V `complex argument + * @param[in] x argument + * @return tangent of the argument + */ +template * = nullptr> +inline auto tan(const T x) { + return std::tan(x); +} + /** * Structure to wrap `tan()` so that it can be vectorized. * @@ -23,7 +47,6 @@ namespace math { struct tan_fun { template static inline auto fun(const T& x) { - using std::tan; return tan(x); } }; @@ -35,11 +58,7 @@ struct tan_fun { * @param x angles in radians * @return Tangent of each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto tan(const Container& x) { return apply_scalar_unary::apply(x); } @@ -53,7 +72,7 @@ inline auto tan(const Container& x) { * @return Tangent of each value in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto tan(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().tan(); }); diff --git a/stan/math/prim/fun/tanh.hpp b/stan/math/prim/fun/tanh.hpp index 197f1e581f0..1ae3faff087 100644 --- a/stan/math/prim/fun/tanh.hpp +++ b/stan/math/prim/fun/tanh.hpp @@ -13,6 +13,30 @@ namespace stan { namespace math { +/** + * Return the hyperbolic tangent of the arithmetic argument. + * + * @tparam V `Arithmetic` argument + * @param[in] x argument + * @return hyperbolic tangent of the argument + */ +template * = nullptr> +inline auto tanh(const T x) { + return std::tanh(x); +} + +/** + * Return the hyperbolic tangent of the complex argument. + * + * @tparam V `complex` argument + * @param[in] x argument + * @return hyperbolic tangent of the argument + */ +template * = nullptr> +inline auto tanh(const T x) { + return std::tanh(x); +} + /** * Structure to wrap `tanh()` so that it can be vectorized. * @@ -23,7 +47,6 @@ namespace math { struct tanh_fun { template static inline auto fun(const T& x) { - using std::tanh; return tanh(x); } }; @@ -35,11 +58,7 @@ struct tanh_fun { * @param x angles in radians * @return Hyperbolic tangent of each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr, - require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - Container>* = nullptr> +template * = nullptr> inline auto tanh(const Container& x) { return apply_scalar_unary::apply(x); } @@ -53,7 +72,7 @@ inline auto tanh(const Container& x) { * @return Hyperbolic tangent of each value in x. */ template * = nullptr> + require_container_bt* = nullptr> inline auto tanh(const Container& x) { return apply_vector_unary::apply( x, [](const auto& v) { return v.array().tanh(); }); @@ -69,7 +88,6 @@ namespace internal { */ template inline std::complex complex_tanh(const std::complex& z) { - using std::exp; auto exp_z = exp(z); auto exp_neg_z = exp(-z); return stan::math::internal::complex_divide(exp_z - exp_neg_z, diff --git a/stan/math/prim/fun/trigamma.hpp b/stan/math/prim/fun/trigamma.hpp index 1121f64f94f..9a30daab99b 100644 --- a/stan/math/prim/fun/trigamma.hpp +++ b/stan/math/prim/fun/trigamma.hpp @@ -35,9 +35,6 @@ namespace math { */ template inline T trigamma_impl(const T& x) { - using std::floor; - using std::sin; - double small = 0.0001; double large = 5.0; T value; diff --git a/stan/math/prim/meta.hpp b/stan/math/prim/meta.hpp index 68d89d34ba5..445816ca69a 100644 --- a/stan/math/prim/meta.hpp +++ b/stan/math/prim/meta.hpp @@ -110,6 +110,7 @@ #include #include #include +#include #include #include #include diff --git a/stan/math/prim/meta/base_type.hpp b/stan/math/prim/meta/base_type.hpp index 80cebb44cb0..26f52e875f5 100644 --- a/stan/math/prim/meta/base_type.hpp +++ b/stan/math/prim/meta/base_type.hpp @@ -2,7 +2,6 @@ #define STAN_MATH_PRIM_META_BASE_TYPE_HPP #include -#include #include #include #include @@ -53,17 +52,5 @@ struct base_type::value>> { using type = base_type_t::Scalar>; }; -/** - * Template metaprogram defining the base type for values - * stored in a complex number. - * - * @tparam T type of complex number - * @ingroup type_trait - */ -template -struct base_type::value>> { - using type = base_type_t::value_type>; -}; - } // namespace stan #endif diff --git a/stan/math/prim/meta/is_complex.hpp b/stan/math/prim/meta/is_complex.hpp index 3d76b1b16ac..2ccbbc97d8d 100644 --- a/stan/math/prim/meta/is_complex.hpp +++ b/stan/math/prim/meta/is_complex.hpp @@ -1,6 +1,9 @@ #ifndef STAN_MATH_PRIM_META_IS_COMPLEX_HPP #define STAN_MATH_PRIM_META_IS_COMPLEX_HPP +#include +#include +#include #include #include #include @@ -27,7 +30,7 @@ struct is_complex_impl> : std::true_type {}; } // namespace internal /** - * If `T` is an arithmetic type (that is, an instance of + * If `T` is a complex type (that is, an instance of * `std::complex`) or a cv-qualified version thereof, provides the * member constant `value` equal `true`; for any other type the value is * `false`. @@ -55,6 +58,55 @@ struct scalar_type::value>> { using type = std::complex::value_type>; }; +/** + * Template metaprogram defining the base type for values + * stored in a complex number. + * + * @tparam T type of complex number + * @ingroup type_trait + */ +template +struct base_type::value>> { + using type = base_type_t::value_type>; +}; + +/** + * If `T` is a complex type with an inner arithmetic type (that is, an instance + * of `std::complex`) or a cv-qualified version thereof, provides + * the member constant `value` equal `true`; for any other type the value is + * `false`. + * + * @tparam T type to check + * @ingroup type_trait + */ +template +struct is_complex_arithmetic : std::false_type {}; + +template +struct is_complex_arithmetic< + T, std::enable_if_t>, + internal::is_complex_impl>>::value>> + : std::true_type {}; + +/** + * If `T` is a complex type with an inner autodiff type (that is, an instance of + * `std::complex` or `std::complex>`) or a cv-qualified version + * thereof, provides the member constant `value` equal `true`; for any other + * type the value is `false`. + * + * @tparam T type to check + * @ingroup type_trait + */ +template +struct is_complex_ad : std::false_type {}; + +template +struct is_complex_ad>, + internal::is_complex_impl>>::value>> + : std::true_type {}; + /*! \ingroup require_stan_scalar_complex */ /*! \defgroup complex_types complex */ /*! \addtogroup complex_types */ @@ -107,6 +159,16 @@ using require_not_vt_complex template using require_not_st_complex = require_not_t>>>; + +/*! \brief Require type satisfies @ref is_eigen */ +/*! and scalar type satisfies `TypeCheck` */ +/*! @tparam TypeCheck The type trait to check the scalar type against */ +/*! @tparam Check The type to test @ref is_eigen for and whose @ref scalar_type + * is checked with `TypeCheck` */ +template