Skip to content

Commit

Permalink
Merge pull request #2830 from stan-dev/fix/constexpr-constants
Browse files Browse the repository at this point in the history
set static const values to static constexpr
  • Loading branch information
andrjohns committed Feb 19, 2024
2 parents 8558ce8 + 44dd969 commit c12fff9
Show file tree
Hide file tree
Showing 408 changed files with 916 additions and 897 deletions.
2 changes: 1 addition & 1 deletion stan/math/opencl/double_d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ inline double_d mul_d_d(double a, double b) {
}

// \cond
static const char* double_d_src = STRINGIFY(
static constexpr const char* double_d_src = STRINGIFY(
// \endcond
typedef struct {
double high;
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernel_generator/colwise_reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class colwise_reduction
using Scalar = typename std::remove_reference_t<T>::Scalar;
using base = operation_cl<Derived, Scalar, T>;
using base::var_name_;
static const bool require_specific_local_size = true;
static constexpr bool require_specific_local_size = true;

protected:
std::string init_;
Expand Down
17 changes: 10 additions & 7 deletions stan/math/opencl/kernel_generator/multi_result_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct multi_result_kernel_internal {
next::check_assign_dimensions(n_rows, n_cols, assignment_pairs);
const auto& expression = std::get<N>(assignment_pairs).second;
const auto& result = std::get<N>(assignment_pairs).first;
const char* function = "results.operator=";
constexpr const char* function = "results.operator=";

int expression_rows = expression.rows();
int expression_cols = expression.cols();
Expand Down Expand Up @@ -437,8 +437,9 @@ class results_cl {
using impl = typename internal::multi_result_kernel_internal<
std::tuple_size<std::tuple<T_expressions...>>::value - 1,
T_res...>::template inner<T_expressions...>;
static const bool require_specific_local_size = std::max(
{std::decay_t<T_expressions>::Deriv::require_specific_local_size...});
static constexpr bool require_specific_local_size
= stan::math::disjunction<stan::bool_constant<std::decay_t<
T_expressions>::Deriv::require_specific_local_size>...>::value;

name_generator ng;
std::unordered_map<const void*, const char*> generated;
Expand Down Expand Up @@ -503,14 +504,16 @@ class results_cl {
std::tuple_size<std::tuple<T_expressions...>>::value - 1,
T_res...>::template inner<T_expressions...>;

static const bool any_output = std::max(
{false, !is_without_output<std::decay_t<T_expressions>>::value...});
static constexpr bool any_output
= stan::math::disjunction<stan::bool_constant<
!is_without_output<std::decay_t<T_expressions>>::value>...>::value;
if (!any_output) {
return;
}

static const bool require_specific_local_size = std::max(
{std::decay_t<T_expressions>::Deriv::require_specific_local_size...});
static constexpr bool require_specific_local_size
= stan::math::disjunction<stan::bool_constant<std::decay_t<
T_expressions>::Deriv::require_specific_local_size>...>::value;

int n_rows = std::get<0>(assignment_pairs).second.thread_rows();
int n_cols = std::get<0>(assignment_pairs).second.thread_cols();
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernel_generator/operation_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class operation_cl : public operation_cl_base {
static constexpr int N = sizeof...(Args);
using view_transitivity = std::tuple<std::is_same<Args, void>...>;
// value representing a not yet determined size
static const int dynamic = -1;
static constexpr int dynamic = -1;

/**
Returns an argument to this operation
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernel_generator/reduction_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class reduction_2d
using Scalar = typename std::remove_reference_t<T>::Scalar;
using base = operation_cl<Derived, Scalar, T>;
using base::var_name_;
static const bool require_specific_local_size = true;
static constexpr bool require_specific_local_size = true;

protected:
std::string init_;
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/add.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const std::string add_batch_kernel_code = STRINGIFY(
static constexpr const char *add_batch_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Sums a batch of matrices. Buffer A contains
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/batch_identity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string batch_identity_kernel_code = STRINGIFY(
static constexpr const char* batch_identity_kernel_code = STRINGIFY(
// \endcond

/** \ingroup opencl_kernels
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/categorical_logit_glm_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const std::string categorical_logit_glm_kernel_code = STRINGIFY(
static constexpr const char* categorical_logit_glm_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* GPU implementation of Generalized Linear Model (GLM)
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/check_symmetric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string is_symmetric_kernel_code = STRINGIFY(
static constexpr const char *is_symmetric_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Check if the <code>matrix_cl</code> is symmetric
Expand Down
4 changes: 2 additions & 2 deletions stan/math/opencl/kernels/cholesky_decompose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string cholesky_decompose_kernel_code = STRINGIFY(
static constexpr const char* cholesky_decompose_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Calculates the Cholesky Decomposition of a matrix on an OpenCL
Expand All @@ -30,7 +30,7 @@ static const std::string cholesky_decompose_kernel_code = STRINGIFY(
* This kernel uses the helper macros available in helpers.cl.
*
*/
__kernel void cholesky_decompose(__global double *A, int rows) {
__kernel void cholesky_decompose(__global double* A, int rows) {
const int local_index = get_local_id(0);
// The following code is the sequential version of the inplace
// cholesky decomposition. Only the innermost loops are parallelized. The
Expand Down
6 changes: 3 additions & 3 deletions stan/math/opencl/kernels/cumulative_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char *cumulative_sum1_kernel_code = STRINGIFY(
static constexpr const char *cumulative_sum1_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* First kernel of the cumulative sum implementation. Each thread sums the
Expand Down Expand Up @@ -62,7 +62,7 @@ static const char *cumulative_sum1_kernel_code = STRINGIFY(
// \endcond

// \cond
static const char *cumulative_sum2_kernel_code = STRINGIFY(
static constexpr const char *cumulative_sum2_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Second kernel of the cumulative sum implementation. Calculates prefix sum
Expand Down Expand Up @@ -116,7 +116,7 @@ static const char *cumulative_sum2_kernel_code = STRINGIFY(
// \endcond

// \cond
static const char *cumulative_sum3_kernel_code = STRINGIFY(
static constexpr const char *cumulative_sum3_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Third kernel of the cumulative sum implementation. Given sums of threads
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* phi_device_function
static constexpr const char* phi_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_PHI\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_PHI\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/Phi_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* phi_approx_device_function
static constexpr const char* phi_approx_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_PHI_APPROX\n"
"#define "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char *atomic_add_double_device_function
static constexpr const char *atomic_add_double_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_ATOMIC_ADD_DOUBLE\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_ATOMIC_ADD_DOUBLE\n"
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* beta_device_function
static constexpr const char* beta_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_BETA\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_BETA\n" STRINGIFY(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* binomial_coefficient_log_device_function
static constexpr const char* binomial_coefficient_log_device_function
= "\n"
"#ifndef "
"STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_BINOMIAL_COEFFICIENT_LOG\n"
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/digamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* digamma_device_function
static constexpr const char* digamma_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_DIGAMMA\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_DIGAMMA\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/inv_Phi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* inv_phi_device_function
static constexpr const char* inv_phi_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_INV_PHI\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_INV_PHI\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/inv_logit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* inv_logit_device_function
static constexpr const char* inv_logit_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_INV_LOGIT\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_INV_LOGIT\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/inv_square.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* inv_square_device_function
static constexpr const char* inv_square_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_INV_SQUARE\n"
"#define "
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/lbeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* lbeta_device_function
static constexpr const char* lbeta_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LBETA\n" STRINGIFY(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* lgamma_stirling_device_function
static constexpr const char* lgamma_stirling_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LGAMMA_STIRLING\n"
"#define "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* lgamma_stirling_diff_device_function
static constexpr const char* lgamma_stirling_diff_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LGAMMA_STIRLING_DIFF\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LGAMMA_STIRLING_DIFF\n"
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/lmultiply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* lmultiply_device_function
static constexpr const char* lmultiply_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LMULTIPLY\n"
"#define "
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/log1m.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log1m_device_function
static constexpr const char* log1m_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1M\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1M\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/log1m_exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log1m_exp_device_function
static constexpr const char* log1m_exp_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1M_EXP\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1M_EXP\n" STRINGIFY(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log1m_inv_logit_device_function
static constexpr const char* log1m_inv_logit_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1M_INV_LOGIT\n"
"#define "
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/log1p_exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log1p_exp_device_function
static constexpr const char* log1p_exp_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1P_EXP\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG1P_EXP\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/log_diff_exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log_diff_exp_device_function
static constexpr const char* log_diff_exp_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG_DIFF_EXP\n"
"#define "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log_inv_logit_device_function
static constexpr const char* log_inv_logit_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG_INV_LOGIT\n"
"#define "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* log_inv_logit_diff_device_function
static constexpr const char* log_inv_logit_diff_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOG_INV_LOGIT_DIFF\n"
"#define "
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/logit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* logit_device_function
static constexpr const char* logit_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOGIT\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_LOGIT\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/multiply_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace math {
namespace opencl_kernels {

// \cond
static const char* multiply_log_device_function
static constexpr const char* multiply_log_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_MULTIPLY_LOG\n"
"#define "
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/device_functions/trigamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const char* trigamma_device_function
static constexpr const char* trigamma_device_function
= "\n"
"#ifndef STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_TRIGAMMA\n"
"#define STAN_MATH_OPENCL_KERNELS_DEVICE_FUNCTIONS_TRIGAMMA\n" STRINGIFY(
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/diag_inv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string diag_inv_kernel_code = STRINGIFY(
static constexpr const char* diag_inv_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Calculates inplace submatrix inversions along the matrix diagonal.
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/divide_columns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string divide_columns_kernel_code = STRINGIFY(
static constexpr const char *divide_columns_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Takes vector A and divides columns vector in A element-wise by the values
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernels/fill_strict_tri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace stan {
namespace math {
namespace opencl_kernels {
// \cond
static const std::string fill_strict_tri_kernel_code = STRINGIFY(
static constexpr const char* fill_strict_tri_kernel_code = STRINGIFY(
// \endcond
/** \ingroup opencl_kernels
* Stores constant in the triangular part of a matrix
Expand Down
Loading

0 comments on commit c12fff9

Please sign in to comment.