Automatic Differentiation
 
Loading...
Searching...
No Matches
tcrossprod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_TCROSSPROD_HPP
2#define STAN_MATH_FWD_FUN_TCROSSPROD_HPP
3
9
10namespace stan {
11namespace math {
12
13template <typename EigMat, require_eigen_vt<is_fvar, EigMat>* = nullptr>
14inline Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime,
15 EigMat::RowsAtCompileTime>
16tcrossprod(const EigMat& m) {
17 if (m.rows() == 0) {
18 return {};
19 }
20 const auto& m_ref = to_ref(m);
21 auto ret = multiply(m_ref, m_ref.transpose());
22 if constexpr (is_stan_scalar<decltype(ret)>::value) {
23 return Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime,
24 EigMat::RowsAtCompileTime>{{ret}};
25 } else {
26 return ret;
27 }
28}
29
30} // namespace math
31} // namespace stan
32#endif
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > tcrossprod(const EigMat &m)
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
Definition multiply.hpp:19
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Checks if decayed type is a var, fvar, or arithmetic.