Skip to content

Cleanup unnecessary prim/fun signatures and checks (redundant as of C++11) #1702

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

Closed
wants to merge 7 commits into from
Closed
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
16 changes: 2 additions & 14 deletions stan/math/prim/fun/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ inline double acosh(double x) {
return x;
} else {
check_greater_or_equal("acosh", "x", x, 1.0);
#ifdef _WIN32
if (is_inf(x))
return x;
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked fine on my Windows box, but will let Jenkins give the final verdict. Will just revert back if Jenkins flags this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what made the test fail on Jenkins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will remove once I update the PR. Was hoping it could go away :)

return std::acosh(x);
}
}
Expand All @@ -39,16 +35,8 @@ inline double acosh(double x) {
* @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);
}
check_greater_or_equal("acosh", "x", x, 1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is_nan for integer inputs is redundant, isnt it?

return std::acosh(x);
}

/**
Expand Down
20 changes: 1 addition & 19 deletions stan/math/prim/fun/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@
namespace stan {
namespace math {

/**
* Return the inverse hyperbolic sine of the specified value.
* Returns infinity for infinity argument and -infinity for
* -infinity argument.
* Returns nan for nan argument.
*
* @param[in] x Argument.
* @return Inverse hyperbolic sine of the argument.
*/
inline double asinh(double x) { return std::asinh(x); }

/**
* Integer version of asinh.
*
* @param[in] x Argument.
* @return Inverse hyperbolic sine of the argument.
*/
inline double asinh(int x) { return std::asinh(x); }

/**
* Structure to wrap asinh() so it can be vectorized.
*
Expand All @@ -36,6 +17,7 @@ inline double asinh(int x) { return std::asinh(x); }
struct asinh_fun {
template <typename T>
static inline T fun(const T& x) {
using std::asinh;
return asinh(x);
}
};
Expand Down
8 changes: 2 additions & 6 deletions stan/math/prim/fun/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ inline double atanh(double x) {
* @throw std::domain_error If argument is less than 1.
*/
inline double atanh(int x) {
if (is_nan(x)) {
return x;
} else {
check_bounded("atanh", "x", x, -1, 1);
return std::atanh(x);
}
check_bounded("atanh", "x", x, -1, 1);
return std::atanh(x);
}

/**
Expand Down
19 changes: 1 addition & 18 deletions stan/math/prim/fun/cbrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@
namespace stan {
namespace math {

/**
* Return the cube root of the specified value
*
* @param[in] x Argument.
* @return Cube root of the argument.
* @throw std::domain_error If argument is negative.
*/
inline double cbrt(double x) { return std::cbrt(x); }

/**
* Integer version of cbrt.
*
* @param[in] x Argument.
* @return Cube root of the argument.
* @throw std::domain_error If argument is less than 1.
*/
inline double cbrt(int x) { return std::cbrt(x); }

/**
* Structure to wrap cbrt() so it can be vectorized.
*
Expand All @@ -35,6 +17,7 @@ inline double cbrt(int x) { return std::cbrt(x); }
struct cbrt_fun {
template <typename T>
static inline T fun(const T& x) {
using std::cbrt;
return cbrt(x);
}
};
Expand Down
22 changes: 1 addition & 21 deletions stan/math/prim/fun/erf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@
namespace stan {
namespace math {

/**
* Return the error function of the specified value.
*
* \f[
* \mbox{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt
* \f]
*
* @param[in] x Argument.
* @return Error function of the argument.
*/
inline double erf(double x) { return std::erf(x); }

/**
* Return the error function of the specified argument. This
* version is required to disambiguate <code>erf(int)</code>.
*
* @param[in] x Argument.
* @return Error function of the argument.
*/
inline double erf(int x) { return std::erf(x); }

/**
* Structure to wrap erf() so it can be vectorized.
*
Expand All @@ -38,6 +17,7 @@ inline double erf(int x) { return std::erf(x); }
struct erf_fun {
template <typename T>
static inline T fun(const T& x) {
using std::erf;
return erf(x);
}
};
Expand Down
22 changes: 1 addition & 21 deletions stan/math/prim/fun/erfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@
namespace stan {
namespace math {

/**
* Return the complementary error function of the specified value.
*
* \f[
* \mbox{erfc}(x) = 1 - \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt
* \f]
*
* @param[in] x Argument.
* @return Complementary error function of the argument.
*/
inline double erfc(double x) { return std::erfc(x); }

/**
* Return the error function of the specified argument. This
* version is required to disambiguate <code>erfc(int)</code>.
*
* @param[in] x Argument.
* @return Complementary error function value of the argument.
*/
inline double erfc(int x) { return std::erfc(x); }

