Automatic Differentiation
 
Loading...
Searching...
No Matches
trace_dot.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TRACE_DOT_HPP
2#define STAN_MATH_PRIM_FUN_TRACE_DOT_HPP
3
7
8namespace stan {
9namespace math {
10
28template <typename EigMat1, typename EigMat2,
29 require_all_eigen_vt<std::is_arithmetic, EigMat1, EigMat2>* = nullptr>
30inline auto trace_dot(EigMat1&& A, EigMat2&& B) {
31 check_size_match("trace_dot", "A.cols()", A.cols(), "B.rows()", B.rows());
32 check_size_match("trace_dot", "A.rows()", A.rows(), "B.cols()", B.cols());
33 return make_holder(
34 [](auto&& A_, auto&& B_) {
35 return A_.cwiseProduct(B_.transpose()).sum();
36 },
37 std::forward<EigMat1>(A), std::forward<EigMat2>(B));
38}
39
40} // namespace math
41} // namespace stan
42
43#endif
return_type_t< EigMat1, EigMat2 > trace_dot(EigMat1 &&A, EigMat2 &&B)
Compute the trace of the product of two matrices with forward-mode autodiff support.
Definition trace_dot.hpp:29
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
Definition holder.hpp:437
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...