Skip to content

Commit adbd8bc

Browse files
committed
get more non-grepl if constexpr sites
1 parent 67021e0 commit adbd8bc

34 files changed

Lines changed: 138 additions & 123 deletions

make/compiler_flags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)
162162
# Update compiler flags with operating system specific modifications
163163
##
164164
ifeq ($(OS),Windows_NT)
165-
CXXFLAGS_WARNINGS ?= -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes
165+
CXXFLAGS_WARNINGS ?= -Wall -Wno-template-id-cdtor -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes
166166
CPPFLAGS_GTEST ?= -DGTEST_HAS_PTHREAD=0
167167
CPPFLAGS_OS ?= -D_USE_MATH_DEFINES
168168
CPPFLAGS_OS += -D_GLIBCXX11_USE_C99_COMPLEX

stan/math/mix/functor/laplace_marginal_density.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ inline auto laplace_marginal_density(const LLFun& ll_fun, LLTupleArgs&& ll_args,
10751075
auto ll_args_filter = internal::filter_var_scalar_types(ll_args_copy);
10761076
stan::math::for_each(
10771077
[](auto&& output_i, auto&& ll_arg_i) {
1078-
if (is_any_var_scalar_v<decltype(ll_arg_i)>) {
1078+
if constexpr (is_any_var_scalar_v<decltype(ll_arg_i)>) {
10791079
internal::collect_adjoints<true>(output_i, ll_arg_i);
10801080
}
10811081
},

stan/math/opencl/kernel_generator/rowwise_reduction.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ struct max_op {
407407
return "max(" + a + ", " + b + ")";
408408
}
409409

410-
inline static std::string init() {
411-
if (std::is_floating_point<T>()) {
410+
inline static constexpr std::string init() {
411+
if constexpr (std::is_floating_point<T>()) {
412412
return "-INFINITY";
413413
}
414414
return "INT_MIN";

stan/math/opencl/mrrr.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ inline void mrrr_cl(const Eigen::Ref<const Eigen::VectorXd> diagonal,
310310
const Eigen::VectorXd subdiagonal_squared
311311
= subdiagonal.array() * subdiagonal.array();
312312
get_gresgorin(diagonal, subdiagonal, min_eigval, max_eigval);
313-
if (!need_eigenvectors) {
313+
if constexpr (!need_eigenvectors) {
314314
matrix_cl<double> diagonal_cl(diagonal);
315315
matrix_cl<double> subdiagonal_squared_cl(subdiagonal_squared);
316316
matrix_cl<double> eigenvalues_cl(n, 1);
@@ -458,7 +458,7 @@ inline void tridiagonal_eigensolver_cl(const matrix_cl<double>& diagonal_cl,
458458
using std::sqrt;
459459
const int n = diagonal_cl.rows();
460460
Eigen::MatrixXd eigenvectors;
461-
if (need_eigenvectors) {
461+
if constexpr (need_eigenvectors) {
462462
eigenvectors.resize(n, n);
463463
}
464464
Eigen::VectorXd eigenvalues(n);
@@ -502,7 +502,7 @@ inline void tridiagonal_eigensolver_cl(const matrix_cl<double>& diagonal_cl,
502502
}
503503
eigenvalues[last] = diagonal[last];
504504
} else {
505-
if (need_eigenvectors) {
505+
if constexpr (need_eigenvectors) {
506506
mrrr_cl<need_eigenvectors>(
507507
diagonal.segment(last, n - last),
508508
subdiagonal.segment(last, subdiagonal.size() - last),
@@ -516,7 +516,7 @@ inline void tridiagonal_eigensolver_cl(const matrix_cl<double>& diagonal_cl,
516516
}
517517
}
518518
eigenvalues_cl = to_matrix_cl(std::move(eigenvalues));
519-
if (need_eigenvectors) {
519+
if constexpr (need_eigenvectors) {
520520
eigenvectors_cl = to_matrix_cl(std::move(eigenvectors));
521521
}
522522
}

stan/math/opencl/prim/bernoulli_logit_glm_lpmf.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> bernoulli_logit_glm_lpmf(
6565
const size_t N = x.rows();
6666
const size_t M = x.cols();
6767

68-
if (is_y_vector) {
68+
if constexpr (is_y_vector) {
6969
check_size_match(function, "Rows of ", "x", N, "rows of ", "y",
7070
math::size(y));
7171
}
7272
check_size_match(function, "Columns of ", "x_cl", M, "size of ", "beta",
7373
math::size(beta));
74-
if (is_alpha_vector) {
74+
if constexpr (is_alpha_vector) {
7575
check_size_match(function, "Rows of ", "x", N, "size of ", "alpha",
7676
math::size(alpha));
7777
}
@@ -141,7 +141,7 @@ return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> bernoulli_logit_glm_lpmf(
141141
= transpose(beta_val * transpose(theta_derivative_cl));
142142
}
143143
if constexpr (is_autodiff_v<T_alpha_cl>) {
144-
if (is_alpha_vector) {
144+
if constexpr (is_alpha_vector) {
145145
partials<1>(ops_partials) = theta_derivative_cl;
146146
} else {
147147
forward_as<internal::broadcast_array<double>>(

stan/math/opencl/prim/bernoulli_lpmf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ return_type_t<T_prob_cl> bernoulli_lpmf(const T_n_cl& n,
5555
auto check_n_bounded = check_cl(function, "n", n, "in the interval [0, 1]");
5656
auto n_bounded_expr = 0 <= n && n <= 1;
5757

58-
if (is_theta_vector) {
58+
if constexpr (is_theta_vector) {
5959
auto logp_expr
6060
= colwise_sum(select(n == 1, log(theta_val), log1p(-theta_val)));
6161
auto deriv_expr = inv(theta_val + select(n == 1, 0, -1));

stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> binomial_logit_glm_lpmf(
108108
partials<0>(ops_partials) = transpose(beta_val * transpose(theta_deriv_cl));
109109
}
110110
if constexpr (is_autodiff_v<T_alpha_cl>) {
111-
if (is_alpha_vector) {
111+
if constexpr (is_alpha_vector) {
112112
partials<1>(ops_partials) = theta_deriv_cl;
113113
} else {
114114
forward_as<internal::broadcast_array<double>>(

stan/math/opencl/prim/categorical_logit_glm_lpmf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ return_type_t<T_x, T_alpha, T_beta> categorical_logit_glm_lpmf(
5959
const size_t N_classes = beta.cols();
6060

6161
static constexpr const char* function = "categorical_logit_glm_lpmf";
62-
if (is_y_vector) {
62+
if constexpr (is_y_vector) {
6363
check_size_match(function, "Rows of ", "x", N_instances, "size of ", "y",
6464
math::size(y));
6565
}
@@ -124,7 +124,7 @@ return_type_t<T_x, T_alpha, T_beta> categorical_logit_glm_lpmf(
124124

125125
auto ops_partials = make_partials_propagator(x, alpha, beta);
126126
if constexpr (is_autodiff_v<T_x>) {
127-
if (is_y_vector) {
127+
if constexpr (is_y_vector) {
128128
partials<0>(ops_partials)
129129
= indexing(beta_val, col_index(x.rows(), x.cols()),
130130
rowwise_broadcast(forward_as<matrix_cl<int>>(y_val) - 1))

stan/math/opencl/prim/neg_binomial_2_log_glm_lpmf.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ neg_binomial_2_log_glm_lpmf(const T_y_cl& y, const T_x_cl& x,
8181
const size_t N = x.rows();
8282
const size_t M = x.cols();
8383

84-
if (is_y_vector) {
84+
if constexpr (is_y_vector) {
8585
check_size_match(function, "Rows of ", "x", N, "rows of ", "y",
8686
math::size(y));
8787
}
8888
check_size_match(function, "Columns of ", "x", M, "size of ", "beta",
8989
math::size(beta));
90-
if (is_phi_vector) {
90+
if constexpr (is_phi_vector) {
9191
check_size_match(function, "Rows of ", "x", N, "size of ", "phi",
9292
math::size(phi));
9393
}
94-
if (is_alpha_vector) {
94+
if constexpr (is_alpha_vector) {
9595
check_size_match(function, "Rows of ", "x", N, "size of ", "alpha",
9696
math::size(alpha));
9797
}
9898
if (N == 0) {
9999
return 0;
100100
}
101-
if (!include_summand<propto, T_x_cl, T_alpha_cl, T_beta_cl,
101+
if constexpr (!include_summand<propto, T_x_cl, T_alpha_cl, T_beta_cl,
102102
T_phi_cl>::value) {
103103
return 0;
104104
}
@@ -200,7 +200,7 @@ neg_binomial_2_log_glm_lpmf(const T_y_cl& y, const T_x_cl& x,
200200
}
201201
}
202202
if constexpr (is_autodiff_v<T_alpha_cl>) {
203-
if (is_alpha_vector) {
203+
if constexpr (is_alpha_vector) {
204204
partials<1>(ops_partials) = std::move(theta_derivative_cl);
205205
} else {
206206
forward_as<internal::broadcast_array<double>>(
@@ -209,7 +209,7 @@ neg_binomial_2_log_glm_lpmf(const T_y_cl& y, const T_x_cl& x,
209209
}
210210
}
211211
if constexpr (is_autodiff_v<T_phi_cl>) {
212-
if (is_phi_vector) {
212+
if constexpr (is_phi_vector) {
213213
partials<3>(ops_partials) = std::move(phi_derivative_cl);
214214
} else {
215215
forward_as<internal::broadcast_array<double>>(

stan/math/opencl/prim/neg_binomial_2_log_lpmf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ neg_binomial_2_log_lpmf(const T_n_cl& n, const T_log_location_cl& eta,
5555
if (N == 0) {
5656
return 0.0;
5757
}
58-
if (!include_summand<propto, T_n_cl, T_log_location_cl,
58+
if constexpr (!include_summand<propto, T_n_cl, T_log_location_cl,
5959
T_precision_cl>::value) {
6060
return 0.0;
6161
}

0 commit comments

Comments
 (0)