Automatic Differentiation
 
Loading...
Searching...
No Matches
dot_product.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_DOT_PRODUCT_HPP
2#define STAN_MATH_OPENCL_REV_DOT_PRODUCT_HPP
3#ifdef STAN_OPENCL
4
10
11namespace stan {
12namespace math {
13
25template <
26 typename T1, typename T2, require_any_var_t<T1, T2>* = nullptr,
27 require_all_nonscalar_prim_or_rev_kernel_expression_t<T1, T2>* = nullptr>
28inline var dot_product(T1&& v1, T2&& v2) {
29 arena_t<T1> v1_arena = std::forward<T1>(v1);
30 arena_t<T2> v2_arena = std::forward<T2>(v2);
31
32 return make_callback_var(dot_product(value_of(v1_arena), value_of(v2_arena)),
33 [v1_arena, v2_arena](vari& res) mutable {
34 adjoint_results(v1_arena, v2_arena)
35 += expressions(res.adj() * value_of(v2_arena),
36 res.adj() * value_of(v1_arena));
37 });
38}
39
40} // namespace math
41} // namespace stan
42
43#endif
44#endif
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...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
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 ...