![]() |
Stan Math Library
5.3.0
Automatic Differentiation
|
|
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 \).
| Mat1 | A type either inheriting from Eigen::DenseBase or a var_value with an inner type inheriting from Eigen::DenseBase |
| Mat2 | A type either inheriting from Eigen::DenseBase or a var_value with an inner type inheriting from Eigen::DenseBase |
| A | first matrix (m x n) |
| B | second matrix (n x m) |
| std::invalid_argument | if A and B have incompatible dimensions |
Definition at line 36 of file trace_dot.hpp.