1 #ifdef STAN_OPENCL
2 #include <stan/math/opencl/prim.hpp>
3 #include <stan/math/prim/fun/tcrossprod.hpp>
4 #include <gtest/gtest.h>
5
test_tcrossprod(const stan::math::matrix_d & x)6 void test_tcrossprod(const stan::math::matrix_d& x) {
7 using stan::math::tcrossprod;
8 stan::math::matrix_cl<double> x_cl(x);
9 stan::math::matrix_d y_cl = from_matrix_cl(tcrossprod(x_cl));
10 stan::math::matrix_d y_correct = tcrossprod(x);
11 EXPECT_EQ(y_correct.rows(), y_cl.rows());
12 EXPECT_EQ(y_correct.cols(), y_cl.cols());
13 for (int m = 0; m < y_correct.rows(); ++m)
14 for (int n = 0; n < y_correct.cols(); ++n)
15 EXPECT_FLOAT_EQ(y_cl(m, n), y_correct(m, n));
16 }
17
TEST(MathMatrixCL,tcrossprod)18 TEST(MathMatrixCL, tcrossprod) {
19 stan::math::matrix_d x;
20 test_tcrossprod(x);
21
22 x = stan::math::matrix_d(1, 1);
23 x << 3.0;
24 test_tcrossprod(x);
25
26 x = stan::math::matrix_d(2, 2);
27 x << 1.0, 0.0, 2.0, 3.0;
28 test_tcrossprod(x);
29
30 x = stan::math::matrix_d(3, 3);
31 x << 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0;
32 test_tcrossprod(x);
33
34 x = Eigen::MatrixXd::Random(100, 100);
35 test_tcrossprod(x);
36 }
37 #endif
38