/**
* Structure to wrap erfc() so that it can be vectorized.
*
Expand All @@ -38,6 +17,7 @@ inline double erfc(int x) { return std::erfc(x); }
struct erfc_fun {
template <typename T>
static inline T fun(const T& x) {
using std::erfc;
return erfc(x);
}
};
Expand Down
9 changes: 0 additions & 9 deletions stan/math/prim/fun/exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
namespace stan {
namespace math {

/**
* Return the natural exponential of the specified argument. This
* version is required to disambiguate <code>exp(int)</code>.
*
* @param[in] x Argument.
* @return Natural exponential of argument.
*/
inline double exp(int x) { return std::exp(x); }

/**
* Structure to wrap <code>exp()</code> so that it can be
* vectorized.
Expand Down
19 changes: 1 addition & 18 deletions stan/math/prim/fun/expm1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@
namespace stan {
namespace math {

/**
* Return the natural exponentiation of x minus one.
* Returns infinity for infinity argument and -infinity for
* -infinity argument.
*
* @param[in] x Argument.
* @return Natural exponentiation of argument minus one.
*/
inline double expm1(double x) { return std::expm1(x); }

/**
* Integer version of expm1.
*
* @param[in] x Argument.
* @return Natural exponentiation of argument minus one.
*/
inline double expm1(int x) { return std::expm1(x); }

