Automatic Differentiation
 
Loading...
Searching...
No Matches
add_diag.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_ADD_DIAG_HPP
2#define STAN_MATH_PRIM_FUN_ADD_DIAG_HPP
3
9#include <algorithm>
10
11namespace stan {
12namespace math {
13
25template <typename T_m, typename T_a, typename = require_eigen_t<T_m>,
26 typename = require_any_t<is_eigen_vector<T_a>, is_stan_scalar<T_a>>>
27inline typename Eigen::Matrix<return_type_t<T_m, T_a>, Eigen::Dynamic,
28 Eigen::Dynamic>
29add_diag(const T_m &mat, const T_a &to_add) {
31 const size_t length_diag = std::min(mat.rows(), mat.cols());
32 check_consistent_size("add_diag", "number of elements of to_add", to_add,
33 length_diag);
34 }
35 Eigen::Matrix<return_type_t<T_m, T_a>, Eigen::Dynamic, Eigen::Dynamic> out
36 = mat;
37 out.diagonal().array()
39 return out;
40}
41
42} // namespace math
43} // namespace stan
44
45#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
T as_array_or_scalar(T &&v)
Returns specified input value.
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if x is consistent with size expected_size.
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 ...
Definition fvar.hpp:9
If the input type T is either an eigen matrix with 1 column or 1 row at compile time or a standard ve...