Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_symmetric.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SYMMETRIC_HPP
2 #define STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SYMMETRIC_HPP
3 
4 #include <sstream>
5 
10 #include <stan/meta/traits.hpp>
11 
12 namespace stan {
13 
14  namespace math {
15 
29  template <typename T_y, typename T_result>
30  inline bool
31  check_symmetric(const char* function,
32  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
33  const char* name,
34  T_result* result) {
35  using Eigen::Dynamic;
36  using Eigen::Matrix;
37  typedef typename index_type<Matrix<T_y,Dynamic,Dynamic> >::type size_type;
38 
39  size_type k = y.rows();
40  if (k == 1)
41  return true;
42  for (size_type m = 0; m < k; ++m) {
43  for (size_type n = m + 1; n < k; ++n) {
44  if (!(fabs(y(m,n) - y(n,m)) <= CONSTRAINT_TOLERANCE)) {
45  std::ostringstream message;
46  message << name << " is not symmetric. "
47  << name << "[" << stan::error_index::value + m << ","
48  << stan::error_index::value +n << "] is %1%, but "
49  << name << "[" << stan::error_index::value +n << ","
51  << "] element is " << y(n,m);
52  std::string msg(message.str());
53  return dom_err(function,y(m,n),name,
54  msg.c_str(),"",
55  result);
56  }
57  }
58  }
59  return true;
60  }
61 
62  }
63 }
64 #endif
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:18
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool check_symmetric(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is symmetric.
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
index_type< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > >::type size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:16

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