Automatic Differentiation
 
Loading...
Searching...
No Matches
columns_dot_self.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_COLUMNS_DOT_SELF_HPP
2#define STAN_MATH_OPENCL_REV_COLUMNS_DOT_SELF_HPP
3#ifdef STAN_OPENCL
4
10
11namespace stan {
12namespace math {
13
20template <typename T,
21 require_all_kernel_expressions_and_none_scalar_t<T>* = nullptr>
23 if (size_zero(v)) {
24 return var_value<matrix_cl<double>>(constant(0.0, 1, v.cols()));
25 }
26
27 return make_callback_var(
28 columns_dot_self(v.val()),
29 [v](const vari_value<matrix_cl<double>>& res) mutable {
30 v.adj()
31 += elt_multiply(colwise_broadcast(res.adj() * 2.0), value_of(v));
32 });
33}
34
35} // namespace math
36} // namespace stan
37
38#endif
39#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
Definition constant.hpp:130
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Definition size_zero.hpp:19
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 columns_dot_self(const T &a)
Returns the dot product of each column of a matrix with itself.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...