Stan Math Library  2.20.0
reverse mode automatic differentiation
is_symmetric.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_IS_SYMMETRIC_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_IS_SYMMETRIC_HPP
3 
9 
10 namespace stan {
11 namespace math {
20 template <typename T_y>
21 inline bool is_symmetric(
22  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
23  if (!is_square(y))
24  return false;
25 
26  typedef typename index_type<
27  Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>>::type size_type;
28 
29  size_type k = y.rows();
30  if (k == 1)
31  return true;
32  for (size_type m = 0; m < k; ++m) {
33  for (size_type n = m + 1; n < k; ++n) {
34  if (!(fabs(value_of(y(m, n)) - value_of(y(n, m)))
36  return false;
37  }
38  }
39  return true;
40 }
41 
42 } // namespace math
43 } // namespace stan
44 #endif
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:17
bool is_square(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the matrix is square.
Definition: is_square.hpp:20
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:11
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
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.

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