Commit 9c17e4ba authored by Andrew Johnson's avatar Andrew Johnson
Browse files

Revert pull to only replace Boost functions not needing error checking

Showing with 93 additions and 454 deletions
+93 -454
......@@ -16,7 +16,6 @@
#include <stan/math/prim/scal/fun/lgamma.hpp>
#include <stan/math/prim/scal/fun/gamma_p.hpp>
#include <stan/math/prim/scal/fun/digamma.hpp>
#include <stan/math/prim/scal/fun/tgamma.hpp>
#include <stan/math/prim/scal/meta/length.hpp>
#include <stan/math/prim/scal/meta/is_constant_struct.hpp>
#include <stan/math/prim/scal/meta/scalar_seq_view.hpp>
......@@ -68,7 +67,7 @@ typename return_type<T_y, T_shape, T_scale>::type inv_gamma_lccdf(
return ops_partials.build(0.0);
}
using stan::math::tgamma;
using boost::math::tgamma;
using std::exp;
using std::log;
using std::pow;
......
#ifndef STAN_MATH_REV_MAT_FUN_MATRIX_EXP_MULTIPLY_HPP
#define STAN_MATH_REV_MAT_FUN_MATRIX_EXP_MULTIPLY_HPP
#include <stan/math/rev/mat.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/prim/mat/fun/matrix_exp_action_handler.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/rev/mat/fun/to_var.hpp>
#include <stan/math/prim/mat/fun/matrix_exp.hpp>
#include <stan/math/prim/arr/err/check_nonzero_size.hpp>
#include <stan/math/prim/mat/err/check_multiplicable.hpp>
#include <stan/math/prim/scal/err/check_not_nan.hpp>
#include <boost/math/tools/promotion.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits.hpp>
#include <vector>
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/fun/matrix_exp.hpp>
#include <stan/math/prim/scal/meta/return_type.hpp>
#include <stan/math/rev/mat/fun/multiply.hpp>
#include <stan/math/rev/core.hpp>
namespace stan {
namespace math {
/**
* Calculate adjoint of matrix exponential action
* exp(At)*B when A is data and B is var, used for chaining action.
*
* @param Ad double array pointer to the data of matrix A
* @param n dim of square matrix A
* @param adjexpAB MatrixXd adjoint of exp(At)*B
* @param t double time data
* @return MatrixXd The adjoint of B.
*/
inline Eigen::MatrixXd exp_action_chain_dv(double* Ad, const int& n,
const Eigen::MatrixXd& adjexpAB,
const double t) {
using Eigen::Map;
matrix_exp_action_handler handle;
return handle.action(Map<Eigen::MatrixXd>(Ad, n, n).transpose(), adjexpAB, t);
}
/**
* Calculate adjoint of matrix exponential action
* exp(At)*B when A is var and B is data, used for chaining action.
*
* @param Ad double array pointer to the data of matrix A
* @param Bd double array pointer to the data of matrix B
* @param n dim(nb. of rows) of square matrix A
* @param m nb. of cols of matrix B
* @param adjexpAB MatrixXd adjoint of exp(At)*B
* @param t double time data
* @return MatrixXd The adjoint of A.
*/
inline Eigen::MatrixXd exp_action_chain_vd(double* Ad, double* Bd, const int& n,
const int& m,
const Eigen::MatrixXd& adjexpAB,
const double t) {
using Eigen::Map;
using Eigen::Matrix;
using Eigen::MatrixXd;
Eigen::MatrixXd adjexpA = Eigen::MatrixXd::Zero(n, n);
Eigen::MatrixXd adjA = Eigen::MatrixXd::Zero(n, n);
// TODO(yizhang): a better way such as complex step approximation
try {
start_nested();
adjexpA = adjexpAB * Map<MatrixXd>(Bd, n, m).transpose();
Eigen::Matrix<stan::math::var, Eigen::Dynamic, Eigen::Dynamic> Av(n, n);
for (int i = 0; i < Av.size(); ++i) {
Av(i) = to_var(Ad[i]);
}
std::vector<stan::math::var> Avec(Av.data(), Av.data() + Av.size());
Eigen::Matrix<stan::math::var, Eigen::Dynamic, Eigen::Dynamic> expA
= matrix_exp(Av);
std::vector<double> g;
for (size_type i = 0; i < expA.size(); ++i) {
stan::math::set_zero_all_adjoints_nested();
expA.coeffRef(i).grad(Avec, g);
for (size_type j = 0; j < adjA.size(); ++j) {
adjA(j) += adjexpA(i) * g[j];
}
}
} catch (const std::exception& e) {
recover_memory_nested();
throw;
}
recover_memory_nested();
return adjA;
}
/**
* This is a subclass of the vari class for matrix
* exponential action exp(At) * B where A is a double
* NxN matrix and B is a NxCb matrix.
*
* The class stores the structure of each matrix,
* the double values of A and B, and pointers to
* the varis for A and B if A or B is a var. It
* also instantiates and stores pointers to
* varis for all elements of A * B.
*
* @tparam Ta Scalar type of matrix A
* @tparam N rows and cols of A
* @tparam Tb Scalar type for matrix B
* @tparam Cb cols for matrix B
*/
template <typename Ta, int N, typename Tb, int Cb>
class matrix_exp_action_vari : public vari {
public:
int n_;
int B_cols_;
int A_size_;
int B_size_;
double t_;
double* Ad_;
double* Bd_;
vari** variRefA_;
vari** variRefB_;
vari** variRefexpAB_;
/**
* Constructor: vari child-class of matrix_exp_action_vari.
* @param A statically-sized matirx
* @param B statically-sized matirx
* @param t double scalar time.
*/
matrix_exp_action_vari(const Eigen::Matrix<Ta, N, N>& A,
const Eigen::Matrix<Tb, N, Cb>& B, const double& t)
: vari(0.0),
n_(A.rows()),
B_cols_(B.cols()),
A_size_(A.size()),
B_size_(B.size()),
t_(t),
Ad_(ChainableStack::instance().memalloc_.alloc_array<double>(A_size_)),
Bd_(ChainableStack::instance().memalloc_.alloc_array<double>(B_size_)),
variRefA_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(A_size_)),
variRefB_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(B_size_)),
variRefexpAB_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(B_size_)) {
using Eigen::Map;
using Eigen::MatrixXd;
for (size_type i = 0; i < A.size(); ++i) {
variRefA_[i] = A.coeffRef(i).vi_;
Ad_[i] = A.coeffRef(i).val();
}
for (size_type i = 0; i < B.size(); ++i) {
variRefB_[i] = B.coeffRef(i).vi_;
Bd_[i] = B.coeffRef(i).val();
}
matrix_exp_action_handler handle;
MatrixXd expAB = handle.action(Map<MatrixXd>(Ad_, n_, n_),
Map<MatrixXd>(Bd_, n_, B_cols_), t_);
for (size_type i = 0; i < expAB.size(); ++i)
variRefexpAB_[i] = new vari(expAB.coeffRef(i), false);
}
/**
* Chain command for the adjoint of matrix exp action.
*/
virtual void chain() {
using Eigen::Map;
using Eigen::MatrixXd;
MatrixXd adjexpAB(n_, B_cols_);
for (size_type i = 0; i < adjexpAB.size(); ++i)
adjexpAB(i) = variRefexpAB_[i]->adj_;
MatrixXd adjA = exp_action_chain_vd(Ad_, Bd_, n_, B_cols_, adjexpAB, t_);
MatrixXd adjB = exp_action_chain_dv(Ad_, n_, adjexpAB, t_);
for (size_type i = 0; i < A_size_; ++i) {
variRefA_[i]->adj_ += adjA(i);
}
for (size_type i = 0; i < B_size_; ++i) {
variRefB_[i]->adj_ += adjB(i);
}
}
};
/**
* This is a subclass of the vari class for matrix
* exponential action exp(At) * B where A is an N by N
* matrix of double, B is N by Cb, and t is data(time)
*
* The class stores the structure of each matrix,
* the double values of A and B, and pointers to
* the varis for A and B if B is a var. It
* also instantiates and stores pointers to
* varis for all elements of exp(At) * B.
*
* @tparam N Rows and cols for matrix A, also rows for B
* @tparam Tb Scalar type for matrix B
* @tparam Cb Columns for matrix B
*/
template <int N, typename Tb, int Cb>
class matrix_exp_action_vari<double, N, Tb, Cb> : public vari {
public:
int n_;
int B_cols_;
int A_size_;
int B_size_;
double t_;
double* Ad_;
double* Bd_;
vari** variRefB_;
vari** variRefexpAB_;
/**
* Constructor for matrix_exp_action_vari.
*
* All memory allocated in
* ChainableStack's stack_alloc arena.
*
* It is critical for the efficiency of this object
* that the constructor create new varis that aren't
* popped onto the var_stack_, but rather are
* popped onto the var_nochain_stack_. This is
* controlled to the second argument to
* vari's constructor.
*
* @param A matrix
* @param B matrix
* @param t double
*/
matrix_exp_action_vari(const Eigen::Matrix<double, N, N>& A,
const Eigen::Matrix<Tb, N, Cb>& B, const double& t)
: vari(0.0),
n_(A.rows()),
B_cols_(B.cols()),
A_size_(A.size()),
B_size_(B.size()),
t_(t),
Ad_(ChainableStack::instance().memalloc_.alloc_array<double>(A_size_)),
Bd_(ChainableStack::instance().memalloc_.alloc_array<double>(B_size_)),
variRefB_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(B_size_)),
variRefexpAB_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(B_size_)) {
using Eigen::Map;
using Eigen::MatrixXd;
for (size_type i = 0; i < A.size(); ++i)
Ad_[i] = A.coeffRef(i);
for (size_type i = 0; i < B.size(); ++i) {
variRefB_[i] = B.coeffRef(i).vi_;
Bd_[i] = B.coeffRef(i).val();
}
matrix_exp_action_handler handle;
MatrixXd expAB = handle.action(Map<MatrixXd>(Ad_, n_, n_),
Map<MatrixXd>(Bd_, n_, B_cols_), t_);
for (size_type i = 0; i < expAB.size(); ++i)
variRefexpAB_[i] = new vari(expAB.coeffRef(i), false);
}
/**
* Chain for matrix_exp_action_vari.
*/
virtual void chain() {
using Eigen::Map;
using Eigen::MatrixXd;
MatrixXd adjexpAB(n_, B_cols_);
// MatrixXd adjB(n_, B_cols_);
for (size_type i = 0; i < adjexpAB.size(); ++i)
adjexpAB(i) = variRefexpAB_[i]->adj_;
MatrixXd adjB = exp_action_chain_dv(Ad_, n_, adjexpAB, t_);
for (size_type i = 0; i < B_size_; ++i) {
variRefB_[i]->adj_ += adjB(i);
}
}
};
/**
* This is a subclass of the vari class for matrix
* exponential action exp(At) * B where A is an N by N
* matrix of var, B is N by Cb matrix of double, and t is data(time)
*
* The class stores the structure of each matrix,
* the double values of A and B, and pointers to
* the varis for A and B if B is a var. It
* also instantiates and stores pointers to
* varis for all elements of exp(At) * B.
*
* @tparam Ta Scalar type for matrix A
* @tparam N Rows and cols for matrix A, also rows for B
* @tparam Cb Columns for matrix B
*/
template <typename Ta, int N, int Cb>
class matrix_exp_action_vari<Ta, N, double, Cb> : public vari {
public:
int n_;
int B_cols_;
int A_size_;
int B_size_;
double t_;
double* Ad_;
double* Bd_;
vari** variRefA_;
vari** variRefexpAB_;
/**
* Constructor for matrix_exp_action_vari.
*
* All memory allocated in
* ChainableStack's stack_alloc arena.
*
* It is critical for the efficiency of this object
* that the constructor create new varis that aren't
* popped onto the var_stack_, but rather are
* popped onto the var_nochain_stack_. This is
* controlled to the second argument to
* vari's constructor.
*
* @param A matrix
* @param B matrix
* @param t double
*/
matrix_exp_action_vari(const Eigen::Matrix<Ta, N, N>& A,
const Eigen::Matrix<double, N, Cb>& B, const double& t)
: vari(0.0),
n_(A.rows()),
B_cols_(B.cols()),
A_size_(A.size()),
B_size_(B.size()),
t_(t),
Ad_(ChainableStack::instance().memalloc_.alloc_array<double>(A_size_)),
Bd_(ChainableStack::instance().memalloc_.alloc_array<double>(B_size_)),
variRefA_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(A_size_)),
variRefexpAB_(
ChainableStack::instance().memalloc_.alloc_array<vari*>(B_size_)) {
using Eigen::Map;
using Eigen::MatrixXd;
for (size_type i = 0; i < A.size(); ++i) {
variRefA_[i] = A.coeffRef(i).vi_;
Ad_[i] = A.coeffRef(i).val();
}
for (size_type i = 0; i < B.size(); ++i) {
Bd_[i] = B.coeffRef(i);
}
matrix_exp_action_handler handle;
MatrixXd expAB = handle.action(Map<MatrixXd>(Ad_, n_, n_),
Map<MatrixXd>(Bd_, n_, B_cols_), t_);
for (size_type i = 0; i < expAB.size(); ++i)
variRefexpAB_[i] = new vari(expAB.coeffRef(i), false);
}
virtual void chain() {
using Eigen::Map;
using Eigen::MatrixXd;
MatrixXd adjexpAB(n_, B_cols_);
for (size_type i = 0; i < adjexpAB.size(); ++i)
adjexpAB(i) = variRefexpAB_[i]->adj_;
MatrixXd adjA = exp_action_chain_vd(Ad_, Bd_, n_, B_cols_, adjexpAB, t_);
for (size_type i = 0; i < A_size_; ++i) {
variRefA_[i]->adj_ += adjA(i);
}
}
};
/**
* Return product of exp(At) and B, where A is a NxN matrix,
* B is a NxCb matrix, and t is a double
* @tparam Ta scalar type matrix A
* @tparam N Rows and cols matrix A, also rows of matrix B
* @tparam Tb scalar type matrix B
* @tparam Cb Columns matrix B
* @param[in] A Matrix
* @param[in] B Matrix
* @param[in] t double
* @return exponential of At multiplies B
*/
template <typename Ta, int N, typename Tb, int Cb>
inline typename boost::enable_if_c<boost::is_same<Ta, var>::value
|| boost::is_same<Tb, var>::value,
Eigen::Matrix<var, N, Cb> >::type
matrix_exp_action(const Eigen::Matrix<Ta, N, N>& A,
const Eigen::Matrix<Tb, N, Cb>& B, const double& t = 1.0) {
matrix_exp_action_vari<Ta, N, Tb, Cb>* baseVari
= new matrix_exp_action_vari<Ta, N, Tb, Cb>(A, B, t);
Eigen::Matrix<var, N, Cb> expAB_v(A.rows(), B.cols());
for (size_type i = 0; i < expAB_v.size(); ++i) {
expAB_v.coeffRef(i).vi_ = baseVari->variRefexpAB_[i];
}
return expAB_v;
}
/**
* Wrapper of matrix_exp_action function for a more literal name
* @tparam Ta scalar type matrix A
......@@ -406,7 +30,7 @@ matrix_exp_multiply(const Eigen::Matrix<Ta, -1, -1>& A,
check_nonzero_size("matrix_exp_multiply", "input matrix", B);
check_multiplicable("matrix_exp_multiply", "A", A, "B", B);
check_square("matrix_exp_multiply", "input matrix", A);
return matrix_exp_action(A, B);
return multiply(matrix_exp(A), B);
}
} // namespace math
......
#ifndef STAN_MATH_REV_MAT_FUN_SCALE_MATRIX_EXP_MULTIPLY_HPP
#define STAN_MATH_REV_MAT_FUN_SCALE_MATRIX_EXP_MULTIPLY_HPP
#include <stan/math/prim/mat.hpp>
#include <stan/math/rev/mat/fun/matrix_exp_multiply.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <boost/math/tools/promotion.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits.hpp>
#include <vector>
#include <stan/math/prim/arr/err/check_nonzero_size.hpp>
#include <stan/math/prim/mat/err/check_multiplicable.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/fun/matrix_exp.hpp>
#include <stan/math/prim/scal/meta/return_type.hpp>
#include <stan/math/rev/mat/fun/multiply.hpp>
#include <stan/math/rev/core.hpp>
namespace stan {
namespace math {
/**
* Wrapper of matrix_exp_action function for a more literal name.
* Return product of exp(At) and B, where A is a NxN matrix,
* B is a NxCb matrix, and t is a double
*
* @tparam Ta scalar type matrix A
* @tparam Tb scalar type matrix B
* @tparam Cb Columns matrix B
......@@ -30,7 +33,7 @@ scale_matrix_exp_multiply(const double& t, const Eigen::Matrix<Ta, -1, -1>& A,
check_nonzero_size("scale_matrix_exp_multiply", "input matrix", B);
check_multiplicable("scale_matrix_exp_multiply", "A", A, "B", B);
check_square("scale_matrix_exp_multiply", "input matrix", A);
return matrix_exp_action(A, B, t);
return multiply(matrix_exp(multiply(A, t)), B);
}
} // namespace math
......
......@@ -22,6 +22,7 @@
#include <stan/math/rev/scal/fun/bessel_second_kind.hpp>
#include <stan/math/rev/scal/fun/binary_log_loss.hpp>
#include <stan/math/rev/scal/fun/boost_fpclassify.hpp>
#include <stan/math/rev/scal/fun/boost_isfinite.hpp>
#include <stan/math/rev/scal/fun/boost_isnormal.hpp>
#include <stan/math/rev/scal/fun/calculate_chain.hpp>
#include <stan/math/rev/scal/fun/cbrt.hpp>
......@@ -58,7 +59,6 @@
#include <stan/math/rev/scal/fun/is_inf.hpp>
#include <stan/math/rev/scal/fun/is_nan.hpp>
#include <stan/math/rev/scal/fun/is_uninitialized.hpp>
#include <stan/math/rev/scal/fun/ldexp.hpp>
#include <stan/math/rev/scal/fun/lgamma.hpp>
#include <stan/math/rev/scal/fun/lmgamma.hpp>
#include <stan/math/rev/scal/fun/log.hpp>
......
#ifndef STAN_MATH_REV_SCAL_FUN_BOOST_ISFINITE_HPP
#define STAN_MATH_REV_SCAL_FUN_BOOST_ISFINITE_HPP
#include <boost/math/special_functions/fpclassify.hpp>
#include <stan/math/rev/core.hpp>
namespace boost {
namespace math {
/**
* Checks if the given number has finite value.
*
* Return <code>true</code> if the specified variable's
* value is finite.
*
* @param v Variable to test.
* @return <code>true</code> if variable is finite.
*/
template <>
inline bool isfinite(const stan::math::var& v) {
return (boost::math::isfinite)(v.val());
}
} // namespace math
} // namespace boost
#endif
......@@ -104,8 +104,7 @@ inline var fdim(const var& a, const var& b) {
* @return The positive difference between the first and second
* arguments.
*/
template <typename Ta>
inline var fdim(const Ta& a, const var& b) {
inline var fdim(double a, const var& b) {
// reversed test to get NaN vals automatically in second case
return a <= b.vi_->val_ ? var(new vari(0.0))
: var(new fdim_dv_vari(a, b.vi_));
......@@ -122,8 +121,7 @@ inline var fdim(const Ta& a, const var& b) {
* @param b Second variable.
* @return The positive difference between the first and second arguments.
*/
template <typename Tb>
inline var fdim(const var& a, const Tb& b) {
inline var fdim(const var& a, double b) {
// reversed test to get NaN vals automatically in second case
return a.vi_->val_ <= b ? var(new vari(0.0))
: var(new fdim_vd_vari(a.vi_, b));
......
......@@ -123,8 +123,7 @@ inline var fma(const var& a, const var& b, const var& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Tc>
inline var fma(const var& a, const var& b, const Tc& c) {
inline var fma(const var& a, const var& b, double c) {
return var(new fma_vvd_vari(a.vi_, b.vi_, c));
}
......@@ -144,8 +143,7 @@ inline var fma(const var& a, const var& b, const Tc& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Tb>
inline var fma(const var& a, const Tb& b, const var& c) {
inline var fma(const var& a, double b, const var& c) {
return var(new fma_vdv_vari(a.vi_, b, c.vi_));
}
......@@ -167,8 +165,7 @@ inline var fma(const var& a, const Tb& b, const var& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Tb, typename Tc>
inline var fma(const var& a, const Tb& b, const Tc& c) {
inline var fma(const var& a, double b, double c) {
return var(new fma_vdd_vari(a.vi_, b, c));
}
......@@ -186,8 +183,7 @@ inline var fma(const var& a, const Tb& b, const Tc& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Ta, typename Tc>
inline var fma(const Ta& a, const var& b, const Tc& c) {
inline var fma(double a, const var& b, double c) {
return var(new fma_vdd_vari(b.vi_, a, c));
}
......@@ -205,8 +201,7 @@ inline var fma(const Ta& a, const var& b, const Tc& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Ta, typename Tb>
inline var fma(const Ta& a, const Tb& b, const var& c) {
inline var fma(double a, double b, const var& c) {
return var(new fma_ddv_vari(a, b, c.vi_));
}
......@@ -226,8 +221,7 @@ inline var fma(const Ta& a, const Tb& b, const var& c) {
* @param c Summand.
* @return Product of the multiplicands plus the summand, ($a * $b) + $c.
*/
template <typename Ta>
inline var fma(const Ta& a, const var& b, const var& c) {
inline var fma(double a, const var& b, const var& c) {
return var(new fma_vdv_vari(b.vi_, a, c.vi_)); // a-b symmetry
}
......
......@@ -84,8 +84,7 @@ inline var fmax(const var& a, const var& b) {
* to the second value, the first variable, otherwise the second
* value promoted to a fresh variable.
*/
template <typename Tb>
inline var fmax(const var& a, const Tb& b) {
inline var fmax(const var& a, double b) {
if (unlikely(is_nan(a))) {
if (unlikely(is_nan(b)))
return var(new precomp_v_vari(NOT_A_NUMBER, a.vi_, NOT_A_NUMBER));
......@@ -110,8 +109,7 @@ inline var fmax(const var& a, const Tb& b) {
* return the first value promoted to a variable, otherwise return the
* second variable.
*/
template <typename Ta>
inline var fmax(const Ta& a, const var& b) {
inline var fmax(double a, const var& b) {
if (unlikely(is_nan(b))) {
if (unlikely(is_nan(a)))
return var(new precomp_v_vari(NOT_A_NUMBER, b.vi_, NOT_A_NUMBER));
......
......@@ -80,8 +80,7 @@ inline var fmin(const var& a, const var& b) {
* value, the first variable, otherwise the second value promoted to a fresh
* variable.
*/
template <typename Tb>
inline var fmin(const var& a, const Tb& b) {
inline var fmin(const var& a, double b) {
if (unlikely(is_nan(a))) {
if (unlikely(is_nan(b)))
return var(new precomp_v_vari(NOT_A_NUMBER, a.vi_, NOT_A_NUMBER));
......@@ -106,8 +105,7 @@ inline var fmin(const var& a, const Tb& b) {
* return the first value promoted to a variable, otherwise return the
* second variable.
*/
template <typename Ta>
inline var fmin(const Ta& a, const var& b) {
inline var fmin(double a, const var& b) {
if (unlikely(is_nan(b))) {
if (unlikely(is_nan(a)))
return var(new precomp_v_vari(NOT_A_NUMBER, b.vi_, NOT_A_NUMBER));
......
......@@ -20,7 +20,7 @@ class gamma_p_vv_vari : public op_vv_vari {
gamma_p_vv_vari(vari* avi, vari* bvi)
: op_vv_vari(gamma_p(avi->val_, bvi->val_), avi, bvi) {}
void chain() {
using stan::math::lgamma;
using boost::math::lgamma;
using std::exp;
using std::fabs;
using std::log;
......
......@@ -57,8 +57,7 @@ inline var hypot(const var& a, const var& b) {
* @param[in] b Length of second side.
* @return Length of hypoteneuse.
*/
template <typename Tb>
inline var hypot(const var& a, const Tb& b) {
inline var hypot(const var& a, double b) {
return var(new hypot_vd_vari(a.vi_, b));
}
......@@ -101,8 +100,7 @@ inline var hypot(const var& a, const Tb& b) {
* @param[in] b Length of second side.
* @return Length of hypoteneuse.
*/
template <typename Ta>
inline var hypot(const Ta& a, const var& b) {
inline var hypot(double a, const var& b) {
return var(new hypot_vd_vari(b.vi_, a));
}
......
......@@ -94,7 +94,7 @@ class ibeta_vdv_vari : public op_vdv_vari {
using boost::math::constants::pi;
using boost::math::digamma;
using boost::math::ibeta;
using stan::math::tgamma;
using boost::math::tgamma;
using std::log;
using std::pow;
using std::sin;
......@@ -117,7 +117,7 @@ class ibeta_vdd_vari : public op_vdd_vari {
using boost::math::constants::pi;
using boost::math::digamma;
using boost::math::ibeta;
using stan::math::tgamma;
using boost::math::tgamma;
using std::log;
using std::pow;
using std::sin;
......@@ -139,7 +139,7 @@ class ibeta_dvv_vari : public op_dvv_vari {
using boost::math::constants::pi;
using boost::math::digamma;
using boost::math::ibeta;
using stan::math::tgamma;
using boost::math::tgamma;
using std::log;
using std::pow;
using std::sin;
......@@ -164,7 +164,7 @@ class ibeta_dvd_vari : public op_dvd_vari {
using boost::math::constants::pi;
using boost::math::digamma;
using boost::math::ibeta;
using stan::math::tgamma;
using boost::math::tgamma;
using std::log;
using std::pow;
using std::sin;
......
......@@ -109,8 +109,8 @@ TEST(AgradFwdMatrixDistance, special_values_fd) {
v1 << 0;
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v2, v1)));
v1 << std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
......@@ -119,8 +119,8 @@ TEST(AgradFwdMatrixDistance, special_values_fd) {
v1 << -std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v2, v1)));
}
TEST(AgradFwdMatrixDistance, vector_ffd_vector_ffd) {
......@@ -227,8 +227,8 @@ TEST(AgradFwdMatrixDistance, special_values_ffd) {
v1 << 0;
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v2, v1)));
v1 << std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
......@@ -237,6 +237,6 @@ TEST(AgradFwdMatrixDistance, special_values_ffd) {
v1 << -std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::distance(v2, v1)));
}
......@@ -109,8 +109,8 @@ TEST(AgradFwdMatrixSquaredDistance, special_values_fd) {
v1 << 0;
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v2, v1)));
v1 << std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
......@@ -119,8 +119,8 @@ TEST(AgradFwdMatrixSquaredDistance, special_values_fd) {
v1 << -std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v2, v1)));
}
TEST(AgradFwdMatrixSquaredDistance, vector_ffd_vector_ffd) {
......@@ -227,8 +227,8 @@ TEST(AgradFwdMatrixSquaredDistance, special_values_ffd) {
v1 << 0;
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v2, v1)));
v1 << std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
......@@ -237,6 +237,6 @@ TEST(AgradFwdMatrixSquaredDistance, special_values_ffd) {
v1 << -std::numeric_limits<double>::infinity();
v2 << std::numeric_limits<double>::infinity();
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(boost::math::isinf(stan::math::squared_distance(v2, v1)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v1, v2)));
EXPECT_TRUE(stan::math::is_inf(stan::math::squared_distance(v2, v1)));
}
......@@ -8,7 +8,7 @@ class AgradFwdAsinh : public testing::Test {
};
TEST_F(AgradFwdAsinh, Fvar) {
using boost::math::asinh;
using stan::math::asinh;
using stan::math::fvar;
using std::sqrt;
......@@ -30,7 +30,7 @@ TEST_F(AgradFwdAsinh, Fvar) {
}
TEST_F(AgradFwdAsinh, FvarFvarDouble) {
using boost::math::asinh;
using stan::math::asinh;
using stan::math::fvar;
fvar<fvar<double> > x;
......
......@@ -4,7 +4,7 @@
#include <test/unit/math/fwd/scal/fun/nan_util.hpp>
TEST(AgradFwdCbrt, Fvar) {
using boost::math::cbrt;
using stan::math::cbrt;
using stan::math::fvar;
using std::isnan;
......@@ -37,7 +37,7 @@ TEST(AgradFwdCbrt, Fvar) {
}
TEST(AgradFwdCbrt, FvarFvarDouble) {
using boost::math::cbrt;
using stan::math::cbrt;
using stan::math::fvar;
fvar<fvar<double> > x;
......
......@@ -4,7 +4,7 @@
#include <test/unit/math/fwd/scal/fun/nan_util.hpp>
TEST(AgradFwdErf, Fvar) {
using boost::math::erf;
using stan::math::erf;
using stan::math::fvar;
using std::exp;
using std::sqrt;
......@@ -23,7 +23,7 @@ TEST(AgradFwdErf, Fvar) {
}
TEST(AgradFwdErf, FvarFvarDouble) {
using boost::math::erf;
using stan::math::erf;
using stan::math::fvar;
using std::exp;
using std::sqrt;
......
......@@ -4,7 +4,7 @@
#include <test/unit/math/fwd/scal/fun/nan_util.hpp>
TEST(AgradFwdErfc, Fvar) {
using boost::math::erfc;
using stan::math::erfc;
using stan::math::fvar;
using std::exp;
using std::sqrt;
......@@ -23,7 +23,7 @@ TEST(AgradFwdErfc, Fvar) {
}
TEST(AgradFwdErfc, FvarFvarDouble) {
using boost::math::erfc;
using stan::math::erfc;
using stan::math::fvar;
using std::exp;
using std::sqrt;
......
......@@ -4,7 +4,7 @@
#include <test/unit/math/fwd/scal/fun/nan_util.hpp>
TEST(AgradFwdRound, Fvar) {
using boost::math::round;
using stan::math::round;
using stan::math::fvar;
fvar<double> x(0.5, 1.0);
......@@ -30,7 +30,7 @@ TEST(AgradFwdRound, Fvar) {
}
TEST(AgradFwdRound, FvarFvarDouble) {
using boost::math::round;
using stan::math::round;
using stan::math::fvar;
fvar<fvar<double> > x;
......
......@@ -3,7 +3,7 @@
#include <test/unit/math/fwd/scal/fun/nan_util.hpp>
TEST(AgradFwdTrunc, Fvar) {
using boost::math::trunc;
using stan::math::trunc;
using stan::math::fvar;
fvar<double> x(0.5, 1.0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment