Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions stan/math/prim/functor/apply_scalar_binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ template <typename F, typename T1, typename T2,
inline auto apply_scalar_binary(F&& f, T1&& x, T2&& y) {
decltype(auto) x_vec = as_column_vector_or_scalar(std::forward<T1>(x));
using T_return = std::decay_t<decltype(f(x[0], y))>;
std::vector<T_return> result(x.size());
std::vector<T_return> result(x_vec.size());
Eigen::Map<Eigen::Matrix<T_return, -1, 1>>(result.data(), result.size())
= x_vec.unaryExpr(
[f_ = std::forward<F>(f), y](auto&& v) { return f_(v, y); });
Expand Down Expand Up @@ -335,9 +335,9 @@ template <typename F, typename T1, typename T2,
require_stan_scalar_t<T1>* = nullptr,
require_std_vector_vt<is_stan_scalar, T2>* = nullptr>
inline auto apply_scalar_binary(F&& f, T1&& x, T2&& y) {
decltype(auto) y_vec = as_column_vector_or_scalar(y);
using T_return = std::decay_t<decltype(f(x, y[0]))>;
std::vector<T_return> result(y.size());
decltype(auto) y_vec = as_column_vector_or_scalar(std::forward<T2>(y));
std::vector<T_return> result(y_vec.size());
Eigen::Map<Eigen::Matrix<T_return, -1, 1>>(result.data(), result.size())
= y_vec.unaryExpr(
[f_ = std::forward<F>(f), x](auto&& v) { return f_(x, v); });
Expand Down
19 changes: 19 additions & 0 deletions test/unit/math/prim/fun/log_modified_bessel_first_kind_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,22 @@ TEST(MathFunctions, log_modified_bessel_first_kind_vec) {
in2 << 7.3, 0.7, 2.8;
stan::test::binary_scalar_tester(f, in1, in2);
}

TEST(MathFunctions, log_modified_bessel_first_kind_aki_regression) {
// https://github.com/stan-dev/cmdstan/issues/1324#issuecomment-3206462728

using stan::math::log_modified_bessel_first_kind;
double rho = 0.5;
double alpha = 2.0;
int M = 20;

double a = (1 / stan::math::pow(rho, 2));
Eigen::Matrix<double, -1, 1> q = stan::math::exp(stan::math::add(
stan::math::log(alpha),
stan::math::multiply(
0.5,
stan::math::add(
(stan::math::log(2) - a),
stan::math::to_vector(stan::math::log_modified_bessel_first_kind(
stan::math::linspaced_int_array(M, 1, M), a))))));
}
Loading