Automatic Differentiation
 
Loading...
Searching...
No Matches
mdivide_right_tri_low.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_REV_MDIVIDE_RIGHT_TRI_LOW_HPP
2#define STAN_MATH_OPENCL_REV_MDIVIDE_RIGHT_TRI_LOW_HPP
3#ifdef STAN_OPENCL
4
11
12namespace stan {
13namespace math {
14
26template <
27 typename T1, typename T2,
28 require_all_nonscalar_prim_or_rev_kernel_expression_t<T1, T2>* = nullptr,
29 require_any_var_t<T1, T2>* = nullptr>
31 check_square("mdivide_right_tri_low", "A", A);
32 check_multiplicable("mdivide_right_tri_low", "b", b, "A", A);
33 if (A.size() == 0 || b.size() == 0) {
34 return var_value<matrix_cl<double>>(matrix_cl<double>(b.rows(), A.cols()));
35 }
36 arena_t<T1> A_arena = std::forward<T1>(A);
37 arena_t<T2> b_arena = std::forward<T2>(b);
39 = tri_inverse<matrix_cl_view::Lower>(value_of(A_arena));
40 return make_callback_var(
41 value_of(b_arena) * A_tri_inv,
42 [A_arena, b_arena, A_tri_inv](const vari_value<matrix_cl<double>>& res) {
43 matrix_cl<double> adjB = res.adj() * transpose(A_tri_inv);
45 matrix_cl<double> adjA = transpose(res.val()) * adjB;
47 adjoint_of(A_arena) -= adjA;
48 }
50 adjoint_of(b_arena) += adjB;
51 }
52 });
53}
54
55} // namespace math
56} // namespace stan
57
58#endif
59#endif
A variant of matrix_cl that schedules its destructor to be called, so it can be used on the AD stack.
const matrix_cl_view & view() const
Definition matrix_cl.hpp:70
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
auto transpose(Arg &&a)
Transposes a kernel generator expression.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
Eigen::Matrix< value_type_t< EigMat1 >, EigMat1::RowsAtCompileTime, EigMat2::ColsAtCompileTime > mdivide_right_tri_low(const EigMat1 &A, const EigMat2 &b)
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 value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
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 ...