comparison armadillo-2.4.4/include/armadillo_bits/GenCube_meat.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup Gen
15 //! @{
16
17
18
19 template<typename eT, typename gen_type>
20 arma_inline
21 GenCube<eT, gen_type>::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
22 : n_rows (in_n_rows )
23 , n_cols (in_n_cols )
24 , n_slices(in_n_slices)
25 {
26 arma_extra_debug_sigprint();
27 }
28
29
30
31 template<typename eT, typename gen_type>
32 arma_inline
33 GenCube<eT, gen_type>::~GenCube()
34 {
35 arma_extra_debug_sigprint();
36 }
37
38
39
40 template<typename eT, typename gen_type>
41 arma_inline
42 eT
43 GenCube<eT, gen_type>::generate()
44 {
45 if(is_same_type<gen_type, gen_ones_full>::value == true) { return eT(1); }
46 else if(is_same_type<gen_type, gen_zeros >::value == true) { return eT(0); }
47 else if(is_same_type<gen_type, gen_randu >::value == true) { return eT(eop_aux_randu<eT>()); }
48 else if(is_same_type<gen_type, gen_randn >::value == true) { return eT(eop_aux_randn<eT>()); }
49 else { return eT(); }
50 }
51
52
53
54 template<typename eT, typename gen_type>
55 arma_inline
56 eT
57 GenCube<eT, gen_type>::operator[](const uword) const
58 {
59 return GenCube<eT, gen_type>::generate();
60 }
61
62
63
64 template<typename eT, typename gen_type>
65 arma_inline
66 eT
67 GenCube<eT, gen_type>::at(const uword, const uword, const uword) const
68 {
69 return GenCube<eT, gen_type>::generate();
70 }
71
72
73
74 template<typename eT, typename gen_type>
75 inline
76 void
77 GenCube<eT, gen_type>::apply(Cube<eT>& out) const
78 {
79 arma_extra_debug_sigprint();
80
81 // NOTE: we're assuming that the cube has already been set to the correct size;
82 // this is done by either the Cube contructor or operator=()
83
84 if(is_same_type<gen_type, gen_ones_full>::value == true) { out.ones(); }
85 else if(is_same_type<gen_type, gen_zeros >::value == true) { out.zeros(); }
86 else if(is_same_type<gen_type, gen_randu >::value == true) { out.randu(); }
87 else if(is_same_type<gen_type, gen_randn >::value == true) { out.randn(); }
88 }
89
90
91
92 template<typename eT, typename gen_type>
93 inline
94 void
95 GenCube<eT, gen_type>::apply_inplace_plus(Cube<eT>& out) const
96 {
97 arma_extra_debug_sigprint();
98
99 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition");
100
101
102 eT* out_mem = out.memptr();
103 const uword n_elem = out.n_elem;
104
105 uword i,j;
106
107 for(i=0, j=1; j<n_elem; i+=2, j+=2)
108 {
109 const eT tmp_i = GenCube<eT, gen_type>::generate();
110 const eT tmp_j = GenCube<eT, gen_type>::generate();
111
112 out_mem[i] += tmp_i;
113 out_mem[j] += tmp_j;
114 }
115
116 if(i < n_elem)
117 {
118 out_mem[i] += GenCube<eT, gen_type>::generate();
119 }
120 }
121
122
123
124
125 template<typename eT, typename gen_type>
126 inline
127 void
128 GenCube<eT, gen_type>::apply_inplace_minus(Cube<eT>& out) const
129 {
130 arma_extra_debug_sigprint();
131
132 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction");
133
134
135 eT* out_mem = out.memptr();
136 const uword n_elem = out.n_elem;
137
138 uword i,j;
139
140 for(i=0, j=1; j<n_elem; i+=2, j+=2)
141 {
142 const eT tmp_i = GenCube<eT, gen_type>::generate();
143 const eT tmp_j = GenCube<eT, gen_type>::generate();
144
145 out_mem[i] -= tmp_i;
146 out_mem[j] -= tmp_j;
147 }
148
149 if(i < n_elem)
150 {
151 out_mem[i] -= GenCube<eT, gen_type>::generate();
152 }
153 }
154
155
156
157
158 template<typename eT, typename gen_type>
159 inline
160 void
161 GenCube<eT, gen_type>::apply_inplace_schur(Cube<eT>& out) const
162 {
163 arma_extra_debug_sigprint();
164
165 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication");
166
167
168 eT* out_mem = out.memptr();
169 const uword n_elem = out.n_elem;
170
171 uword i,j;
172
173 for(i=0, j=1; j<n_elem; i+=2, j+=2)
174 {
175 const eT tmp_i = GenCube<eT, gen_type>::generate();
176 const eT tmp_j = GenCube<eT, gen_type>::generate();
177
178 out_mem[i] *= tmp_i;
179 out_mem[j] *= tmp_j;
180 }
181
182 if(i < n_elem)
183 {
184 out_mem[i] *= GenCube<eT, gen_type>::generate();
185 }
186 }
187
188
189
190
191 template<typename eT, typename gen_type>
192 inline
193 void
194 GenCube<eT, gen_type>::apply_inplace_div(Cube<eT>& out) const
195 {
196 arma_extra_debug_sigprint();
197
198 arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division");
199
200
201 eT* out_mem = out.memptr();
202 const uword n_elem = out.n_elem;
203
204 uword i,j;
205
206 for(i=0, j=1; j<n_elem; i+=2, j+=2)
207 {
208 const eT tmp_i = GenCube<eT, gen_type>::generate();
209 const eT tmp_j = GenCube<eT, gen_type>::generate();
210
211 out_mem[i] /= tmp_i;
212 out_mem[j] /= tmp_j;
213 }
214
215 if(i < n_elem)
216 {
217 out_mem[i] /= GenCube<eT, gen_type>::generate();
218 }
219 }
220
221
222
223
224 //! @}