Stan Math Library  2.20.0
reverse mode automatic differentiation
is_corr_matrix.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_IS_CORR_MATRIX_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_IS_CORR_MATRIX_HPP
3 
11 
12 namespace stan {
13 namespace math {
14 
28 template <typename T_y>
29 inline bool is_corr_matrix(
30  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
31  typedef typename index_type<
32  Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic> >::type size_t;
33 
34  if (!is_size_match(y.rows(), y.cols()))
35  return false;
36  if (!is_positive(y.rows()))
37  return false;
38  if (!is_pos_definite(y))
39  return false;
40  if (is_symmetric(y)) {
41  for (size_t k = 0; k < y.rows(); ++k) {
42  if (!(fabs(y(k, k) - 1.0) <= CONSTRAINT_TOLERANCE))
43  return false;
44  }
45  }
46  return true;
47 }
48 
49 } // namespace math
50 } // namespace stan
51 #endif
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
bool is_positive(const T_y &y)
Return true if y is positive.
Definition: is_positive.hpp:18
bool is_pos_definite(const Eigen::Matrix< T_y, -1, -1 > &y)
Return true if the matrix is square or if the matrix has non-zero size, or if the matrix is symmetric...
bool is_symmetric(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the matrix is square, and no element not on the main diagonal is NaN.
bool is_size_match(T_size1 i, T_size2 j)
Return true if the provided sizes match.
bool is_corr_matrix(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the matrix is square and not 0x0, if the matrix is symmetric, diagonals are near 1...

     [ Stan Home Page ] © 2011–2018, Stan Development Team.