Skip to content

Commit 0932271

Browse files
committed
Merge remote-tracking branch 'origin/5.0-breaking-changes' into move-constraint-transforms-to-separate-folder
2 parents e644962 + 5827e5b commit 0932271

303 files changed

Lines changed: 5369 additions & 6859 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doxygen/contributor_help_pages/distribution_tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Here, I'm just going to describe the steps that are taken to run the tests. Deta
2828

2929
1. `make generate-tests` is called.
3030
1. This first builds the `test/prob/generate_tests` executable from `test/prob/generate_tests.cpp`.
31-
2. For each test file inside `test/prob/*/*`, it will call the executable with the test file as the first argument and the number of template instantiations per file within the second argument. For example, for testing the `bernoulli_log()` function, make will call: `test/prob/generate_tests test/prob/bernoulli/bernoulli_test.hpp 100`
31+
2. For each test file inside `test/prob/*/*`, it will call the executable with the test file as the first argument and the number of template instantiations per file within the second argument. For example, for testing the `bernoulli_lpmf()` function, make will call: `test/prob/generate_tests test/prob/bernoulli/bernoulli_test.hpp 100`
3232
The call to the executable will generate 5 different test files, all within the `test/prob/bernoulli/` folder:
3333
- bernoulli\_00000\_generated\_fd\_test.cpp
3434
- bernoulli\_00000\_generated\_ffd\_test.cpp

doxygen/contributor_help_pages/require_meta.md

Lines changed: 427 additions & 116 deletions
Large diffs are not rendered by default.

stan/math/fwd/fun.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <stan/math/fwd/fun/gamma_p.hpp>
4242
#include <stan/math/fwd/fun/gamma_q.hpp>
4343
#include <stan/math/fwd/fun/grad_inc_beta.hpp>
44+
#include <stan/math/fwd/fun/hypergeometric_1F0.hpp>
4445
#include <stan/math/fwd/fun/hypergeometric_2F1.hpp>
4546
#include <stan/math/fwd/fun/hypergeometric_pFq.hpp>
4647
#include <stan/math/fwd/fun/hypot.hpp>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef STAN_MATH_FWD_FUN_HYPERGEOMETRIC_1F0_HPP
2+
#define STAN_MATH_FWD_FUN_HYPERGEOMETRIC_1F0_HPP
3+
4+
#include <stan/math/prim/meta.hpp>
5+
#include <stan/math/prim/fun/hypergeometric_1F0.hpp>
6+
#include <stan/math/fwd/core.hpp>
7+
8+
namespace stan {
9+
namespace math {
10+
11+
/**
12+
* Returns the Hypergeometric 1F0 function applied to the
13+
* input arguments:
14+
* \f$ _1F_0(a;;z) = \sum_{k=1}^{\infty}\frac{\left(a\right)_kz^k}{k!}\f$
15+
*
16+
* \f$ \frac{\partial _1F_0\left(a;;z\right)}{\partial a} =
17+
* -\left(1-z\right)^{-a}\log\left(1 - z\right) \f$
18+
*
19+
* \f$ \frac{\partial _1F_0\left(a;;z\right)}{\partial z} =
20+
* a\left(1-z\right)^{-a-1} \f$
21+
*
22+
* @tparam Ta Fvar or arithmetic type of 'a' argument
23+
* @tparam Tz Fvar or arithmetic type of 'z' argument
24+
* @param[in] a Scalar 'a' argument
25+
* @param[in] z Scalar z argument
26+
* @return Hypergeometric 1F0 function
27+
*/
28+
template <typename Ta, typename Tz, typename FvarT = return_type_t<Ta, Tz>,
29+
require_all_stan_scalar_t<Ta, Tz>* = nullptr,
30+
require_any_fvar_t<Ta, Tz>* = nullptr>
31+
FvarT hypergeometric_1f0(const Ta& a, const Tz& z) {
32+
partials_type_t<Ta> a_val = value_of(a);
33+
partials_type_t<Tz> z_val = value_of(z);
34+
FvarT rtn = FvarT(hypergeometric_1f0(a_val, z_val), 0.0);
35+
if (!is_constant_all<Ta>::value) {
36+
rtn.d_ += forward_as<FvarT>(a).d() * -rtn.val() * log1m(z_val);
37+
}
38+
if (!is_constant_all<Tz>::value) {
39+
rtn.d_ += forward_as<FvarT>(z).d() * rtn.val() * a_val * inv(1 - z_val);
40+
}
41+
return rtn;
42+
}
43+
44+
} // namespace math
45+
} // namespace stan
46+
#endif

