Skip to content

Commit

Permalink
Use ref_type instead of constant check
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Oct 4, 2024
1 parent b20dd5b commit 9e7af77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
24 changes: 12 additions & 12 deletions stan/math/prim/prob/wiener5_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ inline auto wiener_lpdf(const T_y& y, const T_a& a, const T_t0& t0,
if (!include_summand<propto, T_y, T_a, T_t0, T_w, T_v, T_sv>::value) {
return ret_t(0.0);
}
using T_y_ref = ref_type_if_t<!is_constant<T_y>::value, T_y>;
using T_a_ref = ref_type_if_t<!is_constant<T_a>::value, T_a>;
using T_t0_ref = ref_type_if_t<!is_constant<T_t0>::value, T_t0>;
using T_w_ref = ref_type_if_t<!is_constant<T_w>::value, T_w>;
using T_v_ref = ref_type_if_t<!is_constant<T_v>::value, T_v>;
using T_sv_ref = ref_type_if_t<!is_constant<T_sv>::value, T_sv>;
using T_y_ref = ref_type_t<T_y>;
using T_a_ref = ref_type_t<T_a>;
using T_t0_ref = ref_type_t<T_t0>;
using T_w_ref = ref_type_t<T_w>;
using T_v_ref = ref_type_t<T_v>;
using T_sv_ref = ref_type_t<T_sv>;

static constexpr const char* function_name = "wiener5_lpdf";

Expand Down Expand Up @@ -725,12 +725,12 @@ inline auto wiener_lpdf(const T_y& y, const T_a& a, const T_t0& t0,
return ret_t(0.0);
}

scalar_seq_view<decltype(y_val)> y_vec(y_val);
scalar_seq_view<decltype(a_val)> a_vec(a_val);
scalar_seq_view<decltype(v_val)> v_vec(v_val);
scalar_seq_view<decltype(w_val)> w_vec(w_val);
scalar_seq_view<decltype(t0_val)> t0_vec(t0_val);
scalar_seq_view<decltype(sv_val)> sv_vec(sv_val);
scalar_seq_view<T_y_ref> y_vec(y_ref);
scalar_seq_view<T_a_ref> a_vec(a_ref);
scalar_seq_view<T_t0_ref> t0_vec(t0_ref);
scalar_seq_view<T_w_ref> w_vec(w_ref);
scalar_seq_view<T_v_ref> v_vec(v_ref);
scalar_seq_view<T_sv_ref> sv_vec(sv_ref);
const size_t N_y_t0 = max_size(y, t0);

for (size_t i = 0; i < N_y_t0; ++i) {
Expand Down
35 changes: 19 additions & 16 deletions stan/math/prim/prob/wiener_full_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ inline auto wiener_lpdf(const T_y& y, const T_a& a, const T_t0& t0,
return ret_t(0);
}

using T_y_ref = ref_type_if_t<!is_constant<T_y>::value, T_y>;
using T_a_ref = ref_type_if_t<!is_constant<T_a>::value, T_a>;
using T_v_ref = ref_type_if_t<!is_constant<T_v>::value, T_v>;
using T_w_ref = ref_type_if_t<!is_constant<T_w>::value, T_w>;
using T_t0_ref = ref_type_if_t<!is_constant<T_t0>::value, T_t0>;
using T_sv_ref = ref_type_if_t<!is_constant<T_sv>::value, T_sv>;
using T_sw_ref = ref_type_if_t<!is_constant<T_sw>::value, T_sw>;
using T_st0_ref = ref_type_if_t<!is_constant<T_st0>::value, T_st0>;
using T_y_ref = ref_type_t<T_y>;
using T_a_ref = ref_type_t<T_a>;
using T_v_ref = ref_type_t<T_v>;
using T_w_ref = ref_type_t<T_w>;
using T_t0_ref = ref_type_t<T_t0>;
using T_sv_ref = ref_type_t<T_sv>;
using T_sw_ref = ref_type_t<T_sw>;
using T_st0_ref = ref_type_t<T_st0>;

using T_partials_return
= partials_return_t<T_y, T_a, T_t0, T_w, T_v, T_sv, T_sw, T_st0>;
Expand Down Expand Up @@ -385,14 +385,14 @@ inline auto wiener_lpdf(const T_y& y, const T_a& a, const T_t0& t0,
if (N == 0) {
return ret_t(0);
}
scalar_seq_view<decltype(y_val)> y_vec(y_val);
scalar_seq_view<decltype(a_val)> a_vec(a_val);
scalar_seq_view<decltype(v_val)> v_vec(v_val);
scalar_seq_view<decltype(w_val)> w_vec(w_val);
scalar_seq_view<decltype(t0_val)> t0_vec(t0_val);
scalar_seq_view<decltype(sv_val)> sv_vec(sv_val);
scalar_seq_view<decltype(sw_val)> sw_vec(sw_val);
scalar_seq_view<decltype(st0_val)> st0_vec(st0_val);
scalar_seq_view<T_y_ref> y_vec(y_ref);
scalar_seq_view<T_a_ref> a_vec(a_ref);
scalar_seq_view<T_v_ref> v_vec(v_ref);
scalar_seq_view<T_w_ref> w_vec(w_ref);
scalar_seq_view<T_t0_ref> t0_vec(t0_ref);
scalar_seq_view<T_sv_ref> sv_vec(sv_ref);
scalar_seq_view<T_sw_ref> sw_vec(sw_ref);
scalar_seq_view<T_st0_ref> st0_vec(st0_ref);
const size_t N_y_t0 = max_size(y, t0, st0);

for (size_t i = 0; i < N_y_t0; ++i) {
Expand Down Expand Up @@ -449,6 +449,9 @@ inline auto wiener_lpdf(const T_y& y, const T_a& a, const T_t0& t0,
// calculate density and partials
for (size_t i = 0; i < N; i++) {
if (sw_vec[i] == 0 && st0_vec[i] == 0) {
// note: because we're delegating to wiener5_lpdf,
// we need to make sure is_constant is consistent between
// our inputs and these
result += wiener_lpdf<propto>(y_vec[i], a_vec[i], t0_vec[i], w_vec[i],
v_vec[i], sv_vec[i], precision_derivatives);
continue;
Expand Down

0 comments on commit 9e7af77

Please sign in to comment.