Skip to content

Commit e92490c

Browse files
committed
More template and expression test tweaks
1 parent 977f96e commit e92490c

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

stan/math/prim/constraint/offset_multiplier_constrain.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stan/math/prim/fun/size.hpp>
1010
#include <stan/math/prim/fun/sum.hpp>
1111
#include <stan/math/prim/fun/to_ref.hpp>
12+
#include <stan/math/prim/fun/eval.hpp>
1213
#include <stan/math/prim/functor/apply.hpp>
1314
#include <cmath>
1415

@@ -58,7 +59,7 @@ inline auto offset_multiplier_constrain(const T& x, const M& mu,
5859
check_finite("offset_multiplier_constrain", "offset", value_of_rec(mu_ref));
5960
check_positive_finite("offset_multiplier_constrain", "multiplier",
6061
value_of_rec(sigma_ref));
61-
return fma(sigma_ref, x, mu_ref);
62+
return stan::math::eval(fma(sigma_ref, x, mu_ref));
6263
}
6364

6465
/**
@@ -114,7 +115,7 @@ inline auto offset_multiplier_constrain(const T& x, const M& mu, const S& sigma,
114115
} else {
115116
lp += sum(log(sigma_ref));
116117
}
117-
return fma(sigma_ref, x, mu_ref);
118+
return stan::math::eval(fma(sigma_ref, x, mu_ref));
118119
}
119120

120121
/**

stan/math/prim/constraint/offset_multiplier_free.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/constraint/identity_free.hpp>
77
#include <stan/math/prim/fun/to_ref.hpp>
8+
#include <stan/math/prim/fun/eval.hpp>
89
#include <stan/math/prim/fun/value_of.hpp>
910
#include <cmath>
1011

@@ -55,7 +56,7 @@ inline auto offset_multiplier_free(const T& y, const M& mu, const S& sigma) {
5556
check_finite("offset_multiplier_constrain", "offset", value_of(mu_ref));
5657
check_positive_finite("offset_multiplier_constrain", "multiplier",
5758
value_of(sigma_ref));
58-
return divide(subtract(y, mu_ref), sigma_ref);
59+
return stan::math::eval(divide(subtract(y, mu_ref), sigma_ref));
5960
}
6061

6162
/**

stan/math/prim/fun/read_corr_L.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic> read_corr_L(
8989
*
9090
* @tparam T type of the array (must be derived from \c Eigen::ArrayBase and
9191
* have one compile-time dimension equal to 1)
92+
* @tparam Lp A scalar type for the lp argument. The scalar type of T should be
93+
* convertable to this.
9294
* @param CPCs The (K choose 2) canonical partial correlations in
9395
* (-1, 1).
9496
* @param K Dimensionality of correlation matrix.
@@ -97,9 +99,10 @@ Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic> read_corr_L(
9799
* @return Cholesky factor of correlation matrix for specified
98100
* partial correlations.
99101
*/
100-
template <typename T, require_eigen_vector_t<T>* = nullptr>
102+
template <typename T, typename Lp, require_eigen_vector_t<T>* = nullptr,
103+
require_convertible_t<value_type_t<T>, Lp>* = nullptr>
101104
Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic> read_corr_L(
102-
const T& CPCs, size_t K, value_type_t<T>& log_prob) {
105+
const T& CPCs, size_t K, Lp& log_prob) {
103106
using T_scalar = value_type_t<T>;
104107
if (K == 0) {
105108
return {};

stan/math/prim/fun/read_corr_matrix.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ read_corr_matrix(const T_CPCs& CPCs, size_t K) {
4444
*
4545
* @tparam T_CPCs type of the array (must be derived from \c Eigen::ArrayBase
4646
* and have one compile-time dimension equal to 1)
47+
* @tparam Lp A scalar type for the lp argument. The scalar type of T_CPCs should be
48+
* convertable to this.
4749
* @param CPCs The (K choose 2) canonical partial correlations in
4850
* (-1, 1).
4951
* @param K Dimensionality of correlation matrix.
5052
* @param log_prob Reference to variable to increment with the log
5153
* Jacobian determinant.
5254
* @return Correlation matrix for specified partial correlations.
5355
*/
54-
template <typename T_CPCs, require_eigen_vector_t<T_CPCs>* = nullptr>
56+
template <typename T_CPCs, typename Lp,
57+
require_eigen_vector_t<T_CPCs>* = nullptr,
58+
require_convertible_t<value_type_t<T_CPCs>, Lp>* = nullptr>
5559
Eigen::Matrix<value_type_t<T_CPCs>, Eigen::Dynamic, Eigen::Dynamic>
56-
read_corr_matrix(const T_CPCs& CPCs, size_t K, value_type_t<T_CPCs>& log_prob) {
60+
read_corr_matrix(const T_CPCs& CPCs, size_t K, Lp& log_prob) {
5761
if (K == 0) {
5862
return {};
5963
}

test/sig_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def get_cpp_type(stan_type):
9191
"lkj_corr_lpdf": [1, None],
9292
"log_diff_exp": [3, None],
9393
"log_inv_logit_diff": [1.2, 0.4],
94+
"lub_free": [0.5, 0.1, 0.9],
9495
"mdivide_left_spd": [pos_definite, None],
9596
"multinomial_lpmf": [None, simplex],
9697
"multinomial_rng": [simplex, None, None],
@@ -116,6 +117,7 @@ def get_cpp_type(stan_type):
116117
"positive_ordered_free": [1.0],
117118
"ordered_constrain": [None, scalar_return_type],
118119
"ordered_free": [1.0],
120+
"offset_multiplier_free": [10, None, None],
119121
"simplex_constrain": [None, scalar_return_type],
120122
"simplex_free": [simplex],
121123
"std_normal_log_qf": [-0.1],

0 commit comments

Comments
 (0)