stan/math/fwd/fun/hypergeometric_pFq.hpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,42 @@ namespace math {
2222
* @return Generalized hypergeometric function
2323
*/
2424
template <typename Ta, typename Tb, typename Tz,
25-
require_all_matrix_t<Ta, Tb>* = nullptr,
26-
require_return_type_t<is_fvar, Ta, Tb, Tz>* = nullptr>
27-
inline return_type_t<Ta, Tb, Tz> hypergeometric_pFq(const Ta& a, const Tb& b,
28-
const Tz& z) {
29-
using fvar_t = return_type_t<Ta, Tb, Tz>;
30-
ref_type_t<Ta> a_ref = a;
31-
ref_type_t<Tb> b_ref = b;
32-
auto grad_tuple = grad_pFq(a_ref, b_ref, z);
33-
34-
typename fvar_t::Scalar grad = 0;
35-
36-
if (!is_constant<Ta>::value) {
37-
grad += dot_product(forward_as<promote_scalar_t<fvar_t, Ta>>(a_ref).d(),
38-
std::get<0>(grad_tuple));
25+
typename FvarT = return_type_t<Ta, Tb, Tz>,
26+
bool grad_a = !is_constant<Ta>::value,
27+
bool grad_b = !is_constant<Tb>::value,
28+
bool grad_z = !is_constant<Tz>::value,
29+
require_all_vector_t<Ta, Tb>* = nullptr,
30+
require_fvar_t<FvarT>* = nullptr>
31+
inline FvarT hypergeometric_pFq(const Ta& a, const Tb& b, const Tz& z) {
32+
using PartialsT = partials_type_t<FvarT>;
33+
using ARefT = ref_type_t<Ta>;
34+
using BRefT = ref_type_t<Tb>;
35+
36+
ARefT a_ref = a;
37+
BRefT b_ref = b;
38+
auto&& a_val = value_of(a_ref);
39+
auto&& b_val = value_of(b_ref);
40+
auto&& z_val = value_of(z);
41+
PartialsT pfq_val = hypergeometric_pFq(a_val, b_val, z_val);
42+
auto grad_tuple
43+
= grad_pFq<grad_a, grad_b, grad_z>(pfq_val, a_val, b_val, z_val);
44+
45+
FvarT rtn = FvarT(pfq_val, 0.0);
46+
47+
if (grad_a) {
48+
rtn.d_ += dot_product(forward_as<promote_scalar_t<FvarT, ARefT>>(a_ref).d(),
49+
std::get<0>(grad_tuple));
3950
}
40-
if (!is_constant<Tb>::value) {
41-
grad += dot_product(forward_as<promote_scalar_t<fvar_t, Tb>>(b_ref).d(),
42-
std::get<1>(grad_tuple));
51+
if (grad_b) {
52+
rtn.d_ += dot_product(forward_as<promote_scalar_t<FvarT, BRefT>>(b_ref).d(),
53+
std::get<1>(grad_tuple));
4354
}
44-
if (!is_constant<Tz>::value) {
45-
grad += forward_as<promote_scalar_t<fvar_t, Tz>>(z).d_
46-
* std::get<2>(grad_tuple);
55+
if (grad_z) {
56+
rtn.d_ += forward_as<promote_scalar_t<FvarT, Tz>>(z).d_
57+
* std::get<2>(grad_tuple);
4758
}
4859

49-
return fvar_t(
50-
hypergeometric_pFq(value_of(a_ref), value_of(b_ref), value_of(z)), grad);
60+
return rtn;
5161
}
5262

5363
} // namespace math

stan/math/prim/fun.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#include <stan/math/prim/fun/grad_reg_inc_gamma.hpp>
123123
#include <stan/math/prim/fun/grad_reg_lower_inc_gamma.hpp>
124124
#include <stan/math/prim/fun/head.hpp>
125+
#include <stan/math/prim/fun/hypergeometric_1F0.hpp>
125126
#include <stan/math/prim/fun/hypergeometric_2F1.hpp>
126127
#include <stan/math/prim/fun/hypergeometric_2F2.hpp>
127128
#include <stan/math/prim/fun/hypergeometric_3F2.hpp>

0 commit comments

Comments
 (0)