fn_chi2rnd.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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_chi2rnd
  16. //! @{
  17. arma_warn_unused
  18. inline
  19. double
  20. chi2rnd(const double df)
  21. {
  22. arma_extra_debug_sigprint();
  23. #if defined(ARMA_USE_CXX11)
  24. {
  25. op_chi2rnd_varying_df<double> generator;
  26. return generator(df);
  27. }
  28. #else
  29. {
  30. arma_stop_logic_error("chi2rnd(): C++11 compiler required");
  31. return double(0);
  32. }
  33. #endif
  34. }
  35. template<typename eT>
  36. arma_warn_unused
  37. inline
  38. typename arma_real_only<eT>::result
  39. chi2rnd(const eT df)
  40. {
  41. arma_extra_debug_sigprint();
  42. #if defined(ARMA_USE_CXX11)
  43. {
  44. op_chi2rnd_varying_df<eT> generator;
  45. return generator(df);
  46. }
  47. #else
  48. {
  49. arma_stop_logic_error("chi2rnd(): C++11 compiler required");
  50. return eT(0);
  51. }
  52. #endif
  53. }
  54. template<typename T1>
  55. arma_warn_unused
  56. inline
  57. typename
  58. enable_if2
  59. <
  60. (is_arma_type<T1>::value && is_real<typename T1::elem_type>::value),
  61. const Op<T1, op_chi2rnd>
  62. >::result
  63. chi2rnd(const T1& expr)
  64. {
  65. arma_extra_debug_sigprint();
  66. return Op<T1, op_chi2rnd>(expr);
  67. }
  68. template<typename obj_type>
  69. arma_warn_unused
  70. inline
  71. typename
  72. enable_if2
  73. <
  74. (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
  75. obj_type
  76. >::result
  77. chi2rnd(const typename obj_type::elem_type df, const uword n_rows, const uword n_cols)
  78. {
  79. arma_extra_debug_sigprint();
  80. if(is_Col<obj_type>::value)
  81. {
  82. arma_debug_check( (n_cols != 1), "chi2rnd(): incompatible size" );
  83. }
  84. else
  85. if(is_Row<obj_type>::value)
  86. {
  87. arma_debug_check( (n_rows != 1), "chi2rnd(): incompatible size" );
  88. }
  89. obj_type out(n_rows, n_cols);
  90. op_chi2rnd::fill_constant_df(out, df);
  91. return out;
  92. }
  93. template<typename obj_type>
  94. arma_warn_unused
  95. inline
  96. typename
  97. enable_if2
  98. <
  99. (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
  100. obj_type
  101. >::result
  102. chi2rnd(const typename obj_type::elem_type df, const SizeMat& s)
  103. {
  104. arma_extra_debug_sigprint();
  105. return chi2rnd<obj_type>(df, s.n_rows, s.n_cols);
  106. }
  107. template<typename obj_type>
  108. arma_warn_unused
  109. inline
  110. typename
  111. enable_if2
  112. <
  113. (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
  114. obj_type
  115. >::result
  116. chi2rnd(const typename obj_type::elem_type df, const uword n_elem)
  117. {
  118. arma_extra_debug_sigprint();
  119. if(is_Row<obj_type>::value)
  120. {
  121. return chi2rnd<obj_type>(df, 1, n_elem);
  122. }
  123. else
  124. {
  125. return chi2rnd<obj_type>(df, n_elem, 1);
  126. }
  127. }
  128. arma_warn_unused
  129. inline
  130. mat
  131. chi2rnd(const double df, const uword n_rows, const uword n_cols)
  132. {
  133. arma_extra_debug_sigprint();
  134. return chi2rnd<mat>(df, n_rows, n_cols);
  135. }
  136. arma_warn_unused
  137. inline
  138. mat
  139. chi2rnd(const double df, const SizeMat& s)
  140. {
  141. arma_extra_debug_sigprint();
  142. return chi2rnd<mat>(df, s.n_rows, s.n_cols);
  143. }
  144. arma_warn_unused
  145. inline
  146. vec
  147. chi2rnd(const double df, const uword n_elem)
  148. {
  149. arma_extra_debug_sigprint();
  150. return chi2rnd<vec>(df, n_elem, 1);
  151. }
  152. //! @}