/**
* Structure to wrap expm1() so that it can be vectorized.
*
Expand All @@ -35,6 +17,7 @@ inline double expm1(int x) { return std::expm1(x); }
struct expm1_fun {
template <typename T>
static inline T fun(const T& x) {
using std::expm1;
return expm1(x);
}
};
Expand Down
23 changes: 9 additions & 14 deletions stan/math/prim/fun/gp_matern32_cov.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ gp_matern32_cov(const std::vector<T_x> &x, const T_s &sigma,
const T_l &length_scale) {
using std::exp;
using std::pow;
using std::sqrt;

size_t x_size = size(x);
Eigen::Matrix<return_type_t<T_x, T_s, T_l>, Eigen::Dynamic, Eigen::Dynamic>
Expand All @@ -66,15 +65,14 @@ gp_matern32_cov(const std::vector<T_x> &x, const T_s &sigma,
check_positive_finite(function, "length scale", length_scale);

T_s sigma_sq = square(sigma);
T_l root_3_inv_l = sqrt(3.0) / length_scale;
T_l neg_root_3_inv_l = -1.0 * sqrt(3.0) / length_scale;
T_l root_3_inv_l = std::sqrt(3.0) / length_scale;

for (size_t i = 0; i < x_size; ++i) {
cov(i, i) = sigma_sq;
for (size_t j = i + 1; j < x_size; ++j) {
return_type_t<T_x> dist = distance(x[i], x[j]);
cov(i, j) = sigma_sq * (1.0 + root_3_inv_l * dist)
* exp(neg_root_3_inv_l * dist);
cov(i, j)
= sigma_sq * (1.0 + root_3_inv_l * dist) * exp(-root_3_inv_l * dist);
cov(j, i) = cov(i, j);
}
}
Expand Down Expand Up @@ -130,16 +128,15 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x, -1, 1>> &x,
"number of length scales", l_size);

T_s sigma_sq = square(sigma);
double root_3 = sqrt(3.0);
double neg_root_3 = -1.0 * sqrt(3.0);
double root_3 = std::sqrt(3.0);

std::vector<Eigen::Matrix<return_type_t<T_x, T_l>, -1, 1>> x_new
= divide_columns(x, length_scale);

for (size_t i = 0; i < x_size; ++i) {
for (size_t j = i; j < x_size; ++j) {
return_type_t<T_x, T_l> dist = distance(x_new[i], x_new[j]);
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(neg_root_3 * dist);
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(-root_3 * dist);
cov(j, i) = cov(i, j);
}
}
Expand Down Expand Up @@ -209,14 +206,13 @@ gp_matern32_cov(const std::vector<T_x1> &x1, const std::vector<T_x2> &x2,
check_positive_finite(function, "length scale", length_scale);

T_s sigma_sq = square(sigma);
T_l root_3_inv_l_sq = sqrt(3.0) / length_scale;
T_l neg_root_3_inv_l_sq = -1.0 * sqrt(3.0) / length_scale;
T_l root_3_inv_l_sq = std::sqrt(3.0) / length_scale;

for (size_t i = 0; i < x1_size; ++i) {
for (size_t j = 0; j < x2_size; ++j) {
return_type_t<T_x1, T_x2> dist = distance(x1[i], x2[j]);
cov(i, j) = sigma_sq * (1.0 + root_3_inv_l_sq * dist)
* exp(neg_root_3_inv_l_sq * dist);
* exp(-root_3_inv_l_sq * dist);
}
}
return cov;
Expand Down Expand Up @@ -290,8 +286,7 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x1, -1, 1>> &x1,
}

T_s sigma_sq = square(sigma);
double root_3 = sqrt(3.0);
double neg_root_3 = -1.0 * sqrt(3.0);
double root_3 = std::sqrt(3.0);

std::vector<Eigen::Matrix<return_type_t<T_x1, T_l>, -1, 1>> x1_new
= divide_columns(x1, length_scale);
Expand All @@ -301,7 +296,7 @@ gp_matern32_cov(const std::vector<Eigen::Matrix<T_x1, -1, 1>> &x1,
for (size_t i = 0; i < x1_size; ++i) {
for (size_t j = 0; j < x2_size; ++j) {
return_type_t<T_x1, T_x2, T_l> dist = distance(x1_new[i], x2_new[j]);
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(neg_root_3 * dist);
cov(i, j) = sigma_sq * (1.0 + root_3 * dist) * exp(-root_3 * dist);
}
}
return cov;
Expand Down
19 changes: 8 additions & 11 deletions stan/math/prim/fun/gp_matern52_cov.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ gp_matern52_cov(const std::vector<T_x> &x, const T_s &sigma,
check_positive_finite("gp_matern52_cov", "length scale", length_scale);

T_s sigma_sq = square(sigma);
T_l root_5_inv_l = sqrt(5.0) / length_scale;
T_l root_5_inv_l = std::sqrt(5.0) / length_scale;
T_l inv_l_sq_5_3 = 5.0 / (3.0 * square(length_scale));
T_l neg_root_5_inv_l = -sqrt(5.0) / length_scale;
T_l neg_root_5_inv_l = -std::sqrt(5.0) / length_scale;

for (size_t i = 0; i < x_size; ++i) {
cov(i, i) = sigma_sq;
Expand Down Expand Up @@ -125,9 +125,8 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
"number of length scales", l_size);

T_s sigma_sq = square(sigma);
double root_5 = sqrt(5.0);
double root_5 = std::sqrt(5.0);
double five_thirds = 5.0 / 3.0;
double neg_root_5 = -root_5;

std::vector<Eigen::Matrix<return_type_t<T_x, T_l>, -1, 1>> x_new
= divide_columns(x, length_scale);
Expand All @@ -139,7 +138,7 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
= squared_distance(x_new[i], x_new[j]);
return_type_t<T_x, T_l> dist = sqrt(sq_distance);
cov(i, j) = sigma_sq * (1.0 + root_5 * dist + five_thirds * sq_distance)
* exp(neg_root_5 * dist);
* exp(-root_5 * dist);
cov(j, i) = cov(i, j);
}
}
Expand Down Expand Up @@ -196,17 +195,16 @@ gp_matern52_cov(const std::vector<T_x1> &x1, const std::vector<T_x2> &x2,
check_positive_finite("gp_matern52_cov", "length scale", length_scale);

T_s sigma_sq = square(sigma);
T_l root_5_inv_l = sqrt(5.0) / length_scale;
T_l root_5_inv_l = std::sqrt(5.0) / length_scale;
T_l inv_l_sq_5_3 = 5.0 / (3.0 * square(length_scale));
T_l neg_root_5_inv_l = -sqrt(5.0) / length_scale;

for (size_t i = 0; i < x1_size; ++i) {
for (size_t j = 0; j < x2_size; ++j) {
return_type_t<T_x1, T_x2> sq_distance = squared_distance(x1[i], x2[j]);
return_type_t<T_x1, T_x2> dist = sqrt(sq_distance);
cov(i, j) = sigma_sq
* (1.0 + root_5_inv_l * dist + inv_l_sq_5_3 * sq_distance)
* exp(neg_root_5_inv_l * dist);
* exp(-root_5_inv_l * dist);
}
}
return cov;
Expand Down Expand Up @@ -273,9 +271,8 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x1, Eigen::Dynamic, 1>> &x1,
"number of length scales", l_size);

T_s sigma_sq = square(sigma);
double root_5 = sqrt(5.0);
double root_5 = std::sqrt(5.0);
double five_thirds = 5.0 / 3.0;
double neg_root_5 = -root_5;

std::vector<Eigen::Matrix<return_type_t<T_x1, T_l>, -1, 1>> x1_new
= divide_columns(x1, length_scale);
Expand All @@ -288,7 +285,7 @@ gp_matern52_cov(const std::vector<Eigen::Matrix<T_x1, Eigen::Dynamic, 1>> &x1,
= squared_distance(x1_new[i], x2_new[j]);
return_type_t<T_x1, T_x2, T_l> dist = sqrt(sq_distance);
cov(i, j) = sigma_sq * (1.0 + root_5 * dist + five_thirds * sq_distance)
* exp(neg_root_5 * dist);
* exp(-root_5 * dist);
}
}
return cov;
Expand Down
Loading