diff --git a/.gitignore b/.gitignore index d2fd269da53..a9239123fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ !/test/*.* /test/**/*_generated_*_test.cpp /test/**/*.xml +/test/dummy.cpp # other binary *.o diff --git a/makefile b/makefile index b725c92406b..8bd1d6a7f8f 100644 --- a/makefile +++ b/makefile @@ -109,6 +109,7 @@ endif @echo '' @echo ' To run a single header test, add "-test" to the end of the file name.' @echo ' Example: make stan/math/constants.hpp-test' + @echo '' @echo ' - test-math-dependencies : walks through all the header files and indicates' @echo ' when the math dependencies are violated. Dependencies should follow:' @echo ' * rev -> prim' diff --git a/stan/math/fwd/mat/fun/multiply.hpp b/stan/math/fwd/mat/fun/multiply.hpp index 3ab38193908..17a021e1106 100644 --- a/stan/math/fwd/mat/fun/multiply.hpp +++ b/stan/math/fwd/mat/fun/multiply.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/fwd/mat/fun/qr_Q.hpp b/stan/math/fwd/mat/fun/qr_Q.hpp index a136f5a244a..d95a052edc0 100644 --- a/stan/math/fwd/mat/fun/qr_Q.hpp +++ b/stan/math/fwd/mat/fun/qr_Q.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_FWD_MAT_FUN_QR_Q_HPP #define STAN_MATH_FWD_MAT_FUN_QR_Q_HPP +#include #include -#include -#include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/mat/fun/qr_R.hpp b/stan/math/fwd/mat/fun/qr_R.hpp index f06f7f80ecd..3dbade1c150 100644 --- a/stan/math/fwd/mat/fun/qr_R.hpp +++ b/stan/math/fwd/mat/fun/qr_R.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_FWD_MAT_FUN_QR_R_HPP #define STAN_MATH_FWD_MAT_FUN_QR_R_HPP +#include #include -#include -#include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/fwd/mat/functor/gradient.hpp b/stan/math/fwd/mat/functor/gradient.hpp index fb1de967b74..653a89a5899 100644 --- a/stan/math/fwd/mat/functor/gradient.hpp +++ b/stan/math/fwd/mat/functor/gradient.hpp @@ -15,9 +15,8 @@ namespace stan { *

