comparison armadillo-3.900.4/include/armadillo_bits/GenCube_meat.hpp @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 // Copyright (C) 2011-2013 NICTA (www.nicta.com.au)
2 // Copyright (C) 2011-2013 Conrad Sanderson
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9 //! \addtogroup Gen
10 //! @{
11
12
13
14 template<typename eT, typename gen_type>
15 arma_inline
16 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
17 : n_rows (in_n_rows )
18 , n_cols (in_n_cols )
19 , n_slices(in_n_slices)
20 {
21 arma_extra_debug_sigprint();
22 }
23
24
25
26 template<typename eT, typename gen_type>
27 arma_inline
28 GenCube<eT, gen_type>::~GenCube()
29 {
30 arma_extra_debug_sigprint();
31 }
32
33
34
35 template<typename eT, typename gen_type>
36 arma_inline
37 eT
38 GenCube<eT, gen_type>::generate()
39 {
40 if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
41 else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
42 else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
43 else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
44 else { return eT(); }
45 }
46
47
48
49 template<typename eT, typename gen_type>
50 arma_inline
51 eT
52 GenCube<eT, gen_type>::operator[](const uword) const
53 {
54 return GenCube<eT, gen_type>::generate();
55 }
56
57
58
59 template<typename eT, typename gen_type>
60 arma_inline
61 eT
62 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const
63 {
64 return GenCube<eT, gen_type>::generate();
65 }
66
67
68
69 template<typename eT, typename gen_type>
70 arma_inline
71 eT
72 GenCube<eT, gen_type>::at_alt(const uword) const
73 {
74 return GenCube<eT, gen_type>::generate();
75 }
76
77
78
79 template<typename eT, typename gen_type>
80 inline
81 void
82 GenCube<eT, gen_type>::apply(Cube<eT>& out) const
83 {
84 arma_extra_debug_sigprint();
85
86 // NOTE: we're assuming that the cube has already been set to the correct size;
87 // this is done by either the Cube contructor or operator=()
88
89 if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); }
90 else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
91 else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
92 else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
93 }
94
95
96
97 template<typename eT, typename gen_type>
98 inline
99 void
100 GenCube<eT, gen_type>::apply_inplace_plus(Cube<eT>& out) const
101 {
102 arma_extra_debug_sigprint();
103
104 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
105
106
107 eT* out_mem = out.memptr();
108 const uword n_elem = out.n_elem;
109
110 uword i,j;
111
112 for(i=0, j=1; j<n_elem; i+=2, j+=2)
113 {
114 const eT tmp_i = GenCube<eT, gen_type>::generate();
115 const eT tmp_j = GenCube<eT, gen_type>::generate();
116
117 out_mem[i] += tmp_i;
118 out_mem[j] += tmp_j;
119 }
120
121 if(i < n_elem)
122 {
123 out_mem[i] += GenCube<eT, gen_type>::generate();
124 }
125 }
126
127
128
129
130 template<typename eT, typename gen_type>
131 inline
132 void
133 GenCube<eT, gen_type>::apply_inplace_minus(Cube<eT>& out) const
134 {
135 arma_extra_debug_sigprint();
136
137 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
138
139
140 eT* out_mem = out.memptr();
141 const uword n_elem = out.n_elem;
142
143 uword i,j;
144
145 for(i=0, j=1; j<n_elem; i+=2, j+=2)
146 {
147 const eT tmp_i = GenCube<eT, gen_type>::generate();
148 const eT tmp_j = GenCube<eT, gen_type>::generate();
149
150 out_mem[i] -= tmp_i;
151 out_mem[j] -= tmp_j;
152 }
153
154 if(i < n_elem)
155 {
156 out_mem[i] -= GenCube<eT, gen_type>::generate();
157 }
158 }
159
160
161
162
163 template<typename eT, typename gen_type>
164 inline
165 void
166 GenCube<eT, gen_type>::apply_inplace_schur(Cube<eT>& out) const
167 {
168 arma_extra_debug_sigprint();
169
170 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
171
172
173 eT* out_mem = out.memptr();
174 const uword n_elem = out.n_elem;
175
176 uword i,j;
177
178 for(i=0, j=1; j<n_elem; i+=2, j+=2)
179 {
180 const eT tmp_i = GenCube<eT, gen_type>::generate();
181 const eT tmp_j = GenCube<eT, gen_type>::generate();
182
183 out_mem[i] *= tmp_i;
184 out_mem[j] *= tmp_j;
185 }
186
187 if(i < n_elem)
188 {
189 out_mem[i] *= GenCube<eT, gen_type>::generate();
190 }
191 }
192
193
194
195
196 template<typename eT, typename gen_type>
197 inline
198 void
199 GenCube<eT, gen_type>::apply_inplace_div(Cube<eT>& out) const
200 {
201 arma_extra_debug_sigprint();
202
203 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
204
205
206 eT* out_mem = out.memptr();
207 const uword n_elem = out.n_elem;
208
209 uword i,j;
210
211 for(i=0, j=1; j<n_elem; i+=2, j+=2)
212 {
213 const eT tmp_i = GenCube<eT, gen_type>::generate();
214 const eT tmp_j = GenCube<eT, gen_type>::generate();
215
216 out_mem[i] /= tmp_i;
217 out_mem[j] /= tmp_j;
218 }
219
220 if(i < n_elem)
221 {
222 out_mem[i] /= GenCube<eT, gen_type>::generate();
223 }
224 }
225
226
227
228
229 //! @}