Automatic Differentiation
 
Loading...
Searching...
No Matches
add_diag.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_ADD_DIAG_HPP
2#define STAN_MATH_OPENCL_PRIM_ADD_DIAG_HPP
3#ifdef STAN_OPENCL
8
9namespace stan {
10namespace math {
11
24template <typename T_m, typename T_a,
25 require_all_kernel_expressions_and_none_scalar_t<T_m>* = nullptr,
26 require_all_kernel_expressions_t<T_a>* = nullptr>
27inline auto add_diag(T_m&& mat, T_a&& to_add) { // NOLINT
29 const size_t length_diag = std::min(mat.rows(), mat.cols());
30 check_consistent_sizes("add_diag (OpenCL)", "number of elements of to_add",
31 to_add, "diagonal", length_diag);
32 }
33 matrix_cl<value_type_t<T_m>> mat_eval = mat;
34 diagonal(mat_eval) = diagonal(mat_eval) + to_add;
35 return mat_eval;
36}
37} // namespace math
38} // namespace stan
39
40#endif
41#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
auto diagonal(T &&a)
Diagonal of a kernel generator expression.
Definition diagonal.hpp:136
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
auto add_diag(T_m &&mat, T_a &&to_add)
Returns a Matrix with values added along the main diagonal.
Definition add_diag.hpp:27
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Checks if decayed type is a var, fvar, or arithmetic.