fn_mvnrnd.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_mvnrnd
  16. //! @{
  17. template<typename T1, typename T2>
  18. arma_warn_unused
  19. inline
  20. typename
  21. enable_if2
  22. <
  23. is_real<typename T1::elem_type>::value,
  24. const Glue<T1, T2, glue_mvnrnd_vec>
  25. >::result
  26. mvnrnd(const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C)
  27. {
  28. arma_extra_debug_sigprint();
  29. return Glue<T1, T2, glue_mvnrnd_vec>(M.get_ref(), C.get_ref());
  30. }
  31. template<typename T1, typename T2>
  32. arma_warn_unused
  33. inline
  34. typename
  35. enable_if2
  36. <
  37. is_real<typename T1::elem_type>::value,
  38. const Glue<T1, T2, glue_mvnrnd>
  39. >::result
  40. mvnrnd(const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C, const uword N)
  41. {
  42. arma_extra_debug_sigprint();
  43. return Glue<T1, T2, glue_mvnrnd>(M.get_ref(), C.get_ref(), N);
  44. }
  45. template<typename T1, typename T2>
  46. inline
  47. typename
  48. enable_if2
  49. <
  50. is_real<typename T1::elem_type>::value,
  51. bool
  52. >::result
  53. mvnrnd(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C)
  54. {
  55. arma_extra_debug_sigprint();
  56. const bool status = glue_mvnrnd::apply_direct(out, M.get_ref(), C.get_ref(), uword(1));
  57. if(status == false)
  58. {
  59. arma_debug_warn("mvnrnd(): given covariance matrix is not symmetric positive semi-definite");
  60. return false;
  61. }
  62. return true;
  63. }
  64. template<typename T1, typename T2>
  65. inline
  66. typename
  67. enable_if2
  68. <
  69. is_real<typename T1::elem_type>::value,
  70. bool
  71. >::result
  72. mvnrnd(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C, const uword N)
  73. {
  74. arma_extra_debug_sigprint();
  75. const bool status = glue_mvnrnd::apply_direct(out, M.get_ref(), C.get_ref(), N);
  76. if(status == false)
  77. {
  78. arma_debug_warn("mvnrnd(): given covariance matrix is not symmetric positive semi-definite");
  79. return false;
  80. }
  81. return true;
  82. }
  83. //! @}