All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
check_symmetric.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_SYMMETRIC_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_SYMMETRIC_HPP
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/err/constraint_tolerance.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/mat/fun/value_of.hpp>
#include <stan/math/prim/scal/meta/error_index.hpp>
#include <sstream>
#include <string>
namespace stan {
namespace math {
using Eigen::Dynamic;
template <typename T_y>
inline bool
check_symmetric(const char* function,
const char* name,
const Eigen::Matrix<T_y, Dynamic, Dynamic>& y) {
check_square(function, name, y);
using Eigen::Matrix;
using stan::math::index_type;
using std::fabs;
typedef typename index_type<Matrix<T_y, Dynamic, Dynamic> >::type
size_type;
size_type k = y.rows();
if (k == 1)
return true;
for (size_type m = 0; m < k; ++m) {
for (size_type n = m + 1; n < k; ++n) {
if (!(fabs(value_of(y(m, n)) - value_of(y(n, m)))
<= CONSTRAINT_TOLERANCE)) {
std::ostringstream msg1;
msg1 << "is not symmetric. "
<< name << "[" << stan::error_index::value + m << ","
<< stan::error_index::value +n << "] = ";
std::string msg1_str(msg1.str());
std::ostringstream msg2;
msg2 << ", but "
<< name << "[" << stan::error_index::value +n << ","
<< stan::error_index::value + m
<< "] = " << y(n, m);
std::string msg2_str(msg2.str());
domain_error(function, name, y(m, n),
msg1_str.c_str(), msg2_str.c_str());
return false;
}
}
}
return true;
}
}
}
#endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
stan::math::value_of
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:38
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_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–2015, Stan Development Team.