@@ -71,7 +71,7 @@ constexpr const char*
7171 * the associated array will be zero.
7272 */
7373template <typename ScalarType, std::size_t N>
74- void expect_all_used_only_once (std::array<int , N>& arg_evals,
74+ inline void expect_all_used_only_once (std::array<int , N>& arg_evals,
7575 std::array<int , N>& size_of_arg) {
7676 for (int i = 0 ; i < N; ++i) {
7777 EXPECT_LE (arg_evals[i], size_of_arg[i])
@@ -105,7 +105,7 @@ void expect_all_used_only_once(std::array<int, N>& arg_evals,
105105 * @param arg A type derived from `Eigen::EigenBase`
106106 */
107107template <typename EigMat, stan::require_eigen_t <EigMat>* = nullptr >
108- auto make_expr (int & count, EigMat&& arg) {
108+ inline auto make_expr (int & count, EigMat&& arg) {
109109 return arg.unaryExpr (
110110 stan::test::counterOp<stan::scalar_type_t <EigMat>>(&count));
111111}
@@ -115,7 +115,7 @@ auto make_expr(int& count, EigMat&& arg) {
115115 * @tparam Any type not derived from `Eigen::EigenBase`
116116 */
117117template <typename T, stan::require_not_eigen_t <T>* = nullptr >
118- auto make_expr (int & /* count */ , T&& arg) {
118+ inline constexpr auto make_expr (int & /* count */ , T&& arg) {
119119 return arg;
120120}
121121
@@ -129,7 +129,7 @@ auto make_expr(int& /* count */, T&& arg) {
129129 * `counterOp`.
130130 */
131131template <std::size_t N, typename ... Args>
132- auto make_expr_args (std::array<int , N>& expr_evals, Args&&... args) {
132+ inline constexpr auto make_expr_args (std::array<int , N>& expr_evals, Args&&... args) {
133133 return stan::math::index_apply<N>([&expr_evals, &args...](auto ... Is) {
134134 return std::make_tuple (make_expr (expr_evals[Is], args)...);
135135 });
@@ -148,7 +148,7 @@ inline constexpr int eigen_size(T&& x) {
148148 * @tparam EigMat A type derived from `Eigen::EigenBase`
149149 */
150150template <typename EigMat, stan::require_eigen_t <EigMat>* = nullptr >
151- inline int eigen_size (EigMat&& x) {
151+ inline constexpr Eigen::Index eigen_size (EigMat&& x) {
152152 return x.size ();
153153}
154154
@@ -161,7 +161,7 @@ inline int eigen_size(EigMat&& x) {
161161 * an Eigen type then the value is be zero.
162162 */
163163template <typename ... Args>
164- std::array<int , sizeof ...(Args)> eigen_arg_sizes (Args&&... args) {
164+ inline constexpr std::array<int , sizeof ...(Args)> eigen_arg_sizes (Args&&... args) {
165165 return std::array<int , sizeof ...(Args)>{eigen_size (args)...};
166166}
167167
@@ -170,7 +170,7 @@ std::array<int, sizeof...(Args)> eigen_arg_sizes(Args&&... args) {
170170 */
171171template <typename ScalarType, typename F, typename ... Args,
172172 require_all_not_eigen_t <Args...>* = nullptr >
173- void check_expr_test (F&& f, Args&&... args) {}
173+ inline constexpr void check_expr_test (F&& f, Args&&... args) {}
174174
175175/* *
176176 * Check whether any Eigen inputs are executed too many times.
@@ -200,7 +200,7 @@ void check_expr_test(F&& f, Args&&... args) {}
200200 */
201201template <typename ScalarType, typename F, typename ... Args,
202202 require_any_eigen_t <Args...>* = nullptr >
203- void check_expr_test (F&& f, Args&&... args) {
203+ inline void check_expr_test (F&& f, Args&&... args) {
204204 std::array<int , sizeof ...(args)> expr_eval_counts;
205205 for (int i = 0 ; i < sizeof ...(args); ++i) {
206206 expr_eval_counts[i] = 0 ;
@@ -219,7 +219,7 @@ void check_expr_test(F&& f, Args&&... args) {
219219 [&f](auto &&... args) { return f (std::forward<decltype (args)>(args)...); },
220220 expr_args));
221221 expect_all_used_only_once<ScalarType>(expr_eval_counts, size_of_eigen_args);
222- if (stan::is_var<ScalarType>::value) {
222+ if constexpr (stan::is_var<ScalarType>::value) {
223223 stan::math::recover_memory ();
224224 }
225225}
@@ -233,10 +233,10 @@ void check_expr_test(F&& f, Args&&... args) {
233233 * @param f functor whose `operator()` will be called.
234234 * @param args pack of arguments to pass to the functor.
235235 */
236- template <typename F, typename ... Args,
236+ template <bool ReverseOnly = false , typename F, typename ... Args,
237237 require_all_st_stan_scalar<Args...>* = nullptr ,
238238 require_all_not_st_complex<Args...>* = nullptr >
239- void check_expr_test (F&& f, Args&&... args) {
239+ inline void check_expr_test (F&& f, Args&&... args) {
240240 try {
241241 stan::test::internal::check_expr_test<double >(f, args...);
242242 try {
@@ -245,12 +245,14 @@ void check_expr_test(F&& f, Args&&... args) {
245245 } catch (const std::exception& e) {
246246 stan::math::recover_memory ();
247247 }
248- stan::test::internal::check_expr_test<stan::math::fvar<double >>(f, args...);
248+ if constexpr (!ReverseOnly) {
249+ stan::test::internal::check_expr_test<stan::math::fvar<double >>(f, args...);
250+ }
249251 } catch (const std::exception& e) {
250252 }
251253}
252254
253- template <typename F, typename ... Args,
255+ template <bool ReverseOnly = false , typename F, typename ... Args,
254256 require_any_st_complex<Args...>* = nullptr >
255257void check_expr_test (F&& f, Args&&... args) {
256258 try {
@@ -262,8 +264,10 @@ void check_expr_test(F&& f, Args&&... args) {
262264 } catch (const std::exception& e) {
263265 stan::math::recover_memory ();
264266 }
265- stan::test::internal::check_expr_test<
266- std::complex <stan::math::fvar<double >>>(f, args...);
267+ if constexpr (!ReverseOnly) {
268+ stan::test::internal::check_expr_test<
269+ std::complex <stan::math::fvar<double >>>(f, args...);
270+ }
267271 } catch (const std::exception& e) {
268272 }
269273}
0 commit comments