Automatic Differentiation
 
Loading...
Searching...
No Matches
tcrossprod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TCROSSPROD_HPP
2#define STAN_MATH_PRIM_FUN_TCROSSPROD_HPP
3
8
9namespace stan {
10namespace math {
11
20template <typename T, require_eigen_vt<std::is_arithmetic, T>* = nullptr>
21inline Eigen::Matrix<value_type_t<T>, T::RowsAtCompileTime,
22 T::RowsAtCompileTime>
23tcrossprod(const T& M) {
24 if (M.rows() == 0) {
25 return {};
26 }
27 const auto& M_ref = to_ref(M);
28 if (M.rows() == 1) {
29 return M_ref * M_ref.transpose();
30 }
31 Eigen::Matrix<value_type_t<T>, T::RowsAtCompileTime, T::RowsAtCompileTime>
32 result(M.rows(), M.rows());
33 return result.setZero().template selfadjointView<Eigen::Upper>().rankUpdate(
34 M_ref);
35}
36
37} // namespace math
38} // namespace stan
39
40#endif
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > tcrossprod(const EigMat &m)
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 ...
Definition fvar.hpp:9