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
__anonfe2ed1640102(const auto& a, const auto& b) 7 auto dot_product_functor = [](const auto& a, const auto& b) {
8 return stan::math::dot_product(a, b);
9 };
10
TEST(OpenCLDotProduct,errors)11 TEST(OpenCLDotProduct, errors) {
12 Eigen::VectorXd a(3);
13 Eigen::VectorXd b(8);
14 stan::math::matrix_cl<double> a_cl(a);
15 stan::math::matrix_cl<double> b_cl(b);
16 EXPECT_THROW(stan::math::dot_product(a_cl, b_cl), std::invalid_argument);
17 EXPECT_THROW(stan::math::dot_product(a_cl, b_cl), std::invalid_argument);
18 }
19
TEST(OpenCLDotProduct,prim_rev_small_vector)20 TEST(OpenCLDotProduct, prim_rev_small_vector) {
21 Eigen::VectorXd a(8);
22 a << -2.2, -0.8, 0.5, 1, 1.5, 3, 3.4, 4;
23 Eigen::VectorXd b(8);
24 b << 1, 2, 3, 4, 5, 6, 7, 8;
25 stan::math::test::compare_cpu_opencl_prim_rev(dot_product_functor, a, b);
26 }
27
TEST(OpenCLDotProduct,prim_rev_small_row_vector)28 TEST(OpenCLDotProduct, prim_rev_small_row_vector) {
29 Eigen::RowVectorXd a(8);
30 a << -2.2, -0.8, 0.5, 1, 1.5, 3, 3.4, 4;
31 Eigen::RowVectorXd b(8);
32 b << 1, 2, 3, 4, 5, 6, 7, 8;
33 stan::math::test::compare_cpu_opencl_prim_rev(dot_product_functor, a, b);
34 }
35
TEST(OpenCLDotProduct,prim_rev_size_0)36 TEST(OpenCLDotProduct, prim_rev_size_0) {
37 int N = 0;
38
39 Eigen::VectorXd a(N);
40 stan::math::test::compare_cpu_opencl_prim_rev(dot_product_functor, a, a);
41 }
42
TEST(OpenCLDotProduct,prim_rev_values_large)43 TEST(OpenCLDotProduct, prim_rev_values_large) {
44 int N = 71;
45
46 Eigen::VectorXd a = Eigen::VectorXd::Random(N);
47 Eigen::VectorXd b = Eigen::VectorXd::Random(N);
48 stan::math::test::compare_cpu_opencl_prim_rev(dot_product_functor, a, b);
49 }
50
51 #endif
52