You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace boost::isfinite, etc. with std:: versions #1010
We should move functionality from boost to std libraries wherever possible. There are a bunch of runtime numerical tests like isfinite and isnan that are supported in std now and we should move to those versions.
Figure out which functions are now supported in std.
Change the Stan code to use the std versions.
Example
Line 18 of prim/err/check_finite.hpp:
if (!(boost::math::isfinite)(value_of_rec(y)))
Also, we can get rid of a lot of the type promotion in Boost and just use auto as the return type. For example, stan/math/prim/mat/fun/add.hpp could just be:
#ifndef STAN_MATH_PRIM_MAT_FUN_ADD_HPP
#define STAN_MATH_PRIM_MAT_FUN_ADD_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
namespace stan {
namespace math {
/**
* Return the sum of the specified matrices. The two matrices
* must have the same dimensions.
* @tparam T1 Scalar type of first matrix.
* @tparam T2 Scalar type of second matrix.
* @tparam R Row type of matrices.
* @tparam C Column type of matrices.
* @param m1 First matrix.
* @param m2 Second matrix.
* @return Sum of the matrices.
* @throw std::invalid_argument if m1 and m2 do not have the same
* dimensions.
*/
template <typename T1, typename T2, int R, int C>
inline auto
add(const Eigen::Matrix<T1, R, C>& m1, const Eigen::Matrix<T2, R, C>& m2) {
check_matching_dims("add", "m1", m1, "m2", m2);
return (m1 + m2).eval();
}
/**
* Return the sum of the specified matrix and specified scalar.
*
* @tparam T1 Scalar type of matrix.
* @tparam T2 Type of scalar.
* @param m Matrix.
* @param c Scalar.
* @return The matrix plus the scalar.
*/
template <typename T1, typename T2, int R, int C>
inline auto
add(const Eigen::Matrix<T1, R, C>& m, const T2& c) {
return (m.array() + c).matrix().eval();
}
/**
* Return the sum of the specified scalar and specified matrix.
*
* @tparam T1 Type of scalar.
* @tparam T2 Scalar type of matrix.
* @param c Scalar.
* @param m Matrix.
* @return The scalar plus the matrix.
*/
template <typename T1, typename T2, int R, int C>
inline auto
add(const T1& c, const Eigen::Matrix<T2, R, C>& m) {
return add(m, c);
}
} // namespace math
} // namespace stan
#endif
Updating this issue with the goal of breaking the pulls into more manageable chunks. There are 3 categories of changes to be made (i.e. 3 different pulls):
Boost functions with no required input checks:
asinh
cbrt
erf
erfc
expm1
isinf
isnan
round
trunc
Boost functions that require input checks (to maintain current throwing behaviour):
acosh
Requires throw for x < 1
Requires windows-specific handling of inf input
atanh
Requires throw if x not in [-1,1]
lgamma
Change to return inf for zero input (currently returns nan)
log1p
Requires throw for x < -1
tgamma
Requires throw for x = 0, or x is negative integer
Activity
rok-cesnovar commentedon Aug 28, 2018
Here is quick list of all
boost::mathfunctions used in Stan Math that have their std equivalent since C++11:tgamma
lgamma
cbrt
erf, erfc
expm1
acosh, asinh, atanh
isfinite, isnan, isinf, fpclassify
log1p
round
trunc
andrjohns commentedon Dec 9, 2018
Updating this issue with the goal of breaking the pulls into more manageable chunks. There are 3 categories of changes to be made (i.e. 3 different pulls):
Boost functions with no required input checks:
Boost functions that require input checks (to maintain current throwing behaviour):
Hand-coded functions that can be replaced
mcol commentedon Dec 23, 2019
Curiously enough, despite the issue title none of the PRs referenced here have actually removed the uses of
boost::math::isfinite! :)Overall, the following still need to be done