| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/scal/err/domain_error.hpp>
5 #include <stan/math/prim/mat/err/check_square.hpp>
6 #include <stan/math/prim/mat/err/constraint_tolerance.hpp>
7 #include <stan/math/prim/mat/fun/Eigen.hpp>
8 #include <stan/math/prim/mat/meta/index_type.hpp>
9 #include <stan/math/prim/mat/fun/value_of.hpp>
10 #include <stan/math/prim/scal/meta/error_index.hpp>
11 #include <sstream>
12 #include <string>
13
14 namespace stan {
15
16 namespace math {
17
35 template <typename T_y>
36 inline bool
37 check_symmetric(
38 const char* function,
39 const char* name,
40 const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y
41 ) {
42 check_square(function, name, y);
43
44 using Eigen::Matrix;
45 using stan::math::index_type;
46 using std::fabs;
47 using Eigen::Dynamic;
48
49 typedef typename index_type<Matrix<T_y, Dynamic, Dynamic> >::type
50 size_type;
51
52 size_type k = y.rows();
53 if (k == 1)
54 return true;
55 for (size_type m = 0; m < k; ++m) {
56 for (size_type n = m + 1; n < k; ++n) {
57 if (!(fabs(value_of(y(m, n)) - value_of(y(n, m)))
58 <= CONSTRAINT_TOLERANCE)) {
59 std::ostringstream msg1;
60 msg1 << "is not symmetric. "
61 << name << "[" << stan::error_index::value + m << ","
62 << stan::error_index::value +n << "] = ";
63 std::string msg1_str(msg1.str());
64 std::ostringstream msg2;
65 msg2 << ", but "
66 << name << "[" << stan::error_index::value +n << ","
67 << stan::error_index::value + m
68 << "] = " << y(n, m);
69 std::string msg2_str(msg2.str());
70 domain_error(function, name, y(m, n),
71 msg1_str.c_str(), msg2_str.c_str());
72 return false;
73 }
74 }
75 }
76 return true;
77 }
78
79 }
80 }
81 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
constraint_tolerance.hpp
stan::math::CONSTRAINT_TOLERANCE
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Definition: constraint_tolerance.hpp:11
stan::math::size_type
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
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
index_type.hpp
stan::error_index::value
Definition: error_index.hpp:7
stan::math::domain_error
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.
Definition: domain_error.hpp:32
Eigen.hpp
value_of.hpp
domain_error.hpp
error_index.hpp
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:37
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
check_square.hpp

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