The functor must implement * * - * stan::math::fvar - * operator()(const - * Eigen::Matrix&) + * stan::math::fvar + * operator()(const Eigen::Matrix&) * * * using only operations that are defined for diff --git a/stan/math/fwd/scal.hpp b/stan/math/fwd/scal.hpp index 850d582aa27..d44586df63f 100644 --- a/stan/math/fwd/scal.hpp +++ b/stan/math/fwd/scal.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include diff --git a/stan/math/fwd/scal/meta/OperandsAndPartials.hpp b/stan/math/fwd/scal/meta/OperandsAndPartials.hpp new file mode 100644 index 00000000000..d309b992234 --- /dev/null +++ b/stan/math/fwd/scal/meta/OperandsAndPartials.hpp @@ -0,0 +1,188 @@ +#ifndef STAN_MATH_FWD_SCAL_META_OPERANDSANDPARTIALS_HPP +#define STAN_MATH_FWD_SCAL_META_OPERANDSANDPARTIALS_HPP + +#include +#include +#include +#include + +namespace stan { + namespace math { + + // These are helpers to the OperandsAndPartials specialization for + // stan::math::fvar + namespace { + template ::value, + bool is_const = is_constant_struct::value> + struct increment_derivative { + inline T_derivative operator()(const T& x, + const T_partials& d_dx) { + return 0; + } + }; + + template + struct increment_derivative { + inline T_derivative operator()(const T& x, + const T_partials& d_dx) { + return d_dx[0] * x.d_; + } + }; + + template + struct increment_derivative { + inline T_derivative operator()(const T& x, + const T_partials& d_dx) { + T_derivative derivative(0); + for (size_t n = 0; n < length(x); n++) + derivative += d_dx[n] * x[n].d_; + return derivative; + } + }; + + template + fvar partials_to_fvar(T& logp, + const T1& x1, D1& d_x1, + const T2& x2, D2& d_x2, + const T3& x3, D3& d_x3, + const T4& x4, D4& d_x4, + const T5& x5, D5& d_x5, + const T6& x6, D6& d_x6) { + T deriv = 0; + if (!is_constant_struct::value) + deriv += increment_derivative()(x1, d_x1); + if (!is_constant_struct::value) + deriv += increment_derivative()(x2, d_x2); + if (!is_constant_struct::value) + deriv += increment_derivative()(x3, d_x3); + if (!is_constant_struct::value) + deriv += increment_derivative()(x4, d_x4); + if (!is_constant_struct::value) + deriv += increment_derivative()(x5, d_x5); + if (!is_constant_struct::value) + deriv += increment_derivative()(x6, d_x6); + return stan::math::fvar(logp, deriv); + } + } + + + /** + * This class builds partial derivatives with respect to a set of + * operands. There are two reason for the generality of this + * class. The first is to handle vector and scalar arguments + * without needing to write additional code. The second is to use + * this class for writing probability distributions that handle + * primitives, reverse mode, and forward mode variables + * seamlessly. + * + * This is the partial template specialization for when the return + * type is stan::math::fvar. + * + * @tparam T1 First set of operands. + * @tparam T2 Second set of operands. + * @tparam T3 Third set of operands. + * @tparam T4 Fourth set of operands. + * @tparam T5 Fifth set of operands. + * @tparam T6 Sixth set of operands. + * @tparam T_return_type Return type of the expression. This defaults + * to a template metaprogram that calculates the scalar promotion of + * T1 -- T6. + */ + template + struct OperandsAndPartials > { + typedef typename stan::math::fvar T_return_type; + + const T1& x1_; + const T2& x2_; + const T3& x3_; + const T4& x4_; + const T5& x5_; + const T6& x6_; + + size_t n_partials; + T_partials_return* all_partials; + + + VectorView::value, + is_constant_struct::value> d_x1; + VectorView::value, + is_constant_struct::value> d_x2; + VectorView::value, + is_constant_struct::value> d_x3; + VectorView::value, + is_constant_struct::value> d_x4; + VectorView::value, + is_constant_struct::value> d_x5; + VectorView::value, + is_constant_struct::value> d_x6; + + OperandsAndPartials(const T1& x1 = 0, const T2& x2 = 0, const T3& x3 = 0, + const T4& x4 = 0, const T5& x5 = 0, const T6& x6 = 0) + : x1_(x1), x2_(x2), x3_(x3), x4_(x4), x5_(x5), x6_(x6), + n_partials(!is_constant_struct::value * length(x1) + + !is_constant_struct::value * length(x2) + + !is_constant_struct::value * length(x3) + + !is_constant_struct::value * length(x4) + + !is_constant_struct::value * length(x5) + + !is_constant_struct::value * length(x6)), + all_partials(new T_partials_return[n_partials]), + d_x1(all_partials), + d_x2(all_partials + + (!is_constant_struct::value) * length(x1)), + d_x3(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2)), + d_x4(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3)), + d_x5(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3) + + (!is_constant_struct::value) * length(x4)), + d_x6(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3) + + (!is_constant_struct::value) * length(x4) + + (!is_constant_struct::value) * length(x5)) { + std::fill(all_partials, all_partials + n_partials, 0); + } + + T_return_type + value(T_partials_return value) { + return partials_to_fvar(value, + x1_, d_x1, x2_, d_x2, + x3_, d_x3, x4_, d_x4, + x5_, d_x4, x6_, d_x5); + } + + ~OperandsAndPartials() { + delete all_partials; + } + }; + + + } +} +#endif diff --git a/stan/math/mix/mat/functor/grad_hessian.hpp b/stan/math/mix/mat/functor/grad_hessian.hpp index 4e09c19f9ef..eac4085d7e7 100644 --- a/stan/math/mix/mat/functor/grad_hessian.hpp +++ b/stan/math/mix/mat/functor/grad_hessian.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/mix/mat/functor/grad_tr_mat_times_hessian.hpp b/stan/math/mix/mat/functor/grad_tr_mat_times_hessian.hpp index 1e6dd4694de..d9d8fa01ace 100644 --- a/stan/math/mix/mat/functor/grad_tr_mat_times_hessian.hpp +++ b/stan/math/mix/mat/functor/grad_tr_mat_times_hessian.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/mix/mat/functor/hessian.hpp b/stan/math/mix/mat/functor/hessian.hpp index 0a56f07c421..2f54e8e715c 100644 --- a/stan/math/mix/mat/functor/hessian.hpp +++ b/stan/math/mix/mat/functor/hessian.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/mix/mat/functor/hessian_times_vector.hpp b/stan/math/mix/mat/functor/hessian_times_vector.hpp index f0c07fb6c40..712224e52fe 100644 --- a/stan/math/mix/mat/functor/hessian_times_vector.hpp +++ b/stan/math/mix/mat/functor/hessian_times_vector.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/mix/scal.hpp b/stan/math/mix/scal.hpp index e692ff5fba3..cd43d5cde7a 100644 --- a/stan/math/mix/scal.hpp +++ b/stan/math/mix/scal.hpp @@ -4,10 +4,12 @@ #include #include #include +#include #include #include #include +#include #include #include diff --git a/stan/math/prim/arr.hpp b/stan/math/prim/arr.hpp index f968bebd502..1f316ac3e30 100644 --- a/stan/math/prim/arr.hpp +++ b/stan/math/prim/arr.hpp @@ -4,13 +4,22 @@ #include #include #include +#include #include #include +#include +#include +#include + +#include +#include #include #include #include #include +#include +#include #include #include #include diff --git a/stan/math/prim/scal/err/check_nonzero_size.hpp b/stan/math/prim/arr/err/check_nonzero_size.hpp similarity index 99% rename from stan/math/prim/scal/err/check_nonzero_size.hpp rename to stan/math/prim/arr/err/check_nonzero_size.hpp index 6a02a75da43..06ee8d13df1 100644 --- a/stan/math/prim/scal/err/check_nonzero_size.hpp +++ b/stan/math/prim/arr/err/check_nonzero_size.hpp @@ -2,7 +2,6 @@ #define STAN_MATH_PRIM_SCAL_ERR_CHECK_NONZERO_SIZE_HPP #include - #include namespace stan { diff --git a/stan/math/prim/arr/err/check_ordered.hpp b/stan/math/prim/arr/err/check_ordered.hpp new file mode 100644 index 00000000000..71759ec09e3 --- /dev/null +++ b/stan/math/prim/arr/err/check_ordered.hpp @@ -0,0 +1,56 @@ +#ifndef STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP +#define STAN_MATH_PRIM_ARR_ERR_CHECK_ORDERED_HPP + +#include +#include +#include +#include +#include +#include + +namespace stan { + namespace math { + + /** + * Return true if the specified vector is sorted into + * strictly increasing order. + * + * @tparam T_y Type of scalar + * + * @param function Function name (for error messages) + * @param name Variable name (for error messages) + * @param y std::vector to test + * + * @return true if the vector is ordered + * @throw std::domain_error if the vector elements are + * not ordered, if there are duplicated + * values, or if any element is NaN. + */ + template + bool check_ordered(const char* function, + const char* name, + const std::vector& y) { + if (y.size() == 0) + return true; + + for (size_t n = 1; n < y.size(); n++) { + if (!(y[n] > y[n-1])) { + std::ostringstream msg1; + msg1 << "is not a valid ordered vector." + << " The element at " << stan::error_index::value + n + << " is "; + std::string msg1_str(msg1.str()); + std::ostringstream msg2; + msg2 << ", but should be greater than the previous element, " + << y[n-1]; + std::string msg2_str(msg2.str()); + domain_error(function, name, y[n], + msg1_str.c_str(), msg2_str.c_str()); + return false; + } + } + return true; + } + } +} +#endif diff --git a/stan/math/prim/arr/fun/promote_scalar.hpp b/stan/math/prim/arr/fun/promote_scalar.hpp new file mode 100644 index 00000000000..cb69b2dd46f --- /dev/null +++ b/stan/math/prim/arr/fun/promote_scalar.hpp @@ -0,0 +1,44 @@ +#ifndef STAN_MATH_PRIM_ARR_FUN_PROMOTE_SCALAR_HPP +#define STAN_MATH_PRIM_ARR_FUN_PROMOTE_SCALAR_HPP + +#include +#include +#include +#include + +namespace stan { + namespace math { + + /** + * Struct to hold static function for promoting underlying scalar + * types. This specialization is for standard vector inputs. + * + * @tparam T return scalar type + * @tparam S input type for standard vector elements in static + * nested function, which must have an underlying scalar type + * assignable to T. + */ + template + struct promote_scalar_struct > { + /** + * Return the standard vector consisting of the recursive + * promotion of the elements of the input standard vector to the + * scalar type specified by the return template parameter. + * + * @param x input standard vector. + * @return standard vector with values promoted from input vector. + */ + static std::vector::type> + apply(const std::vector& x) { + typedef std::vector::type> return_t; + typedef typename index_type::type idx_t; + return_t y(x.size()); + for (idx_t i = 0; i < x.size(); ++i) + y[i] = promote_scalar_struct::apply(x[i]); + return y; + } + }; + + } +} +#endif diff --git a/stan/math/prim/arr/fun/promote_scalar_type.hpp b/stan/math/prim/arr/fun/promote_scalar_type.hpp new file mode 100644 index 00000000000..4c36c6aaaed --- /dev/null +++ b/stan/math/prim/arr/fun/promote_scalar_type.hpp @@ -0,0 +1,28 @@ +#ifndef STAN_MATH_PRIM_ARR_FUN_PROMOTE_SCALAR_TYPE_HPP +#define STAN_MATH_PRIM_ARR_FUN_PROMOTE_SCALAR_TYPE_HPP + +#include +#include + +namespace stan { + namespace math { + + /** + * Template metaprogram to calculate a type for a container whose + * underlying scalar is converted from the second template + * parameter type to the first. + * + * @tparam T result scalar type. + * @tparam S input type + */ + template + struct promote_scalar_type > { + /** + * The promoted type. + */ + typedef std::vector::type> type; + }; + + } +} +#endif diff --git a/stan/math/prim/arr/functor/coupled_ode_system.hpp b/stan/math/prim/arr/functor/coupled_ode_system.hpp index 8510e008061..0824702fe35 100644 --- a/stan/math/prim/arr/functor/coupled_ode_system.hpp +++ b/stan/math/prim/arr/functor/coupled_ode_system.hpp @@ -1,7 +1,7 @@ #ifndef STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP #define STAN_MATH_PRIM_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP -#include +#include #include #include @@ -96,9 +96,9 @@ namespace stan { std::vector& dy_dt, double t) { dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_); - stan::math::check_matching_sizes("coupled_ode_system", - "y", y, - "dy_dt", dy_dt); + stan::math::check_size_match("coupled_ode_system", + "y", y.size(), + "dy_dt", dy_dt.size()); } /** diff --git a/stan/math/prim/arr/functor/integrate_ode.hpp b/stan/math/prim/arr/functor/integrate_ode.hpp index 1422a41cf08..9ca15be58eb 100644 --- a/stan/math/prim/arr/functor/integrate_ode.hpp +++ b/stan/math/prim/arr/functor/integrate_ode.hpp @@ -1,14 +1,14 @@ #ifndef STAN_MATH_PRIM_ARR_FUNCTOR_INTEGRATE_ODE_HPP #define STAN_MATH_PRIM_ARR_FUNCTOR_INTEGRATE_ODE_HPP +#include +#include +#include +#include #include #include #include -#include -#include #include -#include -#include #include #include #include diff --git a/stan/math/prim/arr/meta/VectorBuilderHelper.hpp b/stan/math/prim/arr/meta/VectorBuilderHelper.hpp new file mode 100644 index 00000000000..7a140da207b --- /dev/null +++ b/stan/math/prim/arr/meta/VectorBuilderHelper.hpp @@ -0,0 +1,31 @@ +#ifndef STAN_MATH_PRIM_ARR_META_VECTORBUILDER_HELPER_HPP +#define STAN_MATH_PRIM_ARR_META_VECTORBUILDER_HELPER_HPP + +#include +#include +#include + +namespace stan { + + /** + * Template specialization for using a vector + */ + template + class VectorBuilderHelper { + private: + std::vector x_; + public: + explicit VectorBuilderHelper(size_t n) : x_(n) { } + + typedef std::vector type; + + T1& operator[](size_t i) { + return x_[i]; + } + + inline type& data() { + return x_; + } + }; +} +#endif diff --git a/stan/math/prim/arr/meta/VectorView.hpp b/stan/math/prim/arr/meta/VectorView.hpp new file mode 100644 index 00000000000..4759217b247 --- /dev/null +++ b/stan/math/prim/arr/meta/VectorView.hpp @@ -0,0 +1,42 @@ +#ifndef STAN_MATH_ARR_SCAL_META_VECTORVIEW_HPP +#define STAN_MATH_ARR_SCAL_META_VECTORVIEW_HPP + +#include +#include + +namespace stan { + + template + class VectorView, true, false> { + public: + typedef typename scalar_type::type scalar_t; + + template + explicit VectorView(X& x) : x_(&x[0]) { } + + scalar_t& operator[](int i) { + return x_[i]; + } + + private: + scalar_t* x_; + }; + + template + class VectorView, true, false> { + public: + typedef typename boost::add_const::type>::type + scalar_t; + + template + explicit VectorView(X& x) : x_(&x[0]) { } + + scalar_t& operator[](int i) const { + return x_[i]; + } + private: + scalar_t* x_; + }; + +} +#endif diff --git a/stan/math/prim/arr/meta/is_constant_struct.hpp b/stan/math/prim/arr/meta/is_constant_struct.hpp new file mode 100644 index 00000000000..fb8b00fe2eb --- /dev/null +++ b/stan/math/prim/arr/meta/is_constant_struct.hpp @@ -0,0 +1,17 @@ +#ifndef STAN_MATH_PRIM_ARR_META_IS_CONSTANT_STRUCT_HPP +#define STAN_MATH_PRIM_ARR_META_IS_CONSTANT_STRUCT_HPP + +#include +#include +#include + +namespace stan { + + template + struct is_constant_struct > { + enum { value = is_constant_struct::value }; + }; + +} +#endif + diff --git a/stan/math/prim/arr/meta/value_type.hpp b/stan/math/prim/arr/meta/value_type.hpp new file mode 100644 index 00000000000..4f1d37b23f2 --- /dev/null +++ b/stan/math/prim/arr/meta/value_type.hpp @@ -0,0 +1,27 @@ +#ifndef STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP +#define STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP + +#include +#include + +namespace stan { + namespace math { + + /** + * Template metaprogram class to compute the type of values stored + * in a standard vector. + * + * @tparam T type of elements in standard vector. + */ + template + struct value_type > { + /** + * Type of value stored in a standard vector with type + * T entries. + */ + typedef typename std::vector::value_type type; + }; + + } +} +#endif diff --git a/stan/math/prim/mat.hpp b/stan/math/prim/mat.hpp index 8cecefbd2d8..d02688fe207 100644 --- a/stan/math/prim/mat.hpp +++ b/stan/math/prim/mat.hpp @@ -9,11 +9,16 @@ #include #include #include +#include #include #include #include +#include #include +#include #include +#include +#include #include #include diff --git a/stan/math/prim/mat/err/check_ordered.hpp b/stan/math/prim/mat/err/check_ordered.hpp index 70e080300b0..a7cf9a1f9b1 100644 --- a/stan/math/prim/mat/err/check_ordered.hpp +++ b/stan/math/prim/mat/err/check_ordered.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP #define STAN_MATH_PRIM_MAT_ERR_CHECK_ORDERED_HPP -#include #include #include +#include #include #include #include @@ -59,46 +59,6 @@ namespace stan { return true; } - /** - * Return true if the specified vector is sorted into - * strictly increasing order. - * - * @tparam T_y Type of scalar - * - * @param function Function name (for error messages) - * @param name Variable name (for error messages) - * @param y std::vector to test - * - * @return true if the vector is ordered - * @throw std::domain_error if the vector elements are - * not ordered, if there are duplicated - * values, or if any element is NaN. - */ - template - bool check_ordered(const char* function, - const char* name, - const std::vector& y) { - if (y.size() == 0) - return true; - - for (size_t n = 1; n < y.size(); n++) { - if (!(y[n] > y[n-1])) { - std::ostringstream msg1; - msg1 << "is not a valid ordered vector." - << " The element at " << stan::error_index::value + n - << " is "; - std::string msg1_str(msg1.str()); - std::ostringstream msg2; - msg2 << ", but should be greater than the previous element, " - << y[n-1]; - std::string msg2_str(msg2.str()); - domain_error(function, name, y[n], - msg1_str.c_str(), msg2_str.c_str()); - return false; - } - } - return true; - } } } #endif diff --git a/stan/math/prim/mat/err/check_simplex.hpp b/stan/math/prim/mat/err/check_simplex.hpp index 80d3416a62f..3d6292f106f 100644 --- a/stan/math/prim/mat/err/check_simplex.hpp +++ b/stan/math/prim/mat/err/check_simplex.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_SIMPLEX_HPP #define STAN_MATH_PRIM_MAT_ERR_CHECK_SIMPLEX_HPP -#include +#include #include -#include #include #include +#include #include #include #include diff --git a/stan/math/prim/mat/err/check_unit_vector.hpp b/stan/math/prim/mat/err/check_unit_vector.hpp index 35fe1dbbfe2..c9a8336d510 100644 --- a/stan/math/prim/mat/err/check_unit_vector.hpp +++ b/stan/math/prim/mat/err/check_unit_vector.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP #define STAN_MATH_PRIM_MAT_ERR_CHECK_UNIT_VECTOR_HPP -#include +#include #include #include -#include +#include #include #include diff --git a/stan/math/prim/mat/fun/cov_matrix_constrain.hpp b/stan/math/prim/mat/fun/cov_matrix_constrain.hpp index fd4f810f0c9..2d8ab49e18a 100644 --- a/stan/math/prim/mat/fun/cov_matrix_constrain.hpp +++ b/stan/math/prim/mat/fun/cov_matrix_constrain.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace stan { diff --git a/stan/math/prim/mat/fun/eigenvalues_sym.hpp b/stan/math/prim/mat/fun/eigenvalues_sym.hpp index 235387625dc..cc9c8975def 100644 --- a/stan/math/prim/mat/fun/eigenvalues_sym.hpp +++ b/stan/math/prim/mat/fun/eigenvalues_sym.hpp @@ -1,7 +1,7 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_EIGENVALUES_SYM_HPP #define STAN_MATH_PRIM_MAT_FUN_EIGENVALUES_SYM_HPP -#include +#include #include #include diff --git a/stan/math/prim/mat/fun/eigenvectors_sym.hpp b/stan/math/prim/mat/fun/eigenvectors_sym.hpp index ba5f1f2db06..c66c956c930 100644 --- a/stan/math/prim/mat/fun/eigenvectors_sym.hpp +++ b/stan/math/prim/mat/fun/eigenvectors_sym.hpp @@ -1,7 +1,7 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_EIGENVECTORS_SYM_HPP #define STAN_MATH_PRIM_MAT_FUN_EIGENVECTORS_SYM_HPP -#include +#include #include #include diff --git a/stan/math/prim/mat/fun/inverse_spd.hpp b/stan/math/prim/mat/fun/inverse_spd.hpp index fa0c61640af..688ebd70998 100644 --- a/stan/math/prim/mat/fun/inverse_spd.hpp +++ b/stan/math/prim/mat/fun/inverse_spd.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/prim/mat/fun/log_softmax.hpp b/stan/math/prim/mat/fun/log_softmax.hpp index 353087ff8d3..e7661c7e3b9 100644 --- a/stan/math/prim/mat/fun/log_softmax.hpp +++ b/stan/math/prim/mat/fun/log_softmax.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_LOG_SOFTMAX_HPP #define STAN_MATH_PRIM_MAT_FUN_LOG_SOFTMAX_HPP +#include #include #include -#include #include #include #include diff --git a/stan/math/prim/mat/fun/mean.hpp b/stan/math/prim/mat/fun/mean.hpp index 9d27451e169..a3d41bc10c1 100644 --- a/stan/math/prim/mat/fun/mean.hpp +++ b/stan/math/prim/mat/fun/mean.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_MEAN_HPP #define STAN_MATH_PRIM_MAT_FUN_MEAN_HPP +#include #include -#include #include #include diff --git a/stan/math/prim/mat/fun/multiply.hpp b/stan/math/prim/mat/fun/multiply.hpp index 1923c8c60d6..0e26ae929c2 100644 --- a/stan/math/prim/mat/fun/multiply.hpp +++ b/stan/math/prim/mat/fun/multiply.hpp @@ -1,11 +1,12 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_MULTIPLY_HPP #define STAN_MATH_PRIM_MAT_FUN_MULTIPLY_HPP -#include -#include #include #include #include +#include +#include +#include namespace stan { namespace math { diff --git a/stan/math/prim/mat/fun/qr_Q.hpp b/stan/math/prim/mat/fun/qr_Q.hpp index dbbcb70136f..c5af7720e5a 100644 --- a/stan/math/prim/mat/fun/qr_Q.hpp +++ b/stan/math/prim/mat/fun/qr_Q.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_QR_Q_HPP #define STAN_MATH_PRIM_MAT_FUN_QR_Q_HPP -#include -#include +#include #include +#include #include namespace stan { diff --git a/stan/math/prim/mat/fun/qr_R.hpp b/stan/math/prim/mat/fun/qr_R.hpp index 090be58e14c..1a2d7ee8ca0 100644 --- a/stan/math/prim/mat/fun/qr_R.hpp +++ b/stan/math/prim/mat/fun/qr_R.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_QR_R_HPP #define STAN_MATH_PRIM_MAT_FUN_QR_R_HPP +#include #include -#include #include -#include +#include namespace stan { namespace math { diff --git a/stan/math/prim/mat/fun/sd.hpp b/stan/math/prim/mat/fun/sd.hpp index 92ec548410d..55d7c3b8458 100644 --- a/stan/math/prim/mat/fun/sd.hpp +++ b/stan/math/prim/mat/fun/sd.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_SD_HPP #define STAN_MATH_PRIM_MAT_FUN_SD_HPP +#include #include #include -#include #include #include diff --git a/stan/math/prim/mat/fun/softmax.hpp b/stan/math/prim/mat/fun/softmax.hpp index 913f052f7dd..87716ba6a7a 100644 --- a/stan/math/prim/mat/fun/softmax.hpp +++ b/stan/math/prim/mat/fun/softmax.hpp @@ -1,7 +1,7 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_SOFTMAX_HPP #define STAN_MATH_PRIM_MAT_FUN_SOFTMAX_HPP -#include +#include #include #include diff --git a/stan/math/prim/mat/fun/unit_vector_constrain.hpp b/stan/math/prim/mat/fun/unit_vector_constrain.hpp index 8780c71bdf9..0650b750aac 100644 --- a/stan/math/prim/mat/fun/unit_vector_constrain.hpp +++ b/stan/math/prim/mat/fun/unit_vector_constrain.hpp @@ -1,12 +1,12 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP #define STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP +#include +#include #include #include #include #include -#include -#include #include namespace stan { diff --git a/stan/math/prim/mat/fun/variance.hpp b/stan/math/prim/mat/fun/variance.hpp index 05544c084ff..3f5944ca0c0 100644 --- a/stan/math/prim/mat/fun/variance.hpp +++ b/stan/math/prim/mat/fun/variance.hpp @@ -1,9 +1,9 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_VARIANCE_HPP #define STAN_MATH_PRIM_MAT_FUN_VARIANCE_HPP +#include #include #include -#include #include #include diff --git a/stan/math/prim/mat/meta/VectorView.hpp b/stan/math/prim/mat/meta/VectorView.hpp new file mode 100644 index 00000000000..d1fe67d9e93 --- /dev/null +++ b/stan/math/prim/mat/meta/VectorView.hpp @@ -0,0 +1,43 @@ +#ifndef STAN_MATH_MAT_SCAL_META_VECTORVIEW_HPP +#define STAN_MATH_MAT_SCAL_META_VECTORVIEW_HPP + +#include +#include +#include +#include + +namespace stan { + + template + class VectorView, true, false> { + public: + typedef typename scalar_type::type scalar_t; + + template + explicit VectorView(X& x) : x_(x.data()) { } + + scalar_t& operator[](int i) { + return x_[i]; + } + private: + scalar_t* x_; + }; + + template + class VectorView, true, false> { + public: + typedef typename boost::add_const::type>::type + scalar_t; + + template + explicit VectorView(X& x) : x_(x.data()) { } + + scalar_t& operator[](int i) const { + return x_[i]; + } + private: + scalar_t* x_; + }; + +} +#endif diff --git a/stan/math/prim/scal/meta/VectorViewMvt.hpp b/stan/math/prim/mat/meta/VectorViewMvt.hpp similarity index 93% rename from stan/math/prim/scal/meta/VectorViewMvt.hpp rename to stan/math/prim/mat/meta/VectorViewMvt.hpp index 6802edfd371..b8c418bab44 100644 --- a/stan/math/prim/scal/meta/VectorViewMvt.hpp +++ b/stan/math/prim/mat/meta/VectorViewMvt.hpp @@ -1,5 +1,5 @@ -#ifndef STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP -#define STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP +#ifndef STAN_MATH_PRIM_MAT_META_VECTORVIEWMVT_HPP +#define STAN_MATH_PRIM_MAT_META_VECTORVIEWMVT_HPP #include #include diff --git a/stan/math/prim/mat/meta/is_constant_struct.hpp b/stan/math/prim/mat/meta/is_constant_struct.hpp new file mode 100644 index 00000000000..fa120aae207 --- /dev/null +++ b/stan/math/prim/mat/meta/is_constant_struct.hpp @@ -0,0 +1,23 @@ +#ifndef STAN_MATH_PRIM_MAT_META_IS_CONSTANT_STRUCT_HPP +#define STAN_MATH_PRIM_MAT_META_IS_CONSTANT_STRUCT_HPP + +#include +#include +#include + + +namespace stan { + + template + struct is_constant_struct > { + enum { value = is_constant_struct::value }; + }; + + template + struct is_constant_struct > { + enum { value = is_constant_struct::value }; + }; + +} +#endif + diff --git a/stan/math/prim/mat/meta/length_mvt.hpp b/stan/math/prim/mat/meta/length_mvt.hpp new file mode 100644 index 00000000000..e131b0f57c2 --- /dev/null +++ b/stan/math/prim/mat/meta/length_mvt.hpp @@ -0,0 +1,23 @@ +#ifndef STAN_MATH_PRIM_MAT_META_LENGTH_MVT_HPP +#define STAN_MATH_PRIM_MAT_META_LENGTH_MVT_HPP + +#include +#include +#include +#include + +namespace stan { + + template + size_t length_mvt(const Eigen::Matrix& ) { + return 1U; + } + + template + size_t length_mvt(const std::vector >& x) { + return x.size(); + } + +} +#endif + diff --git a/stan/math/prim/mat/meta/scalar_type.hpp b/stan/math/prim/mat/meta/scalar_type.hpp new file mode 100644 index 00000000000..bef88346199 --- /dev/null +++ b/stan/math/prim/mat/meta/scalar_type.hpp @@ -0,0 +1,17 @@ +#ifndef STAN_MATH_PRIM_MAT_META_SCALAR_TYPE_HPP +#define STAN_MATH_PRIM_MAT_META_SCALAR_TYPE_HPP + +#include +#include +#include +#include + +namespace stan { + + template + struct scalar_type > { + typedef typename scalar_type::type type; + }; + +} +#endif diff --git a/stan/math/prim/mat/prob/multi_normal_cholesky_log.hpp b/stan/math/prim/mat/prob/multi_normal_cholesky_log.hpp index 10ed80a7f0d..08d6ecc1c74 100644 --- a/stan/math/prim/mat/prob/multi_normal_cholesky_log.hpp +++ b/stan/math/prim/mat/prob/multi_normal_cholesky_log.hpp @@ -1,11 +1,6 @@ #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_LOG_HPP #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_CHOLESKY_LOG_HPP -#include -#include -#include -#include -#include #include #include #include @@ -17,13 +12,17 @@ #include #include #include -#include -#include +#include +#include +#include +#include #include +#include #include +#include +#include namespace stan { - namespace math { /** * The log of the multivariate normal density for the given y, mu, and @@ -157,5 +156,4 @@ namespace stan { } } - #endif diff --git a/stan/math/prim/mat/prob/multi_normal_log.hpp b/stan/math/prim/mat/prob/multi_normal_log.hpp index c7ddbb4390e..3fab9b4af99 100644 --- a/stan/math/prim/mat/prob/multi_normal_log.hpp +++ b/stan/math/prim/mat/prob/multi_normal_log.hpp @@ -1,21 +1,21 @@ #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_LOG_HPP #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_LOG_HPP -#include -#include #include -#include #include +#include +#include +#include +#include #include #include #include -#include -#include +#include #include -#include #include -#include #include +#include +#include namespace stan { diff --git a/stan/math/prim/mat/prob/multi_normal_prec_log.hpp b/stan/math/prim/mat/prob/multi_normal_prec_log.hpp index 54732dbc201..152bad0097a 100644 --- a/stan/math/prim/mat/prob/multi_normal_prec_log.hpp +++ b/stan/math/prim/mat/prob/multi_normal_prec_log.hpp @@ -2,11 +2,7 @@ #define STAN_MATH_PRIM_MAT_PROB_MULTI_NORMAL_PREC_LOG_HPP #include -#include #include -#include -#include -#include #include #include #include @@ -20,9 +16,13 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include #include +#include #include namespace stan { diff --git a/stan/math/prim/mat/prob/multi_student_t_log.hpp b/stan/math/prim/mat/prob/multi_student_t_log.hpp index 46c419de728..c800b5b4922 100644 --- a/stan/math/prim/mat/prob/multi_student_t_log.hpp +++ b/stan/math/prim/mat/prob/multi_student_t_log.hpp @@ -1,28 +1,27 @@ #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_LOG_HPP #define STAN_MATH_PRIM_MAT_PROB_MULTI_STUDENT_T_LOG_HPP -#include -#include -#include #include -#include #include -#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 { /** * Return the log of the multivariate Student t distribution diff --git a/stan/math/prim/scal.hpp b/stan/math/prim/scal.hpp index e0473611bc9..2494c986fca 100644 --- a/stan/math/prim/scal.hpp +++ b/stan/math/prim/scal.hpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -46,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/fun/grad_reg_inc_gamma.hpp b/stan/math/prim/scal/fun/grad_reg_inc_gamma.hpp index 7243af04740..b5a3f04deff 100644 --- a/stan/math/prim/scal/fun/grad_reg_inc_gamma.hpp +++ b/stan/math/prim/scal/fun/grad_reg_inc_gamma.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace stan { namespace math { diff --git a/stan/math/prim/scal/fun/inc_beta_dda.hpp b/stan/math/prim/scal/fun/inc_beta_dda.hpp index 7891feea2ff..89ee63cb8bb 100644 --- a/stan/math/prim/scal/fun/inc_beta_dda.hpp +++ b/stan/math/prim/scal/fun/inc_beta_dda.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/prim/scal/fun/inc_beta_ddb.hpp b/stan/math/prim/scal/fun/inc_beta_ddb.hpp index 1eb0326e91c..d3887e5951e 100644 --- a/stan/math/prim/scal/fun/inc_beta_ddb.hpp +++ b/stan/math/prim/scal/fun/inc_beta_ddb.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/prim/scal/fun/lub_constrain.hpp b/stan/math/prim/scal/fun/lub_constrain.hpp index 2d78acd2868..dbb577a0082 100644 --- a/stan/math/prim/scal/fun/lub_constrain.hpp +++ b/stan/math/prim/scal/fun/lub_constrain.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace stan { diff --git a/stan/math/prim/scal/fun/promote_scalar.hpp b/stan/math/prim/scal/fun/promote_scalar.hpp index e0a480d5b49..34e1d9bf0f7 100644 --- a/stan/math/prim/scal/fun/promote_scalar.hpp +++ b/stan/math/prim/scal/fun/promote_scalar.hpp @@ -3,11 +3,8 @@ #include #include -#include -#include namespace stan { - namespace math { /** @@ -56,36 +53,6 @@ namespace stan { } }; - /** - * Struct to hold static function for promoting underlying scalar - * types. This specialization is for standard vector inputs. - * - * @tparam T return scalar type - * @tparam S input type for standard vector elements in static - * nested function, which must have an underlying scalar type - * assignable to T. - */ - template - struct promote_scalar_struct > { - /** - * Return the standard vector consisting of the recursive - * promotion of the elements of the input standard vector to the - * scalar type specified by the return template parameter. - * - * @param x input standard vector. - * @return standard vector with values promoted from input vector. - */ - static std::vector::type> - apply(const std::vector& x) { - typedef std::vector::type> return_t; - typedef typename index_type::type idx_t; - return_t y(x.size()); - for (idx_t i = 0; i < x.size(); ++i) - y[i] = promote_scalar_struct::apply(x[i]); - return y; - } - }; - /** * This is the top-level function to call to promote the scalar * types of an input of type S to type T. @@ -101,8 +68,6 @@ namespace stan { return promote_scalar_struct::apply(x); } - } } - #endif diff --git a/stan/math/prim/scal/fun/promote_scalar_type.hpp b/stan/math/prim/scal/fun/promote_scalar_type.hpp index 69baff79321..829724cc4e0 100644 --- a/stan/math/prim/scal/fun/promote_scalar_type.hpp +++ b/stan/math/prim/scal/fun/promote_scalar_type.hpp @@ -1,13 +1,9 @@ #ifndef STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_TYPE_HPP #define STAN_MATH_PRIM_SCAL_FUN_PROMOTE_SCALAR_TYPE_HPP -#include - namespace stan { - namespace math { - /** * Template metaprogram to calculate a type for converting a * convertible type. This is the base case. @@ -23,26 +19,6 @@ namespace stan { typedef T type; }; - - /** - * Template metaprogram to calculate a type for a container whose - * underlying scalar is converted from the second template - * parameter type to the first. - * - * @tparam T result scalar type. - * @tparam S input type - */ - template - struct promote_scalar_type > { - /** - * The promoted type. - */ - typedef std::vector::type> type; - }; - - } - } - #endif diff --git a/stan/math/prim/scal/meta/OperandsAndPartials.hpp b/stan/math/prim/scal/meta/OperandsAndPartials.hpp index 59f3ebaad04..b9664db51f1 100644 --- a/stan/math/prim/scal/meta/OperandsAndPartials.hpp +++ b/stan/math/prim/scal/meta/OperandsAndPartials.hpp @@ -1,340 +1,75 @@ #ifndef STAN_MATH_PRIM_SCAL_META_OPERANDSANDPARTIALS_HPP #define STAN_MATH_PRIM_SCAL_META_OPERANDSANDPARTIALS_HPP -#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 { - class partials_vari : public vari { - private: - const size_t N_; - vari** operands_; - double* partials_; - public: - partials_vari(double value, - size_t N, - vari** operands, double* partials) - : vari(value), - N_(N), - operands_(operands), - partials_(partials) { } - void chain() { - for (size_t n = 0; n < N_; ++n) - operands_[n]->adj_ += adj_ * partials_[n]; - } - }; - - namespace { - template::value, - bool is_const = is_constant_struct::value> - struct incr_deriv { - inline T3 incr(T1 d_x, const T2& x_d ) { - return 0; - } - }; - template - struct incr_deriv { - inline T3 incr(T1 d_x, const T2& x_d) { - return d_x[0]*x_d.d_; - } - }; - template - struct incr_deriv { - inline T3 incr(T1 d_x, const T2& x_d) { - T3 temp = 0; - for (size_t n = 0; n < length(x_d); n++) - temp += d_x[n] * x_d[n].d_; - return temp; - } - }; - - template::value, - bool is_const = stan::is_constant_struct::value> - struct partials_to_var { - inline - T_return_type to_var(double logp, size_t /* nvaris */, - vari** /* all_varis */, - T_partials_return* /* all_partials */, - const T1& x1, const T2& x2, const T3& x3, - const T4& x4, const T5& x5, const T6& x6, - VectorView::value, - is_constant_struct::value> d_x1, - VectorView::value, - is_constant_struct::value> d_x2, - VectorView::value, - is_constant_struct::value> d_x3, - VectorView::value, - is_constant_struct::value> d_x4, - VectorView::value, - is_constant_struct::value> d_x5, - VectorView::value, - is_constant_struct::value> d_x6) { - return logp; - } - }; - - template - struct partials_to_var { - inline T_return_type to_var(T_partials_return logp, size_t nvaris, - vari** all_varis, - T_partials_return* all_partials, - const T1& x1, const T2& x2, const T3& x3, - const T4& x4, const T5& x5, const T6& x6, - VectorView::value, - is_constant_struct::value> d_x1, - VectorView::value, - is_constant_struct::value> d_x2, - VectorView::value, - is_constant_struct::value> d_x3, - VectorView::value, - is_constant_struct::value> d_x4, - VectorView::value, - is_constant_struct::value> d_x5, - VectorView::value, - is_constant_struct::value> d_x6) { - return var(new partials_vari(logp, nvaris, all_varis, - all_partials)); - } - }; - - template - struct partials_to_var { - inline T_return_type to_var(T_partials_return logp, size_t nvaris, - vari** all_varis, - T_partials_return* all_partials, - const T1& x1, const T2& x2, const T3& x3, - const T4& x4, const T5& x5, const T6& x6, - VectorView::value, - is_constant_struct::value> d_x1, - VectorView::value, - is_constant_struct::value> d_x2, - VectorView::value, - is_constant_struct::value> d_x3, - VectorView::value, - is_constant_struct::value> d_x4, - VectorView::value, - is_constant_struct::value> d_x5, - VectorView::value, - is_constant_struct::value> d_x6) { - T_partials_return temp_deriv = 0; - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T1, T_partials_return>().incr(d_x1, x1); - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T2, T_partials_return>().incr(d_x2, x2); - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T3, T_partials_return>().incr(d_x3, x3); - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T4, T_partials_return>().incr(d_x4, x4); - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T5, T_partials_return>().incr(d_x5, x5); - temp_deriv += incr_deriv::value, - is_constant_struct::value>, - T6, T_partials_return>().incr(d_x6, x6); - return stan::math::fvar(logp, temp_deriv); - } - }; - - template::value, - bool is_const = is_constant_struct::value, - bool contain_fvar = contains_fvar::value> - struct set_varis { - inline size_t set(vari** /*varis*/, const T& /*x*/) { - return 0U; - } - }; - template - struct set_varis { - inline size_t set(vari** varis, const T& x) { - for (size_t n = 0; n < length(x); n++) - varis[n] = x[n].vi_; - return length(x); - } - }; - template - struct set_varis { - inline size_t set(vari** varis, const T& x) { - for (size_t n = 0; n < length(x); n++) - varis[n] = 0; - return length(x); - } - }; - template<> - struct set_varis { - inline size_t set(vari** varis, const var& x) { - varis[0] = x.vi_; - return (1); - } - }; - } - /** - * A variable implementation that stores operands and - * derivatives with respect to the variable. + * This class builds partial derivatives with respect to a set of + * operands. There are two reason for the generality of this + * class. The first is to handle vector and scalar arguments + * without needing to write additional code. The second is to use + * this class for writing probability distributions that handle + * primitives, reverse mode, and forward mode variables + * seamlessly. + * + * The default template class handles the case where the arguments + * are primitive. There are template specializations for reverse + * mode and forward mode. + * + * @tparam T1 First set of operands. + * @tparam T2 Second set of operands. + * @tparam T3 Third set of operands. + * @tparam T4 Fourth set of operands. + * @tparam T5 Fifth set of operands. + * @tparam T6 Sixth set of operands. + * @tparam T_return_type Return type of the expression. This defaults + * to a template metaprogram that calculates the scalar promotion of + * T1 -- T6. */ template + typename T4 = double, typename T5 = double, typename T6 = double, + typename T_return_type + = typename stan::return_type::type> struct OperandsAndPartials { - typedef - typename stan::partials_return_type::type - T_partials_return; - - typedef - typename stan::return_type::type T_return_type; - - static const bool all_constant = is_constant::value; - size_t nvaris; - vari** all_varis; - T_partials_return* all_partials; - - VectorView::value, - is_constant_struct::value> d_x1; - VectorView::value, - is_constant_struct::value> d_x2; - VectorView::value, - is_constant_struct::value> d_x3; - VectorView::value, - is_constant_struct::value> d_x4; - VectorView::value, - is_constant_struct::value> d_x5; - VectorView::value, - is_constant_struct::value> d_x6; - - OperandsAndPartials(const T1& x1 = 0, const T2& x2 = 0, const T3& x3 = 0, - const T4& x4 = 0, const T5& x5 = 0, const T6& x6 = 0) - : nvaris(!is_constant_struct::value * length(x1) + - !is_constant_struct::value * length(x2) + - !is_constant_struct::value * length(x3) + - !is_constant_struct::value * length(x4) + - !is_constant_struct::value * length(x5) + - !is_constant_struct::value * length(x6)), - // TODO(carpenter): replace with array allocation fun - all_varis(static_cast - (vari::operator new - (sizeof(vari*) * nvaris))), - all_partials(static_cast - (vari::operator new - (sizeof(T_partials_return) * nvaris))), - d_x1(all_partials), - d_x2(all_partials - + (!is_constant_struct::value) * length(x1)), - d_x3(all_partials - + (!is_constant_struct::value) * length(x1) - + (!is_constant_struct::value) * length(x2)), - d_x4(all_partials - + (!is_constant_struct::value) * length(x1) - + (!is_constant_struct::value) * length(x2) - + (!is_constant_struct::value) * length(x3)), - d_x5(all_partials - + (!is_constant_struct::value) * length(x1) - + (!is_constant_struct::value) * length(x2) - + (!is_constant_struct::value) * length(x3) - + (!is_constant_struct::value) * length(x4)), - d_x6(all_partials - + (!is_constant_struct::value) * length(x1) - + (!is_constant_struct::value) * length(x2) - + (!is_constant_struct::value) * length(x3) - + (!is_constant_struct::value) * length(x4) - + (!is_constant_struct::value) * length(x5)) { - size_t base = 0; - if (!is_constant_struct::value) - base += set_varis().set(&all_varis[base], x1); - if (!is_constant_struct::value) - base += set_varis().set(&all_varis[base], x2); - if (!is_constant_struct::value) - base += set_varis().set(&all_varis[base], x3); - if (!is_constant_struct::value) - base += set_varis().set(&all_varis[base], x4); - if (!is_constant_struct::value) - base += set_varis().set(&all_varis[base], x5); - if (!is_constant_struct::value) - set_varis().set(&all_varis[base], x6); - std::fill(all_partials, all_partials+nvaris, 0); - } - + VectorView d_x1; + VectorView d_x2; + VectorView d_x3; + VectorView d_x4; + VectorView d_x5; + VectorView d_x6; + + /** + * Constructor. + * + * @param x1 first set of operands + * @param x2 second set of operands + * @param x3 third set of operands + * @param x4 fourth set of operands + * @param x5 fifth set of operands + * @param x6 sixth set of operands + */ + OperandsAndPartials(const T1& x1 = 0, const T2& x2 = 0, + const T3& x3 = 0, const T4& x4 = 0, + const T5& x5 = 0, const T6& x6 = 0) { } + + /** + * Returns a T_return_type with the value specified with + * the partial derivatves. + * + * @param[in] value Value of the variable + * @returns a variable with the appropriate value + */ T_return_type - to_var(T_partials_return logp, - const T1& x1 = 0, const T2& x2 = 0, const T3& x3 = 0, - const T4& x4 = 0, const T5& x5 = 0, const T6& x6 = 0) { - return partials_to_var - ().to_var(logp, nvaris, all_varis, - all_partials, - x1, x2, x3, x4, x5, x6, d_x1, d_x2, - d_x3, d_x4, d_x5, d_x6); + value(double value) { + return value; } }; - } } - - #endif diff --git a/stan/math/prim/scal/meta/VectorBuilder.hpp b/stan/math/prim/scal/meta/VectorBuilder.hpp index 946e9d3fd1d..abb026d4dd1 100644 --- a/stan/math/prim/scal/meta/VectorBuilder.hpp +++ b/stan/math/prim/scal/meta/VectorBuilder.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_META_VECTORBUILDER_HPP #define STAN_MATH_PRIM_SCAL_META_VECTORBUILDER_HPP +#include #include -#include -#include namespace stan { @@ -23,38 +22,6 @@ namespace stan { * * These values are mutable. */ - - template - class VectorBuilderHelper { - public: - explicit VectorBuilderHelper(size_t /* n */) { } - T1& operator[](size_t /* i */) { - throw std::logic_error("used is false. this should never be called"); - } - }; - - template - class VectorBuilderHelper { - private: - T1 x_; - public: - explicit VectorBuilderHelper(size_t /* n */) : x_(0.0) { } - T1& operator[](size_t /* i */) { - return x_; - } - }; - - template - class VectorBuilderHelper { - private: - std::vector x_; - public: - explicit VectorBuilderHelper(size_t n) : x_(n) { } - T1& operator[](size_t i) { - return x_[i]; - } - }; - template @@ -62,12 +29,20 @@ namespace stan { public: VectorBuilderHelper::value> a; + explicit VectorBuilder(size_t n) : a(n) { } + T1& operator[](size_t i) { return a[i]; } + + inline typename + VectorBuilderHelper::value>::type + data() { + return a.data(); + } }; } #endif - diff --git a/stan/math/prim/scal/meta/VectorBuilderHelper.hpp b/stan/math/prim/scal/meta/VectorBuilderHelper.hpp new file mode 100644 index 00000000000..5eb319f1a2c --- /dev/null +++ b/stan/math/prim/scal/meta/VectorBuilderHelper.hpp @@ -0,0 +1,58 @@ +#ifndef STAN_MATH_PRIM_SCAL_META_VECTORBUILDER_HELPER_HPP +#define STAN_MATH_PRIM_SCAL_META_VECTORBUILDER_HELPER_HPP + +#include +#include + +namespace stan { + + /** + * VectorBuilder allocates type T1 values to be used as + * intermediate values. There are 2 template parameters: + * - used: boolean variable indicating whether this instance + * is used. If this is false, there is no storage allocated + * and operator[] throws. + * - is_vec: boolean variable indicating whether this instance + * should allocate a vector, if it is used. If this is false, + * the instance will only allocate a single double value. + * If this is true, it will allocate the number requested. + * Note that this is calculated based on template parameters + * T2 through T7. + * + * These values are mutable. + */ + template + class VectorBuilderHelper { + public: + explicit VectorBuilderHelper(size_t /* n */) { } + + T1& operator[](size_t /* i */) { + throw std::logic_error("used is false. this should never be called"); + } + + typedef T1 type; + + inline type& data() { + throw std::logic_error("used is false. this should never be called"); + } + }; + + template + class VectorBuilderHelper { + private: + T1 x_; + public: + explicit VectorBuilderHelper(size_t /* n */) : x_(0.0) { } + T1& operator[](size_t /* i */) { + return x_; + } + + typedef T1 type; + + inline type& data() { + return x_; + } + }; + +} +#endif diff --git a/stan/math/prim/scal/meta/VectorView.hpp b/stan/math/prim/scal/meta/VectorView.hpp index 8d40f5a75fb..d8c3c510a68 100644 --- a/stan/math/prim/scal/meta/VectorView.hpp +++ b/stan/math/prim/scal/meta/VectorView.hpp @@ -1,113 +1,146 @@ #ifndef STAN_MATH_PRIM_SCAL_META_VECTORVIEW_HPP #define STAN_MATH_PRIM_SCAL_META_VECTORVIEW_HPP -#include #include -#include #include +#include #include -#include namespace stan { /** - * VectorView is a template metaprogram that takes its argument and - * allows it to be used like a vector. There are three template parameters - * - T: Type of the thing to be wrapped. For example, double, var, vector, etc. - * - is_array: Boolean variable indicating whether the underlying type is an array. - * - throw_if_accessed: Boolean variable indicating whether this instance should - * not be used and should throw if operator[] is used. + * VectorView is a template expression that is constructed with a + * container or scalar, which it then allows to be used as an array + * using operator[]. * - * For a scalar value, it broadcasts the single value when using - * operator[]. + * For a scalar value, any index returns the reference or pointer + * used to construct the view. * - * For a vector, operator[] looks into the value passed in. - * Note: this is not safe. It is possible to read past the size of - * an array. + * For a container, the index returns a reference to the position in + * the underlying container used to construct the view. WARNING: + * There is no bounds checking for container indices and they will + * segfault if accessed beyond their boundaries. * - * Uses: - * Read arguments to prob functions as vectors, even if scalars, so - * they can be read by common code (and scalars automatically - * broadcast up to behave like vectors) : VectorView of immutable - * const array of double* (no allocation) + * The first use is to read arguments to prob functions as vectors, + * even if scalars, so they can be read by common code (and scalars + * automatically broadcast up to behave like vectors) : VectorView + * of immutable const array of double* (no allocation). * - * Build up derivatives into common storage : VectorView of - * mutable shared array (no allocation because allocated on - * auto-diff arena memory) + * The second use is to build up derivatives into common storage : + * VectorView of mutable shared array (no allocation because + * allocated on auto-diff arena memory). + * + * Because it deals with references to its inputs, it is up to the + * client of VectorView to ensure that the container being wrapped + * is not modified while the VectorView is in use in such a way as + * to disrupt the indexing. Similarly, because it deals with + * references, it cannot be constructed with a literal or expression. + * + * @tparam T Type of scalar or container being wrapped. + * @tparam is_array True if underlying type T can be indexed with + * operator[]. + * @tparam throw_if_accessed True if the behaviro is to throw an + * exception whenever operator[] is called. */ template ::value, bool throw_if_accessed = false> class VectorView { public: - typedef typename scalar_type::type scalar_t; + typedef typename + boost::conditional::value, + typename boost::add_const< + typename scalar_type::type>::type, + typename scalar_type::type>::type scalar_t; + + template + explicit VectorView(X x) { + throw std::logic_error("VectorView: the default template " + "specialization not implemented"); + } - explicit VectorView(scalar_t& c) : x_(&c) { } + scalar_t& operator[](int i) { + throw std::logic_error("VectorView: the default template " + "specialization not implemented"); + } - explicit VectorView(std::vector& v) : x_(&v[0]) { } + scalar_t& operator[](int i) const { + throw std::logic_error("VectorView: the default template " + "specialization not implemented"); + } + }; - template - explicit VectorView(Eigen::Matrix& m) : x_(&m(0)) { } - explicit VectorView(scalar_t* x) : x_(x) { } + template + class VectorView { + public: + typedef typename + boost::conditional::value, + typename boost::add_const< + typename scalar_type::type>::type, + typename scalar_type::type>::type scalar_t; + VectorView() { } + + template + explicit VectorView(X x) { } scalar_t& operator[](int i) { - if (throw_if_accessed) - throw std::out_of_range("VectorView: this cannot be accessed"); - if (is_array) - return x_[i]; - else - return x_[0]; + throw std::logic_error("VectorView: this cannot be accessed"); } - private: - scalar_t* x_; - }; + scalar_t& operator[](int i) const { + throw std::logic_error("VectorView: this cannot be accessed"); + } + }; - /** - * - * VectorView that has const correctness. - */ - template - class VectorView { + // this covers non-vectors: double + template + class VectorView { public: - typedef typename scalar_type::type scalar_t; + typedef typename + boost::conditional::value, + typename boost::add_const< + typename scalar_type::type>::type, + typename scalar_type::type>::type scalar_t; - explicit VectorView(const scalar_t& c) : x_(&c) { } + explicit VectorView(scalar_t& x) : x_(&x) { } - explicit VectorView(const scalar_t* x) : x_(x) { } - - explicit VectorView(const std::vector& v) : x_(&v[0]) { } + explicit VectorView(scalar_t* x) : x_(x) { } - template - explicit VectorView(const Eigen::Matrix& m) : x_(&m(0)) { } + scalar_t& operator[](int i) { + return *x_; + } - const scalar_t& operator[](int i) const { - if (throw_if_accessed) - throw std::out_of_range("VectorView: this cannot be accessed"); - if (is_array) - return x_[i]; - else - return x_[0]; + scalar_t& operator[](int i) const { + return *x_; } private: - const scalar_t* x_; + scalar_t* x_; }; - // simplify to hold value in common case where it's more efficient - template <> - class VectorView { + + // this covers raw memory: double* + template + class VectorView { public: - explicit VectorView(double x) : x_(x) { } - double operator[](int /* i */) const { - return x_; - } - private: - const double x_; - }; + typedef typename + boost::conditional::value, + typename boost::add_const< + typename scalar_type::type>::type, + typename scalar_type::type>::type scalar_t; + explicit VectorView(scalar_t* x) : x_(x) { } + scalar_t& operator[](int i) { + return x_[i]; + } + + scalar_t& operator[](int i) const { + return x_[i]; + } + private: + scalar_t* x_; + }; } #endif - diff --git a/stan/math/prim/scal/meta/is_constant_struct.hpp b/stan/math/prim/scal/meta/is_constant_struct.hpp index 1df18937a16..89576ec82c7 100644 --- a/stan/math/prim/scal/meta/is_constant_struct.hpp +++ b/stan/math/prim/scal/meta/is_constant_struct.hpp @@ -2,9 +2,6 @@ #define STAN_MATH_PRIM_SCAL_META_IS_CONSTANT_STRUCT_HPP #include -#include -#include - namespace stan { @@ -17,21 +14,5 @@ namespace stan { enum { value = is_constant::value }; }; - template - struct is_constant_struct > { - enum { value = is_constant_struct::value }; - }; - - template - struct is_constant_struct > { - enum { value = is_constant_struct::value }; - }; - - template - struct is_constant_struct > { - enum { value = is_constant_struct::value }; - }; - } #endif - diff --git a/stan/math/prim/scal/meta/length_mvt.hpp b/stan/math/prim/scal/meta/length_mvt.hpp index 88ac0c4d78a..5ee462abebd 100644 --- a/stan/math/prim/scal/meta/length_mvt.hpp +++ b/stan/math/prim/scal/meta/length_mvt.hpp @@ -1,26 +1,15 @@ #ifndef STAN_MATH_PRIM_SCAL_META_LENGTH_MVT_HPP #define STAN_MATH_PRIM_SCAL_META_LENGTH_MVT_HPP -#include #include -#include namespace stan { - // length_mvt() should only be applied to std vector or Eigen matrix template size_t length_mvt(const T& ) { throw std::out_of_range("length_mvt passed to an unrecognized type."); return 1U; } - template - size_t length_mvt(const Eigen::Matrix& ) { - return 1U; - } - template - size_t length_mvt(const std::vector >& x) { - return x.size(); - } } #endif diff --git a/stan/math/prim/scal/meta/scalar_type.hpp b/stan/math/prim/scal/meta/scalar_type.hpp index ac390a3b7b3..6b24b2f736b 100644 --- a/stan/math/prim/scal/meta/scalar_type.hpp +++ b/stan/math/prim/scal/meta/scalar_type.hpp @@ -1,11 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_META_SCALAR_TYPE_HPP #define STAN_MATH_PRIM_SCAL_META_SCALAR_TYPE_HPP -#include #include -#include -#include -#include #include namespace stan { @@ -25,6 +21,7 @@ namespace stan { type; }; } + /** * Metaprogram structure to determine the base scalar type * of a template argument. @@ -38,18 +35,10 @@ namespace stan { typedef typename scalar_type_helper::value, T>::type type; }; - // ****************** additions for new VV ************************* - template - struct scalar_type > { - typedef typename scalar_type::type type; - }; - template struct scalar_type { typedef typename scalar_type::type type; }; - } #endif - diff --git a/stan/math/prim/scal/meta/scalar_type_pre.hpp b/stan/math/prim/scal/meta/scalar_type_pre.hpp index 514c0775aae..97d1377c0fd 100644 --- a/stan/math/prim/scal/meta/scalar_type_pre.hpp +++ b/stan/math/prim/scal/meta/scalar_type_pre.hpp @@ -2,9 +2,6 @@ #define STAN_MATH_PRIM_SCAL_META_SCALAR_TYPE_PRE_HPP #include -#include -#include -#include #include namespace stan { diff --git a/stan/math/prim/scal/meta/size_of.hpp b/stan/math/prim/scal/meta/size_of.hpp index 3ecf3180c69..e09c4e5c677 100644 --- a/stan/math/prim/scal/meta/size_of.hpp +++ b/stan/math/prim/scal/meta/size_of.hpp @@ -2,13 +2,10 @@ #define STAN_MATH_PRIM_SCAL_META_SIZE_OF_HPP #include -#include -#include +#include namespace stan { - - template struct size_of_helper { static size_t size_of(const T& /*x*/) { diff --git a/stan/math/prim/scal/meta/value_type.hpp b/stan/math/prim/scal/meta/value_type.hpp index 303127ff47b..1744e592546 100644 --- a/stan/math/prim/scal/meta/value_type.hpp +++ b/stan/math/prim/scal/meta/value_type.hpp @@ -1,10 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_META_VALUE_TYPE_HPP #define STAN_MATH_PRIM_SCAL_META_VALUE_TYPE_HPP -#include - namespace stan { - namespace math { /** @@ -21,7 +18,6 @@ namespace stan { struct value_type { }; - /** * Template class for metaprogram to compute the type of values * stored in a constant container. @@ -33,25 +29,6 @@ namespace stan { typedef typename value_type::type type; }; - - /** - * Template metaprogram class to compute the type of values stored - * in a standard vector. - * - * @tparam T type of elements in standard vector. - */ - template - struct value_type > { - /** - * Type of value stored in a standard vector with type - * T entries. - */ - typedef typename std::vector::value_type type; - }; - - } } - - #endif diff --git a/stan/math/prim/scal/prob/bernoulli_ccdf_log.hpp b/stan/math/prim/scal/prob/bernoulli_ccdf_log.hpp index d1f9f1824a6..f3c3f1f14ad 100644 --- a/stan/math/prim/scal/prob/bernoulli_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/bernoulli_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -58,15 +60,14 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, theta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) >= 1) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - theta); + return operands_and_partials.value(stan::math::negative_infinity()); } else { const T_partials_return Pi = value_of(theta_vec[i]); @@ -77,7 +78,7 @@ namespace stan { } } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/bernoulli_cdf.hpp b/stan/math/prim/scal/prob/bernoulli_cdf.hpp index 2d8b8737660..51fd2437ecf 100644 --- a/stan/math/prim/scal/prob/bernoulli_cdf.hpp +++ b/stan/math/prim/scal/prob/bernoulli_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace stan { @@ -57,7 +59,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, theta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { @@ -78,7 +80,7 @@ namespace stan { for (size_t i = 0; i < stan::length(theta); ++i) operands_and_partials.d_x1[i] *= P; } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } // namespace math diff --git a/stan/math/prim/scal/prob/bernoulli_cdf_log.hpp b/stan/math/prim/scal/prob/bernoulli_cdf_log.hpp index 06351f15350..c57b71bc85f 100644 --- a/stan/math/prim/scal/prob/bernoulli_cdf_log.hpp +++ b/stan/math/prim/scal/prob/bernoulli_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -58,8 +60,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - theta); + return operands_and_partials.value(stan::math::negative_infinity()); } for (size_t i = 0; i < size; i++) { @@ -76,7 +77,7 @@ namespace stan { operands_and_partials.d_x1[i] -= 1 / Pi; } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/bernoulli_log.hpp b/stan/math/prim/scal/prob/bernoulli_log.hpp index 7920cf3c7b9..470b2f3288c 100644 --- a/stan/math/prim/scal/prob/bernoulli_log.hpp +++ b/stan/math/prim/scal/prob/bernoulli_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -111,7 +113,7 @@ namespace stan { } } } - return operands_and_partials.to_var(logp, theta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/bernoulli_logit_log.hpp b/stan/math/prim/scal/prob/bernoulli_logit_log.hpp index 43bdaaac7e3..887f87513fb 100644 --- a/stan/math/prim/scal/prob/bernoulli_logit_log.hpp +++ b/stan/math/prim/scal/prob/bernoulli_logit_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -94,7 +96,7 @@ namespace stan { / (exp_m_ntheta + 1); } } - return operands_and_partials.to_var(logp, theta); + return operands_and_partials.value(logp); } template #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/beta_binomial_ccdf_log.hpp b/stan/math/prim/scal/prob/beta_binomial_ccdf_log.hpp index e7cc84e36b7..d1af56769de 100644 --- a/stan/math/prim/scal/prob/beta_binomial_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/beta_binomial_ccdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CCDF_LOG_HPP +#include +#include #include #include #include @@ -79,15 +81,14 @@ namespace stan { // The gradients are technically ill-defined, but treated as neg infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) <= 0) - return operands_and_partials.to_var(0.0, alpha, beta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) >= value_of(N_vec[i])) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); } const T_partials_return n_dbl = value_of(n_vec[i]); @@ -139,7 +140,7 @@ namespace stan { } } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/beta_binomial_cdf.hpp b/stan/math/prim/scal/prob/beta_binomial_cdf.hpp index 3252ee1e058..ffd8f9abca3 100644 --- a/stan/math/prim/scal/prob/beta_binomial_cdf.hpp +++ b/stan/math/prim/scal/prob/beta_binomial_cdf.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CDF_HPP +#include +#include #include #include #include @@ -79,7 +81,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) <= 0) - return operands_and_partials.to_var(0.0, alpha, beta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { @@ -150,7 +152,7 @@ namespace stan { operands_and_partials.d_x2[i] *= P; } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/beta_binomial_cdf_log.hpp b/stan/math/prim/scal/prob/beta_binomial_cdf_log.hpp index ecc3207a169..250aa9edf8d 100644 --- a/stan/math/prim/scal/prob/beta_binomial_cdf_log.hpp +++ b/stan/math/prim/scal/prob/beta_binomial_cdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_CDF_LOG_HPP +#include +#include #include #include #include @@ -79,8 +81,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as neg infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) <= 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); } for (size_t i = 0; i < size; i++) { @@ -139,7 +140,7 @@ namespace stan { } } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/beta_binomial_log.hpp b/stan/math/prim/scal/prob/beta_binomial_log.hpp index 9556cb01631..2e1b708e0aa 100644 --- a/stan/math/prim/scal/prob/beta_binomial_log.hpp +++ b/stan/math/prim/scal/prob/beta_binomial_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_BINOMIAL_LOG_HPP +#include +#include #include #include #include @@ -75,7 +77,7 @@ namespace stan { for (size_t i = 0; i < size; i++) { if (n_vec[i] < 0 || n_vec[i] > N_vec[i]) - return operands_and_partials.to_var(LOG_ZERO, alpha, beta); + return operands_and_partials.value(LOG_ZERO); } using stan::math::lbeta; @@ -164,7 +166,7 @@ namespace stan { + digamma_alpha_plus_beta[i] - digamma_beta[i]; } - return operands_and_partials.to_var(logp, alpha, beta); + return operands_and_partials.value(logp); } template #include #include #include diff --git a/stan/math/prim/scal/prob/beta_ccdf_log.hpp b/stan/math/prim/scal/prob/beta_ccdf_log.hpp index f4fa7c7a129..91fcb37114d 100644 --- a/stan/math/prim/scal/prob/beta_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/beta_ccdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_CCDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -23,6 +22,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -141,7 +143,7 @@ namespace stan { operands_and_partials.d_x3[n] -= g2 / Pn; } - return operands_and_partials.to_var(ccdf_log, y, alpha, beta); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/beta_cdf.hpp b/stan/math/prim/scal/prob/beta_cdf.hpp index f12f6a7e516..54df9c6ca09 100644 --- a/stan/math/prim/scal/prob/beta_cdf.hpp +++ b/stan/math/prim/scal/prob/beta_cdf.hpp @@ -1,18 +1,17 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_HPP +#include #include #include #include #include #include - #include #include #include #include #include - #include #include #include @@ -24,11 +23,9 @@ #include #include #include - #include #include #include - #include namespace stan { @@ -89,7 +86,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) <= 0) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -164,7 +161,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/beta_cdf_log.hpp b/stan/math/prim/scal/prob/beta_cdf_log.hpp index c0974facd63..dcd1cd68664 100644 --- a/stan/math/prim/scal/prob/beta_cdf_log.hpp +++ b/stan/math/prim/scal/prob/beta_cdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_CDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -22,6 +21,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -140,7 +142,7 @@ namespace stan { operands_and_partials.d_x3[n] += g2 / Pn; } - return operands_and_partials.to_var(cdf_log, y, alpha, beta); + return operands_and_partials.value(cdf_log); } } diff --git a/stan/math/prim/scal/prob/beta_log.hpp b/stan/math/prim/scal/prob/beta_log.hpp index bc4a54b6639..e51406f4671 100644 --- a/stan/math/prim/scal/prob/beta_log.hpp +++ b/stan/math/prim/scal/prob/beta_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BETA_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BETA_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -22,6 +21,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -201,7 +203,7 @@ namespace stan { operands_and_partials.d_x3[n] += log1m_y[n] + digamma_alpha_beta[n] - digamma_beta[n]; } - return operands_and_partials.to_var(logp, y, alpha, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/beta_rng.hpp b/stan/math/prim/scal/prob/beta_rng.hpp index 5a94f76378b..d91bfc1f19f 100644 --- a/stan/math/prim/scal/prob/beta_rng.hpp +++ b/stan/math/prim/scal/prob/beta_rng.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/binomial_ccdf_log.hpp b/stan/math/prim/scal/prob/binomial_ccdf_log.hpp index 1db3685dfb1..77f7e9627ed 100644 --- a/stan/math/prim/scal/prob/binomial_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/binomial_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -77,15 +79,14 @@ namespace stan { // but treated as negative infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, theta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) >= value_of(N_vec[i])) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - theta); + return operands_and_partials.value(stan::math::negative_infinity()); } const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return N_dbl = value_of(N_vec[i]); @@ -101,7 +102,7 @@ namespace stan { * pow(1-theta_dbl, N_dbl-n_dbl-1) / betafunc / Pi; } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/binomial_cdf.hpp b/stan/math/prim/scal/prob/binomial_cdf.hpp index 103ac363dee..5706d957ef0 100644 --- a/stan/math/prim/scal/prob/binomial_cdf.hpp +++ b/stan/math/prim/scal/prob/binomial_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -77,7 +79,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, theta); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { @@ -106,7 +108,7 @@ namespace stan { operands_and_partials.d_x1[i] *= P; } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/binomial_cdf_log.hpp b/stan/math/prim/scal/prob/binomial_cdf_log.hpp index 0a1bacb6537..efe4cba766a 100644 --- a/stan/math/prim/scal/prob/binomial_cdf_log.hpp +++ b/stan/math/prim/scal/prob/binomial_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -77,8 +79,7 @@ namespace stan { // but treated as negative infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - theta); + return operands_and_partials.value(stan::math::negative_infinity()); } for (size_t i = 0; i < size; i++) { @@ -101,7 +102,7 @@ namespace stan { * pow(1-theta_dbl, N_dbl-n_dbl-1) / betafunc / Pi; } - return operands_and_partials.to_var(P, theta); + return operands_and_partials.value(P); } } diff --git a/stan/math/prim/scal/prob/binomial_log.hpp b/stan/math/prim/scal/prob/binomial_log.hpp index e2e1a575748..a10a5809d72 100644 --- a/stan/math/prim/scal/prob/binomial_log.hpp +++ b/stan/math/prim/scal/prob/binomial_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_BINOMIAL_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -21,6 +21,8 @@ #include #include #include +#include +#include namespace stan { @@ -116,7 +118,7 @@ namespace stan { } } - return operands_and_partials.to_var(logp, theta); + return operands_and_partials.value(logp); } template -#include +#include +#include #include #include #include @@ -21,6 +21,8 @@ #include #include #include +#include +#include namespace stan { @@ -120,7 +122,7 @@ namespace stan { } } - return operands_and_partials.to_var(logp, alpha); + return operands_and_partials.value(logp); } template #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/cauchy_ccdf_log.hpp b/stan/math/prim/scal/prob/cauchy_ccdf_log.hpp index f9d3cafac82..ddab1a71058 100644 --- a/stan/math/prim/scal/prob/cauchy_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/cauchy_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -86,7 +88,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x3[n] += rep_deriv * z; } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/cauchy_cdf.hpp b/stan/math/prim/scal/prob/cauchy_cdf.hpp index 7f12e86b609..3279b8f122f 100644 --- a/stan/math/prim/scal/prob/cauchy_cdf.hpp +++ b/stan/math/prim/scal/prob/cauchy_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -74,7 +76,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, mu, sigma); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -125,7 +127,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/cauchy_cdf_log.hpp b/stan/math/prim/scal/prob/cauchy_cdf_log.hpp index bd25e751410..60aa6611b64 100644 --- a/stan/math/prim/scal/prob/cauchy_cdf_log.hpp +++ b/stan/math/prim/scal/prob/cauchy_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CAUCHY_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -86,7 +88,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x3[n] -= rep_deriv * z; } - return operands_and_partials.to_var(cdf_log, y, mu, sigma); + return operands_and_partials.value(cdf_log); } } diff --git a/stan/math/prim/scal/prob/cauchy_log.hpp b/stan/math/prim/scal/prob/cauchy_log.hpp index 704cd8116b0..a68cecfa1dc 100644 --- a/stan/math/prim/scal/prob/cauchy_log.hpp +++ b/stan/math/prim/scal/prob/cauchy_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CAUCHY_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CAUCHY_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -136,7 +138,7 @@ namespace stan { += (y_minus_mu_squared - sigma_squared[n]) * inv_sigma[n] / (sigma_squared[n] + y_minus_mu_squared); } - return operands_and_partials.to_var(logp, y, mu, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/cauchy_rng.hpp b/stan/math/prim/scal/prob/cauchy_rng.hpp index 3f3c435d6d7..66133cd19f7 100644 --- a/stan/math/prim/scal/prob/cauchy_rng.hpp +++ b/stan/math/prim/scal/prob/cauchy_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/chi_square_ccdf_log.hpp b/stan/math/prim/scal/prob/chi_square_ccdf_log.hpp index 4f82460eb73..1abbc312fe0 100644 --- a/stan/math/prim/scal/prob/chi_square_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/chi_square_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include @@ -61,7 +63,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu); + return operands_and_partials.value(0.0); } // Compute ccdf_log and its gradients @@ -92,8 +94,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu); + return operands_and_partials.value(stan::math::negative_infinity()); // Pull out values const T_partials_return y_dbl = value_of(y_vec[n]); @@ -115,7 +116,7 @@ namespace stan { digamma_vec[n]) / Pn; } - return operands_and_partials.to_var(ccdf_log, y, nu); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/chi_square_cdf.hpp b/stan/math/prim/scal/prob/chi_square_cdf.hpp index d8cd29befca..32d80e483b9 100644 --- a/stan/math/prim/scal/prob/chi_square_cdf.hpp +++ b/stan/math/prim/scal/prob/chi_square_cdf.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CDF_HPP +#include +#include #include #include #include @@ -70,7 +72,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -131,7 +133,7 @@ namespace stan { operands_and_partials.d_x2[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, nu); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/chi_square_cdf_log.hpp b/stan/math/prim/scal/prob/chi_square_cdf_log.hpp index ac5988cfe25..d3883bf37d5 100644 --- a/stan/math/prim/scal/prob/chi_square_cdf_log.hpp +++ b/stan/math/prim/scal/prob/chi_square_cdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_CDF_LOG_HPP +#include +#include #include #include #include @@ -61,8 +63,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu); + return operands_and_partials.value(stan::math::negative_infinity()); } // Compute cdf_log and its gradients @@ -93,7 +94,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, nu); + return operands_and_partials.value(0.0); // Pull out values const T_partials_return y_dbl = value_of(y_vec[n]); @@ -115,7 +116,7 @@ namespace stan { digamma_vec[n]) / Pn; } - return operands_and_partials.to_var(cdf_log, y, nu); + return operands_and_partials.value(cdf_log); } } diff --git a/stan/math/prim/scal/prob/chi_square_log.hpp b/stan/math/prim/scal/prob/chi_square_log.hpp index 117b45d9509..d68af71696e 100644 --- a/stan/math/prim/scal/prob/chi_square_log.hpp +++ b/stan/math/prim/scal/prob/chi_square_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_CHI_SQUARE_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -135,7 +137,7 @@ namespace stan { - digamma_half_nu_over_two[n] + log_y[n]*0.5; } } - return operands_and_partials.to_var(logp, y, nu); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/chi_square_rng.hpp b/stan/math/prim/scal/prob/chi_square_rng.hpp index 330132dafc5..e71eb0a2833 100644 --- a/stan/math/prim/scal/prob/chi_square_rng.hpp +++ b/stan/math/prim/scal/prob/chi_square_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/double_exponential_ccdf_log.hpp b/stan/math/prim/scal/prob/double_exponential_ccdf_log.hpp index 0951d85d64a..43c8e9c1958 100644 --- a/stan/math/prim/scal/prob/double_exponential_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/double_exponential_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -96,7 +98,7 @@ namespace stan { operands_and_partials.d_x3[n] += scaled_diff * inv_sigma; } } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/double_exponential_cdf.hpp b/stan/math/prim/scal/prob/double_exponential_cdf.hpp index 0ec88714913..2b79453d85f 100644 --- a/stan/math/prim/scal/prob/double_exponential_cdf.hpp +++ b/stan/math/prim/scal/prob/double_exponential_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -108,7 +110,7 @@ namespace stan { operands_and_partials.d_x3[n] -= rep_deriv * scaled_diff; } } - return operands_and_partials.to_var(cdf, y, mu, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/double_exponential_cdf_log.hpp b/stan/math/prim/scal/prob/double_exponential_cdf_log.hpp index 6a15caa50e8..924e5c645a4 100644 --- a/stan/math/prim/scal/prob/double_exponential_cdf_log.hpp +++ b/stan/math/prim/scal/prob/double_exponential_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -96,7 +98,7 @@ namespace stan { * inv_sigma; } } - return operands_and_partials.to_var(cdf_log, y, mu, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/double_exponential_log.hpp b/stan/math/prim/scal/prob/double_exponential_log.hpp index 48c09f2cd95..9bbfedc0dde 100644 --- a/stan/math/prim/scal/prob/double_exponential_log.hpp +++ b/stan/math/prim/scal/prob/double_exponential_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_DOUBLE_EXPONENTIAL_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -119,7 +121,7 @@ namespace stan { operands_and_partials.d_x3[n] += -inv_sigma[n] + fabs_y_m_mu * inv_sigma_squared[n]; } - return operands_and_partials.to_var(logp, y, mu, sigma); + return operands_and_partials.value(logp); } diff --git a/stan/math/prim/scal/prob/double_exponential_rng.hpp b/stan/math/prim/scal/prob/double_exponential_rng.hpp index 487b7103671..5c27bd89383 100644 --- a/stan/math/prim/scal/prob/double_exponential_rng.hpp +++ b/stan/math/prim/scal/prob/double_exponential_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/exp_mod_normal_ccdf_log.hpp b/stan/math/prim/scal/prob/exp_mod_normal_ccdf_log.hpp index 4cf5c809775..a0984832abc 100644 --- a/stan/math/prim/scal/prob/exp_mod_normal_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/exp_mod_normal_ccdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CCDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -12,6 +11,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -72,10 +74,9 @@ namespace stan { for (size_t n = 0; n < N; n++) { if (boost::math::isinf(y_vec[n])) { if (y_vec[n] > 0.0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, mu, sigma, lambda); + return operands_and_partials.value(stan::math::negative_infinity()); else - return operands_and_partials.to_var(0.0, y, mu, sigma, lambda); + return operands_and_partials.value(0.0); } const T_partials_return y_dbl = value_of(y_vec[n]); @@ -129,7 +130,7 @@ namespace stan { / ccdf_; } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma, lambda); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/exp_mod_normal_cdf.hpp b/stan/math/prim/scal/prob/exp_mod_normal_cdf.hpp index 8ce0874f23a..2c770db6e6c 100644 --- a/stan/math/prim/scal/prob/exp_mod_normal_cdf.hpp +++ b/stan/math/prim/scal/prob/exp_mod_normal_cdf.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CDF_HPP -#include -#include -#include +#include +#include #include #include #include @@ -12,6 +11,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -69,7 +71,7 @@ namespace stan { for (size_t n = 0; n < N; n++) { if (boost::math::isinf(y_vec[n])) { if (y_vec[n] < 0.0) - return operands_and_partials.to_var(0.0, y, mu, sigma, lambda); + return operands_and_partials.value(0.0); } const T_partials_return y_dbl = value_of(y_vec[n]); @@ -135,7 +137,7 @@ namespace stan { operands_and_partials.d_x4[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, mu, sigma, lambda); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/exp_mod_normal_cdf_log.hpp b/stan/math/prim/scal/prob/exp_mod_normal_cdf_log.hpp index 7929c7853c5..36b06a44fa5 100644 --- a/stan/math/prim/scal/prob/exp_mod_normal_cdf_log.hpp +++ b/stan/math/prim/scal/prob/exp_mod_normal_cdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_CDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -12,6 +11,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -71,10 +73,9 @@ namespace stan { for (size_t n = 0; n < N; n++) { if (boost::math::isinf(y_vec[n])) { if (y_vec[n] < 0.0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, mu, sigma, lambda); + return operands_and_partials.value(stan::math::negative_infinity()); else - return operands_and_partials.to_var(0.0, y, mu, sigma, lambda); + return operands_and_partials.value(0.0); } const T_partials_return y_dbl = value_of(y_vec[n]); @@ -129,7 +130,7 @@ namespace stan { / denom; } - return operands_and_partials.to_var(cdf_log, y, mu, sigma, lambda); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/exp_mod_normal_log.hpp b/stan/math/prim/scal/prob/exp_mod_normal_log.hpp index effc53c2c13..036868e4ffe 100644 --- a/stan/math/prim/scal/prob/exp_mod_normal_log.hpp +++ b/stan/math/prim/scal/prob/exp_mod_normal_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXP_MOD_NORMAL_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -12,6 +11,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -129,7 +131,7 @@ namespace stan { += 1 / lambda_dbl + lambda_dbl * sigma_dbl * sigma_dbl + mu_dbl - y_dbl + deriv_logerfc * sigma_dbl / std::sqrt(2.0); } - return operands_and_partials.to_var(logp, y, mu, sigma, lambda); + return operands_and_partials.value(logp); } template -#include -#include -#include #include #include #include #include #include #include -#include #include #include -#include #include #include #include #include +#include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/exponential_ccdf_log.hpp b/stan/math/prim/scal/prob/exponential_ccdf_log.hpp index 3bff55c1b05..b09efd399d0 100644 --- a/stan/math/prim/scal/prob/exponential_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/exponential_ccdf_log.hpp @@ -64,7 +64,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x2[n] -= y_dbl; } - return operands_and_partials.to_var(ccdf_log, y, beta); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/exponential_cdf.hpp b/stan/math/prim/scal/prob/exponential_cdf.hpp index d5bf2b78c19..0ecb294518d 100644 --- a/stan/math/prim/scal/prob/exponential_cdf.hpp +++ b/stan/math/prim/scal/prob/exponential_cdf.hpp @@ -88,7 +88,7 @@ namespace stan { operands_and_partials.d_x2[n] += rep_deriv * y_dbl * cdf; } - return operands_and_partials.to_var(cdf, y, beta); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/exponential_cdf_log.hpp b/stan/math/prim/scal/prob/exponential_cdf_log.hpp index 1f1d89284ed..821ac9dd84c 100644 --- a/stan/math/prim/scal/prob/exponential_cdf_log.hpp +++ b/stan/math/prim/scal/prob/exponential_cdf_log.hpp @@ -70,7 +70,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x2[n] -= rep_deriv * y_dbl; } - return operands_and_partials.to_var(cdf_log, y, beta); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/exponential_log.hpp b/stan/math/prim/scal/prob/exponential_log.hpp index c8ba511c43e..2b3fa172e25 100644 --- a/stan/math/prim/scal/prob/exponential_log.hpp +++ b/stan/math/prim/scal/prob/exponential_log.hpp @@ -1,8 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_LOG_HPP -#include -#include +#include #include #include #include @@ -10,13 +9,14 @@ #include #include #include -#include #include #include #include #include #include #include +#include +#include #include namespace stan { @@ -102,7 +102,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x2[n] += 1 / beta_dbl - y_dbl; } - return operands_and_partials.to_var(logp, y, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/exponential_rng.hpp b/stan/math/prim/scal/prob/exponential_rng.hpp index 9aefb1604ed..ae85e4e9dac 100644 --- a/stan/math/prim/scal/prob/exponential_rng.hpp +++ b/stan/math/prim/scal/prob/exponential_rng.hpp @@ -1,22 +1,19 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_EXPONENTIAL_RNG_HPP -#include -#include -#include #include #include #include #include #include #include -#include #include #include -#include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/frechet_ccdf_log.hpp b/stan/math/prim/scal/prob/frechet_ccdf_log.hpp index 1f19cdcdf9e..851c85ed11d 100644 --- a/stan/math/prim/scal/prob/frechet_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/frechet_ccdf_log.hpp @@ -82,7 +82,7 @@ namespace stan { operands_and_partials.d_x3[n] += alpha_dbl / sigma_dbl * rep_deriv_; } - return operands_and_partials.to_var(ccdf_log, y, alpha, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/frechet_cdf.hpp b/stan/math/prim/scal/prob/frechet_cdf.hpp index 94e6d692652..399a9f266ad 100644 --- a/stan/math/prim/scal/prob/frechet_cdf.hpp +++ b/stan/math/prim/scal/prob/frechet_cdf.hpp @@ -92,7 +92,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, alpha, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/frechet_cdf_log.hpp b/stan/math/prim/scal/prob/frechet_cdf_log.hpp index 6d3e4aa157a..a51d6d9f7a7 100644 --- a/stan/math/prim/scal/prob/frechet_cdf_log.hpp +++ b/stan/math/prim/scal/prob/frechet_cdf_log.hpp @@ -77,7 +77,7 @@ namespace stan { operands_and_partials.d_x3[n] -= pow_ * alpha_dbl / sigma_dbl; } - return operands_and_partials.to_var(cdf_log, y, alpha, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/frechet_log.hpp b/stan/math/prim/scal/prob/frechet_log.hpp index d57abc89a17..30dfcff6ae5 100644 --- a/stan/math/prim/scal/prob/frechet_log.hpp +++ b/stan/math/prim/scal/prob/frechet_log.hpp @@ -131,7 +131,7 @@ namespace stan { += alpha_dbl / value_of(sigma_vec[n]) * (1 - sigma_div_y_pow_alpha[n]); } - return operands_and_partials.to_var(logp, y, alpha, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/frechet_rng.hpp b/stan/math/prim/scal/prob/frechet_rng.hpp index f0b24eceb04..4141fc58387 100644 --- a/stan/math/prim/scal/prob/frechet_rng.hpp +++ b/stan/math/prim/scal/prob/frechet_rng.hpp @@ -1,9 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_FRECHET_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_FRECHET_RNG_HPP -#include -#include -#include #include #include #include @@ -13,13 +10,13 @@ #include #include #include -#include #include #include -#include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/gamma_ccdf_log.hpp b/stan/math/prim/scal/prob/gamma_ccdf_log.hpp index 31f69f4ae6e..af5be7f46d9 100644 --- a/stan/math/prim/scal/prob/gamma_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/gamma_ccdf_log.hpp @@ -80,7 +80,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } // Compute ccdf_log and its gradients @@ -111,8 +111,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); // Pull out values const T_partials_return y_dbl = value_of(y_vec[n]); @@ -137,7 +136,7 @@ namespace stan { * pow(beta_dbl * y_dbl, alpha_dbl-1) / tgamma(alpha_dbl) / Pn; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/gamma_cdf.hpp b/stan/math/prim/scal/prob/gamma_cdf.hpp index 0e00a7dd597..d88e921ee8a 100644 --- a/stan/math/prim/scal/prob/gamma_cdf.hpp +++ b/stan/math/prim/scal/prob/gamma_cdf.hpp @@ -92,7 +92,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -160,7 +160,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/gamma_cdf_log.hpp b/stan/math/prim/scal/prob/gamma_cdf_log.hpp index ea08b03f233..3fd21026ad7 100644 --- a/stan/math/prim/scal/prob/gamma_cdf_log.hpp +++ b/stan/math/prim/scal/prob/gamma_cdf_log.hpp @@ -78,8 +78,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); } // Compute cdf_log and its gradients @@ -110,7 +109,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); // Pull out values const T_partials_return y_dbl = value_of(y_vec[n]); @@ -135,7 +134,7 @@ namespace stan { * pow(beta_dbl * y_dbl, alpha_dbl-1) / tgamma(alpha_dbl) / Pn; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/gamma_log.hpp b/stan/math/prim/scal/prob/gamma_log.hpp index f70b06576df..a7bdbd9532c 100644 --- a/stan/math/prim/scal/prob/gamma_log.hpp +++ b/stan/math/prim/scal/prob/gamma_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_GAMMA_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_GAMMA_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -155,7 +157,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x3[n] += alpha_dbl / beta_dbl - y_dbl; } - return operands_and_partials.to_var(logp, y, alpha, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/gamma_rng.hpp b/stan/math/prim/scal/prob/gamma_rng.hpp index 3a9652b17e9..8029d756b0f 100644 --- a/stan/math/prim/scal/prob/gamma_rng.hpp +++ b/stan/math/prim/scal/prob/gamma_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -16,10 +15,8 @@ #include #include #include -#include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/gumbel_ccdf_log.hpp b/stan/math/prim/scal/prob/gumbel_ccdf_log.hpp index ffec2c83f42..a185e896c14 100644 --- a/stan/math/prim/scal/prob/gumbel_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/gumbel_ccdf_log.hpp @@ -81,7 +81,7 @@ namespace stan { operands_and_partials.d_x3[n] += rep_deriv * scaled_diff / ccdf_log_; } - return operands_and_partials.to_var(ccdf_log, y, mu, beta); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/gumbel_cdf.hpp b/stan/math/prim/scal/prob/gumbel_cdf.hpp index 98c82d2fe01..d8c01cbcb22 100644 --- a/stan/math/prim/scal/prob/gumbel_cdf.hpp +++ b/stan/math/prim/scal/prob/gumbel_cdf.hpp @@ -93,7 +93,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, mu, beta); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/gumbel_cdf_log.hpp b/stan/math/prim/scal/prob/gumbel_cdf_log.hpp index 0cb44ced781..0097f757f53 100644 --- a/stan/math/prim/scal/prob/gumbel_cdf_log.hpp +++ b/stan/math/prim/scal/prob/gumbel_cdf_log.hpp @@ -77,7 +77,7 @@ namespace stan { operands_and_partials.d_x3[n] -= rep_deriv * scaled_diff; } - return operands_and_partials.to_var(cdf_log, y, mu, beta); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/gumbel_log.hpp b/stan/math/prim/scal/prob/gumbel_log.hpp index b0fdc8d2bbf..262230555f2 100644 --- a/stan/math/prim/scal/prob/gumbel_log.hpp +++ b/stan/math/prim/scal/prob/gumbel_log.hpp @@ -109,7 +109,7 @@ namespace stan { += -inv_beta[n] + y_minus_mu_over_beta * inv_beta[n] - scaled_diff * y_minus_mu_over_beta; } - return operands_and_partials.to_var(logp, y, mu, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/gumbel_rng.hpp b/stan/math/prim/scal/prob/gumbel_rng.hpp index 1bf3507be62..3a8e0708ba0 100644 --- a/stan/math/prim/scal/prob/gumbel_rng.hpp +++ b/stan/math/prim/scal/prob/gumbel_rng.hpp @@ -1,22 +1,19 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_GUMBEL_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_GUMBEL_RNG_HPP -#include -#include -#include #include #include #include #include #include -#include #include #include -#include #include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/hypergeometric_log.hpp b/stan/math/prim/scal/prob/hypergeometric_log.hpp index 2b71a30a3da..29a3cbaf8cb 100644 --- a/stan/math/prim/scal/prob/hypergeometric_log.hpp +++ b/stan/math/prim/scal/prob/hypergeometric_log.hpp @@ -1,7 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_HYPERGEOMETRIC_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_HYPERGEOMETRIC_LOG_HPP -#include #include #include #include @@ -9,13 +8,12 @@ #include #include #include -#include #include #include -#include #include #include #include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/inv_chi_square_ccdf_log.hpp b/stan/math/prim/scal/prob/inv_chi_square_ccdf_log.hpp index 9d3013f9bcc..9e51e3df52e 100644 --- a/stan/math/prim/scal/prob/inv_chi_square_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/inv_chi_square_ccdf_log.hpp @@ -69,7 +69,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu); + return operands_and_partials.value(0.0); // Compute ccdf_log and its gradients using stan::math::gamma_q; @@ -98,8 +98,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu); + return operands_and_partials.value(stan::math::negative_infinity()); } // Pull out values @@ -125,7 +124,7 @@ namespace stan { digamma_vec[n]) / Pn; } - return operands_and_partials.to_var(P, y, nu); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_chi_square_cdf.hpp b/stan/math/prim/scal/prob/inv_chi_square_cdf.hpp index 11cfdf8a9e3..66fdbaffc2a 100644 --- a/stan/math/prim/scal/prob/inv_chi_square_cdf.hpp +++ b/stan/math/prim/scal/prob/inv_chi_square_cdf.hpp @@ -69,7 +69,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu); + return operands_and_partials.value(0.0); // Compute CDF and its gradients using stan::math::gamma_q; @@ -131,7 +131,7 @@ namespace stan { operands_and_partials.d_x2[n] *= P; } - return operands_and_partials.to_var(P, y, nu); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_chi_square_cdf_log.hpp b/stan/math/prim/scal/prob/inv_chi_square_cdf_log.hpp index 8c41b6660d3..e306250b416 100644 --- a/stan/math/prim/scal/prob/inv_chi_square_cdf_log.hpp +++ b/stan/math/prim/scal/prob/inv_chi_square_cdf_log.hpp @@ -69,8 +69,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu); + return operands_and_partials.value(stan::math::negative_infinity()); // Compute cdf_log and its gradients using stan::math::gamma_q; @@ -124,7 +123,7 @@ namespace stan { digamma_vec[n]) / Pn; } - return operands_and_partials.to_var(P, y, nu); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_chi_square_log.hpp b/stan/math/prim/scal/prob/inv_chi_square_log.hpp index a62398d151a..63ae5a38478 100644 --- a/stan/math/prim/scal/prob/inv_chi_square_log.hpp +++ b/stan/math/prim/scal/prob/inv_chi_square_log.hpp @@ -133,7 +133,7 @@ namespace stan { - 0.5*log_y[n]; } } - return operands_and_partials.to_var(logp, y, nu); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/inv_chi_square_rng.hpp b/stan/math/prim/scal/prob/inv_chi_square_rng.hpp index afec7e714bf..1ca7c5be6d5 100644 --- a/stan/math/prim/scal/prob/inv_chi_square_rng.hpp +++ b/stan/math/prim/scal/prob/inv_chi_square_rng.hpp @@ -1,9 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_INV_CHI_SQUARE_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_INV_CHI_SQUARE_RNG_HPP -#include -#include -#include #include #include #include @@ -14,13 +11,13 @@ #include #include #include -#include #include #include -#include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/inv_gamma_ccdf_log.hpp b/stan/math/prim/scal/prob/inv_gamma_ccdf_log.hpp index 71b122a5af2..61f70137216 100644 --- a/stan/math/prim/scal/prob/inv_gamma_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/inv_gamma_ccdf_log.hpp @@ -79,7 +79,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } // Compute ccdf_log and its gradients @@ -110,8 +110,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); // Pull out values const T_partials_return y_dbl = value_of(y_vec[n]); @@ -142,7 +141,7 @@ namespace stan { / tgamma(alpha_dbl) / Pn; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_gamma_cdf.hpp b/stan/math/prim/scal/prob/inv_gamma_cdf.hpp index 2e51986c55a..93116dd2ce0 100644 --- a/stan/math/prim/scal/prob/inv_gamma_cdf.hpp +++ b/stan/math/prim/scal/prob/inv_gamma_cdf.hpp @@ -94,7 +94,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -168,7 +168,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_gamma_cdf_log.hpp b/stan/math/prim/scal/prob/inv_gamma_cdf_log.hpp index 82a3bbf6a65..65d00ef7bb3 100644 --- a/stan/math/prim/scal/prob/inv_gamma_cdf_log.hpp +++ b/stan/math/prim/scal/prob/inv_gamma_cdf_log.hpp @@ -79,8 +79,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); } // Compute cdf_log and its gradients @@ -141,7 +140,7 @@ namespace stan { / tgamma(alpha_dbl) / Pn; } - return operands_and_partials.to_var(P, y, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/inv_gamma_log.hpp b/stan/math/prim/scal/prob/inv_gamma_log.hpp index 1108027bfa5..bec7b4bfb70 100644 --- a/stan/math/prim/scal/prob/inv_gamma_log.hpp +++ b/stan/math/prim/scal/prob/inv_gamma_log.hpp @@ -154,7 +154,7 @@ namespace stan { if (!is_constant::type>::value) operands_and_partials.d_x3[n] += alpha_dbl / beta_dbl - inv_y[n]; } - return operands_and_partials.to_var(logp, y, alpha, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/inv_gamma_rng.hpp b/stan/math/prim/scal/prob/inv_gamma_rng.hpp index 9a6bd67f300..200fe5ce5b8 100644 --- a/stan/math/prim/scal/prob/inv_gamma_rng.hpp +++ b/stan/math/prim/scal/prob/inv_gamma_rng.hpp @@ -1,9 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_INV_GAMMA_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_INV_GAMMA_RNG_HPP -#include -#include -#include #include #include #include @@ -16,13 +13,13 @@ #include #include #include -#include #include #include -#include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/logistic_ccdf_log.hpp b/stan/math/prim/scal/prob/logistic_ccdf_log.hpp index 646a76f96cb..07684ac4e67 100644 --- a/stan/math/prim/scal/prob/logistic_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/logistic_ccdf_log.hpp @@ -72,7 +72,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, mu, sigma); + return operands_and_partials.value(0.0); } // Compute vectorized cdf_log and its gradients @@ -80,8 +80,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, mu, sigma); + return operands_and_partials.value(stan::math::negative_infinity()); } // Pull out values @@ -106,7 +105,7 @@ namespace stan { * exp(logistic_log(y_dbl, mu_dbl, sigma_dbl)) / Pn; } - return operands_and_partials.to_var(P, y, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/logistic_cdf.hpp b/stan/math/prim/scal/prob/logistic_cdf.hpp index 7954b2c5982..65a5a30f74a 100644 --- a/stan/math/prim/scal/prob/logistic_cdf.hpp +++ b/stan/math/prim/scal/prob/logistic_cdf.hpp @@ -72,7 +72,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, mu, sigma); + return operands_and_partials.value(0.0); } // Compute vectorized CDF and its gradients @@ -119,7 +119,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/logistic_cdf_log.hpp b/stan/math/prim/scal/prob/logistic_cdf_log.hpp index e4807ae2a3b..e0b5e570e98 100644 --- a/stan/math/prim/scal/prob/logistic_cdf_log.hpp +++ b/stan/math/prim/scal/prob/logistic_cdf_log.hpp @@ -72,7 +72,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) return operands_and_partials - .to_var(-std::numeric_limits::infinity(), y, mu, sigma); + .value(-std::numeric_limits::infinity()); } // Compute vectorized cdf_log and its gradients @@ -105,7 +105,7 @@ namespace stan { * exp(logistic_log(y_dbl, mu_dbl, sigma_dbl)) / Pn; } - return operands_and_partials.to_var(P, y, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/logistic_log.hpp b/stan/math/prim/scal/prob/logistic_log.hpp index 97f3bbc28c8..8b7a9395a8f 100644 --- a/stan/math/prim/scal/prob/logistic_log.hpp +++ b/stan/math/prim/scal/prob/logistic_log.hpp @@ -133,7 +133,7 @@ namespace stan { ((1 - 2 * inv_1p_exp_y_minus_mu_div_sigma) *y_minus_mu*inv_sigma[n] - 1) * inv_sigma[n]; } - return operands_and_partials.to_var(logp, y, mu, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/logistic_rng.hpp b/stan/math/prim/scal/prob/logistic_rng.hpp index 10743f094cc..c4d63c7b5fa 100644 --- a/stan/math/prim/scal/prob/logistic_rng.hpp +++ b/stan/math/prim/scal/prob/logistic_rng.hpp @@ -1,9 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_LOGISTIC_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_LOGISTIC_RNG_HPP -#include -#include -#include #include #include #include @@ -12,12 +9,12 @@ #include #include #include -#include #include #include -#include #include #include +#include +#include namespace stan { namespace math { diff --git a/stan/math/prim/scal/prob/lognormal_ccdf_log.hpp b/stan/math/prim/scal/prob/lognormal_ccdf_log.hpp index 936c4ea6fa3..2cb73a7856f 100644 --- a/stan/math/prim/scal/prob/lognormal_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/lognormal_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -59,7 +61,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0.0) - return operands_and_partials.to_var(0.0, y, mu, sigma); + return operands_and_partials.value(0.0); } const double log_half = std::log(0.5); @@ -87,7 +89,7 @@ namespace stan { / erfc_calc; } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/lognormal_cdf.hpp b/stan/math/prim/scal/prob/lognormal_cdf.hpp index 635f003684b..16bdf7b8af9 100644 --- a/stan/math/prim/scal/prob/lognormal_cdf.hpp +++ b/stan/math/prim/scal/prob/lognormal_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -60,7 +62,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0.0) - return operands_and_partials.to_var(0.0, y, mu, sigma); + return operands_and_partials.value(0.0); } for (size_t n = 0; n < N; n++) { @@ -99,7 +101,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, mu, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/lognormal_cdf_log.hpp b/stan/math/prim/scal/prob/lognormal_cdf_log.hpp index 438314be36a..60a7e857a13 100644 --- a/stan/math/prim/scal/prob/lognormal_cdf_log.hpp +++ b/stan/math/prim/scal/prob/lognormal_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_LOGNORMAL_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -59,8 +61,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0.0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, mu, sigma); + return operands_and_partials.value(stan::math::negative_infinity()); } const double log_half = std::log(0.5); @@ -88,7 +89,7 @@ namespace stan { / erfc_calc; } - return operands_and_partials.to_var(cdf_log, y, mu, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/lognormal_log.hpp b/stan/math/prim/scal/prob/lognormal_log.hpp index e56319b2a78..b1259bcb94b 100644 --- a/stan/math/prim/scal/prob/lognormal_log.hpp +++ b/stan/math/prim/scal/prob/lognormal_log.hpp @@ -149,7 +149,7 @@ namespace stan { operands_and_partials.d_x3[n] += (logy_m_mu_div_sigma * logy_m_mu - 1) * inv_sigma[n]; } - return operands_and_partials.to_var(logp, y, mu, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/lognormal_rng.hpp b/stan/math/prim/scal/prob/lognormal_rng.hpp index 289d739149d..55cba74128c 100644 --- a/stan/math/prim/scal/prob/lognormal_rng.hpp +++ b/stan/math/prim/scal/prob/lognormal_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/neg_binomial_2_ccdf_log.hpp b/stan/math/prim/scal/prob/neg_binomial_2_ccdf_log.hpp index dcc4ee5147b..75f7932f703 100644 --- a/stan/math/prim/scal/prob/neg_binomial_2_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_2_ccdf_log.hpp @@ -1,29 +1,14 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CCDF_LOG_HPP -#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 { // Temporary neg_binomial_2_ccdf implementation that @@ -33,14 +18,15 @@ namespace stan { neg_binomial_2_ccdf_log(const T_n& n, const T_location& mu, const T_precision& phi) { - if ( !( stan::length(n) && stan::length(mu) && stan::length(phi) ) ) - return 0.0; - - using stan::math::check_nonnegative; using stan::math::check_positive_finite; using stan::math::check_not_nan; using stan::math::check_consistent_sizes; - using stan::math::check_less; + + // check if any vectors are zero length + if (!(stan::length(n) + && stan::length(mu) + && stan::length(phi))) + return 0.0; static const char* function("stan::math::neg_binomial_2_cdf"); check_positive_finite(function, "Location parameter", mu); @@ -51,23 +37,17 @@ namespace stan { "Location parameter", mu, "Precision Parameter", phi); - VectorView n_vec(n); VectorView mu_vec(mu); VectorView phi_vec(phi); size_t size_beta = max_size(mu, phi); - std::vector::type> - beta_vec(size_beta); + VectorBuilder::type, + T_location, T_precision> beta_vec(size_beta); for (size_t i = 0; i < size_beta; ++i) beta_vec[i] = phi_vec[i] / mu_vec[i]; - // Cast a vector of size 1 down to a - // scalar to avoid dimension mismatch - if (size_beta == 1) - return neg_binomial_ccdf_log(n, phi, beta_vec[0]); - else - return neg_binomial_ccdf_log(n, phi, beta_vec); + return neg_binomial_ccdf_log(n, phi, beta_vec.data()); } } } diff --git a/stan/math/prim/scal/prob/neg_binomial_2_cdf.hpp b/stan/math/prim/scal/prob/neg_binomial_2_cdf.hpp index 16ba8351934..c77cf780c02 100644 --- a/stan/math/prim/scal/prob/neg_binomial_2_cdf.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_2_cdf.hpp @@ -1,32 +1,21 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CDF_HPP -#include -#include -#include -#include - #include -#include -#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 { @@ -43,15 +32,15 @@ namespace stan { T_partials_return; using stan::math::check_positive_finite; - using stan::math::check_nonnegative; using stan::math::check_not_nan; using stan::math::check_consistent_sizes; - // Ensure non-zero arugment lengths - if (!(stan::length(n) && stan::length(mu) && stan::length(phi))) - return 1.0; - T_partials_return P(1.0); + // check if any vectors are zero length + if (!(stan::length(n) + && stan::length(mu) + && stan::length(phi))) + return P; // Validate arguments check_positive_finite(function, "Location parameter", mu); @@ -82,7 +71,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, mu, phi); + return operands_and_partials.value(0.0); } // Cache a few expensive function calls if phi is a parameter @@ -108,7 +97,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) == std::numeric_limits::max()) - return operands_and_partials.to_var(1.0, mu, phi); + return operands_and_partials.value(1.0); const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return mu_dbl = value_of(mu_vec[i]); @@ -147,9 +136,9 @@ namespace stan { operands_and_partials.d_x2[i] *= P; } - return operands_and_partials.to_var(P, mu, phi); + return operands_and_partials.value(P); } - } // math -} // stan + } +} #endif diff --git a/stan/math/prim/scal/prob/neg_binomial_2_cdf_log.hpp b/stan/math/prim/scal/prob/neg_binomial_2_cdf_log.hpp index 44b274a50bd..01e1aec59f5 100644 --- a/stan/math/prim/scal/prob/neg_binomial_2_cdf_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_2_cdf_log.hpp @@ -1,28 +1,16 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_2_CDF_LOG_HPP -#include #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 { template phi_vec(phi); size_t size_phi_mu = max_size(mu, phi); - size_t size_n = length(n); - - std::vector::type> - phi_mu(size_phi_mu); - std::vector::type> np1(size_n); - + VectorBuilder::type, + T_location, T_precision> phi_mu(size_phi_mu); for (size_t i = 0; i < size_phi_mu; i++) - phi_mu[i] = phi_vec[i]/(phi_vec[i]+mu_vec[i]); + phi_mu[i] = phi_vec[i] / (phi_vec[i] + mu_vec[i]); + size_t size_n = length(n); + VectorBuilder::type, + T_n> np1(size_n); for (size_t i = 0; i < size_n; i++) if (n_vec[i] < 0) return log(0.0); else np1[i] = n_vec[i] + 1.0; - if (size_n == 1) { - if (size_phi_mu == 1) - return beta_cdf_log(phi_mu[0], phi, np1[0]); - else - return beta_cdf_log(phi_mu, phi, np1[0]); - } else { - if (size_phi_mu == 1) - return beta_cdf_log(phi_mu[0], phi, np1); - else - return beta_cdf_log(phi_mu, phi, np1); - } + return beta_cdf_log(phi_mu.data(), phi, np1.data()); } + } } #endif diff --git a/stan/math/prim/scal/prob/neg_binomial_2_log.hpp b/stan/math/prim/scal/prob/neg_binomial_2_log.hpp index 4ea42389f83..69c1a84641a 100644 --- a/stan/math/prim/scal/prob/neg_binomial_2_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_2_log.hpp @@ -131,7 +131,7 @@ namespace stan { + log_phi[i] - log_mu_plus_phi[i] - digamma(phi__[i]) + digamma(n_plus_phi[i]); } - return operands_and_partials.to_var(logp, mu, phi); + return operands_and_partials.value(logp); } template -#include -#include +#include +#include #include #include #include @@ -19,6 +18,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -130,7 +132,7 @@ namespace stan { + log_phi[i] - logsumexp_eta_logphi[i] - digamma(phi__[i]) + digamma(n_plus_phi[i]); } - return operands_and_partials.to_var(logp, eta, phi); + return operands_and_partials.value(logp); } template #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/neg_binomial_2_rng.hpp b/stan/math/prim/scal/prob/neg_binomial_2_rng.hpp index b3b94fdcc7f..f1bf0f6f9b0 100644 --- a/stan/math/prim/scal/prob/neg_binomial_2_rng.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_2_rng.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/neg_binomial_ccdf_log.hpp b/stan/math/prim/scal/prob/neg_binomial_ccdf_log.hpp index 202a0965ba4..dc19b97bae8 100644 --- a/stan/math/prim/scal/prob/neg_binomial_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_ccdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CCDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -19,6 +18,9 @@ #include #include #include +#include +#include +#include #include #include @@ -78,7 +80,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, alpha, beta); + return operands_and_partials.value(0.0); } // Cache a few expensive function calls if alpha is a parameter @@ -107,8 +109,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) == std::numeric_limits::max()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return alpha_dbl = value_of(alpha_vec[i]); @@ -139,7 +140,7 @@ namespace stan { * pow(p_dbl, alpha_dbl-1) / beta_func / Pi; } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/neg_binomial_cdf.hpp b/stan/math/prim/scal/prob/neg_binomial_cdf.hpp index 625660f3583..9c93567f793 100644 --- a/stan/math/prim/scal/prob/neg_binomial_cdf.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_cdf.hpp @@ -1,15 +1,15 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CDF_HPP +#include +#include #include #include #include #include - #include #include #include - #include #include #include @@ -70,7 +70,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, alpha, beta); + return operands_and_partials.value(0.0); } // Cache a few expensive function calls if alpha is a parameter @@ -96,7 +96,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) == std::numeric_limits::max()) - return operands_and_partials.to_var(1.0, alpha, beta); + return operands_and_partials.value(1.0); const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return alpha_dbl = value_of(alpha_vec[i]); @@ -133,7 +133,7 @@ namespace stan { operands_and_partials.d_x2[i] *= P; } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } // prob diff --git a/stan/math/prim/scal/prob/neg_binomial_cdf_log.hpp b/stan/math/prim/scal/prob/neg_binomial_cdf_log.hpp index b57de959d34..42285fd6c01 100644 --- a/stan/math/prim/scal/prob/neg_binomial_cdf_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_cdf_log.hpp @@ -1,9 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_CDF_LOG_HPP -#include -#include -#include +#include +#include #include #include #include @@ -19,6 +18,9 @@ #include #include #include +#include +#include +#include #include #include @@ -79,8 +81,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - alpha, beta); + return operands_and_partials.value(stan::math::negative_infinity()); } // Cache a few expensive function calls if alpha is a parameter @@ -109,7 +110,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) == std::numeric_limits::max()) - return operands_and_partials.to_var(0.0, alpha, beta); + return operands_and_partials.value(0.0); const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return alpha_dbl = value_of(alpha_vec[i]); @@ -140,7 +141,7 @@ namespace stan { * pow(p_dbl, alpha_dbl-1) / beta_func / Pi; } - return operands_and_partials.to_var(P, alpha, beta); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/neg_binomial_log.hpp b/stan/math/prim/scal/prob/neg_binomial_log.hpp index a7ecd4de2bb..633d37e325e 100644 --- a/stan/math/prim/scal/prob/neg_binomial_log.hpp +++ b/stan/math/prim/scal/prob/neg_binomial_log.hpp @@ -1,9 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NEG_BINOMIAL_LOG_HPP -#include -#include -#include +#include #include #include #include @@ -16,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +22,9 @@ #include #include #include +#include +#include +#include #include namespace stan { @@ -173,7 +173,7 @@ namespace stan { - n_vec[i] / (value_of(beta_vec[i]) + 1.0); } } - return operands_and_partials.to_var(logp, alpha, beta); + return operands_and_partials.value(logp); } template #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/normal_ccdf_log.hpp b/stan/math/prim/scal/prob/normal_ccdf_log.hpp index 375c36eb238..d0b416fefd6 100644 --- a/stan/math/prim/scal/prob/normal_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/normal_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NORMAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NORMAL_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -98,7 +100,7 @@ namespace stan { * scaled_diff * stan::math::SQRT_2; } } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/normal_cdf.hpp b/stan/math/prim/scal/prob/normal_cdf.hpp index 82c7e2d94c2..be43dad8070 100644 --- a/stan/math/prim/scal/prob/normal_cdf.hpp +++ b/stan/math/prim/scal/prob/normal_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NORMAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_NORMAL_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include @@ -123,7 +125,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, mu, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/normal_cdf_log.hpp b/stan/math/prim/scal/prob/normal_cdf_log.hpp index b54463c8ed7..1f1fbb95428 100644 --- a/stan/math/prim/scal/prob/normal_cdf_log.hpp +++ b/stan/math/prim/scal/prob/normal_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NORMAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NORMAL_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -97,7 +99,7 @@ namespace stan { * scaled_diff * stan::math::SQRT_2; } } - return operands_and_partials.to_var(cdf_log, y, mu, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/normal_log.hpp b/stan/math/prim/scal/prob/normal_log.hpp index 75f5dd6085a..93c3122d8c8 100644 --- a/stan/math/prim/scal/prob/normal_log.hpp +++ b/stan/math/prim/scal/prob/normal_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_NORMAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_NORMAL_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -127,7 +129,7 @@ namespace stan { } - return operands_and_partials.to_var(logp, y, mu, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/normal_rng.hpp b/stan/math/prim/scal/prob/normal_rng.hpp index ec9c2dcd2df..d2c152de5d8 100644 --- a/stan/math/prim/scal/prob/normal_rng.hpp +++ b/stan/math/prim/scal/prob/normal_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/pareto_ccdf_log.hpp b/stan/math/prim/scal/prob/pareto_ccdf_log.hpp index 02e6f3c36d5..f58669f1a88 100644 --- a/stan/math/prim/scal/prob/pareto_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/pareto_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -66,7 +68,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) < value_of(y_min_vec[i])) - return operands_and_partials.to_var(0.0, y, y_min, alpha); + return operands_and_partials.value(0.0); } // Compute vectorized cdf_log and its gradients @@ -75,8 +77,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, y_min, alpha); + return operands_and_partials.value(stan::math::negative_infinity()); } // Pull out values @@ -96,7 +97,7 @@ namespace stan { operands_and_partials.d_x3[n] += log_dbl; } - return operands_and_partials.to_var(P, y, y_min, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_cdf.hpp b/stan/math/prim/scal/prob/pareto_cdf.hpp index 66bae32c542..b82fd8fd4f8 100644 --- a/stan/math/prim/scal/prob/pareto_cdf.hpp +++ b/stan/math/prim/scal/prob/pareto_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -67,7 +69,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) < value_of(y_min_vec[i])) - return operands_and_partials.to_var(0.0, y, y_min, alpha); + return operands_and_partials.value(0.0); } // Compute vectorized CDF and its gradients @@ -115,7 +117,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, y_min, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_cdf_log.hpp b/stan/math/prim/scal/prob/pareto_cdf_log.hpp index 7f4057432d8..10b61583ef2 100644 --- a/stan/math/prim/scal/prob/pareto_cdf_log.hpp +++ b/stan/math/prim/scal/prob/pareto_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -65,8 +67,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) < value_of(y_min_vec[i])) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, y_min, alpha); + return operands_and_partials.value(stan::math::negative_infinity()); } // Compute vectorized cdf_log and its gradients @@ -75,7 +76,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(0.0, y, y_min, alpha); + return operands_and_partials.value(0.0); } // Pull out values @@ -100,7 +101,7 @@ namespace stan { -= exp(alpha_dbl * log_dbl) * log_dbl / Pn; } - return operands_and_partials.to_var(P, y, y_min, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_log.hpp b/stan/math/prim/scal/prob/pareto_log.hpp index f0d422aaae4..635be265cf1 100644 --- a/stan/math/prim/scal/prob/pareto_log.hpp +++ b/stan/math/prim/scal/prob/pareto_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -121,7 +123,7 @@ namespace stan { operands_and_partials.d_x3[n] += 1 / alpha_dbl + log_y_min[n] - log_y[n]; } - return operands_and_partials.to_var(logp, y, y_min, alpha); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/pareto_rng.hpp b/stan/math/prim/scal/prob/pareto_rng.hpp index bbc7e758e2c..b641eb71159 100644 --- a/stan/math/prim/scal/prob/pareto_rng.hpp +++ b/stan/math/prim/scal/prob/pareto_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/pareto_type_2_ccdf_log.hpp b/stan/math/prim/scal/prob/pareto_type_2_ccdf_log.hpp index d8802203d57..86169106db1 100644 --- a/stan/math/prim/scal/prob/pareto_type_2_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/pareto_type_2_ccdf_log.hpp @@ -1,7 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CCDF_LOG_HPP -#include +#include #include #include #include @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace stan { @@ -122,7 +123,7 @@ namespace stan { operands_and_partials.d_x4[n] -= log_1p_y_over_lambda[n]; } - return operands_and_partials.to_var(P, y, mu, lambda, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_type_2_cdf.hpp b/stan/math/prim/scal/prob/pareto_type_2_cdf.hpp index b57b99eef58..8e3966dd59e 100644 --- a/stan/math/prim/scal/prob/pareto_type_2_cdf.hpp +++ b/stan/math/prim/scal/prob/pareto_type_2_cdf.hpp @@ -1,7 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CDF_HPP -#include +#include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include namespace stan { @@ -139,7 +141,7 @@ namespace stan { operands_and_partials.d_x4[n] *= P; } - return operands_and_partials.to_var(P, y, mu, lambda, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_type_2_cdf_log.hpp b/stan/math/prim/scal/prob/pareto_type_2_cdf_log.hpp index 91ba7e126e4..3c7a733519f 100644 --- a/stan/math/prim/scal/prob/pareto_type_2_cdf_log.hpp +++ b/stan/math/prim/scal/prob/pareto_type_2_cdf_log.hpp @@ -1,7 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_CDF_LOG_HPP -#include +#include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include #include @@ -125,7 +127,7 @@ namespace stan { * inv_p1_pow_alpha_minus_one[n]; } - return operands_and_partials.to_var(P, y, mu, lambda, alpha); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/pareto_type_2_log.hpp b/stan/math/prim/scal/prob/pareto_type_2_log.hpp index 79a53bd5b96..1d9cfe8b32a 100644 --- a/stan/math/prim/scal/prob/pareto_type_2_log.hpp +++ b/stan/math/prim/scal/prob/pareto_type_2_log.hpp @@ -1,7 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_LOG_HPP -#include +#include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include @@ -138,7 +140,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x4[n] += inv_alpha[n] - log1p_scaled_diff[n]; } - return operands_and_partials.to_var(logp, y, mu, lambda, alpha); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/pareto_type_2_rng.hpp b/stan/math/prim/scal/prob/pareto_type_2_rng.hpp index f3bdf3d45db..dc217317476 100644 --- a/stan/math/prim/scal/prob/pareto_type_2_rng.hpp +++ b/stan/math/prim/scal/prob/pareto_type_2_rng.hpp @@ -2,7 +2,6 @@ #define STAN_MATH_PRIM_SCAL_PROB_PARETO_TYPE_2_RNG_HPP #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/poisson_ccdf_log.hpp b/stan/math/prim/scal/prob/poisson_ccdf_log.hpp index 7bfdcfe5640..29334d79c29 100644 --- a/stan/math/prim/scal/prob/poisson_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/poisson_ccdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_POISSON_CCDF_LOG_HPP +#include +#include #include #include #include @@ -65,15 +67,14 @@ namespace stan { // The gradients are technically ill-defined, but treated as neg infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, lambda); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(n_vec[i]) == std::numeric_limits::max()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - lambda); + return operands_and_partials.value(stan::math::negative_infinity()); const T_partials_return n_dbl = value_of(n_vec[i]); const T_partials_return lambda_dbl = value_of(lambda_vec[i]); @@ -86,7 +87,7 @@ namespace stan { * pow(lambda_dbl, n_dbl) / tgamma(n_dbl+1) / Pi; } - return operands_and_partials.to_var(P, lambda); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/poisson_cdf.hpp b/stan/math/prim/scal/prob/poisson_cdf.hpp index 06f9f102ec5..7cb9ca7eaf4 100644 --- a/stan/math/prim/scal/prob/poisson_cdf.hpp +++ b/stan/math/prim/scal/prob/poisson_cdf.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_POISSON_CDF_HPP +#include +#include #include #include #include @@ -65,7 +67,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(0.0, lambda); + return operands_and_partials.value(0.0); } for (size_t i = 0; i < size; i++) { @@ -90,7 +92,7 @@ namespace stan { operands_and_partials.d_x1[i] *= P; } - return operands_and_partials.to_var(P, lambda); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/poisson_cdf_log.hpp b/stan/math/prim/scal/prob/poisson_cdf_log.hpp index faf1be10b90..8b5498be8e3 100644 --- a/stan/math/prim/scal/prob/poisson_cdf_log.hpp +++ b/stan/math/prim/scal/prob/poisson_cdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_POISSON_CDF_LOG_HPP +#include +#include #include #include #include @@ -65,8 +67,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as neg infinity for (size_t i = 0; i < stan::length(n); i++) { if (value_of(n_vec[i]) < 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - lambda); + return operands_and_partials.value(stan::math::negative_infinity()); } for (size_t i = 0; i < size; i++) { @@ -86,7 +87,7 @@ namespace stan { * pow(lambda_dbl, n_dbl) / tgamma(n_dbl+1) / Pi; } - return operands_and_partials.to_var(P, lambda); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/poisson_log.hpp b/stan/math/prim/scal/prob/poisson_log.hpp index dd43e60ef11..a239cc90e4c 100644 --- a/stan/math/prim/scal/prob/poisson_log.hpp +++ b/stan/math/prim/scal/prob/poisson_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_POISSON_LOG_HPP +#include +#include #include #include #include @@ -89,7 +91,7 @@ namespace stan { } - return operands_and_partials.to_var(logp, lambda); + return operands_and_partials.value(logp); } template +#include #include #include #include @@ -100,7 +102,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x1[i] += n_vec[i] - exp_alpha[i]; } - return operands_and_partials.to_var(logp, alpha); + return operands_and_partials.value(logp); } template #include #include #include diff --git a/stan/math/prim/scal/prob/poisson_rng.hpp b/stan/math/prim/scal/prob/poisson_rng.hpp index bf7c8538c90..3f4c0357bb4 100644 --- a/stan/math/prim/scal/prob/poisson_rng.hpp +++ b/stan/math/prim/scal/prob/poisson_rng.hpp @@ -1,7 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_POISSON_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_POISSON_RNG_HPP -#include #include #include #include diff --git a/stan/math/prim/scal/prob/rayleigh_ccdf_log.hpp b/stan/math/prim/scal/prob/rayleigh_ccdf_log.hpp index e75bc29b2be..02040a233a1 100644 --- a/stan/math/prim/scal/prob/rayleigh_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/rayleigh_ccdf_log.hpp @@ -1,8 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_CCDF_LOG_HPP -#include -#include #include #include #include @@ -17,6 +15,8 @@ #include #include #include +#include +#include namespace stan { @@ -80,7 +80,7 @@ namespace stan { * inv_sigma[n]; } - return operands_and_partials.to_var(ccdf_log, y, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/rayleigh_cdf.hpp b/stan/math/prim/scal/prob/rayleigh_cdf.hpp index 025d079c3e3..55f6058ea68 100644 --- a/stan/math/prim/scal/prob/rayleigh_cdf.hpp +++ b/stan/math/prim/scal/prob/rayleigh_cdf.hpp @@ -93,7 +93,7 @@ namespace stan { * inv_sigma[n] * exp_div_1m_exp * cdf; } - return operands_and_partials.to_var(cdf, y, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/rayleigh_cdf_log.hpp b/stan/math/prim/scal/prob/rayleigh_cdf_log.hpp index 9bf367b43d2..ce4d07a331b 100644 --- a/stan/math/prim/scal/prob/rayleigh_cdf_log.hpp +++ b/stan/math/prim/scal/prob/rayleigh_cdf_log.hpp @@ -85,7 +85,7 @@ namespace stan { * inv_sigma[n] * exp_div_1m_exp; } - return operands_and_partials.to_var(cdf_log, y, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/rayleigh_log.hpp b/stan/math/prim/scal/prob/rayleigh_log.hpp index 75e726edcd6..e4039143b8c 100644 --- a/stan/math/prim/scal/prob/rayleigh_log.hpp +++ b/stan/math/prim/scal/prob/rayleigh_log.hpp @@ -100,7 +100,7 @@ namespace stan { operands_and_partials.d_x2[n] += y_over_sigma * scaled_diff - 2.0 * inv_sigma[n]; } - return operands_and_partials.to_var(logp, y, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/rayleigh_rng.hpp b/stan/math/prim/scal/prob/rayleigh_rng.hpp index fc2e35d1c04..113e2737fe0 100644 --- a/stan/math/prim/scal/prob/rayleigh_rng.hpp +++ b/stan/math/prim/scal/prob/rayleigh_rng.hpp @@ -1,9 +1,6 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_RAYLEIGH_RNG_HPP -#include -#include -#include #include #include #include @@ -12,11 +9,11 @@ #include #include #include -#include -#include #include #include #include +#include +#include namespace stan { diff --git a/stan/math/prim/scal/prob/scaled_inv_chi_square_ccdf_log.hpp b/stan/math/prim/scal/prob/scaled_inv_chi_square_ccdf_log.hpp index 3043a10495a..63d58551e05 100644 --- a/stan/math/prim/scal/prob/scaled_inv_chi_square_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/scaled_inv_chi_square_ccdf_log.hpp @@ -1,6 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CCDF_LOG_HPP +#include +#include #include #include #include @@ -70,7 +72,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu, s); + return operands_and_partials.value(0.0); } // Compute cdf_log and its gradients @@ -100,8 +102,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu, s); + return operands_and_partials.value(stan::math::negative_infinity()); } // Pull out values @@ -138,7 +139,7 @@ namespace stan { * gamma_p_deriv / Pn; } - return operands_and_partials.to_var(P, y, nu, s); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf.hpp b/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf.hpp index 763ce6aff57..6adacff898b 100644 --- a/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf.hpp +++ b/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -86,7 +88,7 @@ namespace stan { for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(0.0, y, nu, s); + return operands_and_partials.value(0.0); } // Compute CDF and its gradients @@ -169,7 +171,7 @@ namespace stan { operands_and_partials.d_x3[n] *= P; } - return operands_and_partials.to_var(P, y, nu, s); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf_log.hpp b/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf_log.hpp index d76dbb140cc..fe2c4cdd114 100644 --- a/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf_log.hpp +++ b/stan/math/prim/scal/prob/scaled_inv_chi_square_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -71,8 +73,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == 0) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu, s); + return operands_and_partials.value(stan::math::negative_infinity()); } // Compute cdf_log and its gradients @@ -138,7 +139,7 @@ namespace stan { * y_inv_dbl * gamma_p_deriv / Pn; } - return operands_and_partials.to_var(P, y, nu, s); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/scaled_inv_chi_square_log.hpp b/stan/math/prim/scal/prob/scaled_inv_chi_square_log.hpp index deb55749a12..177b59cbe3e 100644 --- a/stan/math/prim/scal/prob/scaled_inv_chi_square_log.hpp +++ b/stan/math/prim/scal/prob/scaled_inv_chi_square_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SCALED_INV_CHI_SQUARE_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include @@ -164,7 +166,7 @@ namespace stan { += nu_dbl / s_dbl - nu_dbl * inv_y[n] * s_dbl; } } - return operands_and_partials.to_var(logp, y, nu, s); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/scaled_inv_chi_square_rng.hpp b/stan/math/prim/scal/prob/scaled_inv_chi_square_rng.hpp index 39cc5ae2d1e..4a300b052e5 100644 --- a/stan/math/prim/scal/prob/scaled_inv_chi_square_rng.hpp +++ b/stan/math/prim/scal/prob/scaled_inv_chi_square_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/skew_normal_ccdf_log.hpp b/stan/math/prim/scal/prob/skew_normal_ccdf_log.hpp index fda2de4b7e0..a921ad556d2 100644 --- a/stan/math/prim/scal/prob/skew_normal_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/skew_normal_ccdf_log.hpp @@ -1,8 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CCDF_LOG_HPP -#include -#include +#include #include #include #include @@ -15,6 +14,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -109,7 +110,7 @@ namespace stan { / ((1 + alpha_dbl_sq) * 2.0 * pi()) / ccdf_log_; } - return operands_and_partials.to_var(ccdf_log, y, mu, sigma, alpha); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/skew_normal_cdf.hpp b/stan/math/prim/scal/prob/skew_normal_cdf.hpp index 2a22e597ce3..b67700d16e6 100644 --- a/stan/math/prim/scal/prob/skew_normal_cdf.hpp +++ b/stan/math/prim/scal/prob/skew_normal_cdf.hpp @@ -1,8 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CDF_HPP -#include -#include +#include #include #include #include @@ -15,6 +14,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -126,7 +127,7 @@ namespace stan { operands_and_partials.d_x4[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, mu, sigma, alpha); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/skew_normal_cdf_log.hpp b/stan/math/prim/scal/prob/skew_normal_cdf_log.hpp index ee28df29d03..c27274ba20c 100644 --- a/stan/math/prim/scal/prob/skew_normal_cdf_log.hpp +++ b/stan/math/prim/scal/prob/skew_normal_cdf_log.hpp @@ -1,8 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_CDF_LOG_HPP -#include -#include +#include #include #include #include @@ -15,6 +14,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -110,7 +111,7 @@ namespace stan { / ((1 + alpha_dbl_sq) * 2.0 * pi()) / cdf_log_; } - return operands_and_partials.to_var(cdf_log, y, mu, sigma, alpha); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/skew_normal_log.hpp b/stan/math/prim/scal/prob/skew_normal_log.hpp index 0ce4c0dd7f5..4e6fafd46a1 100644 --- a/stan/math/prim/scal/prob/skew_normal_log.hpp +++ b/stan/math/prim/scal/prob/skew_normal_log.hpp @@ -1,8 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_SKEW_NORMAL_LOG_HPP -#include -#include +#include #include #include #include @@ -15,6 +14,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -137,7 +138,7 @@ namespace stan { operands_and_partials.d_x4[n] += deriv_logerf * y_minus_mu_over_sigma / std::sqrt(2.0); } - return operands_and_partials.to_var(logp, y, mu, sigma, alpha); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/skew_normal_rng.hpp b/stan/math/prim/scal/prob/skew_normal_rng.hpp index e8021753b8e..db3fe2a4f9f 100644 --- a/stan/math/prim/scal/prob/skew_normal_rng.hpp +++ b/stan/math/prim/scal/prob/skew_normal_rng.hpp @@ -3,14 +3,12 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/student_t_ccdf_log.hpp b/stan/math/prim/scal/prob/student_t_ccdf_log.hpp index fb9a5e64be4..5e738df6a38 100644 --- a/stan/math/prim/scal/prob/student_t_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/student_t_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -69,7 +71,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, nu, mu, sigma); + return operands_and_partials.value(0.0); } using stan::math::digamma; @@ -108,8 +110,7 @@ namespace stan { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == std::numeric_limits::infinity()) { - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu, mu, sigma); + return operands_and_partials.value(stan::math::negative_infinity()); } const T_partials_return sigma_inv = 1.0 / value_of(sigma_vec[n]); @@ -195,7 +196,7 @@ namespace stan { } } - return operands_and_partials.to_var(P, y, nu, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/student_t_cdf.hpp b/stan/math/prim/scal/prob/student_t_cdf.hpp index 1f631498ad4..b5e62594489 100644 --- a/stan/math/prim/scal/prob/student_t_cdf.hpp +++ b/stan/math/prim/scal/prob/student_t_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -69,7 +71,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(0.0, y, nu, mu, sigma); + return operands_and_partials.value(0.0); } using stan::math::digamma; @@ -208,7 +210,7 @@ namespace stan { operands_and_partials.d_x4[n] *= P; } - return operands_and_partials.to_var(P, y, nu, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/student_t_cdf_log.hpp b/stan/math/prim/scal/prob/student_t_cdf_log.hpp index 7caef0c1505..58b8842aeef 100644 --- a/stan/math/prim/scal/prob/student_t_cdf_log.hpp +++ b/stan/math/prim/scal/prob/student_t_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -69,8 +71,7 @@ namespace stan { // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::length(y); i++) { if (value_of(y_vec[i]) == -std::numeric_limits::infinity()) - return operands_and_partials.to_var(stan::math::negative_infinity(), - y, nu, mu, sigma); + return operands_and_partials.value(stan::math::negative_infinity()); } using stan::math::digamma; @@ -195,7 +196,7 @@ namespace stan { } } - return operands_and_partials.to_var(P, y, nu, mu, sigma); + return operands_and_partials.value(P); } } } diff --git a/stan/math/prim/scal/prob/student_t_log.hpp b/stan/math/prim/scal/prob/student_t_log.hpp index e7846d24ff9..a3330687555 100644 --- a/stan/math/prim/scal/prob/student_t_log.hpp +++ b/stan/math/prim/scal/prob/student_t_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_STUDENT_T_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -211,7 +213,7 @@ namespace stan { * (square_y_minus_mu_over_sigma__over_nu[n] * inv_sigma); } } - return operands_and_partials.to_var(logp, y, nu, mu, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/student_t_rng.hpp b/stan/math/prim/scal/prob/student_t_rng.hpp index bae802a86d1..96d90b2e5c1 100644 --- a/stan/math/prim/scal/prob/student_t_rng.hpp +++ b/stan/math/prim/scal/prob/student_t_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/uniform_ccdf_log.hpp b/stan/math/prim/scal/prob/uniform_ccdf_log.hpp index 611722c1689..583674add94 100644 --- a/stan/math/prim/scal/prob/uniform_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/uniform_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -86,7 +88,7 @@ namespace stan { / b_min_a / ccdf_log_; } - return operands_and_partials.to_var(ccdf_log, y, alpha, beta); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/uniform_cdf.hpp b/stan/math/prim/scal/prob/uniform_cdf.hpp index 2262e6c2c30..09679df1e72 100644 --- a/stan/math/prim/scal/prob/uniform_cdf.hpp +++ b/stan/math/prim/scal/prob/uniform_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include namespace stan { @@ -94,7 +96,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, alpha, beta); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/uniform_cdf_log.hpp b/stan/math/prim/scal/prob/uniform_cdf_log.hpp index fe966e1cafc..8406a8c38be 100644 --- a/stan/math/prim/scal/prob/uniform_cdf_log.hpp +++ b/stan/math/prim/scal/prob/uniform_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_UNIFORM_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -63,7 +65,7 @@ namespace stan { || y_dbl > value_of(beta_vec[n])) return stan::math::negative_infinity(); if (y_dbl == value_of(beta_vec[n])) - return operands_and_partials.to_var(0.0, y, alpha, beta); + return operands_and_partials.value(0.0); } for (size_t n = 0; n < N; n++) { @@ -86,7 +88,7 @@ namespace stan { operands_and_partials.d_x3[n] -= 1.0 / b_min_a; } - return operands_and_partials.to_var(cdf_log, y, alpha, beta); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/uniform_log.hpp b/stan/math/prim/scal/prob/uniform_log.hpp index 26b2af60e97..fe52909c512 100644 --- a/stan/math/prim/scal/prob/uniform_log.hpp +++ b/stan/math/prim/scal/prob/uniform_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_UNIFORM_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_UNIFORM_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -115,7 +117,7 @@ namespace stan { if (!is_constant_struct::value) operands_and_partials.d_x3[n] -= inv_beta_minus_alpha[n]; } - return operands_and_partials.to_var(logp, y, alpha, beta); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/uniform_rng.hpp b/stan/math/prim/scal/prob/uniform_rng.hpp index 093d6f8b893..7b45b336dc8 100644 --- a/stan/math/prim/scal/prob/uniform_rng.hpp +++ b/stan/math/prim/scal/prob/uniform_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/von_mises_log.hpp b/stan/math/prim/scal/prob/von_mises_log.hpp index b0d5640c44e..4e78645d81e 100644 --- a/stan/math/prim/scal/prob/von_mises_log.hpp +++ b/stan/math/prim/scal/prob/von_mises_log.hpp @@ -1,6 +1,7 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_VON_MISES_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_VON_MISES_LOG_HPP +#include #include #include #include @@ -87,7 +88,8 @@ namespace stan { = log(modified_bessel_first_kind(0, value_of(kappa_vec[i]))); } - OperandsAndPartials oap(y, mu, kappa); + OperandsAndPartials + operands_and_partials(y, mu, kappa); size_t N = max_size(y, mu, kappa); @@ -117,14 +119,15 @@ namespace stan { // Gradient. if (!y_const) - oap.d_x1[n] += kappa_sin; + operands_and_partials.d_x1[n] += kappa_sin; if (!mu_const) - oap.d_x2[n] -= kappa_sin; + operands_and_partials.d_x2[n] -= kappa_sin; if (!kappa_const) - oap.d_x3[n] += kappa_cos / kappa_dbl[n] - bessel1 / bessel0; + operands_and_partials.d_x3[n] += kappa_cos / kappa_dbl[n] + - bessel1 / bessel0; } - return oap.to_var(logp, y, mu, kappa); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/von_mises_rng.hpp b/stan/math/prim/scal/prob/von_mises_rng.hpp index 0a845403aa1..9320cfa1225 100644 --- a/stan/math/prim/scal/prob/von_mises_rng.hpp +++ b/stan/math/prim/scal/prob/von_mises_rng.hpp @@ -1,13 +1,11 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_VON_MISES_RNG_HPP #define STAN_MATH_PRIM_SCAL_PROB_VON_MISES_RNG_HPP -#include #include #include #include #include #include -#include #include #include #include diff --git a/stan/math/prim/scal/prob/weibull_ccdf_log.hpp b/stan/math/prim/scal/prob/weibull_ccdf_log.hpp index 438bb8096e2..0f2428944bb 100644 --- a/stan/math/prim/scal/prob/weibull_ccdf_log.hpp +++ b/stan/math/prim/scal/prob/weibull_ccdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CCDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CCDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -72,7 +74,7 @@ namespace stan { operands_and_partials.d_x3[n] += alpha_dbl / sigma_dbl * pow_; } - return operands_and_partials.to_var(ccdf_log, y, alpha, sigma); + return operands_and_partials.value(ccdf_log); } } } diff --git a/stan/math/prim/scal/prob/weibull_cdf.hpp b/stan/math/prim/scal/prob/weibull_cdf.hpp index 8388b45d33b..50aff46a001 100644 --- a/stan/math/prim/scal/prob/weibull_cdf.hpp +++ b/stan/math/prim/scal/prob/weibull_cdf.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CDF_HPP #define STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CDF_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -89,7 +91,7 @@ namespace stan { operands_and_partials.d_x3[n] *= cdf; } - return operands_and_partials.to_var(cdf, y, alpha, sigma); + return operands_and_partials.value(cdf); } } } diff --git a/stan/math/prim/scal/prob/weibull_cdf_log.hpp b/stan/math/prim/scal/prob/weibull_cdf_log.hpp index 6d09b25ebbb..de5b88eed68 100644 --- a/stan/math/prim/scal/prob/weibull_cdf_log.hpp +++ b/stan/math/prim/scal/prob/weibull_cdf_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CDF_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_WEIBULL_CDF_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -76,7 +78,7 @@ namespace stan { operands_and_partials.d_x3[n] -= rep_deriv * alpha_dbl / sigma_dbl; } - return operands_and_partials.to_var(cdf_log, y, alpha, sigma); + return operands_and_partials.value(cdf_log); } } } diff --git a/stan/math/prim/scal/prob/weibull_log.hpp b/stan/math/prim/scal/prob/weibull_log.hpp index ec4c1e3acba..7dfd7e86c22 100644 --- a/stan/math/prim/scal/prob/weibull_log.hpp +++ b/stan/math/prim/scal/prob/weibull_log.hpp @@ -1,8 +1,8 @@ #ifndef STAN_MATH_PRIM_SCAL_PROB_WEIBULL_LOG_HPP #define STAN_MATH_PRIM_SCAL_PROB_WEIBULL_LOG_HPP -#include -#include +#include +#include #include #include #include @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include namespace stan { @@ -132,7 +134,7 @@ namespace stan { operands_and_partials.d_x3[n] += alpha_dbl * inv_sigma[n] * (y_div_sigma_pow_alpha[n] - 1.0); } - return operands_and_partials.to_var(logp, y, alpha, sigma); + return operands_and_partials.value(logp); } template diff --git a/stan/math/prim/scal/prob/weibull_rng.hpp b/stan/math/prim/scal/prob/weibull_rng.hpp index a044cf0af19..697808c89c0 100644 --- a/stan/math/prim/scal/prob/weibull_rng.hpp +++ b/stan/math/prim/scal/prob/weibull_rng.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/stan/math/rev/arr/functor/coupled_ode_system.hpp b/stan/math/rev/arr/functor/coupled_ode_system.hpp index e5634b0f0a4..514becfc185 100644 --- a/stan/math/rev/arr/functor/coupled_ode_system.hpp +++ b/stan/math/rev/arr/functor/coupled_ode_system.hpp @@ -1,17 +1,15 @@ #ifndef STAN_MATH_REV_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP #define STAN_MATH_REV_ARR_FUNCTOR_COUPLED_ODE_SYSTEM_HPP -#include #include -#include #include - +#include +#include #include #include #include -#include -#include #include +#include #include namespace stan { diff --git a/stan/math/rev/arr/functor/coupled_ode_system_cvode.hpp b/stan/math/rev/arr/functor/coupled_ode_system_cvode.hpp index 4c1a9fec040..fd6c6c0f7d0 100644 --- a/stan/math/rev/arr/functor/coupled_ode_system_cvode.hpp +++ b/stan/math/rev/arr/functor/coupled_ode_system_cvode.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace stan { diff --git a/stan/math/rev/arr/functor/integrate_ode_cvode.hpp b/stan/math/rev/arr/functor/integrate_ode_cvode.hpp index cc924d7c411..4b5d8ef9178 100644 --- a/stan/math/rev/arr/functor/integrate_ode_cvode.hpp +++ b/stan/math/rev/arr/functor/integrate_ode_cvode.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_REV_ARR_FUNCTOR_INTEGRATE_ODE_CVODE_HPP #define STAN_MATH_REV_ARR_FUNCTOR_INTEGRATE_ODE_CVODE_HPP +#include +#include #include #include #include -#include -#include #include #include #include @@ -44,6 +44,7 @@ namespace stan { * @param[in] x_int integer data vector for the ODE. * @param[in] rel_tol relative tolerance passed to CVODE. * @param[in] abs_tol absolute tolerance passed to CVODE. + * @param[in] max_num_steps maximum number of steps to pass to CVODE. * @param[in, out] msgs the print stream for warning messages. * @return a vector of states, each state being a vector of the * same size as the state variable, corresponding to a time in ts. diff --git a/stan/math/rev/core/precomputed_gradients.hpp b/stan/math/rev/core/precomputed_gradients.hpp index 66fa2dc8b7a..2da0f136ca9 100644 --- a/stan/math/rev/core/precomputed_gradients.hpp +++ b/stan/math/rev/core/precomputed_gradients.hpp @@ -4,8 +4,8 @@ #include #include #include -#include #include +#include namespace stan { diff --git a/stan/math/rev/core/set_zero_all_adjoints_nested.hpp b/stan/math/rev/core/set_zero_all_adjoints_nested.hpp index fd39ee775b9..ecf6c2796ab 100644 --- a/stan/math/rev/core/set_zero_all_adjoints_nested.hpp +++ b/stan/math/rev/core/set_zero_all_adjoints_nested.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/rev/mat/fun/log_softmax.hpp b/stan/math/rev/mat/fun/log_softmax.hpp index 9d94795ba5b..57fca1e9357 100644 --- a/stan/math/rev/mat/fun/log_softmax.hpp +++ b/stan/math/rev/mat/fun/log_softmax.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_REV_MAT_FUN_LOG_SOFTMAX_HPP #define STAN_MATH_REV_MAT_FUN_LOG_SOFTMAX_HPP -#include +#include #include #include #include -#include +#include #include #include #include diff --git a/stan/math/rev/mat/fun/multiply.hpp b/stan/math/rev/mat/fun/multiply.hpp index 458895e695b..a046cc2419e 100644 --- a/stan/math/rev/mat/fun/multiply.hpp +++ b/stan/math/rev/mat/fun/multiply.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace stan { namespace math { diff --git a/stan/math/rev/mat/fun/sd.hpp b/stan/math/rev/mat/fun/sd.hpp index cb7e5d4de06..640f15d0d14 100644 --- a/stan/math/rev/mat/fun/sd.hpp +++ b/stan/math/rev/mat/fun/sd.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_REV_MAT_FUN_SD_HPP #define STAN_MATH_REV_MAT_FUN_SD_HPP +#include #include #include #include -#include #include #include #include diff --git a/stan/math/rev/mat/fun/softmax.hpp b/stan/math/rev/mat/fun/softmax.hpp index 3a2618b712a..c6834235b38 100644 --- a/stan/math/rev/mat/fun/softmax.hpp +++ b/stan/math/rev/mat/fun/softmax.hpp @@ -1,10 +1,10 @@ #ifndef STAN_MATH_REV_MAT_FUN_SOFTMAX_HPP #define STAN_MATH_REV_MAT_FUN_SOFTMAX_HPP +#include #include #include #include -#include #include namespace stan { diff --git a/stan/math/rev/mat/fun/unit_vector_constrain.hpp b/stan/math/rev/mat/fun/unit_vector_constrain.hpp index 1b614c6acbf..09cc271825d 100644 --- a/stan/math/rev/mat/fun/unit_vector_constrain.hpp +++ b/stan/math/rev/mat/fun/unit_vector_constrain.hpp @@ -1,11 +1,11 @@ #ifndef STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP #define STAN_MATH_PRIM_MAT_FUN_UNIT_VECTOR_CONSTRAIN_HPP +#include #include #include #include #include -#include #include #include #include diff --git a/stan/math/rev/mat/fun/variance.hpp b/stan/math/rev/mat/fun/variance.hpp index 44a4adc9207..b058d52f848 100644 --- a/stan/math/rev/mat/fun/variance.hpp +++ b/stan/math/rev/mat/fun/variance.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace stan { diff --git a/stan/math/rev/mat/functor/gradient.hpp b/stan/math/rev/mat/functor/gradient.hpp index f35c0501ab3..a5265975b53 100644 --- a/stan/math/rev/mat/functor/gradient.hpp +++ b/stan/math/rev/mat/functor/gradient.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace stan { diff --git a/stan/math/rev/mat/functor/jacobian.hpp b/stan/math/rev/mat/functor/jacobian.hpp index c293bd63ca5..debdb364261 100644 --- a/stan/math/rev/mat/functor/jacobian.hpp +++ b/stan/math/rev/mat/functor/jacobian.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace stan { diff --git a/stan/math/rev/scal.hpp b/stan/math/rev/scal.hpp index 0d02e982639..3f576baae72 100644 --- a/stan/math/rev/scal.hpp +++ b/stan/math/rev/scal.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include diff --git a/stan/math/rev/scal/fun/log_mix.hpp b/stan/math/rev/scal/fun/log_mix.hpp index ad10c7d5d5e..b611bc85a07 100644 --- a/stan/math/rev/scal/fun/log_mix.hpp +++ b/stan/math/rev/scal/fun/log_mix.hpp @@ -139,7 +139,7 @@ namespace stan { = one_m_t_prod_exp_lam2_m_lam1 * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1; - return operands_and_partials.to_var(log_mix_function_value); + return operands_and_partials.value(log_mix_function_value); } } // namespace math diff --git a/stan/math/rev/scal/meta/OperandsAndPartials.hpp b/stan/math/rev/scal/meta/OperandsAndPartials.hpp new file mode 100644 index 00000000000..e4024fcbba1 --- /dev/null +++ b/stan/math/rev/scal/meta/OperandsAndPartials.hpp @@ -0,0 +1,193 @@ +#ifndef STAN_MATH_REV_SCAL_META_OPERANDSANDPARTIALS_HPP +#define STAN_MATH_REV_SCAL_META_OPERANDSANDPARTIALS_HPP + +#include +#include +#include +#include +#include + +namespace stan { + namespace math { + + // These are helpers to the OperandsAndPartials specialization for + // stan::math::var + namespace { + class partials_vari : public vari { + private: + const size_t N_; + vari** operands_; + double* partials_; + public: + partials_vari(double value, + size_t N, + vari** operands, double* partials) + : vari(value), + N_(N), + operands_(operands), + partials_(partials) { } + void chain() { + for (size_t n = 0; n < N_; ++n) + operands_[n]->adj_ += adj_ * partials_[n]; + } + }; + + var partials_to_var(double logp, size_t nvaris, + vari** all_varis, + double* all_partials) { + return var(new partials_vari(logp, nvaris, all_varis, + all_partials)); + } + + template::value, + bool is_const = is_constant_struct::value> + struct set_varis { + inline size_t set(vari** /*varis*/, const T& /*x*/) { + return 0U; + } + }; + template + struct set_varis { + inline size_t set(vari** varis, const T& x) { + for (size_t n = 0; n < length(x); n++) + varis[n] = x[n].vi_; + return length(x); + } + }; + template<> + struct set_varis { + inline size_t set(vari** varis, const var& x) { + varis[0] = x.vi_; + return (1); + } + }; + } + + /** + * This class builds partial derivatives with respect to a set of + * operands. There are two reason for the generality of this + * class. The first is to handle vector and scalar arguments + * without needing to write additional code. The second is to use + * this class for writing probability distributions that handle + * primitives, reverse mode, and forward mode variables + * seamlessly. + * + * This is the partial template specialization for when the return + * type is stan::math::var. + * + * @tparam T1 First set of operands. + * @tparam T2 Second set of operands. + * @tparam T3 Third set of operands. + * @tparam T4 Fourth set of operands. + * @tparam T5 Fifth set of operands. + * @tparam T6 Sixth set of operands. + * @tparam T_return_type Return type of the expression. This defaults + * to a template metaprogram that calculates the scalar promotion of + * T1 -- T6. + */ + template + struct OperandsAndPartials { + size_t nvaris; + vari** all_varis; + double* all_partials; + + VectorView::value, + is_constant_struct::value> d_x1; + VectorView::value, + is_constant_struct::value> d_x2; + VectorView::value, + is_constant_struct::value> d_x3; + VectorView::value, + is_constant_struct::value> d_x4; + VectorView::value, + is_constant_struct::value> d_x5; + VectorView::value, + is_constant_struct::value> d_x6; + + /** + * Constructor. + * + * @param x1 first set of operands + * @param x2 second set of operands + * @param x3 third set of operands + * @param x4 fourth set of operands + * @param x5 fifth set of operands + * @param x6 sixth set of operands + */ + OperandsAndPartials(const T1& x1 = 0, const T2& x2 = 0, const T3& x3 = 0, + const T4& x4 = 0, const T5& x5 = 0, const T6& x6 = 0) + : nvaris(!is_constant_struct::value * length(x1) + + !is_constant_struct::value * length(x2) + + !is_constant_struct::value * length(x3) + + !is_constant_struct::value * length(x4) + + !is_constant_struct::value * length(x5) + + !is_constant_struct::value * length(x6)), + // TODO(carpenter): replace with array allocation fun + all_varis(static_cast + (vari::operator new + (sizeof(vari*) * nvaris))), + all_partials(static_cast + (vari::operator new + (sizeof(double) * nvaris))), + d_x1(all_partials), + d_x2(all_partials + + (!is_constant_struct::value) * length(x1)), + d_x3(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2)), + d_x4(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3)), + d_x5(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3) + + (!is_constant_struct::value) * length(x4)), + d_x6(all_partials + + (!is_constant_struct::value) * length(x1) + + (!is_constant_struct::value) * length(x2) + + (!is_constant_struct::value) * length(x3) + + (!is_constant_struct::value) * length(x4) + + (!is_constant_struct::value) * length(x5)) { + size_t base = 0; + if (!is_constant_struct::value) + base += set_varis().set(&all_varis[base], x1); + if (!is_constant_struct::value) + base += set_varis().set(&all_varis[base], x2); + if (!is_constant_struct::value) + base += set_varis().set(&all_varis[base], x3); + if (!is_constant_struct::value) + base += set_varis().set(&all_varis[base], x4); + if (!is_constant_struct::value) + base += set_varis().set(&all_varis[base], x5); + if (!is_constant_struct::value) + set_varis().set(&all_varis[base], x6); + std::fill(all_partials, all_partials+nvaris, 0); + } + + /** + * Returns a T_return_type with the value specified with + * the partial derivatves. + * + * @param[in] value Value of the variable + * @returns a variable with the appropriate value and + * the adjoints set for reverse mode autodiff + */ + stan::math::var value(double value) { + return partials_to_var(value, nvaris, all_varis, + all_partials); + } + }; + + } +} +#endif diff --git a/test/prob/neg_binomial_2/neg_binomial_2_log_test.hpp b/test/prob/neg_binomial_2/neg_binomial_2_log_test.hpp index e7072c5ae3c..5ffb76d8597 100644 --- a/test/prob/neg_binomial_2/neg_binomial_2_log_test.hpp +++ b/test/prob/neg_binomial_2/neg_binomial_2_log_test.hpp @@ -72,6 +72,8 @@ class AgradDistributionsNegBinomial2Log : public AgradDistributionTest { if (n != 0) return binomial_coefficient_log::type>(n + phi - 1.0, n) +n*eta + multiply_log(phi,phi) - (n+phi)*log_sum_exp(eta,log(phi)); + else + return 0; } }; diff --git a/test/tmp_test.cpp b/test/tmp_test.cpp new file mode 100644 index 00000000000..cd145ddafba --- /dev/null +++ b/test/tmp_test.cpp @@ -0,0 +1,58 @@ +#include +#include + +TEST(foo, 000) { + int n = 5; + double mu = 2; + double phi = 1; + EXPECT_FLOAT_EQ(-2.4327908, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + +TEST(foo, 100) { + std::vector n; + n.push_back(5); + double mu = 2; + double phi = 1; + EXPECT_FLOAT_EQ(-2.4327908, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + +TEST(foo, 010) { + int n = 5; + std::vector mu; + mu.push_back(2); + double phi = 1; + EXPECT_FLOAT_EQ(-2.4327908, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + + +TEST(foo, 001) { + int n = 5; + double mu = 2; + std::vector phi; + phi.push_back(1); + EXPECT_FLOAT_EQ(-2.4327908, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + +TEST(foo, 001_zero_length) { + int n = 5; + double mu = 0; + std::vector phi; + EXPECT_FLOAT_EQ(0, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + + +TEST(foo, 111_zero_length) { + std::vector n; + std::vector mu; + std::vector phi; + EXPECT_FLOAT_EQ(0, stan::math::neg_binomial_2_ccdf_log(n, mu, phi)); +} + + + +TEST(foo, fd_111_zero_length) { + std::vector n; + std::vector > mu; + std::vector > phi; + EXPECT_FLOAT_EQ(1, stan::math::neg_binomial_2_cdf(n, mu, phi).val_); +} diff --git a/test/unit/math/fwd/arr/meta/OperandsAndPartials_test.cpp b/test/unit/math/fwd/arr/meta/OperandsAndPartials_test.cpp index 38644885fe7..3cdc0d1406f 100644 --- a/test/unit/math/fwd/arr/meta/OperandsAndPartials_test.cpp +++ b/test/unit/math/fwd/arr/meta/OperandsAndPartials_test.cpp @@ -21,38 +21,38 @@ TEST(AgradPartialsVari, OperandsAndPartialsFvarVec) { o.d_x2[0] += 19.0; o.d_x3[0] += 23.0; o.d_x3[0] += 23.0; - fvar y = o.to_var(-1.0,x1,x2,x3); + fvar y = o.value(-1.0); EXPECT_FLOAT_EQ(2*17 + 3*13 - 2*19 + 2*4*23,y.d_); EXPECT_FLOAT_EQ(-1,y.val_); } -TEST(AgradPartialsVari, incr_deriv_vec_fvar) { - using stan::VectorView; - using stan::math::incr_deriv; - using stan::is_vector; - using stan::is_constant_struct; - using stan::math::fvar; +// TEST(AgradPartialsVari, incr_deriv_vec_fvar) { +// using stan::VectorView; +// using stan::math::incr_deriv; +// using stan::is_vector; +// using stan::is_constant_struct; +// using stan::math::fvar; - fvar c(1,1); +// fvar c(1,1); - std::vector > d; - d.push_back(c); - d.push_back(c); +// std::vector > d; +// d.push_back(c); +// d.push_back(c); - std::vector d_deriv; - d_deriv.push_back(3); - d_deriv.push_back(4); - - VectorView > >::value, - stan::is_constant_struct > >::value> - d_d(d_deriv); - - double result3 = incr_deriv > >::value, - is_constant_struct > >::value>, - std::vector >,double>().incr(d_d,d); - - EXPECT_FLOAT_EQ(7, result3); -} +// std::vector d_deriv; +// d_deriv.push_back(3); +// d_deriv.push_back(4); + +// VectorView, +// stan::is_vector > >::value, +// stan::is_constant_struct > >::value> +// d_d(d_deriv); + +// double result3 = incr_deriv, +// is_vector > >::value, +// is_constant_struct > >::value>, +// std::vector >,double>().incr(d_d,d); + +// EXPECT_FLOAT_EQ(7, result3); +// } diff --git a/test/unit/math/fwd/scal/fun/nan_util.hpp b/test/unit/math/fwd/scal/fun/nan_util.hpp index c1d07bf0706..b76932e2f82 100644 --- a/test/unit/math/fwd/scal/fun/nan_util.hpp +++ b/test/unit/math/fwd/scal/fun/nan_util.hpp @@ -4,6 +4,7 @@ #include #include #include +#include template void test_nan_fd(const F& f, diff --git a/test/unit/math/fwd/scal/meta/OperandsAndPartials_test.cpp b/test/unit/math/fwd/scal/meta/OperandsAndPartials_test.cpp index c2d837815c3..44150748c1f 100644 --- a/test/unit/math/fwd/scal/meta/OperandsAndPartials_test.cpp +++ b/test/unit/math/fwd/scal/meta/OperandsAndPartials_test.cpp @@ -16,33 +16,33 @@ TEST(AgradPartialsVari, OperandsAndPartialsFvar) { o.d_x1[0] += 17.0; o.d_x2[0] += 19.0; o.d_x3[0] += 23.0; - fvar y = o.to_var(-1.0,x1,x2,x3); + fvar y = o.value(-1.0); EXPECT_FLOAT_EQ(107,y.d_); EXPECT_FLOAT_EQ(-1,y.val_); } -TEST(AgradPartialsVari, incr_deriv_fvar) { - using stan::VectorView; - using stan::math::incr_deriv; - using stan::is_vector; - using stan::is_constant_struct; - using stan::math::fvar; - - fvar c; - c.val_ = 1.0; - c.d_ = 1.0; - - double c_deriv = 2; - VectorView >::value, - stan::is_constant_struct >::value> - d_c(c_deriv); - - double result2 = incr_deriv >::value, - is_constant_struct >::value>, - fvar,double>().incr(d_c,c); - - EXPECT_FLOAT_EQ(2, result2); -} +// TEST(AgradPartialsVari, incr_deriv_fvar) { +// using stan::VectorView; +// using stan::math::incr_deriv; +// using stan::is_vector; +// using stan::is_constant_struct; +// using stan::math::fvar; + +// fvar c; +// c.val_ = 1.0; +// c.d_ = 1.0; + +// double c_deriv = 2; +// VectorView >::value, +// stan::is_constant_struct >::value> +// d_c(c_deriv); + +// double result2 = incr_deriv >::value, +// is_constant_struct >::value>, +// fvar,double>().incr(d_c,c); + +// EXPECT_FLOAT_EQ(2, result2); +// } diff --git a/test/unit/math/mix/core/operator_addition_test.cpp b/test/unit/math/mix/core/operator_addition_test.cpp index 22bc8a8bb5e..08718bd5973 100644 --- a/test/unit/math/mix/core/operator_addition_test.cpp +++ b/test/unit/math/mix/core/operator_addition_test.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include TEST(AgradMixOperatorAddition,FvarVar_FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_divide_equal_test.cpp b/test/unit/math/mix/core/operator_divide_equal_test.cpp index 45c48dee9f2..437ab03ea01 100644 --- a/test/unit/math/mix/core/operator_divide_equal_test.cpp +++ b/test/unit/math/mix/core/operator_divide_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorDivideEqual, FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_division_test.cpp b/test/unit/math/mix/core/operator_division_test.cpp index 29ad6f1e27f..4515baff54f 100644 --- a/test/unit/math/mix/core/operator_division_test.cpp +++ b/test/unit/math/mix/core/operator_division_test.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include TEST(AgradMixOperatorDivision, FvarVar_FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_equal_test.cpp b/test/unit/math/mix/core/operator_equal_test.cpp index e345dd4b717..f053a2eadb8 100644 --- a/test/unit/math/mix/core/operator_equal_test.cpp +++ b/test/unit/math/mix/core/operator_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorEqual, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_greater_than_or_equal_test.cpp b/test/unit/math/mix/core/operator_greater_than_or_equal_test.cpp index 63065844b56..0f89ae944c1 100644 --- a/test/unit/math/mix/core/operator_greater_than_or_equal_test.cpp +++ b/test/unit/math/mix/core/operator_greater_than_or_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorGreaterThanOrEqual, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_greater_than_test.cpp b/test/unit/math/mix/core/operator_greater_than_test.cpp index 12798fa9562..ef1b0b86013 100644 --- a/test/unit/math/mix/core/operator_greater_than_test.cpp +++ b/test/unit/math/mix/core/operator_greater_than_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorGreaterThan, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_less_than_or_equal_test.cpp b/test/unit/math/mix/core/operator_less_than_or_equal_test.cpp index 748159a51d2..45d0c16f119 100644 --- a/test/unit/math/mix/core/operator_less_than_or_equal_test.cpp +++ b/test/unit/math/mix/core/operator_less_than_or_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorLessThanOrEqual, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_less_than_test.cpp b/test/unit/math/mix/core/operator_less_than_test.cpp index 117bad4cede..bb401f5b2a7 100644 --- a/test/unit/math/mix/core/operator_less_than_test.cpp +++ b/test/unit/math/mix/core/operator_less_than_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorLessThan, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_minus_equal_test.cpp b/test/unit/math/mix/core/operator_minus_equal_test.cpp index 9d0b7257da8..e62750af84b 100644 --- a/test/unit/math/mix/core/operator_minus_equal_test.cpp +++ b/test/unit/math/mix/core/operator_minus_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorMinusEqual, FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_minus_minus_test.cpp b/test/unit/math/mix/core/operator_minus_minus_test.cpp index 30674d95530..ea45f210714 100644 --- a/test/unit/math/mix/core/operator_minus_minus_test.cpp +++ b/test/unit/math/mix/core/operator_minus_minus_test.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/test/unit/math/mix/core/operator_multiplication_test.cpp b/test/unit/math/mix/core/operator_multiplication_test.cpp index 67dfc36c30d..76c1c58df24 100644 --- a/test/unit/math/mix/core/operator_multiplication_test.cpp +++ b/test/unit/math/mix/core/operator_multiplication_test.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include TEST(AgradMixOperatorMultiplication, FvarVar_Double_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_multiply_equal_test.cpp b/test/unit/math/mix/core/operator_multiply_equal_test.cpp index 658b7f15460..ae1e6a3c4f9 100644 --- a/test/unit/math/mix/core/operator_multiply_equal_test.cpp +++ b/test/unit/math/mix/core/operator_multiply_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorMultiplyEqual, FvarVar_FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_not_equal_test.cpp b/test/unit/math/mix/core/operator_not_equal_test.cpp index f7ed16f2d12..0b784b9deb3 100644 --- a/test/unit/math/mix/core/operator_not_equal_test.cpp +++ b/test/unit/math/mix/core/operator_not_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorNotEqual, FvarVar) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_plus_equal_test.cpp b/test/unit/math/mix/core/operator_plus_equal_test.cpp index ee4cc8dc7a1..df34c8da97c 100644 --- a/test/unit/math/mix/core/operator_plus_equal_test.cpp +++ b/test/unit/math/mix/core/operator_plus_equal_test.cpp @@ -1,7 +1,6 @@ +#include #include #include -#include -#include TEST(AgradMixOperatorPlusEqual, FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_plus_plus_test.cpp b/test/unit/math/mix/core/operator_plus_plus_test.cpp index d02f0283a08..619fabd7ac1 100644 --- a/test/unit/math/mix/core/operator_plus_plus_test.cpp +++ b/test/unit/math/mix/core/operator_plus_plus_test.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/test/unit/math/mix/core/operator_subtraction_test.cpp b/test/unit/math/mix/core/operator_subtraction_test.cpp index cd96e3b4284..74ecaeaab58 100644 --- a/test/unit/math/mix/core/operator_subtraction_test.cpp +++ b/test/unit/math/mix/core/operator_subtraction_test.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include TEST(AgradMixOperatorSubtraction, FvarVar_FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/operator_unary_minus_test.cpp b/test/unit/math/mix/core/operator_unary_minus_test.cpp index b263233d1ad..ef1c3465dfd 100644 --- a/test/unit/math/mix/core/operator_unary_minus_test.cpp +++ b/test/unit/math/mix/core/operator_unary_minus_test.cpp @@ -1,7 +1,7 @@ +#include #include #include #include -#include TEST(AgradMixOperatorUnaryMinus, FvarVar_1stDeriv) { using stan::math::fvar; diff --git a/test/unit/math/mix/core/std_numeric_limits_test.cpp b/test/unit/math/mix/core/std_numeric_limits_test.cpp index 647a68a3b6c..313a4f4e485 100644 --- a/test/unit/math/mix/core/std_numeric_limits_test.cpp +++ b/test/unit/math/mix/core/std_numeric_limits_test.cpp @@ -1,7 +1,5 @@ +#include #include -#include -#include -#include TEST(AgradMixNumericLimits,All_Fvar) { using stan::math::fvar; diff --git a/test/unit/math/prim/arr/err/check_nonzero_size_test.cpp b/test/unit/math/prim/arr/err/check_nonzero_size_test.cpp new file mode 100644 index 00000000000..0e87e1ab2fb --- /dev/null +++ b/test/unit/math/prim/arr/err/check_nonzero_size_test.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix) { + using stan::math::check_nonzero_size; + + std::vector a; + a.push_back(3.0); + a.push_back(3.0); + a.push_back(3.0); + a.push_back(3.0); + + + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "a", a)); + + a.resize(2); + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "a", a)); + + a.resize(0); + EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "a", a), + std::invalid_argument, + "has size 0"); +} + +TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix_nan) { + double nan = std::numeric_limits::quiet_NaN(); + + std::vector a; + a.push_back(nan); + a.push_back(nan); + a.push_back(nan); + a.push_back(nan); + + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "a", a)); + + a.resize(2); + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "a", a)); + + a.resize(0); + EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "a", a), + std::invalid_argument, + "has size 0"); +} diff --git a/test/unit/math/prim/arr/err/check_ordered_test.cpp b/test/unit/math/prim/arr/err/check_ordered_test.cpp new file mode 100644 index 00000000000..da7b5e535c6 --- /dev/null +++ b/test/unit/math/prim/arr/err/check_ordered_test.cpp @@ -0,0 +1,74 @@ +#include +#include + +using stan::math::check_ordered; + +TEST(ErrorHandling, checkOrdered) { + std::vector y_; + y_.push_back(0.0); + y_.push_back(1.0); + y_.push_back(2.0); + EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); + + y_[2] = std::numeric_limits::infinity(); + EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); + + y_[0] = -10.0; + EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); + + y_[0] = -std::numeric_limits::infinity(); + EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); + + y_[0] = 0.0; + y_[1] = 0.0; + y_[2] = 0.0; + EXPECT_THROW(check_ordered("check_ordered", "y", y_), + std::domain_error); + + y_[1] = std::numeric_limits::infinity(); + y_[2] = std::numeric_limits::infinity(); + EXPECT_THROW(check_ordered("check_ordered", "y", y_), + std::domain_error); +} + +TEST(ErrorHandling, checkOrdered_one_indexed_message) { + std::string message; + std::vector y; + y.push_back(0); + y.push_back(5); + y.push_back(1); + + try { + check_ordered("check_ordered", "y", y); + FAIL() << "should have thrown"; + } catch (std::domain_error& e) { + message = e.what(); + } catch (...) { + FAIL() << "threw the wrong error"; + } + + EXPECT_NE(std::string::npos, message.find("element at 3")) + << message; +} + +TEST(ErrorHandling, checkOrdered_nan) { + double nan = std::numeric_limits::quiet_NaN(); + std::vector y_; + y_.push_back(0.0); + y_.push_back(1.0); + y_.push_back(2.0); + for (size_t i = 0; i < y_.size(); i++) { + y_[i] = nan; + EXPECT_THROW(check_ordered("check_ordered", "y", y_), + std::domain_error); + y_[i] = i; + } + for (size_t i = 0; i < y_.size(); i++) { + y_[0] = 0.0; + y_[1] = 10.0; + y_[2] = std::numeric_limits::infinity(); + y_[i] = nan; + EXPECT_THROW(check_ordered("check_ordered", "y", y_), + std::domain_error); + } +} diff --git a/test/unit/math/prim/arr/fun/promote_scalar_type_test.cpp b/test/unit/math/prim/arr/fun/promote_scalar_type_test.cpp new file mode 100644 index 00000000000..6620109e0a4 --- /dev/null +++ b/test/unit/math/prim/arr/fun/promote_scalar_type_test.cpp @@ -0,0 +1,12 @@ +#include +#include +#include + +TEST(MathFunctionsPromoteScalarType,StdVector) { + using std::vector; + expect_promote_type >, + double, vector > >(); + expect_promote_type >, + double, vector > >(); +} + diff --git a/test/unit/math/prim/arr/meta/OperandsAndPartials_test.cpp b/test/unit/math/prim/arr/meta/OperandsAndPartials_test.cpp new file mode 100644 index 00000000000..f49dcf8540e --- /dev/null +++ b/test/unit/math/prim/arr/meta/OperandsAndPartials_test.cpp @@ -0,0 +1,41 @@ +#include +#include + +// TEST(AgradPartialsVari, incr_deriv_vec_double) { +// using stan::VectorView; +// using stan::math::incr_deriv; +// using stan::is_vector; +// using stan::is_constant_struct; + +// std::vector b; +// b.push_back(1); +// b.push_back(1); + +// VectorView, +// stan::is_vector >::value, +// stan::is_constant_struct >::value> +// d_b(stan::length(b) * 0); + +// double result = incr_deriv, +// is_vector >::value, +// is_constant_struct >::value>, +// std::vector,double>().incr(d_b,b); + +// EXPECT_FLOAT_EQ(0, result); +// } + +TEST(AgradPartialsVari, OperandsAndPartials_check_throw) { + using stan::math::OperandsAndPartials; + using std::vector; + + vector D; + + OperandsAndPartials,vector,vector, + vector,vector,vector > o3(D,D,D,D,D,D); + EXPECT_THROW(o3.d_x1[0], std::logic_error); + EXPECT_THROW(o3.d_x2[0], std::logic_error); + EXPECT_THROW(o3.d_x3[0], std::logic_error); + EXPECT_THROW(o3.d_x4[0], std::logic_error); + EXPECT_THROW(o3.d_x5[0], std::logic_error); + EXPECT_THROW(o3.d_x6[0], std::logic_error); +} diff --git a/test/unit/math/prim/arr/meta/VectorBuilderHelper_test.cpp b/test/unit/math/prim/arr/meta/VectorBuilderHelper_test.cpp index c335c38015b..3fd511c1e18 100644 --- a/test/unit/math/prim/arr/meta/VectorBuilderHelper_test.cpp +++ b/test/unit/math/prim/arr/meta/VectorBuilderHelper_test.cpp @@ -10,6 +10,7 @@ TEST(MetaTraits, VectorBuilderHelper_false_false) { VectorBuilderHelper dvv2(length(a_std_vector)); EXPECT_THROW(dvv2[0], std::logic_error); + EXPECT_THROW(dvv2.data(), std::logic_error); } TEST(MetaTraits, VectorBuilderHelper_true_false) { @@ -23,4 +24,7 @@ TEST(MetaTraits, VectorBuilderHelper_true_false) { EXPECT_FLOAT_EQ(0.0, dvv2[0]); EXPECT_FLOAT_EQ(0.0, dvv2[1]); EXPECT_FLOAT_EQ(0.0, dvv2[2]); + double data2(10); + EXPECT_NO_THROW(data2 = dvv2.data()); + EXPECT_FLOAT_EQ(0.0, data2); } diff --git a/test/unit/math/prim/arr/meta/VectorBuilder_test.cpp b/test/unit/math/prim/arr/meta/VectorBuilder_test.cpp index 9fd9da2dd52..38de5a02a42 100644 --- a/test/unit/math/prim/arr/meta/VectorBuilder_test.cpp +++ b/test/unit/math/prim/arr/meta/VectorBuilder_test.cpp @@ -10,6 +10,7 @@ TEST(MetaTraits, VectorBuilder_false_false) { VectorBuilder dvv2(length(a_std_vector)); EXPECT_THROW(dvv2[0], std::logic_error); + EXPECT_THROW(dvv2.data(), std::logic_error); } TEST(MetaTraits, VectorBuilder_true_false) { @@ -22,5 +23,8 @@ TEST(MetaTraits, VectorBuilder_true_false) { VectorBuilder dvv2(length(a_std_vector)); EXPECT_FLOAT_EQ(0.0, dvv2[0]); EXPECT_FLOAT_EQ(0.0, dvv2[1]); - EXPECT_FLOAT_EQ(0.0, dvv2[2]); + EXPECT_FLOAT_EQ(0.0, dvv2[2]); + double data2 = 0; + EXPECT_NO_THROW(data2 = dvv2.data()); + EXPECT_FLOAT_EQ(0.0, data2); } diff --git a/test/unit/math/prim/arr/meta/VectorView_test.cpp b/test/unit/math/prim/arr/meta/VectorView_test.cpp index 17dd11adef2..840b48b4225 100644 --- a/test/unit/math/prim/arr/meta/VectorView_test.cpp +++ b/test/unit/math/prim/arr/meta/VectorView_test.cpp @@ -20,8 +20,8 @@ TEST(MetaTraits, VectorView_vector_double) { const vector y(x); VectorView > yv(y); - for (size_t n = 0; n < 10; ++n) - EXPECT_FLOAT_EQ(y[n], yv[n]); + // for (size_t n = 0; n < 10; ++n) + // EXPECT_FLOAT_EQ(y[n], yv[n]); } TEST(MetaTraits,VectorView) { @@ -32,8 +32,8 @@ TEST(MetaTraits,VectorView) { sv.push_back(1.0); sv.push_back(4.0); sv.push_back(9.0); - VectorView > sv_VectorView(sv); - EXPECT_FLOAT_EQ(1.0,sv_VectorView[0]); - EXPECT_FLOAT_EQ(4.0,sv_VectorView[1]); - EXPECT_FLOAT_EQ(9.0,sv_VectorView[2]); + // VectorView > sv_VectorView(sv); + // EXPECT_FLOAT_EQ(1.0,sv_VectorView[0]); + // EXPECT_FLOAT_EQ(4.0,sv_VectorView[1]); + // EXPECT_FLOAT_EQ(9.0,sv_VectorView[2]); } diff --git a/test/unit/math/prim/mat/err/check_nonzero_size_test.cpp b/test/unit/math/prim/mat/err/check_nonzero_size_test.cpp new file mode 100644 index 00000000000..d03f61ffea4 --- /dev/null +++ b/test/unit/math/prim/mat/err/check_nonzero_size_test.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix) { + Eigen::Matrix y; + using stan::math::check_nonzero_size; + + y.resize(3,3); + EXPECT_TRUE(check_nonzero_size("checkNonzeroSize", + "y", y)); + y.resize(2, 3); + EXPECT_TRUE(check_nonzero_size("checkNonzeroSize", + "y", y)); + + y.resize(0,0); + EXPECT_THROW_MSG(check_nonzero_size("checkNonzeroSize", + "y", y), + std::invalid_argument, + "has size 0"); +} + +TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix_nan) { + Eigen::Matrix y; + double nan = std::numeric_limits::quiet_NaN(); + + y.resize(3,3); + y << nan, nan, nan,nan, nan, nan,nan, nan, nan; + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "y", y)); + y.resize(2, 3); + y << nan, nan, nan,nan, nan, nan; + EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", + "y", y)); + + y.resize(0,0); + EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "y", y), + std::invalid_argument, + "has size 0"); +} diff --git a/test/unit/math/prim/mat/err/check_ordered_test.cpp b/test/unit/math/prim/mat/err/check_ordered_test.cpp index 5d33d72a948..a0f27bc1bd5 100644 --- a/test/unit/math/prim/mat/err/check_ordered_test.cpp +++ b/test/unit/math/prim/mat/err/check_ordered_test.cpp @@ -31,32 +31,6 @@ TEST(ErrorHandlingMatrix, checkOrdered) { y << -1, 3, 2; EXPECT_THROW(check_ordered("check_ordered", "y", y), std::domain_error); - - std::vector y_; - y_.push_back(0.0); - y_.push_back(1.0); - y_.push_back(2.0); - EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); - - y_[2] = std::numeric_limits::infinity(); - EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); - - y_[0] = -10.0; - EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); - - y_[0] = -std::numeric_limits::infinity(); - EXPECT_TRUE(check_ordered("check_ordered", "y", y_)); - - y_[0] = 0.0; - y_[1] = 0.0; - y_[2] = 0.0; - EXPECT_THROW(check_ordered("check_ordered", "y", y_), - std::domain_error); - - y_[1] = std::numeric_limits::infinity(); - y_[2] = std::numeric_limits::infinity(); - EXPECT_THROW(check_ordered("check_ordered", "y", y_), - std::domain_error); } TEST(ErrorHandlingMatrix, checkOrdered_one_indexed_message) { @@ -80,34 +54,20 @@ TEST(ErrorHandlingMatrix, checkOrdered_one_indexed_message) { TEST(ErrorHandlingMatrix, checkOrdered_nan) { Eigen::Matrix y; - std::vector y_; double nan = std::numeric_limits::quiet_NaN(); y.resize(3); y << 0, 1, 2; - y_.push_back(0.0); - y_.push_back(1.0); - y_.push_back(2.0); for (int i = 0; i < y.size(); i++) { y[i] = nan; - y_[i] = nan; EXPECT_THROW(check_ordered("check_ordered", "y", y), std::domain_error); - EXPECT_THROW(check_ordered("check_ordered", "y", y_), - std::domain_error); y[i] = i; - y_[i] = i; } for (int i = 0; i < y.size(); i++) { y << 0, 10, std::numeric_limits::infinity(); - y_[0] = 0.0; - y_[1] = 10.0; - y_[2] = std::numeric_limits::infinity(); y[i] = nan; - y_[i] = nan; EXPECT_THROW(check_ordered("check_ordered", "y", y), std::domain_error); - EXPECT_THROW(check_ordered("check_ordered", "y", y_), - std::domain_error); } } diff --git a/test/unit/math/prim/mat/meta/VectorBuilderHelper_test.cpp b/test/unit/math/prim/mat/meta/VectorBuilderHelper_test.cpp index fadf25336be..d5371569d38 100644 --- a/test/unit/math/prim/mat/meta/VectorBuilderHelper_test.cpp +++ b/test/unit/math/prim/mat/meta/VectorBuilderHelper_test.cpp @@ -13,9 +13,11 @@ TEST(MetaTraits, VectorBuilderHelper_false_false) { VectorBuilderHelper dvv3(length(a_vector)); EXPECT_THROW(dvv3[0], std::logic_error); + EXPECT_THROW(dvv3.data(), std::logic_error); VectorBuilderHelper dvv4(length(a_row_vector)); EXPECT_THROW(dvv4[0], std::logic_error); + EXPECT_THROW(dvv4.data(), std::logic_error); } TEST(MetaTraits, VectorBuilderHelper_true_false) { @@ -30,10 +32,16 @@ TEST(MetaTraits, VectorBuilderHelper_true_false) { VectorBuilderHelper dvv3(length(a_vector)); EXPECT_FLOAT_EQ(0.0, dvv3[0]); EXPECT_FLOAT_EQ(0.0, dvv3[1]); - EXPECT_FLOAT_EQ(0.0, dvv3[2]); + EXPECT_FLOAT_EQ(0.0, dvv3[2]); + double data3 = 0; + EXPECT_NO_THROW(data3 = dvv3.data()); + EXPECT_FLOAT_EQ(0.0, data3); VectorBuilderHelper dvv4(length(a_row_vector)); EXPECT_FLOAT_EQ(0.0, dvv4[0]); EXPECT_FLOAT_EQ(0.0, dvv4[1]); EXPECT_FLOAT_EQ(0.0, dvv4[2]); + double data4 = 0; + EXPECT_NO_THROW(data4 = dvv4.data()); + EXPECT_FLOAT_EQ(0.0, data4); } diff --git a/test/unit/math/prim/mat/meta/VectorBuilder_test.cpp b/test/unit/math/prim/mat/meta/VectorBuilder_test.cpp index 5d53b8007dc..819869658f4 100644 --- a/test/unit/math/prim/mat/meta/VectorBuilder_test.cpp +++ b/test/unit/math/prim/mat/meta/VectorBuilder_test.cpp @@ -12,9 +12,11 @@ TEST(MetaTraits, VectorBuilder_false_false) { VectorBuilder dvv3(length(a_vector)); EXPECT_THROW(dvv3[0], std::logic_error); + EXPECT_THROW(dvv3.data(), std::logic_error); VectorBuilder dvv4(length(a_row_vector)); EXPECT_THROW(dvv4[0], std::logic_error); + EXPECT_THROW(dvv4.data(), std::logic_error); } TEST(MetaTraits, VectorBuilder_true_false) { @@ -29,11 +31,17 @@ TEST(MetaTraits, VectorBuilder_true_false) { VectorBuilder dvv3(length(a_vector)); EXPECT_FLOAT_EQ(0.0, dvv3[0]); EXPECT_FLOAT_EQ(0.0, dvv3[1]); - EXPECT_FLOAT_EQ(0.0, dvv3[2]); + EXPECT_FLOAT_EQ(0.0, dvv3[2]); + double data3 = 0.0; + EXPECT_NO_THROW(data3 = dvv3.data()); + EXPECT_FLOAT_EQ(0.0, data3); VectorBuilder dvv4(length(a_row_vector)); EXPECT_FLOAT_EQ(0.0, dvv4[0]); EXPECT_FLOAT_EQ(0.0, dvv4[1]); EXPECT_FLOAT_EQ(0.0, dvv4[2]); + double data4 = 0.0; + EXPECT_NO_THROW(data4 = dvv4.data()); + EXPECT_FLOAT_EQ(0.0, data4); } diff --git a/test/unit/math/prim/mat/meta/scalar_type_test.cpp b/test/unit/math/prim/mat/meta/scalar_type_test.cpp new file mode 100644 index 00000000000..d2aa8e944a2 --- /dev/null +++ b/test/unit/math/prim/mat/meta/scalar_type_test.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +TEST(MetaTraits, scalar_type) { + using boost::is_same; + using stan::scalar_type; + using Eigen::Matrix; + using Eigen::Dynamic; + + stan::scalar_type >::type x = 1; + EXPECT_FLOAT_EQ(1, x); + + // hack to get value of template into Google test macro + bool b3 = is_same >::type>::value; + EXPECT_TRUE(b3); +} diff --git a/test/unit/math/prim/mat/prob/categorical_logit_test.cpp b/test/unit/math/prim/mat/prob/categorical_logit_test.cpp index 0c54320c6f7..c5f86c8873f 100644 --- a/test/unit/math/prim/mat/prob/categorical_logit_test.cpp +++ b/test/unit/math/prim/mat/prob/categorical_logit_test.cpp @@ -1,13 +1,6 @@ -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/categorical_test.cpp b/test/unit/math/prim/mat/prob/categorical_test.cpp index 295e212d94e..e49d1e68ec9 100644 --- a/test/unit/math/prim/mat/prob/categorical_test.cpp +++ b/test/unit/math/prim/mat/prob/categorical_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include #include diff --git a/test/unit/math/prim/mat/prob/dirichlet_test.cpp b/test/unit/math/prim/mat/prob/dirichlet_test.cpp index 07ce51b8fc4..a3e983e9fa2 100644 --- a/test/unit/math/prim/mat/prob/dirichlet_test.cpp +++ b/test/unit/math/prim/mat/prob/dirichlet_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include #include diff --git a/test/unit/math/prim/mat/prob/gaussian_dlm_obs_test.cpp b/test/unit/math/prim/mat/prob/gaussian_dlm_obs_test.cpp index 81d9fe43450..aa7bd672762 100644 --- a/test/unit/math/prim/mat/prob/gaussian_dlm_obs_test.cpp +++ b/test/unit/math/prim/mat/prob/gaussian_dlm_obs_test.cpp @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/inv_wishart_test.cpp b/test/unit/math/prim/mat/prob/inv_wishart_test.cpp index ce05421943d..d1ed8e7ddf3 100644 --- a/test/unit/math/prim/mat/prob/inv_wishart_test.cpp +++ b/test/unit/math/prim/mat/prob/inv_wishart_test.cpp @@ -1,16 +1,8 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include #include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/lkj_cov_test.cpp b/test/unit/math/prim/mat/prob/lkj_cov_test.cpp index d1b6adf7cbb..9c1c065da14 100644 --- a/test/unit/math/prim/mat/prob/lkj_cov_test.cpp +++ b/test/unit/math/prim/mat/prob/lkj_cov_test.cpp @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include TEST(ProbDistributionsLkjCorr,testIdentity) { unsigned int K = 4; diff --git a/test/unit/math/prim/mat/prob/matrix_normal_test.cpp b/test/unit/math/prim/mat/prob/matrix_normal_test.cpp index cfd7a081495..b9df87dbf85 100644 --- a/test/unit/math/prim/mat/prob/matrix_normal_test.cpp +++ b/test/unit/math/prim/mat/prob/matrix_normal_test.cpp @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/multi_gp_cholesky_test.cpp b/test/unit/math/prim/mat/prob/multi_gp_cholesky_test.cpp index 0cc1c828479..9a84da37953 100644 --- a/test/unit/math/prim/mat/prob/multi_gp_cholesky_test.cpp +++ b/test/unit/math/prim/mat/prob/multi_gp_cholesky_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/multi_gp_test.cpp b/test/unit/math/prim/mat/prob/multi_gp_test.cpp index f95cb16432d..33a6bc580db 100644 --- a/test/unit/math/prim/mat/prob/multi_gp_test.cpp +++ b/test/unit/math/prim/mat/prob/multi_gp_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/multi_normal_prec_test.cpp b/test/unit/math/prim/mat/prob/multi_normal_prec_test.cpp index 3b88559b1a5..7675a303712 100644 --- a/test/unit/math/prim/mat/prob/multi_normal_prec_test.cpp +++ b/test/unit/math/prim/mat/prob/multi_normal_prec_test.cpp @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/mat/prob/multi_student_t_test.cpp b/test/unit/math/prim/mat/prob/multi_student_t_test.cpp index 807d6127c2a..817b1e5c2c6 100644 --- a/test/unit/math/prim/mat/prob/multi_student_t_test.cpp +++ b/test/unit/math/prim/mat/prob/multi_student_t_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include #include diff --git a/test/unit/math/prim/mat/prob/multinomial_test.cpp b/test/unit/math/prim/mat/prob/multinomial_test.cpp index 3d8d928d3e7..c85ff291d04 100644 --- a/test/unit/math/prim/mat/prob/multinomial_test.cpp +++ b/test/unit/math/prim/mat/prob/multinomial_test.cpp @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include #include diff --git a/test/unit/math/prim/mat/prob/wishart_test.cpp b/test/unit/math/prim/mat/prob/wishart_test.cpp index 3b72f9c805d..9ef61fbf68e 100644 --- a/test/unit/math/prim/mat/prob/wishart_test.cpp +++ b/test/unit/math/prim/mat/prob/wishart_test.cpp @@ -1,17 +1,8 @@ -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include #include #include -#include -#include using Eigen::Dynamic; using Eigen::Matrix; diff --git a/test/unit/math/prim/scal/err/check_nonzero_size_test.cpp b/test/unit/math/prim/scal/err/check_nonzero_size_test.cpp deleted file mode 100644 index 7bbbd0936e7..00000000000 --- a/test/unit/math/prim/scal/err/check_nonzero_size_test.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include - -TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix) { - Eigen::Matrix y; - using stan::math::check_nonzero_size; - - y.resize(3,3); - EXPECT_TRUE(check_nonzero_size("checkNonzeroSize", - "y", y)); - y.resize(2, 3); - EXPECT_TRUE(check_nonzero_size("checkNonzeroSize", - "y", y)); - - y.resize(0,0); - EXPECT_THROW_MSG(check_nonzero_size("checkNonzeroSize", - "y", y), - std::invalid_argument, - "has size 0"); - - std::vector a; - a.push_back(3.0); - a.push_back(3.0); - a.push_back(3.0); - a.push_back(3.0); - - - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "a", a)); - - a.resize(2); - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "a", a)); - - a.resize(0); - EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "a", a), - std::invalid_argument, - "has size 0"); -} - -TEST(ErrorHandlingMatrix, checkNonzeroSizeMatrix_nan) { - Eigen::Matrix y; - double nan = std::numeric_limits::quiet_NaN(); - - y.resize(3,3); - y << nan, nan, nan,nan, nan, nan,nan, nan, nan; - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "y", y)); - y.resize(2, 3); - y << nan, nan, nan,nan, nan, nan; - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "y", y)); - - y.resize(0,0); - EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "y", y), - std::invalid_argument, - "has size 0"); - - std::vector a; - a.push_back(nan); - a.push_back(nan); - a.push_back(nan); - a.push_back(nan); - - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "a", a)); - - a.resize(2); - EXPECT_TRUE(stan::math::check_nonzero_size("checkNonzeroSize", - "a", a)); - - a.resize(0); - EXPECT_THROW_MSG(stan::math::check_nonzero_size("checkNonzeroSize", "a", a), - std::invalid_argument, - "has size 0"); -} diff --git a/test/unit/math/prim/scal/fun/promote_scalar_type_test.cpp b/test/unit/math/prim/scal/fun/promote_scalar_type_test.cpp index 05e7a7bb511..ba94c1f2ebb 100644 --- a/test/unit/math/prim/scal/fun/promote_scalar_type_test.cpp +++ b/test/unit/math/prim/scal/fun/promote_scalar_type_test.cpp @@ -11,12 +11,3 @@ TEST(MathFunctionsPromoteScalarType,primitive) { expect_promote_type, double, vector >(); } - -TEST(MathFunctionsPromoteScalarType,StdVector) { - using std::vector; - expect_promote_type >, - double, vector > >(); - expect_promote_type >, - double, vector > >(); -} - diff --git a/test/unit/math/prim/scal/meta/OperandsAndPartials_test.cpp b/test/unit/math/prim/scal/meta/OperandsAndPartials_test.cpp index afe6d5354e2..d37c4b96f15 100644 --- a/test/unit/math/prim/scal/meta/OperandsAndPartials_test.cpp +++ b/test/unit/math/prim/scal/meta/OperandsAndPartials_test.cpp @@ -1,45 +1,46 @@ #include #include -TEST(AgradPartialsVari, incr_deriv_double) { - using stan::VectorView; - using stan::math::incr_deriv; - using stan::is_vector; - using stan::is_constant_struct; +TEST(AgradPartialsVari, OperandsAndPartials) { + using stan::math::OperandsAndPartials; - double a = 1; - - VectorView::value, - stan::is_constant_struct::value> d_a(stan::length(a) * 0); + OperandsAndPartials o1; + OperandsAndPartials o2; + + SUCCEED() << "Construction should be ok."; +} +// TEST(AgradPartialsVari, incr_deriv_double) { +// using stan::VectorView; +// using stan::math::incr_deriv; +// using stan::is_vector; +// using stan::is_constant_struct; +// double a = 1; - double result = incr_deriv::value, - is_constant_struct::value>, - double,double>().incr(d_a,a); - EXPECT_FLOAT_EQ(0, result); -} +// VectorView::value, +// stan::is_constant_struct::value> d_a(stan::length(a) * 0); -TEST(AgradPartialsVari, incr_deriv_vec_double) { - using stan::VectorView; - using stan::math::incr_deriv; - using stan::is_vector; - using stan::is_constant_struct; - std::vector b; - b.push_back(1); - b.push_back(1); - VectorView, - stan::is_vector >::value, - stan::is_constant_struct >::value> - d_b(stan::length(b) * 0); +// double result = incr_deriv::value, +// is_constant_struct::value>, +// double,double>().incr(d_a,a); +// EXPECT_FLOAT_EQ(0, result); +// } - double result = incr_deriv, - is_vector >::value, - is_constant_struct >::value>, - std::vector,double>().incr(d_b,b); - EXPECT_FLOAT_EQ(0, result); +TEST(AgradPartialsVari, OperandsAndPartials_check_throw) { + using stan::math::OperandsAndPartials; + + double d; + + OperandsAndPartials<> o1(d,d,d,d,d,d); + EXPECT_THROW(o1.d_x1[0], std::logic_error); + EXPECT_THROW(o1.d_x2[0], std::logic_error); + EXPECT_THROW(o1.d_x3[0], std::logic_error); + EXPECT_THROW(o1.d_x4[0], std::logic_error); + EXPECT_THROW(o1.d_x5[0], std::logic_error); + EXPECT_THROW(o1.d_x6[0], std::logic_error); } diff --git a/test/unit/math/prim/scal/meta/VectorBuilderHelper_test.cpp b/test/unit/math/prim/scal/meta/VectorBuilderHelper_test.cpp new file mode 100644 index 00000000000..fbabd2631fa --- /dev/null +++ b/test/unit/math/prim/scal/meta/VectorBuilderHelper_test.cpp @@ -0,0 +1,29 @@ +#include +#include + +TEST(MetaTraits, VectorBuilderHelper_false_false) { + using stan::VectorBuilderHelper; + using stan::length; + + double a_double(1); + + VectorBuilderHelper dvv1(length(a_double)); + EXPECT_THROW(dvv1[0], std::logic_error); + EXPECT_THROW(dvv1.data(), std::logic_error); +} + +TEST(MetaTraits, VectorBuilderHelper_true_false) { + using stan::VectorBuilderHelper; + using stan::length; + + double a_double(1); + + VectorBuilderHelper dvv1(length(a_double)); + EXPECT_FLOAT_EQ(0.0, dvv1[0]); + EXPECT_FLOAT_EQ(0.0, dvv1[1]); + EXPECT_FLOAT_EQ(0.0, dvv1[100]); + + double data = dvv1.data(); + EXPECT_FLOAT_EQ(0.0, data); +} + diff --git a/test/unit/math/prim/scal/meta/VectorBuilder_test.cpp b/test/unit/math/prim/scal/meta/VectorBuilder_test.cpp index 69302eeb067..46a43c96191 100644 --- a/test/unit/math/prim/scal/meta/VectorBuilder_test.cpp +++ b/test/unit/math/prim/scal/meta/VectorBuilder_test.cpp @@ -1,28 +1,5 @@ #include #include -#include - -TEST(MetaTraits, VectorBuilderHelper_false_false) { - using stan::VectorBuilderHelper; - using stan::length; - - double a_double(1); - - VectorBuilderHelper dvv1(length(a_double)); - EXPECT_THROW(dvv1[0], std::logic_error); -} - -TEST(MetaTraits, VectorBuilderHelper_true_false) { - using stan::VectorBuilderHelper; - using stan::length; - - double a_double(1); - - VectorBuilderHelper dvv1(length(a_double)); - EXPECT_FLOAT_EQ(0.0, dvv1[0]); - EXPECT_FLOAT_EQ(0.0, dvv1[1]); - EXPECT_FLOAT_EQ(0.0, dvv1[100]); -} TEST(MetaTraits, VectorBuilder_false_false) { using stan::VectorBuilder; @@ -32,6 +9,7 @@ TEST(MetaTraits, VectorBuilder_false_false) { VectorBuilder dvv1(length(a_double)); EXPECT_THROW(dvv1[0], std::logic_error); + EXPECT_THROW(dvv1.data(), std::logic_error); } TEST(MetaTraits, VectorBuilder_true_false) { @@ -44,4 +22,7 @@ TEST(MetaTraits, VectorBuilder_true_false) { EXPECT_FLOAT_EQ(0.0, dvv1[0]); EXPECT_FLOAT_EQ(0.0, dvv1[1]); EXPECT_FLOAT_EQ(0.0, dvv1[100]); + double data1 = 0; + EXPECT_NO_THROW(data1 = dvv1.data()); + EXPECT_FLOAT_EQ(0.0, data1); } diff --git a/test/unit/math/prim/scal/meta/VectorView_test.cpp b/test/unit/math/prim/scal/meta/VectorView_test.cpp index ba6bb8edc46..9ac9dac7f68 100644 --- a/test/unit/math/prim/scal/meta/VectorView_test.cpp +++ b/test/unit/math/prim/scal/meta/VectorView_test.cpp @@ -52,3 +52,10 @@ TEST(MetaTraits, VectorView_double_star) { EXPECT_FLOAT_EQ(10, bv[0]); EXPECT_FLOAT_EQ(10, b); } + +TEST(MetaTraits, VectorView_throw_if_accessed) { + using stan::VectorView; + double d(10); + VectorView dv(d); + EXPECT_THROW(dv[0], std::logic_error); +} diff --git a/test/unit/math/rev/arr/meta/OperandsAndPartials_test.cpp b/test/unit/math/rev/arr/meta/OperandsAndPartials_test.cpp index 8a88ca07591..7fe30453d6c 100644 --- a/test/unit/math/rev/arr/meta/OperandsAndPartials_test.cpp +++ b/test/unit/math/rev/arr/meta/OperandsAndPartials_test.cpp @@ -7,8 +7,6 @@ TEST(AgradPartialsVari, OperandsAndPartials) { std::vector d_vec(4); OperandsAndPartials > o3(d_vec); - EXPECT_EQ(0U, o3.nvaris); - std::vector v_vec; v_vec.push_back(var(0.0)); v_vec.push_back(var(1.0)); @@ -23,7 +21,7 @@ TEST(AgradPartialsVari, OperandsAndPartials) { o4.d_x1[2] = 30.0; o4.d_x1[3] = 40.0; - var v = o4.to_var(10.0,v_vec); + var v = o4.value(10.0); v.grad(v_vec, grad); EXPECT_EQ(4U, o4.nvaris); EXPECT_FLOAT_EQ(10.0, v.val()); @@ -38,17 +36,7 @@ TEST(AgradPartialsVari, OperandsAndPartials_check_throw) { using stan::math::var; using std::vector; - vector D; vector V; - - OperandsAndPartials,vector,vector, - vector,vector,vector > o3(D,D,D,D,D,D); - EXPECT_THROW(o3.d_x1[0], std::out_of_range); - EXPECT_THROW(o3.d_x2[0], std::out_of_range); - EXPECT_THROW(o3.d_x3[0], std::out_of_range); - EXPECT_THROW(o3.d_x4[0], std::out_of_range); - EXPECT_THROW(o3.d_x5[0], std::out_of_range); - EXPECT_THROW(o3.d_x6[0], std::out_of_range); OperandsAndPartials,vector,vector, vector,vector,vector > o4(V,V,V,V,V,V); diff --git a/test/unit/math/rev/arr/meta/VectorBuilderHelper_test.cpp b/test/unit/math/rev/arr/meta/VectorBuilderHelper_test.cpp index 103bce80281..739dd8ad38a 100644 --- a/test/unit/math/rev/arr/meta/VectorBuilderHelper_test.cpp +++ b/test/unit/math/rev/arr/meta/VectorBuilderHelper_test.cpp @@ -11,6 +11,7 @@ TEST(MetaTraits, VectorBuilderHelper_false_true) { VectorBuilderHelper dvv2(length(a_std_vector)); EXPECT_THROW(dvv2[0], std::logic_error); + EXPECT_THROW(dvv2.data(), std::logic_error); } TEST(MetaTraits, VectorBuilderHelper_true_true) { @@ -19,7 +20,14 @@ TEST(MetaTraits, VectorBuilderHelper_true_true) { using stan::math::var; using stan::length; + var a_var(1); std::vector a_std_vector(3); + VectorBuilderHelper dvv1(length(a_var)); + dvv1[0] = 0.0; + EXPECT_FLOAT_EQ(0.0, dvv1[0]); + std::vector data1; + EXPECT_NO_THROW(data1 = dvv1.data()); + EXPECT_EQ(length(a_var), data1.size()); VectorBuilderHelper dvv2(length(a_std_vector)); dvv2[0] = 0.0; @@ -28,4 +36,7 @@ TEST(MetaTraits, VectorBuilderHelper_true_true) { EXPECT_FLOAT_EQ(0.0, dvv2[0]); EXPECT_FLOAT_EQ(1.0, dvv2[1]); EXPECT_FLOAT_EQ(2.0, dvv2[2]); + std::vector data2; + EXPECT_NO_THROW(data2 = dvv2.data()); + EXPECT_EQ(length(a_std_vector), data2.size()); } diff --git a/test/unit/math/rev/arr/meta/VectorBuilder_test.cpp b/test/unit/math/rev/arr/meta/VectorBuilder_test.cpp index bfdfb66ccd3..2acfe1d12a0 100644 --- a/test/unit/math/rev/arr/meta/VectorBuilder_test.cpp +++ b/test/unit/math/rev/arr/meta/VectorBuilder_test.cpp @@ -12,9 +12,11 @@ TEST(MetaTraits, VectorBuilder_false_true) { VectorBuilder > dvv1(length(a_var)); EXPECT_THROW(dvv1[0], std::logic_error); + EXPECT_THROW(dvv1.data(), std::logic_error); VectorBuilder > dvv2(length(a_std_vector)); EXPECT_THROW(dvv2[0], std::logic_error); + EXPECT_THROW(dvv2.data(), std::logic_error); } TEST(MetaTraits, VectorBuilder_true_true) { @@ -29,6 +31,9 @@ TEST(MetaTraits, VectorBuilder_true_true) { VectorBuilder > dvv1(length(a_var)); dvv1[0] = 0.0; EXPECT_FLOAT_EQ(0.0, dvv1[0]); + std::vector data1; + EXPECT_NO_THROW(data1 = dvv1.data()); + EXPECT_EQ(length(a_var), data1.size()); VectorBuilder > dvv2(length(a_std_vector)); dvv2[0] = 0.0; @@ -37,5 +42,8 @@ TEST(MetaTraits, VectorBuilder_true_true) { EXPECT_FLOAT_EQ(0.0, dvv2[0]); EXPECT_FLOAT_EQ(1.0, dvv2[1]); EXPECT_FLOAT_EQ(2.0, dvv2[2]); + std::vector data2; + EXPECT_NO_THROW(data2 = dvv2.data()); + EXPECT_EQ(length(a_std_vector), data2.size()); } diff --git a/test/unit/math/rev/mat/meta/VectorBuilderHelper_test.cpp b/test/unit/math/rev/mat/meta/VectorBuilderHelper_test.cpp index f5f95702592..d602738d80f 100644 --- a/test/unit/math/rev/mat/meta/VectorBuilderHelper_test.cpp +++ b/test/unit/math/rev/mat/meta/VectorBuilderHelper_test.cpp @@ -13,9 +13,11 @@ TEST(MetaTraits, VectorBuilderHelper_false_true) { VectorBuilderHelper dvv3(length(a_vector)); EXPECT_THROW(dvv3[0], std::logic_error); + EXPECT_THROW(dvv3.data(), std::logic_error); VectorBuilderHelper dvv4(length(a_row_vector)); EXPECT_THROW(dvv4[0], std::logic_error); + EXPECT_THROW(dvv3.data(), std::logic_error); } TEST(MetaTraits, VectorBuilderHelper_true_true) { @@ -34,8 +36,12 @@ TEST(MetaTraits, VectorBuilderHelper_true_true) { dvv3[2] = 2.0; EXPECT_FLOAT_EQ(0.0, dvv3[0]); EXPECT_FLOAT_EQ(1.0, dvv3[1]); - EXPECT_FLOAT_EQ(2.0, dvv3[2]); - + EXPECT_FLOAT_EQ(2.0, dvv3[2]); + std::vector data3; + EXPECT_NO_THROW(data3 = dvv3.data()); + EXPECT_EQ(length(a_vector), data3.size()); + + VectorBuilderHelper dvv4(length(a_row_vector)); dvv4[0] = 0.0; dvv4[1] = 1.0; @@ -43,4 +49,7 @@ TEST(MetaTraits, VectorBuilderHelper_true_true) { EXPECT_FLOAT_EQ(0.0, dvv4[0]); EXPECT_FLOAT_EQ(1.0, dvv4[1]); EXPECT_FLOAT_EQ(2.0, dvv4[2]); + std::vector data4; + EXPECT_NO_THROW(data4 = dvv4.data()); + EXPECT_EQ(length(a_row_vector), data4.size()); } diff --git a/test/unit/math/rev/mat/meta/VectorBuilder_test.cpp b/test/unit/math/rev/mat/meta/VectorBuilder_test.cpp index 70c7860cdb9..64e59d381f1 100644 --- a/test/unit/math/rev/mat/meta/VectorBuilder_test.cpp +++ b/test/unit/math/rev/mat/meta/VectorBuilder_test.cpp @@ -13,9 +13,11 @@ TEST(MetaTraits, VectorBuilder_false_true) { VectorBuilder > dvv3(length(a_vector)); EXPECT_THROW(dvv3[0], std::logic_error); + EXPECT_THROW(dvv3.data(), std::logic_error); VectorBuilder > dvv4(length(a_row_vector)); EXPECT_THROW(dvv4[0], std::logic_error); + EXPECT_THROW(dvv4.data(), std::logic_error); } TEST(MetaTraits, VectorBuilder_true_true) { @@ -35,6 +37,9 @@ TEST(MetaTraits, VectorBuilder_true_true) { EXPECT_FLOAT_EQ(0.0, dvv3[0]); EXPECT_FLOAT_EQ(1.0, dvv3[1]); EXPECT_FLOAT_EQ(2.0, dvv3[2]); + std::vector data3; + EXPECT_NO_THROW(data3 = dvv3.data()); + EXPECT_EQ(length(a_vector), data3.size()); VectorBuilder > dvv4(length(a_row_vector)); dvv4[0] = 0.0; @@ -43,4 +48,7 @@ TEST(MetaTraits, VectorBuilder_true_true) { EXPECT_FLOAT_EQ(0.0, dvv4[0]); EXPECT_FLOAT_EQ(1.0, dvv4[1]); EXPECT_FLOAT_EQ(2.0, dvv4[2]); + std::vector data4; + EXPECT_NO_THROW(data4 = dvv4.data()); + EXPECT_EQ(length(a_row_vector), data4.size()); } diff --git a/test/unit/math/rev/scal/meta/OperandsAndPartials_test.cpp b/test/unit/math/rev/scal/meta/OperandsAndPartials_test.cpp index 9b5ba9e8a53..ef5345ad081 100644 --- a/test/unit/math/rev/scal/meta/OperandsAndPartials_test.cpp +++ b/test/unit/math/rev/scal/meta/OperandsAndPartials_test.cpp @@ -1,16 +1,6 @@ #include #include -TEST(AgradPartialsVari, OperandsAndPartials) { - using stan::math::OperandsAndPartials; - using stan::math::var; - - OperandsAndPartials o1; - EXPECT_EQ(0U, o1.nvaris); - - OperandsAndPartials o2; - EXPECT_EQ(0U, o2.nvaris); -} TEST(AgradPartialsVari,OperandsAndPartials1) { using stan::math::vari; using stan::math::OperandsAndPartials; @@ -21,7 +11,7 @@ TEST(AgradPartialsVari,OperandsAndPartials1) { OperandsAndPartials o(z); o.d_x1[0] += 5.0; // dy/dz = 5 - var y = o.to_var(-1.0); + var y = o.value(-1.0); stan::math::grad(y.vi_); EXPECT_FLOAT_EQ(-15.0, x.adj()); // dy/dx = -15 @@ -38,7 +28,7 @@ TEST(AgradPartialsVari,OperandsAndPartials2) { OperandsAndPartials o(z1,z2); o.d_x1[0] += 11.0; // dy/dz1 = 11.0 o.d_x2[0] += 13.0; // dy/dz2 = 13.0 - var y = o.to_var(-1.0); + var y = o.value(-1.0); stan::math::grad(y.vi_); EXPECT_FLOAT_EQ(-55.0, x1.adj()); // dy/dx1 = -55 @@ -60,7 +50,7 @@ TEST(AgradPartialsVari, OperandsAndPartials3) { o.d_x1[0] += 17.0; // dy/dz1 = 17.0 o.d_x2[0] += 19.0; // dy/dz2 = 19.0 o.d_x3[0] += 23.0; // dy/dz3 = 23.0 - var y = o.to_var(-1.0); + var y = o.value(-1.0); stan::math::grad(y.vi_); EXPECT_FLOAT_EQ(-119.0, x1.adj()); // dy/dx1 = -119 @@ -71,16 +61,7 @@ TEST(AgradPartialsVari, OperandsAndPartials_check_throw) { using stan::math::OperandsAndPartials; using stan::math::var; - double d; var v; - - OperandsAndPartials<> o1(d,d,d,d,d,d); - EXPECT_THROW(o1.d_x1[0], std::out_of_range); - EXPECT_THROW(o1.d_x2[0], std::out_of_range); - EXPECT_THROW(o1.d_x3[0], std::out_of_range); - EXPECT_THROW(o1.d_x4[0], std::out_of_range); - EXPECT_THROW(o1.d_x5[0], std::out_of_range); - EXPECT_THROW(o1.d_x6[0], std::out_of_range); OperandsAndPartials o2(v,v,v,v,v,v); EXPECT_NO_THROW(o2.d_x1[0]); diff --git a/test/unit/math/rev/scal/meta/VectorBuilderHelper_test.cpp b/test/unit/math/rev/scal/meta/VectorBuilderHelper_test.cpp index d9c811afd35..1dd8cea7ec4 100644 --- a/test/unit/math/rev/scal/meta/VectorBuilderHelper_test.cpp +++ b/test/unit/math/rev/scal/meta/VectorBuilderHelper_test.cpp @@ -10,6 +10,7 @@ TEST(MetaTraits, VectorBuilderHelper_false_true) { VectorBuilderHelper dvv1(length(a_var)); EXPECT_THROW(dvv1[0], std::logic_error); + EXPECT_THROW(dvv1.data(), std::logic_error); } TEST(MetaTraits, VectorBuilderHelper_true_true) { @@ -20,6 +21,8 @@ TEST(MetaTraits, VectorBuilderHelper_true_true) { var a_var(1); VectorBuilderHelper dvv1(length(a_var)); - dvv1[0] = 0.0; - EXPECT_FLOAT_EQ(0.0, dvv1[0]); + EXPECT_THROW(dvv1[0], + std::logic_error) + << "This uses the default template; if the arr version is included, " + << "it will use the template specialization."; }