Skip to content

Commit f627b37

Browse files
committed
Re-use computation
1 parent ffdc348 commit f627b37

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

stan/math/prim/prob/weibull_cdf.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ return_type_t<T_y, T_shape, T_scale> weibull_cdf(const T_y& y,
6969
constexpr bool any_derivs = !is_constant_all<T_y, T_shape, T_scale>::value;
7070
const auto& log_y = to_ref_if<any_derivs>(log(y_val));
7171
const auto& log_sigma = to_ref_if<any_derivs>(log(sigma_val));
72-
const auto& log_pow_n
73-
= to_ref_if<any_derivs>(alpha_val * log_y - alpha_val * log_sigma);
72+
const auto& log_y_div_sigma = to_ref_if<any_derivs>(log_y - log_sigma);
73+
const auto& log_pow_n = to_ref_if<any_derivs>(alpha_val * log_y_div_sigma);
7474
const auto& pow_n = to_ref_if<any_derivs>(exp(log_pow_n));
7575
const auto& log_cdf_n = to_ref_if<any_derivs>(log1m_exp(-pow_n));
7676

@@ -88,7 +88,7 @@ return_type_t<T_y, T_shape, T_scale> weibull_cdf(const T_y& y,
8888
}
8989
}
9090
if (!is_constant_all<T_shape>::value) {
91-
partials<1>(ops_partials) = exp(log_rep_deriv) * (log_y - log_sigma);
91+
partials<1>(ops_partials) = exp(log_rep_deriv) * log_y_div_sigma;
9292
}
9393
}
9494
return ops_partials.build(exp(log_cdf));

stan/math/prim/prob/weibull_lcdf.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ return_type_t<T_y, T_shape, T_scale> weibull_lcdf(const T_y& y,
6868
constexpr bool any_derivs = !is_constant_all<T_y, T_shape, T_scale>::value;
6969
const auto& log_y = to_ref_if<any_derivs>(log(y_val));
7070
const auto& log_sigma = to_ref_if<any_derivs>(log(sigma_val));
71-
const auto& log_pow_n
72-
= to_ref_if<any_derivs>(alpha_val * log_y - alpha_val * log_sigma);
71+
const auto& log_y_div_sigma = to_ref_if<any_derivs>(log_y - log_sigma);
72+
const auto& log_pow_n = to_ref_if<any_derivs>(alpha_val * log_y_div_sigma);
7373
const auto& pow_n = to_ref_if<any_derivs>(exp(log_pow_n));
7474

7575
if (any_derivs) {
@@ -85,7 +85,7 @@ return_type_t<T_y, T_shape, T_scale> weibull_lcdf(const T_y& y,
8585
}
8686
}
8787
if (!is_constant_all<T_shape>::value) {
88-
partials<1>(ops_partials) = exp(log_rep_deriv) * (log_y - log_sigma);
88+
partials<1>(ops_partials) = exp(log_rep_deriv) * log_y_div_sigma;
8989
}
9090
}
9191
return ops_partials.build(sum(log1m_exp(-pow_n)));

0 commit comments

Comments
 (0)