"Fossies" - the Fresh Open Source Software Archive 
Member "armadillo-9.800.3/include/armadillo_bits/fn_randu.hpp" (16 Jun 2016, 4329 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "fn_randu.hpp" see the
Fossies "Dox" file reference documentation.
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
16
17 //! \addtogroup fn_randu
18 //! @{
19
20
21
22 arma_warn_unused
23 inline
24 double
25 randu()
26 {
27 return double(arma_rng::randu<double>());
28 }
29
30
31
32 template<typename eT>
33 arma_warn_unused
34 inline
35 typename arma_real_or_cx_only<eT>::result
36 randu()
37 {
38 return eT(arma_rng::randu<eT>());
39 }
40
41
42
43 //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution)
44 arma_warn_unused
45 arma_inline
46 const Gen<vec, gen_randu>
47 randu(const uword n_elem)
48 {
49 arma_extra_debug_sigprint();
50
51 return Gen<vec, gen_randu>(n_elem, 1);
52 }
53
54
55
56 template<typename obj_type>
57 arma_warn_unused
58 arma_inline
59 const Gen<obj_type, gen_randu>
60 randu(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
61 {
62 arma_extra_debug_sigprint();
63 arma_ignore(junk1);
64 arma_ignore(junk2);
65
66 if(is_Row<obj_type>::value)
67 {
68 return Gen<obj_type, gen_randu>(1, n_elem);
69 }
70 else
71 {
72 return Gen<obj_type, gen_randu>(n_elem, 1);
73 }
74 }
75
76
77
78 //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution)
79 arma_warn_unused
80 arma_inline
81 const Gen<mat, gen_randu>
82 randu(const uword n_rows, const uword n_cols)
83 {
84 arma_extra_debug_sigprint();
85
86 return Gen<mat, gen_randu>(n_rows, n_cols);
87 }
88
89
90
91 arma_warn_unused
92 arma_inline
93 const Gen<mat, gen_randu>
94 randu(const SizeMat& s)
95 {
96 arma_extra_debug_sigprint();
97
98 return Gen<mat, gen_randu>(s.n_rows, s.n_cols);
99 }
100
101
102
103 template<typename obj_type>
104 arma_warn_unused
105 arma_inline
106 const Gen<obj_type, gen_randu>
107 randu(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
108 {
109 arma_extra_debug_sigprint();
110 arma_ignore(junk);
111
112 if(is_Col<obj_type>::value)
113 {
114 arma_debug_check( (n_cols != 1), "randu(): incompatible size" );
115 }
116 else
117 if(is_Row<obj_type>::value)
118 {
119 arma_debug_check( (n_rows != 1), "randu(): incompatible size" );
120 }
121
122 return Gen<obj_type, gen_randu>(n_rows, n_cols);
123 }
124
125
126
127 template<typename obj_type>
128 arma_warn_unused
129 arma_inline
130 const Gen<obj_type, gen_randu>
131 randu(const SizeMat& s, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
132 {
133 arma_extra_debug_sigprint();
134 arma_ignore(junk);
135
136 return randu<obj_type>(s.n_rows, s.n_cols);
137 }
138
139
140
141 arma_warn_unused
142 arma_inline
143 const GenCube<cube::elem_type, gen_randu>
144 randu(const uword n_rows, const uword n_cols, const uword n_slices)
145 {
146 arma_extra_debug_sigprint();
147
148 return GenCube<cube::elem_type, gen_randu>(n_rows, n_cols, n_slices);
149 }
150
151
152
153 arma_warn_unused
154 arma_inline
155 const GenCube<cube::elem_type, gen_randu>
156 randu(const SizeCube& s)
157 {
158 arma_extra_debug_sigprint();
159
160 return GenCube<cube::elem_type, gen_randu>(s.n_rows, s.n_cols, s.n_slices);
161 }
162
163
164
165 template<typename cube_type>
166 arma_warn_unused
167 arma_inline
168 const GenCube<typename cube_type::elem_type, gen_randu>
169 randu(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
170 {
171 arma_extra_debug_sigprint();
172 arma_ignore(junk);
173
174 return GenCube<typename cube_type::elem_type, gen_randu>(n_rows, n_cols, n_slices);
175 }
176
177
178
179 template<typename cube_type>
180 arma_warn_unused
181 arma_inline
182 const GenCube<typename cube_type::elem_type, gen_randu>
183 randu(const SizeCube& s, const typename arma_Cube_only<cube_type>::result* junk = 0)
184 {
185 arma_extra_debug_sigprint();
186 arma_ignore(junk);
187
188 return GenCube<typename cube_type::elem_type, gen_randu>(s.n_rows, s.n_cols, s.n_slices);
189 }
190
191
192
193 //! @}