Stan Math Library  2.15.0
reverse mode automatic differentiation
check_symmetric.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_SYMMETRIC_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_SYMMETRIC_HPP
3 
11 #include <sstream>
12 #include <string>
13 
14 namespace stan {
15  namespace math {
16 
33  template <typename T_y>
34  inline void
35  check_symmetric(const char* function,
36  const char* name,
37  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
38  check_square(function, name, y);
39 
40  using Eigen::Matrix;
41  using std::fabs;
42  using Eigen::Dynamic;
43 
44  typedef typename index_type<Matrix<T_y, Dynamic, Dynamic> >::type
45  size_type;
46 
47  size_type k = y.rows();
48  if (k == 1)
49  return;
50  for (size_type m = 0; m < k; ++m) {
51  for (size_type n = m + 1; n < k; ++n) {
52  if (!(fabs(value_of(y(m, n)) - value_of(y(n, m)))
54  std::ostringstream msg1;
55  msg1 << "is not symmetric. "
56  << name << "[" << stan::error_index::value + m << ","
57  << stan::error_index::value +n << "] = ";
58  std::string msg1_str(msg1.str());
59  std::ostringstream msg2;
60  msg2 << ", but "
61  << name << "[" << stan::error_index::value +n << ","
63  << "] = " << y(n, m);
64  std::string msg2_str(msg2.str());
65  domain_error(function, name, y(m, n),
66  msg1_str.c_str(), msg2_str.c_str());
67  }
68  }
69  }
70  }
71 
72  }
73 }
74 #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:16
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:13
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
void check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is symmetric.
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.

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