Skip to content
Open
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
7 changes: 4 additions & 3 deletions test/unit/math/opencl/pinned_matrix_test.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/prim.hpp>
#include <stan/math.hpp>
#include <test/unit/math/rev/util.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>

TEST(AgradRev, pinned_matrix_matrix_test) {
TEST_F(AgradRev, pinned_matrix_matrix_test) {
using Eigen::MatrixXd;
using stan::math::pinned_matrix;

Expand Down Expand Up @@ -45,7 +46,7 @@ TEST(AgradRev, pinned_matrix_matrix_test) {
stan::math::recover_memory();
}

TEST(AgradRev, pinned_matrix_vector_test) {
TEST_F(AgradRev, pinned_matrix_vector_test) {
using Eigen::VectorXd;
using stan::math::pinned_matrix;

Expand Down Expand Up @@ -86,7 +87,7 @@ TEST(AgradRev, pinned_matrix_vector_test) {
stan::math::recover_memory();
}

TEST(AgradRev, pinned_matrix_row_vector_test) {
TEST_F(AgradRev, pinned_matrix_row_vector_test) {
using Eigen::RowVectorXd;
using stan::math::pinned_matrix;

Expand Down
9 changes: 5 additions & 4 deletions test/unit/math/opencl/rev/arena_matrix_cl_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev.hpp>
#include <test/unit/math/rev/util.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>

TEST(AgradRev, arena_matrix_cl_shallow_copies) {
TEST_F(AgradRev, arena_matrix_cl_shallow_copies) {
stan::math::arena_matrix_cl<double> a(3, 2);
stan::math::arena_matrix_cl<double> b(a);
stan::math::arena_matrix_cl<double> c;
Expand All @@ -12,21 +13,21 @@ TEST(AgradRev, arena_matrix_cl_shallow_copies) {
EXPECT_EQ(a.buffer()(), c.buffer()());
}

TEST(AgradRev, arena_matrix_cl_to_matrix_cl_conversion) {
TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_conversion) {
stan::math::arena_matrix_cl<double> a(3, 2);
const stan::math::matrix_cl<double>& b(a);
EXPECT_EQ(a.buffer()(), b.buffer()());
}

TEST(AgradRev, arena_matrix_cl_to_matrix_cl_move_construction) {
TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_move_construction) {
stan::math::arena_matrix_cl<double> a(3, 2);
cl::Buffer a_buf = a.buffer();
stan::math::matrix_cl<double> b(std::move(a));
EXPECT_EQ(a_buf(), a.buffer()());
EXPECT_EQ(a_buf(), b.buffer()());
}

TEST(AgradRev, arena_matrix_cl_to_matrix_cl_move_assignment) {
TEST_F(AgradRev, arena_matrix_cl_to_matrix_cl_move_assignment) {
stan::math::arena_matrix_cl<double> a(3, 2);
cl::Buffer a_buf = a.buffer();
stan::math::matrix_cl<double> b;
Expand Down
7 changes: 4 additions & 3 deletions test/unit/math/opencl/rev/to_arena_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifdef STAN_OPENCL
#include <stan/math/opencl/rev.hpp>
#include <test/unit/math/rev/util.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>

TEST(AgradRev, to_arena_matrix_cl_test) {
TEST_F(AgradRev, to_arena_matrix_cl_test) {
Eigen::MatrixXd m(3, 2);
m << 1, 2, 3, 4, 5, 6;
stan::math::matrix_cl<double> a(m);
Expand All @@ -22,7 +23,7 @@ TEST(AgradRev, to_arena_matrix_cl_test) {
stan::math::recover_memory();
}

TEST(AgradRev, to_arena_kg_expression_test) {
TEST_F(AgradRev, to_arena_kg_expression_test) {
Eigen::MatrixXd m(3, 2);
m << 1, 2, 3, 4, 5, 6;
stan::math::matrix_cl<double> a(m);
Expand All @@ -40,7 +41,7 @@ TEST(AgradRev, to_arena_kg_expression_test) {
stan::math::recover_memory();
}

TEST(AgradRev, to_arena_var_value_matrix_cl_test) {
TEST_F(AgradRev, to_arena_var_value_matrix_cl_test) {
Eigen::MatrixXd val(3, 2);
val << 1, 2, 3, 4, 5, 6;
Eigen::MatrixXd adj(3, 2);
Expand Down
10 changes: 6 additions & 4 deletions test/unit/math/opencl/rev/vari_test.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#ifdef STAN_OPENCL
#include <stan/math/rev/core.hpp>
#include <stan/math/opencl/rev/vari.hpp>
#include <test/unit/math/rev/util.hpp>
#include <test/unit/util.hpp>
#include <gtest/gtest.h>

TEST(AgradRev, matrix_cl_vari_block) {
TEST_F(AgradRev, matrix_cl_vari_block) {
using stan::math::vari_value;
Eigen::MatrixXd a = Eigen::MatrixXd::Random(3, 3);
Eigen::MatrixXd b = Eigen::MatrixXd::Random(3, 3);
stan::math::matrix_cl<double> a_cl(a);
stan::math::matrix_cl<double> b_cl(b);

vari_value<stan::math::matrix_cl<double>> A(a);
stan::math::nested_rev_autodiff nested;
auto& A = *new vari_value<stan::math::matrix_cl<double>>(a);
EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2),
stan::math::from_matrix_cl(A.block(0, 1, 2, 2).val_));
vari_value<stan::math::matrix_cl<double>> B(a_cl);
auto& B = *new vari_value<stan::math::matrix_cl<double>>(a_cl);
B.adj_ = b_cl;
EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2),
stan::math::from_matrix_cl(B.block(0, 1, 2, 2).val_));
EXPECT_MATRIX_EQ(b.block(0, 1, 2, 2),
stan::math::from_matrix_cl(B.block(0, 1, 2, 2).adj_));
vari_value<stan::math::matrix_cl<double>> C(a_cl, a_cl);
auto& C = *new vari_value<stan::math::matrix_cl<double>>(a_cl, a_cl);
EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2),
stan::math::from_matrix_cl(C.block(0, 1, 2, 2).val_));
EXPECT_MATRIX_EQ(a.block(0, 1, 2, 2),
Expand Down
8 changes: 4 additions & 4 deletions test/unit/math/prim/functor/reduce_sum_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,22 @@ inline void test_slices(T1 result, T2&& vec_value, Args&&... args) {
<< "Failed for reduce_sum";
}

auto reduce_sum_static_int_sum_lpdf = [](auto&&... args) {
inline auto reduce_sum_static_int_sum_lpdf = [](auto&&... args) {
return stan::math::reduce_sum_static<sum_lpdf>(std::vector<int>(2, 10.0), 1,
get_new_msg(), args...);
};

auto reduce_sum_static_sum_lpdf = [](auto&& data, auto&&... args) {
inline auto reduce_sum_static_sum_lpdf = [](auto&& data, auto&&... args) {
return stan::math::reduce_sum_static<sum_lpdf>(data, 1, get_new_msg(),
args...);
};

auto reduce_sum_int_sum_lpdf = [](auto&&... args) {
inline auto reduce_sum_int_sum_lpdf = [](auto&&... args) {
return stan::math::reduce_sum<sum_lpdf>(std::vector<int>(2, 10.0), 1,
get_new_msg(), args...);
};

auto reduce_sum_sum_lpdf = [](auto&& data, auto&&... args) {
inline auto reduce_sum_sum_lpdf = [](auto&& data, auto&&... args) {
return stan::math::reduce_sum<sum_lpdf>(data, 1, get_new_msg(), args...);
};

Expand Down
4 changes: 2 additions & 2 deletions test/unit/math/rev/core/gradable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct gradable {
double adj() { return f_.adj(); }
};

gradable setup_quad_form() {
inline gradable setup_quad_form() {
using Eigen::Dynamic;
using Eigen::Matrix;
using stan::math::quad_form;
Expand All @@ -52,7 +52,7 @@ gradable setup_quad_form() {
return gradable(x, f, g_expected);
}

gradable setup_simple() {
inline gradable setup_simple() {
stan::math::var a = 3;
stan::math::var b = 7;
std::vector<stan::math::var> x;
Expand Down
8 changes: 4 additions & 4 deletions test/unit/math/rev/fun/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct third_order_mixed {
}
};

Eigen::Matrix<double, 3, 3> third_order_mixed_hess(
inline Eigen::Matrix<double, 3, 3> third_order_mixed_hess(
const Eigen::Matrix<double, Eigen::Dynamic, 1>& inp_vec) {
Eigen::Matrix<double, 3, 3> hess;

Expand All @@ -46,7 +46,7 @@ Eigen::Matrix<double, 3, 3> third_order_mixed_hess(
return hess;
}

Eigen::Matrix<double, 3, 3> norm_hess(
inline Eigen::Matrix<double, 3, 3> norm_hess(
const Eigen::Matrix<double, Eigen::Dynamic, 1>& inp_vec) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand All @@ -62,7 +62,7 @@ Eigen::Matrix<double, 3, 3> norm_hess(
return hess;
}

std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>>
inline std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>>
third_order_mixed_grad_hess(
const Eigen::Matrix<double, Eigen::Dynamic, 1>& inp_vec) {
using Eigen::Dynamic;
Expand Down Expand Up @@ -91,7 +91,7 @@ third_order_mixed_grad_hess(
return grad_hess_ret;
}

std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>>
inline std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>>
norm_grad_hess(const Eigen::Matrix<double, Eigen::Dynamic, 1>& inp_vec) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down
31 changes: 16 additions & 15 deletions test/unit/math/rev/functor/map_rect_mpi_prim_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include <iostream>
#include <vector>

STAN_REGISTER_MAP_RECT(0, hard_work)
STAN_REGISTER_MAP_RECT(1, hard_work)
STAN_REGISTER_MAP_RECT(2, faulty_functor)
STAN_REGISTER_MAP_RECT(3, faulty_functor)
// Keep call IDs unique across the grouped functor executable.
STAN_REGISTER_MAP_RECT(10, hard_work)
STAN_REGISTER_MAP_RECT(11, hard_work)
STAN_REGISTER_MAP_RECT(12, faulty_functor)
STAN_REGISTER_MAP_RECT(13, faulty_functor)

struct MpiJob : public ::testing::Test {
struct MpiPrimJob : public ::testing::Test {
Eigen::VectorXd shared_params_d;
std::vector<Eigen::VectorXd> job_params_d;
const std::size_t N = 10;
Expand Down Expand Up @@ -64,11 +65,11 @@ struct MpiJobSmallWorld : public ::testing::Test {
}
};

TEST_F(MpiJob, hard_work_dd) {
Eigen::VectorXd result_mpi = stan::math::map_rect<0, hard_work>(
TEST_F(MpiPrimJob, hard_work_dd) {
Eigen::VectorXd result_mpi = stan::math::map_rect<10, hard_work>(
shared_params_d, job_params_d, x_r, x_i);
Eigen::VectorXd result_concurrent
= stan::math::internal::map_rect_concurrent<0, hard_work>(
= stan::math::internal::map_rect_concurrent<10, hard_work>(
shared_params_d, job_params_d, x_r, x_i);

EXPECT_EQ(result_mpi.rows(), result_concurrent.rows());
Expand All @@ -80,10 +81,10 @@ TEST_F(MpiJob, hard_work_dd) {

// execute fewer jobs than the cluster size
TEST_F(MpiJobSmallWorld, hard_work_dd) {
Eigen::VectorXd result_mpi = stan::math::map_rect<1, hard_work>(
Eigen::VectorXd result_mpi = stan::math::map_rect<11, hard_work>(
shared_params_d, job_params_d, x_r, x_i);
Eigen::VectorXd result_concurrent
= stan::math::internal::map_rect_concurrent<1, hard_work>(
= stan::math::internal::map_rect_concurrent<11, hard_work>(
shared_params_d, job_params_d, x_r, x_i);

EXPECT_EQ(result_mpi.rows(), result_concurrent.rows());
Expand All @@ -93,10 +94,10 @@ TEST_F(MpiJobSmallWorld, hard_work_dd) {
}
}

TEST_F(MpiJob, always_faulty_functor) {
TEST_F(MpiPrimJob, always_faulty_functor) {
Eigen::VectorXd result;

EXPECT_NO_THROW((result = stan::math::map_rect<2, faulty_functor>(
EXPECT_NO_THROW((result = stan::math::map_rect<12, faulty_functor>(
shared_params_d, job_params_d, x_r, x_i)));

// faulty functor throws on theta(0) being -1.0
Expand All @@ -106,16 +107,16 @@ TEST_F(MpiJob, always_faulty_functor) {

// upon the second evaluation throwing is handled internally
// different
EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<12, faulty_functor>(
shared_params_d, job_params_d, x_r, x_i)),
std::domain_error, "Error during MPI evaluation.");

// throwing on the very first evaluation
EXPECT_THROW_MSG((result = stan::math::map_rect<3, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<13, faulty_functor>(
shared_params_d, job_params_d, x_r, x_i)),
std::domain_error, "MPI error on first evaluation.");
// things don't get better if we repeat
EXPECT_THROW_MSG((result = stan::math::map_rect<3, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<13, faulty_functor>(
shared_params_d, job_params_d, x_r, x_i)),
std::domain_error, "MPI error on first evaluation.");
}
Expand Down
29 changes: 15 additions & 14 deletions test/unit/math/rev/functor/map_rect_mpi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include <iostream>
#include <vector>

STAN_REGISTER_MAP_RECT(0, hard_work)
STAN_REGISTER_MAP_RECT(1, faulty_functor)
STAN_REGISTER_MAP_RECT(2, faulty_functor)
// Keep call IDs unique across the grouped functor executable.
STAN_REGISTER_MAP_RECT(20, hard_work)
STAN_REGISTER_MAP_RECT(21, faulty_functor)
STAN_REGISTER_MAP_RECT(22, faulty_functor)

struct MpiJob : public ::testing::Test {
stan::math::vector_d shared_params_d;
Expand Down Expand Up @@ -67,11 +68,11 @@ TEST_F(MpiJob, hard_work_vv) {
job_params_v2_vec.push_back(stan::math::to_array_1d(job_params_v2[i]));
}

stan::math::vector_v result_mpi = stan::math::map_rect<0, hard_work>(
stan::math::vector_v result_mpi = stan::math::map_rect<20, hard_work>(
shared_params_v, job_params_v, x_r, x_i, 0);

stan::math::vector_v result_concurrent
= stan::math::internal::map_rect_concurrent<0, hard_work>(
= stan::math::internal::map_rect_concurrent<20, hard_work>(
shared_params_v2, job_params_v2, x_r, x_i, 0);

std::vector<double> z_grad1;
Expand Down Expand Up @@ -111,7 +112,7 @@ TEST_F(MpiJob, hard_work_vv) {
TEST_F(MpiJob, always_faulty_functor_vv) {
stan::math::vector_v result;

EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>(
shared_params_v, job_params_v, x_r, x_i)));

// faulty functor throws on theta(0) being -1.0
Expand All @@ -120,20 +121,20 @@ TEST_F(MpiJob, always_faulty_functor_vv) {
job_params_v[0](0) = -1;

// upon the second evaluation throwing is handled internally different
EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>(
shared_params_v, job_params_v, x_r, x_i)),
std::domain_error, "Error during MPI evaluation.");

// throwing on the very first evaluation
EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>(
shared_params_v, job_params_v, x_r, x_i)),
std::domain_error, "MPI error on first evaluation.");
}

TEST_F(MpiJob, always_faulty_functor_vd) {
stan::math::vector_v result;

EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>(
shared_params_v, job_params_d, x_r, x_i)));

// faulty functor throws on theta(0) being -1.0
Expand All @@ -142,20 +143,20 @@ TEST_F(MpiJob, always_faulty_functor_vd) {
job_params_d[0](0) = -1;

// upon the second evaluation throwing is handled internally different
EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>(
shared_params_v, job_params_d, x_r, x_i)),
std::domain_error, "Error during MPI evaluation.");

// throwing on the very first evaluation
EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>(
shared_params_v, job_params_d, x_r, x_i)),
std::domain_error, "MPI error on first evaluation.");
}

TEST_F(MpiJob, always_faulty_functor_dv) {
stan::math::vector_v result;

EXPECT_NO_THROW((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_NO_THROW((result = stan::math::map_rect<21, faulty_functor>(
shared_params_d, job_params_v, x_r, x_i)));

// faulty functor throws on theta(0) being -1.0
Expand All @@ -164,12 +165,12 @@ TEST_F(MpiJob, always_faulty_functor_dv) {
job_params_v[0](0) = -1;

// upon the second evaluation throwing is handled internally different
EXPECT_THROW_MSG((result = stan::math::map_rect<1, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<21, faulty_functor>(
shared_params_d, job_params_v, x_r, x_i)),
std::domain_error, "Error during MPI evaluation.");

// throwing on the very first evaluation
EXPECT_THROW_MSG((result = stan::math::map_rect<2, faulty_functor>(
EXPECT_THROW_MSG((result = stan::math::map_rect<22, faulty_functor>(
shared_params_d, job_params_v, x_r, x_i)),
std::domain_error, "MPI error on first evaluation.");
}
Expand Down
Loading
Loading