Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
072813a
pass1
andrjohns Sep 17, 2026
d950473
Simplify and optimise
andrjohns Sep 17, 2026
fca878a
Reuse across cdfs, forwarding
andrjohns Sep 17, 2026
8569c47
Expand reuse
andrjohns Sep 17, 2026
bdb2b64
Delegate Phi, clean tests
andrjohns Sep 18, 2026
a997a65
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Sep 18, 2026
33217d0
Remove c++20 code
andrjohns Sep 18, 2026
a28c1c1
Fix finite-diff tol for extreme tail
andrjohns Sep 18, 2026
7fa96c9
Merge remote-tracking branch 'origin/develop' into normal-lcdf-opt
SteveBronder Sep 29, 2026
9a8deff
Refactor normal log-CDF dispatch and density expressions
SteveBronder Oct 9, 2026
d581f3b
Merge commit '43bc5684a395b7db8a38c286e2a6d3ee780a0ad9' into HEAD
yashikno Oct 9, 2026
5ebeed8
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Oct 9, 2026
644ef93
fix neg_binomial_2_lpmf.hpp for log1p
SteveBronder Oct 12, 2026
8620825
Merge remote-tracking branch 'refs/remotes/origin/normal-lcdf-opt' in…
SteveBronder Oct 12, 2026
8cff6fd
Fuse lpdf reductions and test vectorized edge cases
SteveBronder Oct 13, 2026
fed93f4
Fix test template call for normal_lccdf
SteveBronder Oct 13, 2026
7d0acec
Merge commit '2b96aee1cf7fd5114d0ddbbf75e4030ea19c44a3' into HEAD
yashikno Oct 13, 2026
7c783c3
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Oct 13, 2026
7e99d35
Remove unnecessary function template values from calls to functions
SteveBronder Oct 14, 2026
26256d4
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Oct 14, 2026
201dcab
Restore to_ref on lcdf inputs to cut expression test memory
SteveBronder Oct 15, 2026
f37ea7c
Evaluate std_normal lcdf input once
SteveBronder Oct 15, 2026
686fc67
use decltype(auto) as return type for
SteveBronder Oct 16, 2026
5f33a10
Reuse the erfcx helpers in std_normal_lcdf instead of duplicated Cody…
avehtari Oct 19, 2026
bf5861a
Compute Phi as 0.5 * erfc(-x / sqrt(2)) instead of exp(log Phi)
avehtari Oct 19, 2026
0d4ac36
Compute std_normal_cdf, normal_cdf and lognormal_cdf from erfc instea…
avehtari Oct 19, 2026
f4cd10e
Evaluate the standardized log argument once in lognormal_cdf and logn…
avehtari Oct 19, 2026
c30ee6f
Evaluate reused temporaries once in the normal, lognormal and exp_mod…
avehtari Oct 19, 2026
9b38ecb
Compute Phi and the normal cdfs from erfcx and exp instead of the C-l…
avehtari Oct 20, 2026
927099e
Evaluate z and score once in the autodiff path of skew_normal_lpdf
avehtari Oct 20, 2026
a17bba2
Compute exp_mod_normal lcdf, lccdf and cdf from erfcx differences
avehtari Oct 20, 2026
39886e0
Port the exp_mod_normal lcdf algorithm to OpenCL
avehtari Oct 20, 2026
243a4c0
Merge commit 'e4745c87ffe1b9361c50c63d9c63cf237462fdfa' into HEAD
yashikno Oct 20, 2026
e8bb9a0
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Oct 20, 2026
e1fea06
Speed up exp_mod_normal_cdf and the exp_mod_normal argument checks
SteveBronder Oct 20, 2026
cf177ef
Make the std_normal_lcdf array path one pass and shorten its division…
SteveBronder Oct 21, 2026
d081fff
Divide by sigma in normal_lcdf and lognormal_lcdf where 1 / sigma ove…
avehtari Oct 22, 2026
1f8b6ba
Keep exp_mod_normal cdf gradients finite in the deep lower tail
avehtari Oct 22, 2026
2015557
Skip the far upper tail work in std_normal_lcdf and vectorize exp in …
SteveBronder Oct 22, 2026
e076f6a
Divide by sigma for z in normal_lcdf and lognormal_lcdf
SteveBronder Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions stan/math/opencl/kernel_generator/elt_function_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stan/math/opencl/kernels/device_functions/beta.hpp>
#include <stan/math/opencl/kernels/device_functions/digamma.hpp>
#include <stan/math/opencl/kernels/device_functions/erfcx.hpp>
#include <stan/math/opencl/kernels/device_functions/exp_mod_normal_lcdf.hpp>
#include <stan/math/opencl/kernels/device_functions/inv_logit.hpp>
#include <stan/math/opencl/kernels/device_functions/inv_Phi.hpp>
#include <stan/math/opencl/kernels/device_functions/inv_square.hpp>
Expand Down Expand Up @@ -313,17 +314,19 @@ ADD_UNARY_FUNCTION_WITH_INCLUDES(inv_logit,
opencl_kernels::inv_logit_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(logit, opencl_kernels::log1m_device_function,
opencl_kernels::logit_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(Phi, opencl_kernels::phi_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(Phi, opencl_kernels::erfcx_device_function,
opencl_kernels::phi_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(Phi_approx,
opencl_kernels::inv_logit_device_function,
opencl_kernels::phi_approx_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(
std_normal_lcdf_scaled_impl,
std_normal_lcdf_impl, opencl_kernels::erfcx_device_function,
opencl_kernels::std_normal_lcdf_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(
std_normal_lcdf_dscaled_impl,
std_normal_lcdf_derivative, opencl_kernels::erfcx_device_function,
opencl_kernels::std_normal_lcdf_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(inv_Phi, opencl_kernels::log1m_device_function,
opencl_kernels::erfcx_device_function,
opencl_kernels::phi_device_function,
opencl_kernels::inv_phi_device_function)
ADD_UNARY_FUNCTION_WITH_INCLUDES(
Expand Down Expand Up @@ -355,6 +358,32 @@ ADD_BINARY_FUNCTION_WITH_INCLUDES(copysign)

ADD_BINARY_FUNCTION_WITH_INCLUDES(
erfcx_derivative, stan::math::opencl_kernels::erfcx_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lcdf_value,
stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lcdf_d_z, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lcdf_d_v, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lcdf_d_s, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lccdf_value,
stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lccdf_d_z, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lccdf_d_v, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
exp_mod_normal_lccdf_d_s, stan::math::opencl_kernels::erfcx_device_function,
stan::math::opencl_kernels::exp_mod_normal_lcdf_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
beta, stan::math::opencl_kernels::beta_device_function)
ADD_BINARY_FUNCTION_WITH_INCLUDES(
Expand Down
32 changes: 24 additions & 8 deletions stan/math/opencl/kernels/device_functions/Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@ static constexpr const char* phi_device_function
* @return Phi(x)
*/
inline double Phi(double x) {
if (x < -37.5) {
return 0;
} else if (x < -5.0) {
return 0.5 * erfc(-M_SQRT1_2 * x);
} else if (x > 8.25) {
return 1;
} else {
return 0.5 * (1.0 + erf(M_SQRT1_2 * x));
// erfcx_cody_middle and erfcx_cody_tail come from the erfcx
// device function, which the registration includes first.
const double u = M_SQRT1_2 * x;
const double a = fabs(u);
if (a < 0.46875) {
const double s = u * u;
const double num
= (((1.85777706184603153e-1 * s + 3.16112374387056560) * s
+ 1.13864154151050156e2)
* s
+ 3.77485237685302021e2)
* s
+ 3.20937758913846947e3;
const double den
= (((s + 2.36012909523441209e1) * s + 2.44024637934444173e2)
* s
+ 1.28261652607737228e3)
* s
+ 2.84423683343917062e3;
return 0.5 + 0.5 * (u * num / den);
}
const double tail
= 0.5 * exp(-(0.5 * x) * x)
* (a >= 4.0 ? erfcx_cody_tail(a) : erfcx_cody_middle(a));
return x < 0.0 ? tail : 1.0 - tail;
}
// \cond
) "\n#endif\n"; // NOLINT
Expand Down
Loading
Loading