Automatic Differentiation
 
Loading...
Searching...
No Matches
rows_dot_product.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_ROWS_DOT_PRODUCT_HPP
2#define STAN_MATH_OPENCL_REV_ROWS_DOT_PRODUCT_HPP
3#ifdef STAN_OPENCL
4
11
12namespace stan {
13namespace math {
14
27template <
28 typename T1, typename T2, require_any_var_t<T1, T2>* = nullptr,
29 require_all_nonscalar_prim_or_rev_kernel_expression_t<T1, T2>* = nullptr>
31 check_matching_sizes("rows_dot_product(OpenCL)", "v1", v1, "v2", v2);
32
33 arena_t<T1> v1_arena = std::forward<T1>(v1);
34 arena_t<T2> v2_arena = std::forward<T2>(v2);
35
36 return make_callback_var(
38 [v1_arena, v2_arena](const vari_value<matrix_cl<double>>& res) mutable {
39 adjoint_results(v1_arena, v2_arena) += expressions(
40 elt_multiply(rowwise_broadcast(res.adj()), value_of(v2_arena)),
41 elt_multiply(rowwise_broadcast(res.adj()), value_of(v1_arena)));
42 });
43}
44
45} // namespace math
46} // namespace stan
47
48#endif
49#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
auto rowwise_broadcast(T &&a)
Broadcast an expression in rowwise dimmension.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
adjoint_results_cl< T_results... > adjoint_results(T_results &&... results)
Deduces types for constructing adjoint_results_cl object.
var_value< plain_type_t< T > > make_callback_var(T &&value, F &&functor)
Creates a new var initialized with a callback_vari with a given value and reverse-pass callback funct...
auto rows_dot_product(T_a &&a, T_b &&b)
Returns the dot product of rows of the specified matrices.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
void check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Check if two structures at the same size.
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...