Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions stan/math/fwd/fun/mdivide_left_tri_low.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ template <typename T1, typename T2,
inline Eigen::Matrix<value_type_t<T1>, std::decay_t<T1>::RowsAtCompileTime,
std::decay_t<T2>::ColsAtCompileTime>
mdivide_left_tri_low(T1&& A, T2&& b) {
constexpr int S1 = std::decay_t<T1>::RowsAtCompileTime;
constexpr int C2 = std::decay_t<T2>::ColsAtCompileTime;

check_square("mdivide_left_tri_low", "A", A);
check_multiplicable("mdivide_left_tri_low", "A", A, "b", b);
if (A.size() == 0) {
Expand All @@ -47,7 +44,6 @@ template <typename T1, typename T2, require_eigen_t<T1>* = nullptr,
inline Eigen::Matrix<value_type_t<T2>, std::decay_t<T1>::RowsAtCompileTime,
std::decay_t<T2>::ColsAtCompileTime>
mdivide_left_tri_low(T1&& A, T2&& b) {
constexpr int S1 = std::decay_t<T1>::RowsAtCompileTime;
check_square("mdivide_left_tri_low", "A", A);
check_multiplicable("mdivide_left_tri_low", "A", A, "b", b);
if (A.size() == 0) {
Expand All @@ -64,8 +60,6 @@ template <typename T1, typename T2, require_eigen_vt<is_fvar, T1>* = nullptr,
inline Eigen::Matrix<value_type_t<T1>, std::decay_t<T1>::RowsAtCompileTime,
std::decay_t<T2>::ColsAtCompileTime>
mdivide_left_tri_low(T1&& A, T2&& b) {
constexpr int S1 = std::decay_t<T1>::RowsAtCompileTime;
constexpr int C2 = std::decay_t<T2>::ColsAtCompileTime;
check_square("mdivide_left_tri_low", "A", A);
check_multiplicable("mdivide_left_tri_low", "A", A, "b", b);
if (A.size() == 0) {
Expand Down
3 changes: 0 additions & 3 deletions stan/math/opencl/kernel_generator/colwise_reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class colwise_sum_ : public colwise_reduction<colwise_sum_<T>, T, sum_op> {
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto colwise_sum(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return colwise_sum_<as_operation_cl_t<T>>(
as_operation_cl(std::forward<T>(a)));
}
Expand Down Expand Up @@ -266,7 +265,6 @@ class colwise_prod_ : public colwise_reduction<colwise_prod_<T>, T, prod_op> {
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto colwise_prod(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return colwise_prod_<as_operation_cl_t<T>>(
as_operation_cl(std::forward<T>(a)));
}
Expand Down Expand Up @@ -315,7 +313,6 @@ class colwise_max_ : public colwise_reduction<
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto colwise_max(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return colwise_max_<as_operation_cl_t<T>>(
as_operation_cl(std::forward<T>(a)));
}
Expand Down
3 changes: 0 additions & 3 deletions stan/math/opencl/kernel_generator/reduction_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class sum_2d_ : public reduction_2d<sum_2d_<T>, T, sum_op> {
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto sum_2d(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return sum_2d_<as_operation_cl_t<T>>(as_operation_cl(std::forward<T>(a)));
}

Expand Down Expand Up @@ -274,7 +273,6 @@ class prod_2d_ : public reduction_2d<prod_2d_<T>, T, prod_op> {
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto prod_2d(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return prod_2d_<as_operation_cl_t<T>>(as_operation_cl(std::forward<T>(a)));
}

Expand Down Expand Up @@ -321,7 +319,6 @@ class max_2d_
*/
template <typename T, require_all_kernel_expressions_t<T>* = nullptr>
inline auto max_2d(T&& a) {
auto&& arg_copy = as_operation_cl(std::forward<T>(a)).deep_copy();
return max_2d_<as_operation_cl_t<T>>(as_operation_cl(std::forward<T>(a)));
}

Expand Down
1 change: 0 additions & 1 deletion stan/math/opencl/prim/binomial_logit_glm_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ inline return_type_t<T_x_cl, T_alpha_cl, T_beta_cl> binomial_logit_glm_lpmf(
const T_beta_cl& beta) {
static const char* function = "binomial_logit_glm_lpmf(OpenCL)";
using T_partials_return = partials_return_t<T_x_cl, T_alpha_cl, T_beta_cl>;
constexpr bool is_y_vector = !is_stan_scalar<T_n_cl>::value;
constexpr bool is_alpha_vector = !is_stan_scalar<T_alpha_cl>::value;

const size_t N_instances
Expand Down
1 change: 0 additions & 1 deletion stan/math/opencl/zeros_strict_tri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ inline void matrix_cl<T>::zeros_strict_tri() try {
return;
}
this->view_ = both(this->view_, invert(matrix_view));
cl::CommandQueue& cmdQueue = opencl_context.queue();
opencl_kernels::fill_strict_tri(cl::NDRange(this->rows(), this->cols()),
*this, 0.0, this->rows(), this->cols(),
matrix_view);
Expand Down
2 changes: 1 addition & 1 deletion stan/math/prim/constraint/unit_vector_free.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline auto unit_vector_free(EigVec&& x) {
auto&& x_ref = to_ref(std::forward<EigVec>(x));
check_unit_vector("stan::math::unit_vector_free", "Unit vector variable",
x_ref);
return x_ref;
return std::forward<decltype(x_ref)>(x_ref);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/fun/log_softmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stan/math/prim/fun/log_sum_exp.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#include <stan/math/prim/functor/apply_vector_unary.hpp>
#include <utility>

namespace stan {
namespace math {
Expand Down Expand Up @@ -53,7 +54,7 @@ inline auto log_softmax(Container&& x) {
std::forward<decltype(a)>(a),
[](auto&& v) -> plain_type_t<decltype(v)> {
if (v.size() == 0) {
return v;
return std::forward<decltype(v)>(v);
}
return (v.array() - log_sum_exp(v)).matrix();
});
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/fun/softmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/fun/to_ref.hpp>
#include <stan/math/prim/functor/apply_vector_unary.hpp>
#include <utility>

namespace stan {
namespace math {
Expand Down Expand Up @@ -56,7 +57,7 @@ inline auto softmax(Container&& x) {
std::forward<decltype(a)>(a),
[](auto&& v) -> plain_type_t<decltype(v)> {
if (v.size() == 0) {
return v;
return std::forward<decltype(v)>(v);
}
const auto theta = (v.array() - v.maxCoeff()).exp();
return (theta / theta.sum()).matrix();
Expand Down
2 changes: 0 additions & 2 deletions stan/math/prim/prob/normal_sufficient_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ inline return_type_t<T_y, T_s, T_loc, T_scale> normal_sufficient_lpdf(
decltype(auto) y_val = to_ref(as_value_column_array_or_scalar(y_ref));
decltype(auto) s_squared_val
= to_ref(as_value_column_array_or_scalar(s_squared_ref));
decltype(auto) n_obs_val_int
= to_ref(as_value_column_array_or_scalar(n_obs_ref));
decltype(auto) n_obs_val = to_ref(
promote_scalar<double>(as_value_column_array_or_scalar(n_obs_ref)));
decltype(auto) mu_val = to_ref(as_value_column_array_or_scalar(mu_ref));
Expand Down
1 change: 0 additions & 1 deletion stan/math/prim/prob/student_t_qf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ template <typename T_p, typename T_nu, typename T_mu, typename T_sigma,
inline auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu,
const T_sigma& sigma) {
using ret_scalar = return_type_t<T_p, T_nu, T_mu, T_sigma>;
static constexpr const char* function = "student_t_qf";
const size_t max_size_all = max_size(p, nu, mu, sigma);
Eigen::Matrix<ret_scalar, -1, 1> result(max_size_all);

Expand Down
2 changes: 0 additions & 2 deletions stan/math/rev/prob/student_t_qf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ inline var student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu,
const double p_val_flip = p_val < 0.5 ? p_val : 1.0 - p_val;
const double p_sign = p_val < 0.5 ? -1.0 : 1.0;
const double ibeta_arg = inv_inc_beta(0.5 * nu_val, 0.5, 2 * p_val_flip);
const double sqrt_inv_ibeta_m1 = sqrt(inv(ibeta_arg) - 1.0);
double ret_val
= mu_val
+ p_sign * sigma_val * sqrt(nu_val) * sqrt(-1.0 + 1.0 / ibeta_arg);
Expand All @@ -49,7 +48,6 @@ inline var student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu,
const double mu_val = value_of(mu);
const double sigma_val = value_of(sigma);
const double nu_val = value_of(nu);
const double p_val_flip = p_val < 0.5 ? p_val : 1.0 - p_val;
const double p_sign = p_val < 0.5 ? -1.0 : 1.0;
const double sqrt_inv_ibeta_m1 = sqrt(inv(ibeta_arg) - 1.0);
if constexpr (is_autodiff_v<T_p>) {
Expand Down
1 change: 0 additions & 1 deletion test/unit/math/opencl/kernel_generator/calc_if_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ TEST(KernelGenerator, calc_if_multi_result_pass_test) {
}

TEST(KernelGenerator, calc_if_multi_result_no_output_test) {
double eps = 0;
MatrixXd m(2, 2);
m << 1, 2, 3, 4;
matrix_cl<double> m_cl(m);
Expand Down
20 changes: 20 additions & 0 deletions test/unit/math/opencl/kernel_generator/colwise_reduction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ TEST(KernelGenerator, colwise_prod_test) {
EXPECT_MATRIX_NEAR(correct, res, 1e-9);
}

TEST(KernelGenerator, colwise_reductions_rvalue_input) {
MatrixXd m(3, 2);
m << 1.1, 1.2, 1.3, 1.4, 1.5, 1.6;

matrix_cl<double> res_cl = stan::math::colwise_sum(matrix_cl<double>(m));
MatrixXd res = stan::math::from_matrix_cl(res_cl).colwise().sum();
MatrixXd correct = m.colwise().sum();
EXPECT_MATRIX_NEAR(correct, res, 1e-9);

matrix_cl<double> prod_cl = stan::math::colwise_prod(matrix_cl<double>(m));
MatrixXd prod = stan::math::from_matrix_cl(prod_cl).colwise().prod();
MatrixXd correct_prod = m.colwise().prod();
EXPECT_MATRIX_NEAR(correct_prod, prod, 1e-9);

matrix_cl<double> max_cl = stan::math::colwise_max(matrix_cl<double>(m));
MatrixXd max = stan::math::from_matrix_cl(max_cl).colwise().maxCoeff();
MatrixXd correct_max = m.colwise().maxCoeff();
EXPECT_MATRIX_NEAR(correct_max, max, 1e-9);
}

TEST(KernelGenerator, colwise_min_test) {
MatrixXd m(3, 2);
m << 1.1, 1.2, 1.3, 1.4, 1.5, 1.6;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/math/opencl/kernel_generator/reduction_2d_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ TEST(KernelGenerator, prod_2d_test) {
EXPECT_NEAR(correct, res, 1e-9);
}

TEST(KernelGenerator, reductions_2d_rvalue_input) {
MatrixXd m(3, 2);
m << 1.1, 1.2, 1.3, 1.4, 1.5, 1.6;

matrix_cl<double> res_cl = stan::math::sum_2d(matrix_cl<double>(m));
double res = stan::math::from_matrix_cl(res_cl).sum();
EXPECT_NEAR(m.sum(), res, 1e-9);

matrix_cl<double> prod_cl = stan::math::prod_2d(matrix_cl<double>(m));
double prod = stan::math::from_matrix_cl(prod_cl).prod();
EXPECT_NEAR(m.prod(), prod, 1e-9);

matrix_cl<double> max_cl = stan::math::max_2d(matrix_cl<double>(m));
double max = stan::math::from_matrix_cl(max_cl).maxCoeff();
EXPECT_NEAR(m.maxCoeff(), max, 1e-9);
}

TEST(KernelGenerator, min_2d_test) {
MatrixXd m(3, 2);
m << 1.1, 1.2, 1.3, 1.4, 1.5, 1.6;
Expand Down
1 change: 0 additions & 1 deletion test/unit/math/opencl/matrix_cl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ TEST(MathMatrixCL, matrix_cl_value) {
TEST(MathMatrixCL, assignment) {
using stan::math::matrix_cl;
Eigen::Matrix<double, 2, 2> mat_1;
Eigen::Matrix<double, 2, 2> mat_2;
mat_1 << 1, 2, 3, 4;
matrix_cl<double> mat1_cl(mat_1);
matrix_cl<double> mat2_cl(2, 2);
Expand Down
2 changes: 0 additions & 2 deletions test/unit/math/opencl/prim/mdivide_left_tri_low_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ inline void mdivide_left_tri_low_Ab_test(int size) {
stan::math::matrix_cl<double> m0_cl(m1, stan::math::matrix_cl_view::Lower);
stan::math::matrix_d m1_cl = stan::math::from_matrix_cl(
stan::math::mdivide_left_tri_low(m0_cl, m0_cl));
double max_error = 0;
for (int i = 0; i < m1_cpu.size(); i++) {
stan::test::expect_near_rel("mdivide_left_tri_low (OpenCL)", m1_cpu(i),
m1_cl(i));
Expand Down Expand Up @@ -77,7 +76,6 @@ inline void mdivide_left_tri_low_A_test(int size) {

stan::math::matrix_cl<double> m1_A_cl(m1, stan::math::matrix_cl_view::Lower);
m1_cl = stan::math::from_matrix_cl(stan::math::mdivide_left_tri_low(m1_A_cl));
double max_error = 0;
for (int i = 0; i < size; i++) {
for (int j = 0; j <= i; j++) {
stan::test::expect_near_rel("mdivide_left_tri_low (OpenCL)", m1_cpu(i, j),
Expand Down
1 change: 0 additions & 1 deletion test/unit/math/opencl/prim/mdivide_right_tri_low_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ inline void mdivide_right_tri_low_Ab_test(int size) {
stan::math::matrix_cl<double> m1_A_cl(m1, stan::math::matrix_cl_view::Lower);
stan::math::matrix_d m1_cl = stan::math::from_matrix_cl(
stan::math::mdivide_right_tri_low(m1_A_cl, m1_A_cl));
double max_error = 0;
for (int i = 0; i < m1_cpu.size(); i++) {
stan::test::expect_near_rel("mdivide_right_tri_low (OpenCL)", m1_cpu(i),
m1_cl(i));
Expand Down
2 changes: 0 additions & 2 deletions test/unit/math/opencl/rev/append_array_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ TEST(OpenCLAppendArray, prim_rev_values_small) {
}

TEST(OpenCLAppendArray, prim_rev_size_0) {
int N = 0;

std::vector<double> a{};
std::vector<double> b{};
stan::math::test::compare_cpu_opencl_prim_rev(append_array_functor, a, b);
Expand Down
4 changes: 0 additions & 4 deletions test/unit/math/opencl/rev/bernoulli_cdf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ auto bernoulli_cdf_functor = [](const auto& n, const auto& theta) {

TEST(ProbDistributionsBernoulliCdf, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

std::vector<int> n{0, 1, 3};
Eigen::VectorXd theta(N);
Expand All @@ -59,7 +58,6 @@ TEST(ProbDistributionsBernoulliCdf, opencl_matches_cpu_small) {

TEST(ProbDistributionsBernoulliCdf, opencl_matches_cpu_small_n_negative) {
int N = 3;
int M = 2;

std::vector<int> n{0, 1, -5};
Eigen::VectorXd theta(N);
Expand All @@ -83,8 +81,6 @@ TEST(ProbDistributionsBernoulliCdf, opencl_broadcast_n) {
}

TEST(ProbDistributionsBernoulliCdf, opencl_broadcast_theta) {
int N = 3;

std::vector<int> n{0, 1, 0};
double theta_scal = 0.4;

Expand Down
5 changes: 0 additions & 5 deletions test/unit/math/opencl/rev/bernoulli_lccdf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ auto bernoulli_lccdf_functor = [](const auto& n, const auto& theta) {

TEST(ProbDistributionsBernoulliLccdf, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

std::vector<int> n{0, 0, 0};
Eigen::VectorXd theta(N);
Expand All @@ -59,7 +58,6 @@ TEST(ProbDistributionsBernoulliLccdf, opencl_matches_cpu_small) {

TEST(ProbDistributionsBernoulliLccdf, opencl_matches_cpu_small_n_negative) {
int N = 3;
int M = 2;

std::vector<int> n{0, 0, -5};
Eigen::VectorXd theta(N);
Expand All @@ -73,7 +71,6 @@ TEST(ProbDistributionsBernoulliLccdf, opencl_matches_cpu_small_n_negative) {

TEST(ProbDistributionsBernoulliLccdf, opencl_matches_cpu_small_n_over_one) {
int N = 3;
int M = 2;

std::vector<int> n{0, 1, 5};
Eigen::VectorXd theta(N);
Expand All @@ -97,8 +94,6 @@ TEST(ProbDistributionsBernoulliLccdf, opencl_broadcast_n) {
}

TEST(ProbDistributionsBernoulliLccdf, opencl_broadcast_theta) {
int N = 3;

std::vector<int> n{0, 0, 0};
double theta_scal = 0.4;

Expand Down
3 changes: 0 additions & 3 deletions test/unit/math/opencl/rev/bernoulli_logit_lpmf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ auto bernoulli_logit_lpmf_functor_propto

TEST(ProbDistributionsBernoulliLogit, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

std::vector<int> n{0, 1, 1};
Eigen::VectorXd theta(N);
Expand Down Expand Up @@ -78,8 +77,6 @@ TEST(ProbDistributionsBernoulliLogit, opencl_broadcast_n) {
}

TEST(ProbDistributionsBernoulliLogit, opencl_broadcast_theta) {
int N = 3;

std::vector<int> n{0, 1, 0};
double theta = 0.4;

Expand Down
3 changes: 0 additions & 3 deletions test/unit/math/opencl/rev/bernoulli_lpmf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ auto bernoulli_lpmf_functor_propto = [](const auto& n, const auto& theta) {

TEST(ProbDistributionsBernoulli, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

std::vector<int> n{0, 1, 0};
Eigen::VectorXd theta(N);
Expand Down Expand Up @@ -77,8 +76,6 @@ TEST(ProbDistributionsBernoulli, opencl_broadcast_n) {
}

TEST(ProbDistributionsBernoulli, opencl_broadcast_theta) {
int N = 3;

std::vector<int> n{0, 1, 0};
double theta_scal = 0.4;

Expand Down
1 change: 0 additions & 1 deletion test/unit/math/opencl/rev/beta_lpdf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ auto beta_lpdf_functor_propto

TEST(ProbDistributionsBeta, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

Eigen::VectorXd y(N);
y << 0, 0.5, 1;
Expand Down
1 change: 0 additions & 1 deletion test/unit/math/opencl/rev/beta_proportion_lpdf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ auto beta_proportion_lpdf_functor_propto

TEST(ProbDistributionsBetaProportion, opencl_matches_cpu_small) {
int N = 3;
int M = 2;

Eigen::VectorXd y(N);
y << 0.3, 0.8, 1.0;
Expand Down
2 changes: 0 additions & 2 deletions test/unit/math/opencl/rev/binomial_logit_lpmf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ TEST(ProbDistributionsBinomialLogit, opencl_broadcast_N) {
}

TEST(ProbDistributionsBinomialLogit, opencl_broadcast_alpha) {
int N = 3;

std::vector<int> n{0, 1, 12};
std::vector<int> m{0, 1, 123};
double alpha_scal = 0.4;
Expand Down
2 changes: 0 additions & 2 deletions test/unit/math/opencl/rev/binomial_lpmf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ TEST(ProbDistributionsBinomial, opencl_broadcast_N) {
}

TEST(ProbDistributionsBinomial, opencl_broadcast_theta) {
int N = 3;

std::vector<int> n{0, 1, 12};
std::vector<int> m{0, 1, 123};
double theta_scal = 0.4;
Expand Down
Loading
Loading