1#ifndef STAN_MATH_OPENCL_REV_DIAG_POST_MULTIPLY_HPP
2#define STAN_MATH_OPENCL_REV_DIAG_POST_MULTIPLY_HPP
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>
40 if (v2_arena.rows() == 1) {
42 = elt_multiply(res.adj(), colwise_broadcast(value_of(v2_arena)));
44 = colwise_sum(elt_multiply(res.adj(), value_of(v1_arena)));
45 matrix_cl<double> tmp;
46 auto&& v1_adj = adjoint_of(v1_arena);
47 results(v1_adj, tmp) = expressions(
48 calc_if<!is_constant<std::decay_t<T1>>::value>(v1_adj
50 calc_if<!is_constant<std::decay_t<T2>>::value>(v2_adj_inc));
52 if (!is_constant<std::decay_t<T2>>::value) {
53 while (tmp.rows() > 1) {
54 tmp = eval(colwise_sum(tmp));
56 adjoint_of(v2_arena) += tmp;
70 while (tmp.
rows() > 1) {
Represents an arithmetic matrix on the OpenCL device.
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
auto transpose(Arg &&a)
Transposes a kernel generator expression.
calc_if_< true, as_operation_cl_t< T > > calc_if(T &&a)
auto colwise_broadcast(T &&a)
Broadcast an expression in colwise dimmension.
auto colwise_sum(T &&a)
Column wise sum - reduction of a kernel generator expression.
expressions_cl< T_expressions... > expressions(T_expressions &&... expressions)
Deduces types for constructing expressions_cl object.
auto diag_post_multiply(const T1 &m1, const T2 &m2)
Return the product of a matrix and the diagonal matrix formed from the vector or row_vector.
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 & adjoint_of(const T &x)
Returns a reference to a variable's adjoint.
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
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 ...
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...