Stan  1.0
probability, sampling & optimization
error_handling.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING_HPP__
2 #define __STAN__MATH__ERROR_HANDLING_HPP__
3 
4 #include <algorithm>
5 #include <cstddef>
6 #include <limits>
7 #include <utility>
8 #include <iostream>
9 
10 #include <boost/math/policies/policy.hpp>
11 #include <boost/type_traits/is_unsigned.hpp>
12 
13 #include <stan/meta/traits.hpp>
15 
16 namespace stan {
17 
18  namespace math {
19 
24  const double CONSTRAINT_TOLERANCE = 1E-8;
25 
26 
30  typedef boost::math::policies::policy<> default_policy;
31 
32  namespace {
33 
34  // local output stream for pairs
35  template <typename T1, typename T2>
36  std::ostream& operator<<(std::ostream& o,
37  std::pair<T1,T2> xs) {
38  o << '(' << xs.first << ", " << xs.second << ')';
39  return o;
40  }
41 
42  template <typename T_y,
43  typename T_result,
44  typename T_msg2,
45  class Policy>
46  inline bool dom_err(const char* function,
47  const T_y& y,
48  const char* name,
49  const char* error_msg,
50  T_msg2 error_msg2,
51  T_result* result,
52  const Policy&) {
54  std::ostringstream msg_o;
55  msg_o << name << error_msg << error_msg2;
56  T_result tmp = raise_domain_error<T_result,T_y>(function,
57  msg_o.str().c_str(),
58  y,
59  Policy());
60  if (result != 0)
61  *result = tmp;
62  return false;
63  }
64 
65  template <typename T_y,
66  typename T_result,
67  typename T_msg2,
68  class Policy>
69  inline bool dom_err_vec(size_t i,
70  const char* function,
71  const T_y& y,
72  const char* name,
73  const char* error_msg,
74  T_msg2 error_msg2,
75  T_result* result,
76  const Policy&) {
78  std::ostringstream msg_o;
79  msg_o << name << "[" << i << "] " << error_msg << error_msg2;
80  T_result tmp = raise_domain_error<T_result,typename T_y::value_type>(function,
81  msg_o.str().c_str(),
82  y[i],
83  Policy());
84  if (result != 0)
85  *result = tmp;
86  return false;
87  }
88  } // end anon namespace
89 
90  namespace {
91  template <typename T_y,
92  typename T_result,
93  class Policy,
94  bool is_vec>
95  struct not_nan {
96  static bool check(const char* function,
97  const T_y& y,
98  const char* name,
99  T_result* result,
100  const Policy&) {
101  if ((boost::math::isnan)(y))
102  return dom_err(function,y,name,
103  " is %1%, but must not be nan!","",
104  result,Policy());
105  return true;
106  }
107  };
108 
109  template <typename T_y,
110  typename T_result,
111  class Policy>
112  struct not_nan<T_y, T_result, Policy, true> {
113  static bool check(const char* function,
114  const T_y& y,
115  const char* name,
116  T_result* result,
117  const Policy&) {
118  // using stan::length;
119  for (size_t n = 0; n < stan::length(y); n++) {
120  if ((boost::math::isnan)(y[n]))
121  return dom_err_vec(n,function,y,name,
122  " is %1%, but must not be nan!","",
123  result,Policy());
124  }
125  return true;
126  }
127  };
128  }
129 
141  template <typename T_y,
142  typename T_result,
143  class Policy>
144  inline bool check_not_nan(const char* function,
145  const T_y& y,
146  const char* name,
147  T_result* result,
148  const Policy&) {
149  return not_nan<T_y,T_result,Policy,is_vector<T_y>::value>::check(function, y, name, result, Policy());
150  }
151 
163  template <typename T_y,
164  typename T_result>
165  inline bool check_not_nan(const char* function,
166  const T_y& y,
167  const char* name,
168  T_result* result = 0) {
169  return check_not_nan(function,y,name,result,default_policy());
170  }
171  // need this sig to infer types for result from type of y
172  template <typename T>
173  inline bool check_not_nan(const char* function,
174  const T& y,
175  const char* name) {
176  return check_not_nan<T, typename scalar_type<T>::type *>
177  (function,y,name,0,default_policy());
178  }
179 
180 
181  namespace {
182  template <typename T_y,
183  typename T_result,
184  class Policy,
185  bool is_vec>
186  struct finite {
187  static bool check(const char* function,
188  const T_y& y,
189  const char* name,
190  T_result* result,
191  const Policy&) {
192  if (!(boost::math::isfinite)(y))
193  return dom_err(function,y,name,
194  " is %1%, but must be finite!","",
195  result,Policy());
196  return true;
197  }
198  };
199 
200  template <typename T_y,
201  typename T_result,
202  class Policy>
203  struct finite<T_y, T_result, Policy, true> {
204  static bool check(const char* function,
205  const T_y& y,
206  const char* name,
207  T_result* result,
208  const Policy&) {
209  using stan::length;
210  for (size_t n = 0; n < length(y); n++) {
211  if (!(boost::math::isfinite)(y[n]))
212  return dom_err_vec(n,function,y,name,
213  " is %1%, but must be finite!","",
214  result,Policy());
215  }
216  return true;
217  }
218  };
219  }
223  template <typename T_y, typename T_result, class Policy>
224  inline bool check_finite(const char* function,
225  const T_y& y,
226  const char* name,
227  T_result* result,
228  const Policy&) {
229  return finite<T_y,T_result,Policy,is_vector<T_y>::value>::check(function, y, name, result, Policy());
230  }
231 
232  template <typename T_y, typename T_result>
233  inline bool check_finite(const char* function,
234  const T_y& y,
235  const char* name,
236  T_result* result) {
237  return check_finite(function,y,name,result,default_policy());
238  }
239 
240  template <typename T>
241  inline bool check_finite(const char* function,
242  const T& y,
243  const char* name) {
244  return check_finite<T,typename scalar_type<T>::type *>
245  (function,y,name,0,default_policy());
246  }
247 
248  namespace {
249  template <typename T_y,
250  typename T_low,
251  typename T_result,
252  class Policy,
253  bool is_vec>
254  struct greater {
255  static bool check(const char* function,
256  const T_y& y,
257  const T_low& low,
258  const char* name,
259  T_result* result,
260  const Policy&) {
261  using stan::length;
262  VectorView<const T_low> low_vec(low);
263  for (size_t n = 0; n < length(low); n++) {
264  if (!(y > low_vec[n]))
265  return dom_err(function,y,name,
266  " is %1%, but must be greater than ",
267  low_vec[n],result,Policy());
268  }
269  return true;
270  }
271  };
272 
273  template <typename T_y,
274  typename T_low,
275  typename T_result,
276  class Policy>
277  struct greater<T_y, T_low, T_result, Policy, true> {
278  static bool check(const char* function,
279  const T_y& y,
280  const T_low& low,
281  const char* name,
282  T_result* result,
283  const Policy&) {
284  using stan::length;
285  VectorView<const T_low> low_vec(low);
286  for (size_t n = 0; n < length(y); n++) {
287  if (!(y[n] > low_vec[n])) {
288  return dom_err_vec(n,function,y,name,
289  " is %1%, but must be greater than ",
290  low_vec[n],result,Policy());
291  }
292  }
293  return true;
294  }
295  };
296  }
297  template <typename T_y, typename T_low, typename T_result, class Policy>
298  inline bool check_greater(const char* function,
299  const T_y& y,
300  const T_low& low,
301  const char* name,
302  T_result* result,
303  const Policy&) {
304  return greater<T_y,T_low,T_result,Policy,
305  is_vector<T_y>::value>::check(function,y,low,name,result,Policy());
306  }
307  template <typename T_y, typename T_low, typename T_result>
308  inline bool check_greater(const char* function,
309  const T_y& y,
310  const T_low& low,
311  const char* name,
312  T_result* result) {
313  return check_greater(function,y,low,name,result,default_policy());
314  }
315  template <typename T_y, typename T_low>
316  inline bool check_greater(const char* function,
317  const T_y& y,
318  const T_low& low,
319  const char* name) {
320  return check_greater<T_y,T_low,typename scalar_type<T_y>::type *>
321  (function,y,low,name,0,default_policy());
322  }
323 
324  namespace {
325  template <typename T_y,
326  typename T_low,
327  typename T_result,
328  class Policy,
329  bool is_vec>
330  struct greater_or_equal {
331  static bool check(const char* function,
332  const T_y& y,
333  const T_low& low,
334  const char* name,
335  T_result* result,
336  const Policy&) {
337  using stan::length;
338  VectorView<const T_low> low_vec(low);
339  for (size_t n = 0; n < length(low); n++) {
340  if (!(y >= low_vec[n]))
341  return dom_err(function,y,name,
342  " is %1%, but must be greater than ",
343  low_vec[n],result,Policy());
344  }
345  return true;
346  }
347  };
348 
349  template <typename T_y,
350  typename T_low,
351  typename T_result,
352  class Policy>
353  struct greater_or_equal<T_y, T_low, T_result, Policy, true> {
354  static bool check(const char* function,
355  const T_y& y,
356  const T_low& low,
357  const char* name,
358  T_result* result,
359  const Policy&) {
360  using stan::length;
361  VectorView<const T_low> low_vec(low);
362  for (size_t n = 0; n < length(y); n++) {
363  if (!(y[n] >= low_vec[n]))
364  return dom_err_vec(n,function,y,name,
365  " is %1%, but must be greater than or equal to ",
366  low_vec[n],result,Policy());
367  }
368  return true;
369  }
370  };
371  }
372  template <typename T_y, typename T_low, typename T_result, class Policy>
373  inline bool check_greater_or_equal(const char* function,
374  const T_y& y,
375  const T_low& low,
376  const char* name,
377  T_result* result,
378  const Policy&) {
379  return greater_or_equal<T_y,T_low,T_result,Policy,is_vector<T_y>::value>::check(function,y,low,name,result,Policy());
380  }
381  template <typename T_y, typename T_low, typename T_result>
382  inline bool check_greater_or_equal(const char* function,
383  const T_y& y,
384  const T_low& low,
385  const char* name,
386  T_result* result) {
387  return check_greater_or_equal(function,y,low,name,result,
388  default_policy());
389  }
390  template <typename T_y, typename T_low>
391  inline bool check_greater_or_equal(const char* function,
392  const T_y& y,
393  const T_low& low,
394  const char* name) {
395  return check_greater_or_equal<T_y,T_low,typename scalar_type<T_y>::type *>
396  (function,y,low,name,0,default_policy());
397  }
398 
399  namespace {
400  template <typename T_y,
401  typename T_high,
402  typename T_result,
403  class Policy,
404  bool is_vec>
405  struct less {
406  static bool check(const char* function,
407  const T_y& y,
408  const T_high& high,
409  const char* name,
410  T_result* result,
411  const Policy&) {
412  using stan::length;
413  VectorView<const T_high> high_vec(high);
414  for (size_t n = 0; n < length(high); n++) {
415  if (!(y < high_vec[n]))
416  return dom_err(function,y,name,
417  " is %1%, but must be less than ",
418  high_vec[n],result,Policy());
419  }
420  return true;
421  }
422  };
423 
424  template <typename T_y,
425  typename T_high,
426  typename T_result,
427  class Policy>
428  struct less<T_y, T_high, T_result, Policy, true> {
429  static bool check(const char* function,
430  const T_y& y,
431  const T_high& high,
432  const char* name,
433  T_result* result,
434  const Policy&) {
435  using stan::length;
436  VectorView<const T_high> high_vec(high);
437  for (size_t n = 0; n < length(y); n++) {
438  if (!(y[n] < high_vec[n]))
439  return dom_err_vec(n,function,y,name,
440  " is %1%, but must be less than ",
441  high_vec[n],result,Policy());
442  }
443  return true;
444  }
445  };
446  }
447  template <typename T_y, typename T_high, typename T_result, class Policy>
448  inline bool check_less(const char* function,
449  const T_y& y,
450  const T_high& high,
451  const char* name,
452  T_result* result,
453  const Policy&) {
454  return less<T_y,T_high,T_result,Policy,is_vector<T_y>::value>::check(function,y,high,name,result,Policy());
455  }
456  template <typename T_y, typename T_high, typename T_result>
457  inline bool check_less(const char* function,
458  const T_y& y,
459  const T_high& high,
460  const char* name,
461  T_result* result) {
462  return check_less(function,y,high,name,result,default_policy());
463  }
464  template <typename T_y, typename T_high>
465  inline bool check_less(const char* function,
466  const T_y& y,
467  const T_high& high,
468  const char* name) {
469  return check_less<T_y,T_high,typename scalar_type<T_y>::type *>
470  (function,y,high,name,0,default_policy());
471  }
472 
473  namespace {
474  template <typename T_y,
475  typename T_high,
476  typename T_result,
477  class Policy,
478  bool is_vec>
479  struct less_or_equal {
480  static bool check(const char* function,
481  const T_y& y,
482  const T_high& high,
483  const char* name,
484  T_result* result,
485  const Policy&) {
486  using stan::length;
487  VectorView<const T_high> high_vec(high);
488  for (size_t n = 0; n < length(high); n++) {
489  if (!(y <= high_vec[n]))
490  return dom_err(function,y,name,
491  " is %1%, but must be less than or equal to ",
492  high_vec[n],result,Policy());
493  }
494  return true;
495  }
496  };
497 
498  template <typename T_y,
499  typename T_high,
500  typename T_result,
501  class Policy>
502  struct less_or_equal<T_y, T_high, T_result, Policy, true> {
503  static bool check(const char* function,
504  const T_y& y,
505  const T_high& high,
506  const char* name,
507  T_result* result,
508  const Policy&) {
509  using stan::length;
510  VectorView<const T_high> high_vec(high);
511  for (size_t n = 0; n < length(y); n++) {
512  if (!(y[n] <= high_vec[n]))
513  return dom_err_vec(n,function,y,name,
514  " is %1%, but must be less than or equal to ",
515  high_vec[n],result,Policy());
516  }
517  return true;
518  }
519  };
520  }
521  template <typename T_y, typename T_high, typename T_result, class Policy>
522  inline bool check_less_or_equal(const char* function,
523  const T_y& y,
524  const T_high& high,
525  const char* name,
526  T_result* result,
527  const Policy&) {
528  return less_or_equal<T_y,T_high,T_result,Policy,is_vector<T_y>::value>::check(function,y,high,name,result,Policy());
529  }
530  template <typename T_y, typename T_high, typename T_result>
531  inline bool check_less_or_equal(const char* function,
532  const T_y& y,
533  const T_high& high,
534  const char* name,
535  T_result* result) {
536  return check_less_or_equal(function,y,high,name,result,default_policy());
537  }
538  template <typename T_y, typename T_high>
539  inline bool check_less_or_equal(const char* function,
540  const T_y& y,
541  const T_high& high,
542  const char* name) {
543  return check_less_or_equal<T_y,T_high,typename scalar_type<T_y>::type *>
544  (function,y,high,name,0,default_policy());
545  }
546 
547  namespace {
548  template <typename T_y,
549  typename T_low,
550  typename T_high,
551  typename T_result,
552  class Policy,
553  bool is_vec>
554  struct bounded {
555  static bool check(const char* function,
556  const T_y& y,
557  const T_low& low,
558  const T_high& high,
559  const char* name,
560  T_result* result,
561  const Policy&) {
562  using stan::length;
563  using stan::max_size;
564  VectorView<const T_low> low_vec(low);
565  VectorView<const T_high> high_vec(high);
566  for (size_t n = 0; n < max_size(low, high); n++) {
567  if (!(low_vec[n] <= y && y <= high_vec[n]))
568  return dom_err(function,y,name," is %1%, but must be between ",
569  std::pair<typename scalar_type<T_low>::type, typename scalar_type<T_high>::type>(low_vec[n],high_vec[n]),
570  result,Policy());
571  }
572  return true;
573  }
574  };
575 
576  template <typename T_y,
577  typename T_low,
578  typename T_high,
579  typename T_result,
580  class Policy>
581  struct bounded<T_y, T_low, T_high, T_result, Policy, true> {
582  static bool check(const char* function,
583  const T_y& y,
584  const T_low& low,
585  const T_high& high,
586  const char* name,
587  T_result* result,
588  const Policy&) {
589  using stan::length;
590  VectorView<const T_low> low_vec(low);
591  VectorView<const T_high> high_vec(high);
592  for (size_t n = 0; n < length(y); n++) {
593  if (!(low_vec[n] <= y[n] && y[n] <= high_vec[n]))
594  return dom_err_vec(n,function,y,name,
595  " is %1%, but must be between ",
596  std::pair<typename scalar_type<T_low>::type, typename scalar_type<T_high>::type>(low_vec[n],high_vec[n]),
597  result,Policy());
598  }
599  return true;
600  }
601  };
602  }
603  template <typename T_y, typename T_low, typename T_high, typename T_result, class Policy>
604  inline bool check_bounded(const char* function,
605  const T_y& y,
606  const T_low& low,
607  const T_high& high,
608  const char* name,
609  T_result* result,
610  const Policy&) {
611  return bounded<T_y,T_low,T_high,T_result,Policy,is_vector<T_y>::value>::check(function,y,low,high,name,result,Policy());
612  }
613  template <typename T_y, typename T_low, typename T_high, typename T_result>
614  inline bool check_bounded(const char* function,
615  const T_y& y,
616  const T_low& low,
617  const T_high& high,
618  const char* name,
619  T_result* result) {
620  return check_bounded(function,y,low,high,name,result,default_policy());
621  }
622  template <typename T_y, typename T_low, typename T_high>
623  inline bool check_bounded(const char* function,
624  const T_y& y,
625  const T_low& low,
626  const T_high& high,
627  const char* name) {
628  return check_bounded<T_y,T_low,T_high,typename scalar_type<T_y>::type *>
629  (function,y,low,high,name,0,default_policy());
630  }
631 
632  namespace {
633  template <typename T_y,
634  typename T_result,
635  class Policy,
636  bool is_vec>
637  struct nonnegative {
638  static bool check(const char* function,
639  const T_y& y,
640  const char* name,
641  T_result* result,
642  const Policy&) {
643  // have to use not is_unsigned. is_signed will be false
644  // floating point types that have no unsigned versions.
645  if (!boost::is_unsigned<T_y>::value && !(y >= 0))
646  return dom_err(function,y,name,
647  " is %1%, but must be >= 0!","",
648  result,Policy());
649  return true;
650  }
651  };
652 
653  template <typename T_y,
654  typename T_result,
655  class Policy>
656  struct nonnegative<T_y, T_result, Policy, true> {
657  static bool check(const char* function,
658  const T_y& y,
659  const char* name,
660  T_result* result,
661  const Policy&) {
662  using stan::length;
663  for (size_t n = 0; n < length(y); n++) {
664  if (!boost::is_unsigned<typename T_y::value_type>::value && !(y[n] >= 0))
665  return dom_err_vec(n,function,y,name,
666  " is %1%, but must be >= 0!","",
667  result,Policy());
668  }
669  return true;
670  }
671  };
672  }
673  template <typename T_y, typename T_result, class Policy>
674  inline bool check_nonnegative(const char* function,
675  const T_y& y,
676  const char* name,
677  T_result* result,
678  const Policy&) {
679  return nonnegative<T_y,T_result,Policy,is_vector<T_y>::value>::check(function, y, name, result, Policy());
680  }
681  template <typename T_y, typename T_result>
682  inline bool check_nonnegative(const char* function,
683  const T_y& y,
684  const char* name,
685  T_result* result) {
686  return check_nonnegative(function,y,name,result,default_policy());
687  }
688  template <typename T_y>
689  inline bool check_nonnegative(const char* function,
690  const T_y& y,
691  const char* name) {
692  return check_nonnegative<T_y,typename scalar_type<T_y>::type *>
693  (function,y,name,0,default_policy());
694  }
695 
696 
697 
698  namespace {
699  template <typename T_y,
700  typename T_result,
701  class Policy,
702  bool is_vec>
703  struct positive {
704  static bool check(const char* function,
705  const T_y& y,
706  const char* name,
707  T_result* result,
708  const Policy&) {
709  // have to use not is_unsigned. is_signed will be false
710  // floating point types that have no unsigned versions.
711  if (!boost::is_unsigned<T_y>::value && !(y > 0))
712  return dom_err(function,y,name,
713  " is %1%, but must be > 0!","",
714  result,Policy());
715  return true;
716  }
717  };
718 
719  template <typename T_y,
720  typename T_result,
721  class Policy>
722  struct positive<T_y, T_result, Policy, true> {
723  static bool check(const char* function,
724  const T_y& y,
725  const char* name,
726  T_result* result,
727  const Policy&) {
728  using stan::length;
729  for (size_t n = 0; n < length(y); n++) {
730  if (!boost::is_unsigned<typename T_y::value_type>::value && !(y[n] > 0))
731  return dom_err_vec(n,function,y,name,
732  " is %1%, but must be > 0!","",
733  result,Policy());
734  }
735  return true;
736  }
737  };
738  }
739  template <typename T_y, typename T_result, class Policy>
740  inline bool check_positive(const char* function,
741  const T_y& y,
742  const char* name,
743  T_result* result,
744  const Policy&) {
745  return positive<T_y,T_result,Policy,is_vector<T_y>::value>::check(function, y, name, result, Policy());
746  }
747  template <typename T_x, typename T_result>
748  inline bool check_positive(const char* function,
749  const T_x& x,
750  const char* name,
751  T_result* result) {
752  return check_positive(function,x,name,result,default_policy());
753  }
754  template <typename T>
755  inline bool check_positive(const char* function,
756  const T& x,
757  const char* name) {
758  return check_positive<T,typename scalar_type<T>::type *>
759  (function,x,name,0,default_policy());
760  }
761 
762  template <typename T, typename T_result, class Policy>
763  inline bool check_consistent_size(size_t max_size,
764  const char* function,
765  const T& x,
766  const char* name,
767  T_result* result,
768  const Policy&) {
769  size_t x_size = stan::size_of(x);
770  if (is_vector<T>::value && x_size == max_size)
771  return true;
772  if (!is_vector<T>::value && x_size == 1)
773  return true;
774  return dom_err(
775  function,x_size,name,
776  " (max size) is %1%, but must be consistent, 1 or max=",max_size,
777  result,Policy());
778  }
779 
780  template <typename T1, typename T2, typename T_result,
781  class Policy>
782  inline bool check_consistent_sizes(const char* function,
783  const T1& x1,
784  const T2& x2,
785  const char* name1,
786  const char* name2,
787  T_result* result,
788  const Policy&) {
789  size_t max_size = std::max(size_of(x1),
790  size_of(x2));
791  return check_consistent_size(max_size,function,x1,name1,result,Policy())
792  && check_consistent_size(max_size,function,x2,name2,result,Policy());
793  }
794  template <typename T1, typename T2, typename T_result>
795  inline bool check_consistent_sizes(const char* function,
796  const T1& x1,
797  const T2& x2,
798  const char* name1,
799  const char* name2,
800  T_result* result) {
801  return check_consistent_sizes(function,x1,x2,name1,name2,
802  result,default_policy());
803  }
804 
805  template <typename T1, typename T2, typename T3, typename T_result,
806  class Policy>
807  inline bool check_consistent_sizes(const char* function,
808  const T1& x1,
809  const T2& x2,
810  const T3& x3,
811  const char* name1,
812  const char* name2,
813  const char* name3,
814  T_result* result,
815  const Policy&) {
816  size_t max_size = std::max(size_of(x1),
817  std::max(size_of(x2),size_of(x3)));
818  return check_consistent_size(max_size,function,x1,name1,result,Policy())
819  && check_consistent_size(max_size,function,x2,name2,result,Policy())
820  && check_consistent_size(max_size,function,x3,name3,result,Policy());
821  }
822  template <typename T1, typename T2, typename T3, typename T_result>
823  inline bool check_consistent_sizes(const char* function,
824  const T1& x1,
825  const T2& x2,
826  const T3& x3,
827  const char* name1,
828  const char* name2,
829  const char* name3,
830  T_result* result) {
831  return check_consistent_sizes(function,x1,x2,x3,name1,name2,name3,
832  result,default_policy());
833  }
834  template <typename T1, typename T2, typename T3, typename T4,
835  typename T_result,
836  class Policy>
837  inline bool check_consistent_sizes(const char* function,
838  const T1& x1,
839  const T2& x2,
840  const T3& x3,
841  const T4& x4,
842  const char* name1,
843  const char* name2,
844  const char* name3,
845  const char* name4,
846  T_result* result,
847  const Policy&) {
848  size_t max_size = std::max(size_of(x1),
849  std::max(size_of(x2),
850  std::max(size_of(x3), size_of(x4))));
851  return check_consistent_size(max_size,function,x1,name1,result,Policy())
852  && check_consistent_size(max_size,function,x2,name2,result,Policy())
853  && check_consistent_size(max_size,function,x3,name3,result,Policy())
854  && check_consistent_size(max_size,function,x4,name4,result,Policy());
855  }
856  template <typename T1, typename T2, typename T3, typename T4, typename T_result>
857  inline bool check_consistent_sizes(const char* function,
858  const T1& x1,
859  const T2& x2,
860  const T3& x3,
861  const T4& x4,
862  const char* name1,
863  const char* name2,
864  const char* name3,
865  const char* name4,
866  T_result* result) {
867  return check_consistent_sizes(function,x1,x2,x3,x4,
868  name1,name2,name3,name4,
869  result,default_policy());
870  }
871 
872 
873  }
874 }
875 
876 #endif
877 
bool isfinite(const stan::agrad::var v)
Checks if the given number has finite value.
bool isnan(const stan::agrad::var v)
Checks if the given number is NaN.
std::ostream & operator<<(std::ostream &o, const expr_type &et)
Definition: ast_def.cpp:92
T_result raise_domain_error(const char *function, const char *message, const T_val &val, const Policy &)
bool check_greater_or_equal(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: matrix.hpp:968
const double E
The base of the natural logarithm, .
Definition: constants.hpp:14
bool check_less(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is nan.
bool check_greater(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result, const Policy &)
bool check_consistent_size(size_t max_size, const char *function, const T &x, const char *name, T_result *result, const Policy &)
bool check_less_or_equal(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result, const Policy &)
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result, const Policy &)
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is finite.
bool check_nonnegative(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
Probability, optimization and sampling library.
Definition: agrad.cpp:6
size_t length(const T &x)
Definition: traits.hpp:111
size_t size_of(const T &x)
Definition: traits.hpp:143
size_t max_size(const T1 &x1, const T2 &x2)
Definition: traits.hpp:148
scalar_type_helper< is_vector< T >::value, T >::type type
Definition: traits.hpp:105

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