Skip to content

Commit 8b8871c

Browse files
committed
Merge branch 'develop' of github.com:stan-dev/math into develop
2 parents 051ec0b + 83b3731 commit 8b8871c

34 files changed

+1746
-541
lines changed

make/compiler_flags

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ ifdef STAN_OPENCL
219219
CPPFLAGS_OPENCL += -DCL_HPP_TARGET_OPENCL_VERSION=120 -DCL_HPP_MINIMUM_OPENCL_VERSION=120
220220
CPPFLAGS_OPENCL += -DCL_HPP_ENABLE_EXCEPTIONS -Wno-ignored-attributes
221221
CXXFLAGS_OPENCL ?= -I $(OPENCL)
222+
223+
ifdef INTEGRATED_OPENCL
224+
CPPFLAGS_OPENCL += -DINTEGRATED_OPENCL=1
225+
else
226+
CPPFLAGS_OPENCL += -DINTEGRATED_OPENCL=0
227+
endif
222228
endif
223229

224230
################################################################################

stan/math/fwd/fun.hpp

+1
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_2F1.hpp>
4445
#include <stan/math/fwd/fun/hypergeometric_pFq.hpp>
4546
#include <stan/math/fwd/fun/hypot.hpp>
4647
#include <stan/math/fwd/fun/inc_beta.hpp>

