Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs 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 #include <boost/type_traits/common_type.hpp>
10 
11 namespace stan {
12  namespace math {
13 
26  template <typename T_y, typename T_result, class Policy>
27  inline bool check_symmetric(const char* function,
28  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
29  const char* name,
30  T_result* result,
31  const Policy&) {
32  typedef
34  size_type;
35  size_type k = y.rows();
36  if (k == 1)
37  return true;
38  for (size_type m = 0; m < k; ++m) {
39  for (size_type n = m + 1; n < k; ++n) {
40  if (fabs(y(m,n) - y(n,m)) > CONSTRAINT_TOLERANCE) {
41  std::ostringstream message;
42  message << name << " is not symmetric. "
43  << name << "[" << m << "," << n << "] is %1%, but "
44  << name << "[" << n << "," << m
45  << "] element is " << y(n,m);
46  T_result tmp
47  = policies::raise_domain_error<T_y>(function,
48  message.str().c_str(),
49  y(m,n), Policy());
50  if (result != 0)
51  *result = tmp;
52  return false;
53  }
54  }
55  }
56  return true;
57  }
58 
59 
60  template <typename T_y, typename T_result>
61  inline bool check_symmetric(const char* function,
62  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
63  const char* name,
64  T_result* result) {
65  return check_symmetric(function,y,name,result,default_policy());
66  }
67 
68  template <typename T>
69  inline bool check_symmetric(const char* function,
70  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>& y,
71  const char* name,
72  T* result = 0) {
73  return check_symmetric(function,y,name,result,default_policy());
74  }
75 
76  }
77 }
78 #endif

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