Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
validate_symmetric.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__VALIDATE_SYMMETRIC_HPP__
2 #define __STAN__MATH__MATRIX__VALIDATE_SYMMETRIC_HPP__
3 
4 #include <sstream>
5 #include <stdexcept>
8 
9 namespace stan {
10  namespace math {
11 
12  template <typename T, int R, int C>
13  void validate_symmetric(const Eigen::Matrix<T,R,C>& x,
14  const char* msg) {
15  // tolerance = 1E-8
16  validate_square(x,msg);
17  for (int i = 0; i < x.rows(); ++i) {
18  for (int j = 0; j < x.cols(); ++j) {
19  if (x(i,j) != x(j,i)) {
20  std::stringstream ss;
21  ss << "error in call to " << msg
22  << "; require symmetric matrix, but found"
23  << "; x[" << i << "," << j << "]=" << x(i,j)
24  << "; x[" << j << "," << i << "]=" << x(j,i);
25  throw std::domain_error(ss.str());
26  }
27  }
28  }
29  }
30 
31  }
32 }
33 #endif

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