stan/math/fwd/fun/grad_inc_beta.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ void grad_inc_beta(fvar<T>& g1, fvar<T>& g2, fvar<T> a, fvar<T> b, fvar<T> z) {
4141
fvar<T> dF1 = 0;
4242
fvar<T> dF2 = 0;
4343
fvar<T> dF3 = 0;
44+
fvar<T> dFz = 0;
4445

45-
if (value_of(value_of(C))) {
46-
grad_2F1(dF1, dF2, dF3, a + b, fvar<T>(1.0), a + 1, z);
46+
if (value_of_rec(C)) {
47+
std::forward_as_tuple(dF1, dF2, dF3, dFz)
48+
= grad_2F1<true>(a + b, fvar<T>(1.0), a + 1, z);
4749
}
4850

4951
g1 = (c1 - 1.0 / a) * c3 + C * (dF1 + dF3);
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef STAN_MATH_FWD_FUN_HYPERGEOMETRIC_2F1_HPP
2+
#define STAN_MATH_FWD_FUN_HYPERGEOMETRIC_2F1_HPP
3+
4+
#include <stan/math/prim/meta.hpp>
5+
#include <stan/math/fwd/core.hpp>
6+
#include <stan/math/prim/fun/hypergeometric_2F1.hpp>
7+
#include <stan/math/prim/fun/grad_2F1.hpp>
8+
9+
namespace stan {
10+
namespace math {
11+
12+
/**
13+
* Returns the Gauss hypergeometric function applied to the
14+
* input arguments:
15+
* \f$_2F_1(a_1,a_2;b;z)\f$
16+
*
17+
* See 'grad_2F1.hpp' for the derivatives wrt each parameter
18+
*
19+
* @tparam Ta1 Type of scalar first 'a' argument
20+
* @tparam Ta2 Type of scalar second 'a' argument
21+
* @tparam Tb Type of scalar 'b' argument
22+
* @tparam Tz Type of scalar 'z' argument
23+
* @param[in] a1 First of 'a' arguments to function
24+
* @param[in] a2 Second of 'a' arguments to function
25+
* @param[in] b 'b' argument to function
26+
* @param[in] z Scalar z argument
27+
* @return Gauss hypergeometric function
28+
*/
29+
template <typename Ta1, typename Ta2, typename Tb, typename Tz,
30+
require_all_stan_scalar_t<Ta1, Ta2, Tb, Tz>* = nullptr,
31+
require_any_fvar_t<Ta1, Ta2, Tb, Tz>* = nullptr>
32+
inline return_type_t<Ta1, Ta1, Tb, Tz> hypergeometric_2F1(const Ta1& a1,
33+
const Ta2& a2,
34+
const Tb& b,
35+
const Tz& z) {
36+
using fvar_t = return_type_t<Ta1, Ta1, Tb, Tz>;
37+
38+
auto a1_val = value_of(a1);
39+
auto a2_val = value_of(a2);
40+
auto b_val = value_of(b);
41+
auto z_val = value_of(z);
42+
43+
auto grad_tuple = grad_2F1(a1, a2, b, z);
44+
45+
typename fvar_t::Scalar grad = 0;
46+
47+
if (!is_constant<Ta1>::value) {
48+
grad += forward_as<fvar_t>(a1).d() * std::get<0>(grad_tuple);
49+
}
50+
if (!is_constant<Ta2>::value) {
51+
grad += forward_as<fvar_t>(a2).d() * std::get<1>(grad_tuple);
52+
}
53+
if (!is_constant<Tb>::value) {
54+
grad += forward_as<fvar_t>(b).d() * std::get<2>(grad_tuple);
55+
}
56+
if (!is_constant<Tz>::value) {
57+
grad += forward_as<fvar_t>(z).d() * std::get<3>(grad_tuple);
58+
}
59+
60+
return fvar_t(hypergeometric_2F1(a1_val, a2_val, b_val, z_val), grad);
61+
}
62+
63+
} // namespace math
64+
} // namespace stan
65+
#endif

stan/math/opencl/matrix_cl.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,11 @@ class matrix_cl : public matrix_cl_base {
545545
cl::CommandQueue& queue = opencl_context.queue();
546546
try {
547547
if (opencl_context.device()[0].getInfo<CL_DEVICE_HOST_UNIFIED_MEMORY>()) {
548+
constexpr auto copy_or_share
549+
= CL_MEM_COPY_HOST_PTR * INTEGRATED_OPENCL
550+
| (CL_MEM_USE_HOST_PTR * !INTEGRATED_OPENCL);
548551
buffer_cl_
549-
= cl::Buffer(ctx, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
552+
= cl::Buffer(ctx, CL_MEM_READ_WRITE | copy_or_share,
550553
sizeof(T) * size(), A); // this is always synchronous
551554
} else {
552555
buffer_cl_ = cl::Buffer(ctx, CL_MEM_READ_WRITE, sizeof(T) * size());

stan/math/prim/fun.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@
129129
#include <stan/math/prim/fun/grad_reg_inc_gamma.hpp>
130130
#include <stan/math/prim/fun/grad_reg_lower_inc_gamma.hpp>
131131
#include <stan/math/prim/fun/head.hpp>
132-
#include <stan/math/prim/fun/hypergeometric_pFq.hpp>
132+
#include <stan/math/prim/fun/hypergeometric_2F1.hpp>
133133
#include <stan/math/prim/fun/hypergeometric_2F2.hpp>
134+
#include <stan/math/prim/fun/hypergeometric_pFq.hpp>
134135
#include <stan/math/prim/fun/hypot.hpp>
135136
#include <stan/math/prim/fun/identity_constrain.hpp>
136137
#include <stan/math/prim/fun/identity_free.hpp>

stan/math/prim/fun/fft.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ inline Eigen::Matrix<scalar_type_t<V>, -1, 1> inv_fft(const V& y) {
8282
* @param[in] x matrix to transform
8383
* @return discrete 2D Fourier transform of `x`
8484
*/
85-
template <typename M, require_eigen_dense_dynamic_vt<is_complex, M>* = nullptr>
85+
template <typename M, require_eigen_dense_dynamic_vt<is_complex, M>* = nullptr,
86+
require_not_var_t<base_type_t<value_type_t<M>>>* = nullptr>
8687
inline Eigen::Matrix<scalar_type_t<M>, -1, -1> fft2(const M& x) {
8788
Eigen::Matrix<scalar_type_t<M>, -1, -1> y(x.rows(), x.cols());
8889
for (int i = 0; i < y.rows(); ++i)
@@ -103,7 +104,8 @@ inline Eigen::Matrix<scalar_type_t<M>, -1, -1> fft2(const M& x) {
103104
* @param[in] y matrix to inverse trnasform
104105
* @return inverse discrete 2D Fourier transform of `y`
105106
*/
106-
template <typename M, require_eigen_dense_dynamic_vt<is_complex, M>* = nullptr>
107+
template <typename M, require_eigen_dense_dynamic_vt<is_complex, M>* = nullptr,
108+
require_not_var_t<base_type_t<value_type_t<M>>>* = nullptr>
107109
inline Eigen::Matrix<scalar_type_t<M>, -1, -1> inv_fft2(const M& y) {
108110
Eigen::Matrix<scalar_type_t<M>, -1, -1> x(y.rows(), y.cols());
109111
for (int j = 0; j < x.cols(); ++j)

0 commit comments

Comments
 (0)