1 #ifdef STAN_OPENCL
2 #include <stan/math/opencl/rev.hpp>
3 #include <stan/math.hpp>
4 #include <gtest/gtest.h>
5 #include <test/unit/math/opencl/util.hpp>
6
__anon3dc8fa590102(const auto& a) 7 auto reverse_functor = [](const auto& a) { return stan::math::reverse(a); };
8
TEST(OpenCLReverse,error)9 TEST(OpenCLReverse, error) {
10 Eigen::MatrixXd a(3, 3);
11 a << 1, 2, 3, 4, 5, 6, 76, 8, 9;
12 stan::math::matrix_cl<double> a_cl(a);
13 EXPECT_THROW(stan::math::reverse(a_cl), std::invalid_argument);
14 }
15
TEST(OpenCLReverse,prim_rev_values_small)16 TEST(OpenCLReverse, prim_rev_values_small) {
17 Eigen::VectorXd a(8);
18 a << -2.2, -0.8, 0.5, 1 + std::numeric_limits<double>::epsilon(), 1.5, 3, 3.4,
19 4;
20 stan::math::test::compare_cpu_opencl_prim_rev(reverse_functor, a);
21 stan::math::test::compare_cpu_opencl_prim_rev(
22 reverse_functor, stan::math::eval(stan::math::transpose(a)));
23 }
24
TEST(OpenCLReverse,prim_rev_size_0)25 TEST(OpenCLReverse, prim_rev_size_0) {
26 int N = 0;
27
28 Eigen::VectorXd a(N);
29 stan::math::test::compare_cpu_opencl_prim_rev(reverse_functor, a);
30 stan::math::test::compare_cpu_opencl_prim_rev(
31 reverse_functor, stan::math::eval(stan::math::transpose(a)));
32 }
33
TEST(OpenCLReverse,prim_rev_values_large)34 TEST(OpenCLReverse, prim_rev_values_large) {
35 int N = 71;
36
37 Eigen::VectorXd a = Eigen::VectorXd::Random(N);
38 stan::math::test::compare_cpu_opencl_prim_rev(reverse_functor, a);
39 stan::math::test::compare_cpu_opencl_prim_rev(
40 reverse_functor, stan::math::eval(stan::math::transpose(a)));
41 }
42
43 #endif
44