Skip to content

Commit 3962c69

Browse files
committed
Merge branch 'kg_cast' of https://github.com/bstatcomp/math into kg_cast
2 parents 1722825 + a3cdcd8 commit 3962c69

19 files changed

+23
-35
lines changed

stan/math/opencl/kernel_generator/cast.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ inline auto cast(T&& a) {
8989
* @param a input argument
9090
* @return Typecast of given expression
9191
*/
92-
template <typename Scalar, typename T,
93-
require_stan_scalar_t<T>* = nullptr>
92+
template <typename Scalar, typename T, require_stan_scalar_t<T>* = nullptr>
9493
inline Scalar cast(T a) {
9594
return a;
9695
}

stan/math/opencl/prim/cauchy_cdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl> cauchy_cdf(
6363
= check_cl(function, "Scale parameter", sigma_val, "positive finite");
6464
auto sigma_positive_finite_expr = 0 < sigma_val && isfinite(sigma_val);
6565

66-
auto any_y_neg_inf
67-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
66+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
6867
auto cond = y_val == INFTY;
6968
auto sigma_inv = elt_divide(1.0, sigma_val);
7069
auto z = elt_multiply(y_val - mu_val, sigma_inv);

stan/math/opencl/prim/exp_mod_normal_cdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl> exp_mod_normal_cdf(
7272
= check_cl(function, "Inv_cale parameter", lambda_val, "positive finite");
7373
auto lambda_positive_finite_expr = 0 < lambda_val && isfinite(lambda_val);
7474

75-
auto any_y_neg_inf
76-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
75+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
7776
auto inv_sigma = elt_divide(1.0, sigma_val);
7877
auto diff = y_val - mu_val;
7978
auto v = elt_multiply(lambda_val, sigma_val);

stan/math/opencl/prim/exp_mod_normal_lccdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ exp_mod_normal_lccdf(const T_y_cl& y, const T_loc_cl& mu,
7373
= check_cl(function, "Inv_cale parameter", lambda_val, "positive finite");
7474
auto lambda_positive_finite_expr = 0 < lambda_val && isfinite(lambda_val);
7575

76-
auto any_y_neg_inf
77-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
76+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
7877
auto any_y_pos_inf = colwise_max(cast<char>(y_val == INFTY));
7978
auto inv_sigma = elt_divide(1.0, sigma_val);
8079
auto diff = y_val - mu_val;

stan/math/opencl/prim/exp_mod_normal_lcdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl, T_inv_scale_cl> exp_mod_normal_lcdf(
7373
= check_cl(function, "Inv_cale parameter", lambda_val, "positive finite");
7474
auto lambda_positive_finite_expr = 0 < lambda_val && isfinite(lambda_val);
7575

76-
auto any_y_neg_inf
77-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
76+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
7877
auto any_y_pos_inf = colwise_max(cast<char>(y_val == INFTY));
7978
auto sigma_inv = elt_divide(1.0, sigma_val);
8079
auto diff = y_val - mu_val;

stan/math/opencl/prim/logistic_cdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl> logistic_cdf(
6363
= check_cl(function, "Scale parameter", sigma_val, "positive finite");
6464
auto sigma_positive_finite_expr = 0 < sigma_val && isfinite(sigma_val);
6565

66-
auto any_y_neg_inf
67-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
66+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
6867
auto cond = y_val == INFTY;
6968
auto inv_sigma = elt_divide(1.0, sigma_val);
7069
auto mu_minus_y_div_sigma = elt_multiply(mu_val - y_val, inv_sigma);

stan/math/opencl/prim/logistic_lccdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl> logistic_lccdf(
6363
= check_cl(function, "Scale parameter", sigma_val, "positive finite");
6464
auto sigma_positive_finite_expr = 0 < sigma_val && isfinite(sigma_val);
6565

66-
auto any_y_neg_inf
67-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
66+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
6867
auto any_y_pos_inf = colwise_max(cast<char>(y_val == INFTY));
6968
auto inv_sigma = elt_divide(1.0, sigma_val);
7069
auto mu_minus_y_div_sigma = elt_multiply(mu_val - y_val, inv_sigma);

stan/math/opencl/prim/logistic_lcdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_loc_cl, T_scale_cl> logistic_lcdf(
6363
= check_cl(function, "Scale parameter", sigma_val, "positive finite");
6464
auto sigma_positive_finite_expr = 0 < sigma_val && isfinite(sigma_val);
6565

66-
auto any_y_neg_inf
67-
= colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
66+
auto any_y_neg_inf = colwise_max(cast<char>(y_val == NEGATIVE_INFTY));
6867
auto cond = y_val == INFTY;
6968
auto inv_sigma = elt_divide(1.0, sigma_val);
7069
auto mu_minus_y_div_sigma = elt_multiply(mu_val - y_val, inv_sigma);

stan/math/opencl/prim/pareto_cdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ return_type_t<T_y_cl, T_scale_cl, T_shape_cl> pareto_cdf(
6262
= check_cl(function, "Shape parameter", alpha_val, "positive finite");
6363
auto alpha_positive_finite_expr = 0 < alpha_val && isfinite(alpha_val);
6464

65-
auto any_y_lower_than_y_min
66-
= colwise_max(cast<char>(y_val < y_min_val));
65+
auto any_y_lower_than_y_min = colwise_max(cast<char>(y_val < y_min_val));
6766
auto cond = y_val == INFTY;
6867
auto log_dbl = log(elt_divide(y_min_val, y_val));
6968
auto y_min_inv = elt_divide(1.0, y_min_val);

stan/math/opencl/prim/pareto_lccdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_scale_cl, T_shape_cl> pareto_lccdf(
6363
= check_cl(function, "Shape parameter", alpha_val, "positive finite");
6464
auto alpha_positive_finite_expr = 0 < alpha_val && isfinite(alpha_val);
6565

66-
auto any_y_lower_than_y_min
67-
= colwise_max(cast<char>(y_val < y_min_val));
66+
auto any_y_lower_than_y_min = colwise_max(cast<char>(y_val < y_min_val));
6867
auto any_y_inf = colwise_max(cast<char>(isinf(y_val)));
6968

7069
auto log_quot = log(elt_divide(y_min_val, y_val));

stan/math/opencl/prim/pareto_lcdf.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ return_type_t<T_y_cl, T_scale_cl, T_shape_cl> pareto_lcdf(
6363
= check_cl(function, "Shape parameter", alpha_val, "positive finite");
6464
auto alpha_positive_finite_expr = 0 < alpha_val && isfinite(alpha_val);
6565

66-
auto any_y_lower_than_y_min
67-
= colwise_max(cast<char>(y_val < y_min_val));
66+
auto any_y_lower_than_y_min = colwise_max(cast<char>(y_val < y_min_val));
6867
auto any_y_inf = colwise_max(cast<char>(isinf(y_val)));
6968

7069
auto log_quot = log(elt_divide(y_min_val, y_val));

stan/math/opencl/prim/poisson_log_lpmf.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ return_type_t<T_log_rate_cl> poisson_log_lpmf(const T_n_cl& n,
6060
= check_cl(function, "Log rate parameter", alpha_val, "not nan");
6161
auto alpha_not_nan = !isnan(alpha_val);
6262

63-
auto return_log_zero = colwise_max(
64-
cast<char>(isinf(alpha_val) && (alpha_val > 0 || n != 0)));
63+
auto return_log_zero
64+
= colwise_max(cast<char>(isinf(alpha_val) && (alpha_val > 0 || n != 0)));
6565
auto exp_alpha = exp(alpha_val);
6666

6767
auto logp1 = elt_multiply(n, alpha_val);

stan/math/opencl/prim/poisson_lpmf.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ return_type_t<T_rate_cl> poisson_lpmf(const T_n_cl& n,
6060
auto lambda_nonnegative = 0.0 <= lambda_val;
6161

6262
auto return_log_zero = colwise_max(
63-
cast<char> (isinf(lambda_val) || (lambda_val == 0 && n != 0)));
63+
cast<char>(isinf(lambda_val) || (lambda_val == 0 && n != 0)));
6464

6565
auto logp1 = multiply_log(n, lambda_val);
6666
auto logp2 = static_select<include_summand<propto, T_rate_cl>::value>(

stan/math/opencl/prim/uniform_cdf.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ return_type_t<T_y_cl, T_low_cl, T_high_cl> uniform_cdf(const T_y_cl& y,
6868
"positive");
6969
auto diff_positive_expr = b_minus_a > 0.0;
7070

71-
auto any_y_out_of_bounds = colwise_max(
72-
cast<char>(y_val < alpha_val || y_val > beta_val));
71+
auto any_y_out_of_bounds
72+
= colwise_max(cast<char>(y_val < alpha_val || y_val > beta_val));
7373
auto cdf_n = elt_divide(y_val - alpha_val, b_minus_a);
7474
auto cdf_expr = colwise_prod(cdf_n);
7575

stan/math/opencl/prim/uniform_lccdf.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ return_type_t<T_y_cl, T_low_cl, T_high_cl> uniform_lccdf(
6767
"positive");
6868
auto diff_positive_expr = b_minus_a > 0.0;
6969

70-
auto any_y_out_of_bounds = colwise_max(
71-
cast<char>(y_val < alpha_val || y_val > beta_val));
70+
auto any_y_out_of_bounds
71+
= colwise_max(cast<char>(y_val < alpha_val || y_val > beta_val));
7272
auto y_minus_alpha = y_val - alpha_val;
7373
auto ccdf_n = 1.0 - elt_divide(y_minus_alpha, b_minus_a);
7474
auto lccdf_expr = colwise_sum(log(ccdf_n));

stan/math/opencl/prim/uniform_lcdf.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ return_type_t<T_y_cl, T_low_cl, T_high_cl> uniform_lcdf(const T_y_cl& y,
6868
"positive");
6969
auto diff_positive_expr = b_minus_a > 0.0;
7070

71-
auto any_y_out_of_bounds = colwise_max(
72-
cast<char> (y_val < alpha_val || y_val > beta_val));
71+
auto any_y_out_of_bounds
72+
= colwise_max(cast<char>(y_val < alpha_val || y_val > beta_val));
7373
auto y_minus_alpha = y_val - alpha_val;
7474
auto cdf_n = elt_divide(y_minus_alpha, b_minus_a);
7575
auto lcdf_expr = colwise_sum(log(cdf_n));

stan/math/opencl/prim/uniform_lpdf.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ inline return_type_t<T_y_cl, T_low_cl, T_high_cl> uniform_lpdf(
8181
function, "Difference between upper and lower bound", diff, "positive");
8282
auto diff_positive = diff > 0;
8383

84-
auto y_out_of_bounds = colwise_max(cast<char>(y_val < alpha_val || beta_val < y_val));
84+
auto y_out_of_bounds
85+
= colwise_max(cast<char>(y_val < alpha_val || beta_val < y_val));
8586

8687
auto logp_expr = colwise_sum(
8788
static_select<include_summand<propto, T_low_cl, T_high_cl>::value>(

stan/math/opencl/prim/weibull_lpdf.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ inline return_type_t<T_y_cl, T_shape_cl, T_scale_cl> weibull_lpdf(
6666
= check_cl(function, "Scale parameter", sigma_val, "positive finite");
6767
auto sigma_positive_finite = isfinite(sigma_val) && 0 < sigma_val;
6868

69-
auto any_y_negative = colwise_max(cast<char> (y_val < 0));
69+
auto any_y_negative = colwise_max(cast<char>(y_val < 0));
7070
auto log_y = log(y_val);
7171
auto log_sigma = log(sigma_val);
7272
auto inv_sigma = elt_divide(1., sigma_val);

test/unit/math/opencl/kernel_generator/cast_test.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,4 @@ TEST(KernelGenerator, cast_multiple_operations_lvalue) {
6565
EXPECT_MATRIX_NEAR(res, correct, 1e-9);
6666
}
6767

68-
69-
7068
#endif

0 commit comments

Comments
 (0)