Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ trace_dot() [2/3]

template<typename EigMat1 , typename EigMat2 , require_all_eigen_vt< std::is_arithmetic, EigMat1, EigMat2 > * = nullptr>
auto stan::math::trace_dot ( EigMat1 &&  A,
EigMat2 &&  B 
)
inline

Compute the trace of the product of two matrices, \( \text{tr}(A \cdot B) = \sum_{i,j} A_{ij} B_{ji} \).

This is more efficient than computing the full product and taking the trace, as it avoids forming the intermediate matrix.

Template Parameters
EigMat1A type either inheriting from Eigen::DenseBase or a var_value with an inner type inheriting from Eigen::DenseBase
EigMat2A type either inheriting from Eigen::DenseBase or a var_value with an inner type inheriting from Eigen::DenseBase
Parameters
Afirst matrix (m x n)
Bsecond matrix (n x m)
Returns
trace of A * B
Exceptions
std::invalid_argumentif A and B have incompatible dimensions

Definition at line 30 of file trace_dot.hpp.