Automatic Differentiation
 
Loading...
Searching...
No Matches
prod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_PROD_HPP
2#define STAN_MATH_OPENCL_PRIM_PROD_HPP
3#ifdef STAN_OPENCL
4
9
10namespace stan {
11namespace math {
12
19template <typename T,
20 require_all_kernel_expressions_and_none_scalar_t<T>* = nullptr>
21value_type_t<T> prod(const T& m) {
22 if (is_matrix_cl<T>::value && m.size() < 1000) {
23 // for small matrices running another kernel is not worth it
24 return prod(from_matrix_cl(m));
25 }
27 if (m.rows() <= 8) {
28 // without transpose we would use just a few threads in a work group
29 res = prod_2d(transpose(m));
30 } else {
31 res = prod_2d(m);
32 }
33 return prod(from_matrix_cl(res));
34}
35
36} // namespace math
37} // namespace stan
38
39#endif
40#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
auto transpose(Arg &&a)
Transposes a kernel generator expression.
auto prod_2d(T &&a)
Two dimensional product - reduction of a kernel generator expression.
auto from_matrix_cl(const T &src)
Copies the source matrix that is stored on the OpenCL device to the destination Eigen matrix.
Definition copy.hpp:61
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
value_type_t< T > prod(const T &m)
Calculates product of given kernel generator expression elements.
Definition prod.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Checks if the decayed type of T is a matrix_cl.