Chris@49
|
1 // Copyright (C) 2008-2012 NICTA (www.nicta.com.au)
|
Chris@49
|
2 // Copyright (C) 2008-2012 Conrad Sanderson
|
Chris@49
|
3 //
|
Chris@49
|
4 // This Source Code Form is subject to the terms of the Mozilla Public
|
Chris@49
|
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
|
Chris@49
|
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
Chris@49
|
7
|
Chris@49
|
8
|
Chris@49
|
9 //! \addtogroup fn_randn
|
Chris@49
|
10 //! @{
|
Chris@49
|
11
|
Chris@49
|
12
|
Chris@49
|
13 inline
|
Chris@49
|
14 double
|
Chris@49
|
15 randn()
|
Chris@49
|
16 {
|
Chris@49
|
17 return double(eop_aux_randn<double>());
|
Chris@49
|
18 }
|
Chris@49
|
19
|
Chris@49
|
20
|
Chris@49
|
21 template<typename eT>
|
Chris@49
|
22 inline
|
Chris@49
|
23 typename arma_scalar_only<eT>::result
|
Chris@49
|
24 randn()
|
Chris@49
|
25 {
|
Chris@49
|
26 return eT(eop_aux_randn<eT>());
|
Chris@49
|
27 }
|
Chris@49
|
28
|
Chris@49
|
29
|
Chris@49
|
30
|
Chris@49
|
31 //! Generate a vector with all elements set to random values with a gaussian distribution (zero mean, unit variance)
|
Chris@49
|
32 arma_inline
|
Chris@49
|
33 const Gen<vec, gen_randn>
|
Chris@49
|
34 randn(const uword n_elem)
|
Chris@49
|
35 {
|
Chris@49
|
36 arma_extra_debug_sigprint();
|
Chris@49
|
37
|
Chris@49
|
38 return Gen<vec, gen_randn>(n_elem, 1);
|
Chris@49
|
39 }
|
Chris@49
|
40
|
Chris@49
|
41
|
Chris@49
|
42
|
Chris@49
|
43 template<typename obj_type>
|
Chris@49
|
44 arma_inline
|
Chris@49
|
45 const Gen<obj_type, gen_randn>
|
Chris@49
|
46 randn(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only<obj_type>::result* junk2 = 0)
|
Chris@49
|
47 {
|
Chris@49
|
48 arma_extra_debug_sigprint();
|
Chris@49
|
49 arma_ignore(junk1);
|
Chris@49
|
50 arma_ignore(junk2);
|
Chris@49
|
51
|
Chris@49
|
52 if(is_Row<obj_type>::value == true)
|
Chris@49
|
53 {
|
Chris@49
|
54 return Gen<obj_type, gen_randn>(1, n_elem);
|
Chris@49
|
55 }
|
Chris@49
|
56 else
|
Chris@49
|
57 {
|
Chris@49
|
58 return Gen<obj_type, gen_randn>(n_elem, 1);
|
Chris@49
|
59 }
|
Chris@49
|
60 }
|
Chris@49
|
61
|
Chris@49
|
62
|
Chris@49
|
63
|
Chris@49
|
64 //! Generate a dense matrix with all elements set to random values with a gaussian distribution (zero mean, unit variance)
|
Chris@49
|
65 arma_inline
|
Chris@49
|
66 const Gen<mat, gen_randn>
|
Chris@49
|
67 randn(const uword n_rows, const uword n_cols)
|
Chris@49
|
68 {
|
Chris@49
|
69 arma_extra_debug_sigprint();
|
Chris@49
|
70
|
Chris@49
|
71 return Gen<mat, gen_randn>(n_rows, n_cols);
|
Chris@49
|
72 }
|
Chris@49
|
73
|
Chris@49
|
74
|
Chris@49
|
75
|
Chris@49
|
76 template<typename obj_type>
|
Chris@49
|
77 arma_inline
|
Chris@49
|
78 const Gen<obj_type, gen_randn>
|
Chris@49
|
79 randn(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only<obj_type>::result* junk = 0)
|
Chris@49
|
80 {
|
Chris@49
|
81 arma_extra_debug_sigprint();
|
Chris@49
|
82 arma_ignore(junk);
|
Chris@49
|
83
|
Chris@49
|
84 if(is_Col<obj_type>::value == true)
|
Chris@49
|
85 {
|
Chris@49
|
86 arma_debug_check( (n_cols != 1), "randn(): incompatible size" );
|
Chris@49
|
87 }
|
Chris@49
|
88 else
|
Chris@49
|
89 if(is_Row<obj_type>::value == true)
|
Chris@49
|
90 {
|
Chris@49
|
91 arma_debug_check( (n_rows != 1), "randn(): incompatible size" );
|
Chris@49
|
92 }
|
Chris@49
|
93
|
Chris@49
|
94 return Gen<obj_type, gen_randn>(n_rows, n_cols);
|
Chris@49
|
95 }
|
Chris@49
|
96
|
Chris@49
|
97
|
Chris@49
|
98
|
Chris@49
|
99 arma_inline
|
Chris@49
|
100 const GenCube<cube::elem_type, gen_randn>
|
Chris@49
|
101 randn(const uword n_rows, const uword n_cols, const uword n_slices)
|
Chris@49
|
102 {
|
Chris@49
|
103 arma_extra_debug_sigprint();
|
Chris@49
|
104
|
Chris@49
|
105 return GenCube<cube::elem_type, gen_randn>(n_rows, n_cols, n_slices);
|
Chris@49
|
106 }
|
Chris@49
|
107
|
Chris@49
|
108
|
Chris@49
|
109
|
Chris@49
|
110 template<typename cube_type>
|
Chris@49
|
111 arma_inline
|
Chris@49
|
112 const GenCube<typename cube_type::elem_type, gen_randn>
|
Chris@49
|
113 randn(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only<cube_type>::result* junk = 0)
|
Chris@49
|
114 {
|
Chris@49
|
115 arma_extra_debug_sigprint();
|
Chris@49
|
116 arma_ignore(junk);
|
Chris@49
|
117
|
Chris@49
|
118 return GenCube<typename cube_type::elem_type, gen_randn>(n_rows, n_cols, n_slices);
|
Chris@49
|
119 }
|
Chris@49
|
120
|
Chris@49
|
121
|
Chris@49
|
122
|
Chris@49
|
123 //! @}
|