Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_size_match.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SIZE_MATCH_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_SIZE_MATCH_HPP__
3 
4 #include <sstream>
5 #include <boost/type_traits/common_type.hpp>
8 
9 namespace stan {
10  namespace math {
11 
12  // FIXME: update warnings
13  template <typename T_size1, typename T_size2, typename T_result,
14  class Policy>
15  inline bool check_size_match(const char* function,
16  T_size1 i,
17  const char* name_i,
18  T_size2 j,
19  const char* name_j,
20  T_result* result,
21  const Policy&) {
23  typedef typename boost::common_type<T_size1,T_size2>::type common_type;
24  if (static_cast<common_type>(i) != static_cast<common_type>(j)) {
25  std::ostringstream msg;
26  msg << name_i << " (%1%) and " << name_j << " (" << j << ") must match in size";
27  T_result tmp = policies::raise_domain_error<T_result,T_size1>(function,
28  msg.str().c_str(),
29  i, Policy());
30  if (result != 0)
31  *result = tmp;
32  return false;
33  }
34  return true;
35  }
36 
37  template <typename T_size1, typename T_size2, typename T_result>
38  inline
39  bool check_size_match(const char* function,
40  T_size1 i,
41  const char* name_i,
42  T_size2 j,
43  const char* name_j,
44  T_result* result) {
45  return check_size_match(function,i,name_i,j,name_j,result,default_policy());
46  }
47 
48  template <typename T_size1, typename T_size2>
49  inline
50  bool check_size_match(const char* function,
51  T_size1 i,
52  const char* name_i,
53  T_size2 j,
54  const char* name_j,
55  T_size1* result = 0) {
56  return check_size_match(function,i,name_i,j,name_j,result,default_policy());
57  }
58 
59  }
60 }
61 #endif

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