Stan Math Library  2.20.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 
10 #include <sstream>
11 #include <string>
12 
13 namespace stan {
14 namespace math {
15 
28 template <typename T_y>
29 inline void check_symmetric(
30  const char* function, const char* name,
31  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
32  check_square(function, name, y);
33 
34  typedef typename index_type<
35  Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic> >::type size_type;
36 
37  size_type k = y.rows();
38  if (k == 1)
39  return;
40  for (size_type m = 0; m < k; ++m) {
41  for (size_type n = m + 1; n < k; ++n) {
42  if (!(fabs(value_of(y(m, n)) - value_of(y(n, m)))
44  std::ostringstream msg1;
45  msg1 << "is not symmetric. " << name << "["
46  << stan::error_index::value + m << ","
47  << stan::error_index::value + n << "] = ";
48  std::string msg1_str(msg1.str());
49  std::ostringstream msg2;
50  msg2 << ", but " << name << "[" << stan::error_index::value + n << ","
51  << stan::error_index::value + m << "] = " << y(n, m);
52  std::string msg2_str(msg2.str());
53  domain_error(function, name, y(m, n), msg1_str.c_str(),
54  msg2_str.c_str());
55  }
56  }
57  }
58 }
59 
60 } // namespace math
61 } // namespace stan
62 #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
void check_square(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is square.
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
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_symmetric(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl is symmetric.

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