1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17
18
19 //! \addtogroup fn_chi2rnd
20 //! @{
21
22
23
24 arma_warn_unused
25 inline
26 double
chi2rnd(const double df)27 chi2rnd(const double df)
28 {
29 arma_extra_debug_sigprint();
30
31 op_chi2rnd_varying_df<double> generator;
32
33 return generator(df);
34 }
35
36
37
38 template<typename eT>
39 arma_warn_unused
40 inline
41 typename arma_real_only<eT>::result
chi2rnd(const eT df)42 chi2rnd(const eT df)
43 {
44 arma_extra_debug_sigprint();
45
46 op_chi2rnd_varying_df<eT> generator;
47
48 return generator(df);
49 }
50
51
52
53 template<typename T1>
54 arma_warn_unused
55 inline
56 typename
57 enable_if2
58 <
59 (is_arma_type<T1>::value && is_real<typename T1::elem_type>::value),
60 const Op<T1, op_chi2rnd>
61 >::result
chi2rnd(const T1 & expr)62 chi2rnd(const T1& expr)
63 {
64 arma_extra_debug_sigprint();
65
66 return Op<T1, op_chi2rnd>(expr);
67 }
68
69
70
71 template<typename obj_type>
72 arma_warn_unused
73 inline
74 typename
75 enable_if2
76 <
77 (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
78 obj_type
79 >::result
chi2rnd(const typename obj_type::elem_type df,const uword n_rows,const uword n_cols)80 chi2rnd(const typename obj_type::elem_type df, const uword n_rows, const uword n_cols)
81 {
82 arma_extra_debug_sigprint();
83
84 if(is_Col<obj_type>::value)
85 {
86 arma_debug_check( (n_cols != 1), "chi2rnd(): incompatible size" );
87 }
88 else
89 if(is_Row<obj_type>::value)
90 {
91 arma_debug_check( (n_rows != 1), "chi2rnd(): incompatible size" );
92 }
93
94 obj_type out(n_rows, n_cols, arma_nozeros_indicator());
95
96 op_chi2rnd::fill_constant_df(out, df);
97
98 return out;
99 }
100
101
102
103 template<typename obj_type>
104 arma_warn_unused
105 inline
106 typename
107 enable_if2
108 <
109 (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
110 obj_type
111 >::result
chi2rnd(const typename obj_type::elem_type df,const SizeMat & s)112 chi2rnd(const typename obj_type::elem_type df, const SizeMat& s)
113 {
114 arma_extra_debug_sigprint();
115
116 return chi2rnd<obj_type>(df, s.n_rows, s.n_cols);
117 }
118
119
120
121 template<typename obj_type>
122 arma_warn_unused
123 inline
124 typename
125 enable_if2
126 <
127 (is_Mat<obj_type>::value && is_real<typename obj_type::elem_type>::value),
128 obj_type
129 >::result
chi2rnd(const typename obj_type::elem_type df,const uword n_elem)130 chi2rnd(const typename obj_type::elem_type df, const uword n_elem)
131 {
132 arma_extra_debug_sigprint();
133
134 if(is_Row<obj_type>::value)
135 {
136 return chi2rnd<obj_type>(df, 1, n_elem);
137 }
138 else
139 {
140 return chi2rnd<obj_type>(df, n_elem, 1);
141 }
142 }
143
144
145
146 arma_warn_unused
147 inline
148 mat
chi2rnd(const double df,const uword n_rows,const uword n_cols)149 chi2rnd(const double df, const uword n_rows, const uword n_cols)
150 {
151 arma_extra_debug_sigprint();
152
153 return chi2rnd<mat>(df, n_rows, n_cols);
154 }
155
156
157
158 arma_warn_unused
159 inline
160 mat
chi2rnd(const double df,const SizeMat & s)161 chi2rnd(const double df, const SizeMat& s)
162 {
163 arma_extra_debug_sigprint();
164
165 return chi2rnd<mat>(df, s.n_rows, s.n_cols);
166 }
167
168
169
170 arma_warn_unused
171 inline
172 vec
chi2rnd(const double df,const uword n_elem)173 chi2rnd(const double df, const uword n_elem)
174 {
175 arma_extra_debug_sigprint();
176
177 return chi2rnd<vec>(df, n_elem, 1);
178 }
179
180
181
182 //! @}
183