1 #ifndef STAN_MATH_PRIM_FUN_INVERSE_HPP 2 #define STAN_MATH_PRIM_FUN_INVERSE_HPP 3 4 #include <stan/math/prim/meta.hpp> 5 #include <stan/math/prim/err.hpp> 6 #include <stan/math/prim/fun/Eigen.hpp> 7 8 namespace stan { 9 namespace math { 10 11 /** 12 * Returns the inverse of the specified matrix. 13 * 14 * @tparam T type of elements in the matrix 15 * @tparam R number of rows, can be Eigen::Dynamic 16 * @tparam C number of columns, can be Eigen::Dynamic 17 * 18 * @param m specified matrix 19 * @return Inverse of the matrix (an empty matrix if the specified matrix has 20 * size zero). 21 * @throw std::invalid_argument if the matrix is not square. 22 */ 23 template <typename EigMat, 24 require_eigen_vt<std::is_arithmetic, EigMat>* = nullptr> 25 inline Eigen::Matrix<value_type_t<EigMat>, EigMat::RowsAtCompileTime, 26 EigMat::ColsAtCompileTime> inverse(const EigMat & m)27inverse(const EigMat& m) { 28 check_square("inverse", "m", m); 29 if (m.size() == 0) { 30 return {}; 31 } 32 return m.inverse(); 33 } 34 35 } // namespace math 36 } // namespace stan 37 38 #endif 39