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

◆ trace_dot() [3/3]

template<typename Mat1 , typename Mat2 , require_all_matrix_t< Mat1, Mat2 > * = nullptr, require_any_rev_matrix_t< Mat1, Mat2 > * = nullptr>
var stan::math::trace_dot ( Mat1 &&  A,
Mat2 &&  B 
)
inline

Compute the trace of the product of two matrices with autodiff support.

\( \text{tr}(A \cdot B) = \sum_{i,j} A_{ij} B_{ji} \)

The gradients are: \( \frac{\partial}{\partial A} \text{tr}(A B) = B^T \), \( \frac{\partial}{\partial B} \text{tr}(A B) = A^T \).

Template Parameters
Mat1A type either inheriting from Eigen::DenseBase or a var_value with an inner type inheriting from Eigen::DenseBase
Mat2A 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 36 of file trace_dot.hpp.