Skip to content

fix apply_scalar_unary and abs so that abs(complex<T>) return T #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stan/math/mix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include <stan/math/mix/fun.hpp>
#include <stan/math/mix/functor.hpp>

#ifdef STAN_OPENCL
#include <stan/math/opencl/rev.hpp>
#endif

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/meta.hpp>
#include <stan/math/fwd/fun.hpp>
#include <stan/math/fwd/functor.hpp>

#ifdef STAN_OPENCL
#include <stan/math/opencl/rev.hpp>
#endif

#include <stan/math/rev/core.hpp>
#include <stan/math/rev/meta.hpp>
#include <stan/math/rev/fun.hpp>
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inline double Phi(double x) {
*/
struct Phi_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return Phi(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/Phi_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Phi_approx_fun {
* @return approximate value of Phi applied to argument
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return Phi_approx(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inline auto abs(T x) {
*/
struct abs_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return abs(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/acos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace math {
*/
struct acos_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::acos;
return acos(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct acosh_fun {
* @return Inverse hyperbolic cosine of the argument.
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return acosh(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/asin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace math {
*/
struct asin_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::asin;
return asin(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace math {
*/
struct asinh_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::asinh;
return asinh(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/atan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace math {
*/
struct atan_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::atan;
return atan(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct atanh_fun {
* @return Inverse hyperbolic tangent of the argument.
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return atanh(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/cbrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace math {
*/
struct cbrt_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::cbrt;
return cbrt(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace math {
*/
struct ceil_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::ceil;
return ceil(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace math {
*/
struct cos_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::cos;
return cos(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/cosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace math {
*/
struct cosh_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::cosh;
return cosh(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/digamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ inline double digamma(double x) {
*/
struct digamma_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return digamma(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/erf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace math {
*/
struct erf_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::erf;
return erf(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/erfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace math {
*/
struct erfc_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::erfc;
return erfc(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct exp_fun {
* @return Exponential of argument.
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::exp;
return exp(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/exp2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct exp2_fun {
* @return Base two exponent of the argument.
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::exp2;
return exp2(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/expm1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace math {
*/
struct expm1_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::expm1;
return expm1(x);
}
Expand Down
6 changes: 3 additions & 3 deletions stan/math/prim/fun/fabs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace stan {
namespace math {

template <typename T, require_arithmetic_t<T>* = nullptr>
auto fabs(T x) {
inline auto fabs(T x) {
return std::abs(x);
}

template <typename T, require_complex_t<T>* = nullptr>
auto fabs(T x) {
inline auto fabs(T x) {
return hypot(x.real(), x.imag());
}

Expand All @@ -29,7 +29,7 @@ auto fabs(T x) {
*/
struct fabs_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return fabs(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace math {
*/
struct floor_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::floor;
return floor(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/inv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace math {
*/
struct inv_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return 1.0 / x;
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/inv_Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ inline double inv_Phi(double p) {
*/
struct inv_Phi_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return inv_Phi(x);
}
};
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/fun/inv_cloglog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace math {
*/
inline double inv_cloglog(double x) {
using std::exp;
return 1 - exp(-exp(x));
return 1. - exp(-exp(x));
}

/**
Expand All @@ -59,7 +59,7 @@ inline double inv_cloglog(double x) {
*/
struct inv_cloglog_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return inv_cloglog(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/inv_erfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ inline auto inv_erfc(const T& x) {
*/
struct inv_erfc_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return inv_erfc(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/inv_logit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ inline double inv_logit(double a) {
*/
struct inv_logit_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return inv_logit(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/inv_sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ inline auto inv_sqrt(T x) {
*/
struct inv_sqrt_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return inv_sqrt(x);
}
};
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/fun/lambert_w.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace internal {
*/
struct lambert_w0_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return lambert_w0(x);
}
};
Expand All @@ -64,7 +64,7 @@ struct lambert_w0_fun {
*/
struct lambert_wm1_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return lambert_wm1(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/lgamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inline double lgamma(int x) {
*/
struct lgamma_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return lgamma(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct log_fun {
* @return Natural log of x.
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::log;
return log(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log10.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace math {
*/
struct log10_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::log10;
return log10(x);
}
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log1m.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ inline double log1m(double x) {
*/
struct log1m_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return log1m(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log1m_exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline double log1m_exp(double a) {
*/
struct log1m_exp_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return log1m_exp(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log1m_inv_logit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct log1m_inv_logit_fun {
* @return natural log of one minus inverse logit of argument
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return log1m_inv_logit(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log1p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct log1p_fun {
* @return natural log of one plus the argument
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return log1p(x);
}
};
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/fun/log1p_exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline double log1p_exp(double a) {
*/
struct log1p_exp_fun {
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
return log1p_exp(x);
}
};
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/fun/log2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace math {
*
* @return Natural logarithm of two.
*/
inline double log2() { return LOG_TWO; }
inline constexpr double log2() { return LOG_TWO; }

/**
* Structure to wrap `log2()` so it can be vectorized.
Expand All @@ -28,7 +28,7 @@ struct log2_fun {
* @return base two log of the argument
*/
template <typename T>
static inline T fun(const T& x) {
static inline auto fun(const T& x) {
using std::log2;
return log2(x);
}
Expand Down
Loading