max@0
|
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2010-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 //! \addtogroup subview_elem1
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18 template<typename eT, typename T1>
|
max@0
|
19 inline
|
max@0
|
20 subview_elem1<eT,T1>::~subview_elem1()
|
max@0
|
21 {
|
max@0
|
22 arma_extra_debug_sigprint();
|
max@0
|
23 }
|
max@0
|
24
|
max@0
|
25
|
max@0
|
26 template<typename eT, typename T1>
|
max@0
|
27 arma_inline
|
max@0
|
28 subview_elem1<eT,T1>::subview_elem1(const Mat<eT>& in_m, const Base<uword,T1>& in_a)
|
max@0
|
29 : m(in_m)
|
max@0
|
30 , m_ptr(0)
|
max@0
|
31 , a(in_a)
|
max@0
|
32 {
|
max@0
|
33 arma_extra_debug_sigprint();
|
max@0
|
34 }
|
max@0
|
35
|
max@0
|
36
|
max@0
|
37
|
max@0
|
38 template<typename eT, typename T1>
|
max@0
|
39 arma_inline
|
max@0
|
40 subview_elem1<eT,T1>::subview_elem1(Mat<eT>& in_m, const Base<uword,T1>& in_a)
|
max@0
|
41 : m(in_m)
|
max@0
|
42 , m_ptr(&in_m)
|
max@0
|
43 , a(in_a)
|
max@0
|
44 {
|
max@0
|
45 arma_extra_debug_sigprint();
|
max@0
|
46 }
|
max@0
|
47
|
max@0
|
48
|
max@0
|
49
|
max@0
|
50 template<typename eT, typename T1>
|
max@0
|
51 template<typename op_type>
|
max@0
|
52 inline
|
max@0
|
53 void
|
max@0
|
54 subview_elem1<eT,T1>::inplace_op(const eT val)
|
max@0
|
55 {
|
max@0
|
56 Mat<eT>& m_local = *m_ptr;
|
max@0
|
57
|
max@0
|
58 eT* m_mem = m_local.memptr();
|
max@0
|
59 const uword m_n_elem = m_local.n_elem;
|
max@0
|
60
|
max@0
|
61 const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local);
|
max@0
|
62 const umat& aa = tmp.M;
|
max@0
|
63
|
max@0
|
64 arma_debug_check
|
max@0
|
65 (
|
max@0
|
66 ( aa.is_vec() == false ),
|
max@0
|
67 "Mat::elem(): given object is not a vector"
|
max@0
|
68 );
|
max@0
|
69
|
max@0
|
70 const uword* aa_mem = aa.memptr();
|
max@0
|
71 const uword aa_n_elem = aa.n_elem;
|
max@0
|
72
|
max@0
|
73 uword i,j;
|
max@0
|
74 for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
|
max@0
|
75 {
|
max@0
|
76 const uword ii = aa_mem[i];
|
max@0
|
77 const uword jj = aa_mem[j];
|
max@0
|
78
|
max@0
|
79 arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
|
max@0
|
80
|
max@0
|
81 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = val; m_mem[jj] = val; }
|
max@0
|
82 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += val; m_mem[jj] += val; }
|
max@0
|
83 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= val; m_mem[jj] -= val; }
|
max@0
|
84 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= val; m_mem[jj] *= val; }
|
max@0
|
85 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= val; m_mem[jj] /= val; }
|
max@0
|
86 }
|
max@0
|
87
|
max@0
|
88 if(i < aa_n_elem)
|
max@0
|
89 {
|
max@0
|
90 const uword ii = aa_mem[i];
|
max@0
|
91
|
max@0
|
92 arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
|
max@0
|
93
|
max@0
|
94 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = val; }
|
max@0
|
95 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += val; }
|
max@0
|
96 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= val; }
|
max@0
|
97 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= val; }
|
max@0
|
98 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= val; }
|
max@0
|
99 }
|
max@0
|
100 }
|
max@0
|
101
|
max@0
|
102
|
max@0
|
103
|
max@0
|
104 template<typename eT, typename T1>
|
max@0
|
105 template<typename op_type, typename T2>
|
max@0
|
106 inline
|
max@0
|
107 void
|
max@0
|
108 subview_elem1<eT,T1>::inplace_op(const subview_elem1<eT,T2>& x)
|
max@0
|
109 {
|
max@0
|
110 subview_elem1<eT,T1>& t = *this;
|
max@0
|
111
|
max@0
|
112 if(&(t.m) == &(x.m))
|
max@0
|
113 {
|
max@0
|
114 arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected");
|
max@0
|
115
|
max@0
|
116 const Mat<eT> tmp(x);
|
max@0
|
117
|
max@0
|
118 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { t.operator= (tmp); }
|
max@0
|
119 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t.operator+=(tmp); }
|
max@0
|
120 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t.operator-=(tmp); }
|
max@0
|
121 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t.operator%=(tmp); }
|
max@0
|
122 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { t.operator/=(tmp); }
|
max@0
|
123 }
|
max@0
|
124 else
|
max@0
|
125 {
|
max@0
|
126 Mat<eT>& t_m_local = *(t.m_ptr);
|
max@0
|
127 const Mat<eT>& x_m_local = x.m;
|
max@0
|
128
|
max@0
|
129 const unwrap_check_mixed<T1> t_tmp(t.a.get_ref(), t_m_local);
|
max@0
|
130 const unwrap_check_mixed<T2> x_tmp(x.a.get_ref(), t_m_local);
|
max@0
|
131
|
max@0
|
132 const umat& t_aa = t_tmp.M;
|
max@0
|
133 const umat& x_aa = x_tmp.M;
|
max@0
|
134
|
max@0
|
135 arma_debug_check
|
max@0
|
136 (
|
max@0
|
137 ( (t_aa.is_vec() == false) || (x_aa.is_vec() == false) ),
|
max@0
|
138 "Mat::elem(): given object is not a vector"
|
max@0
|
139 );
|
max@0
|
140
|
max@0
|
141 const uword* t_aa_mem = t_aa.memptr();
|
max@0
|
142 const uword* x_aa_mem = x_aa.memptr();
|
max@0
|
143
|
max@0
|
144 const uword t_aa_n_elem = t_aa.n_elem;
|
max@0
|
145
|
max@0
|
146 arma_debug_check( (t_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mismatch" );
|
max@0
|
147
|
max@0
|
148
|
max@0
|
149 eT* t_m_mem = t_m_local.memptr();
|
max@0
|
150 const uword t_m_n_elem = t_m_local.n_elem;
|
max@0
|
151
|
max@0
|
152 const eT* x_m_mem = x_m_local.memptr();
|
max@0
|
153 const uword x_m_n_elem = x_m_local.n_elem;
|
max@0
|
154
|
max@0
|
155 uword i,j;
|
max@0
|
156 for(i=0, j=1; j<t_aa_n_elem; i+=2, j+=2)
|
max@0
|
157 {
|
max@0
|
158 const uword t_ii = t_aa_mem[i];
|
max@0
|
159 const uword t_jj = t_aa_mem[j];
|
max@0
|
160
|
max@0
|
161 const uword x_ii = x_aa_mem[i];
|
max@0
|
162 const uword x_jj = x_aa_mem[j];
|
max@0
|
163
|
max@0
|
164 arma_debug_check
|
max@0
|
165 (
|
max@0
|
166 (t_ii >= t_m_n_elem) || (t_jj >= t_m_n_elem) || (x_ii >= x_m_n_elem) || (x_jj >= x_m_n_elem),
|
max@0
|
167 "Mat::elem(): index out of bounds"
|
max@0
|
168 );
|
max@0
|
169
|
max@0
|
170 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { t_m_mem[t_ii] = x_m_mem[x_ii]; t_m_mem[t_jj] = x_m_mem[x_jj]; }
|
max@0
|
171 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t_m_mem[t_ii] += x_m_mem[x_ii]; t_m_mem[t_jj] += x_m_mem[x_jj]; }
|
max@0
|
172 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; t_m_mem[t_jj] -= x_m_mem[x_jj]; }
|
max@0
|
173 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; t_m_mem[t_jj] *= x_m_mem[x_jj]; }
|
max@0
|
174 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; t_m_mem[t_jj] /= x_m_mem[x_jj]; }
|
max@0
|
175 }
|
max@0
|
176
|
max@0
|
177 if(i < t_aa_n_elem)
|
max@0
|
178 {
|
max@0
|
179 const uword t_ii = t_aa_mem[i];
|
max@0
|
180 const uword x_ii = x_aa_mem[i];
|
max@0
|
181
|
max@0
|
182 arma_debug_check
|
max@0
|
183 (
|
max@0
|
184 ( (t_ii >= t_m_n_elem) || (x_ii >= x_m_n_elem) ),
|
max@0
|
185 "Mat::elem(): index out of bounds"
|
max@0
|
186 );
|
max@0
|
187
|
max@0
|
188 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { t_m_mem[t_ii] = x_m_mem[x_ii]; }
|
max@0
|
189 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { t_m_mem[t_ii] += x_m_mem[x_ii]; }
|
max@0
|
190 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; }
|
max@0
|
191 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; }
|
max@0
|
192 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; }
|
max@0
|
193 }
|
max@0
|
194 }
|
max@0
|
195 }
|
max@0
|
196
|
max@0
|
197
|
max@0
|
198
|
max@0
|
199 template<typename eT, typename T1>
|
max@0
|
200 template<typename op_type, typename T2>
|
max@0
|
201 inline
|
max@0
|
202 void
|
max@0
|
203 subview_elem1<eT,T1>::inplace_op(const Base<eT,T2>& x)
|
max@0
|
204 {
|
max@0
|
205 arma_extra_debug_sigprint();
|
max@0
|
206
|
max@0
|
207 Mat<eT>& m_local = *m_ptr;
|
max@0
|
208
|
max@0
|
209 eT* m_mem = m_local.memptr();
|
max@0
|
210 const uword m_n_elem = m_local.n_elem;
|
max@0
|
211
|
max@0
|
212 const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local);
|
max@0
|
213 const umat& aa = tmp.M;
|
max@0
|
214
|
max@0
|
215 arma_debug_check
|
max@0
|
216 (
|
max@0
|
217 ( aa.is_vec() == false ),
|
max@0
|
218 "Mat::elem(): given object is not a vector"
|
max@0
|
219 );
|
max@0
|
220
|
max@0
|
221 const uword* aa_mem = aa.memptr();
|
max@0
|
222 const uword aa_n_elem = aa.n_elem;
|
max@0
|
223
|
max@0
|
224 const Proxy<T2> P(x.get_ref());
|
max@0
|
225
|
max@0
|
226 arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size mismatch" );
|
max@0
|
227
|
max@0
|
228 if( (P.is_alias(m) == false) && (Proxy<T2>::prefer_at_accessor == false) )
|
max@0
|
229 {
|
max@0
|
230 typename Proxy<T2>::ea_type X = P.get_ea();
|
max@0
|
231
|
max@0
|
232 uword i,j;
|
max@0
|
233 for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
|
max@0
|
234 {
|
max@0
|
235 const uword ii = aa_mem[i];
|
max@0
|
236 const uword jj = aa_mem[j];
|
max@0
|
237
|
max@0
|
238 arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
|
max@0
|
239
|
max@0
|
240 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; }
|
max@0
|
241 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; }
|
max@0
|
242 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; }
|
max@0
|
243 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; }
|
max@0
|
244 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; }
|
max@0
|
245 }
|
max@0
|
246
|
max@0
|
247 if(i < aa_n_elem)
|
max@0
|
248 {
|
max@0
|
249 const uword ii = aa_mem[i];
|
max@0
|
250
|
max@0
|
251 arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
|
max@0
|
252
|
max@0
|
253 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; }
|
max@0
|
254 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; }
|
max@0
|
255 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; }
|
max@0
|
256 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; }
|
max@0
|
257 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; }
|
max@0
|
258 }
|
max@0
|
259 }
|
max@0
|
260 else
|
max@0
|
261 {
|
max@0
|
262 arma_extra_debug_print("subview_elem1::inplace_op(): aliasing or prefer_at_accessor detected");
|
max@0
|
263
|
max@0
|
264 const unwrap_check<typename Proxy<T2>::stored_type> tmp(P.Q, m_local);
|
max@0
|
265 const Mat<eT>& M = tmp.M;
|
max@0
|
266
|
max@0
|
267 const eT* X = M.memptr();
|
max@0
|
268
|
max@0
|
269 uword i,j;
|
max@0
|
270 for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
|
max@0
|
271 {
|
max@0
|
272 const uword ii = aa_mem[i];
|
max@0
|
273 const uword jj = aa_mem[j];
|
max@0
|
274
|
max@0
|
275 arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
|
max@0
|
276
|
max@0
|
277 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; }
|
max@0
|
278 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; }
|
max@0
|
279 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; }
|
max@0
|
280 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; }
|
max@0
|
281 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; }
|
max@0
|
282 }
|
max@0
|
283
|
max@0
|
284 if(i < aa_n_elem)
|
max@0
|
285 {
|
max@0
|
286 const uword ii = aa_mem[i];
|
max@0
|
287
|
max@0
|
288 arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
|
max@0
|
289
|
max@0
|
290 if(is_same_type<op_type, op_subview_elem_equ >::value == true) { m_mem[ii] = X[i]; }
|
max@0
|
291 else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { m_mem[ii] += X[i]; }
|
max@0
|
292 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { m_mem[ii] -= X[i]; }
|
max@0
|
293 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { m_mem[ii] *= X[i]; }
|
max@0
|
294 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { m_mem[ii] /= X[i]; }
|
max@0
|
295 }
|
max@0
|
296 }
|
max@0
|
297 }
|
max@0
|
298
|
max@0
|
299
|
max@0
|
300
|
max@0
|
301 //
|
max@0
|
302 //
|
max@0
|
303
|
max@0
|
304
|
max@0
|
305
|
max@0
|
306 template<typename eT, typename T1>
|
max@0
|
307 inline
|
max@0
|
308 void
|
max@0
|
309 subview_elem1<eT,T1>::fill(const eT val)
|
max@0
|
310 {
|
max@0
|
311 arma_extra_debug_sigprint();
|
max@0
|
312
|
max@0
|
313 inplace_op<op_subview_elem_equ>(val);
|
max@0
|
314 }
|
max@0
|
315
|
max@0
|
316
|
max@0
|
317
|
max@0
|
318 template<typename eT, typename T1>
|
max@0
|
319 inline
|
max@0
|
320 void
|
max@0
|
321 subview_elem1<eT,T1>::zeros()
|
max@0
|
322 {
|
max@0
|
323 arma_extra_debug_sigprint();
|
max@0
|
324
|
max@0
|
325 inplace_op<op_subview_elem_equ>(eT(0));
|
max@0
|
326 }
|
max@0
|
327
|
max@0
|
328
|
max@0
|
329
|
max@0
|
330 template<typename eT, typename T1>
|
max@0
|
331 inline
|
max@0
|
332 void
|
max@0
|
333 subview_elem1<eT,T1>::ones()
|
max@0
|
334 {
|
max@0
|
335 arma_extra_debug_sigprint();
|
max@0
|
336
|
max@0
|
337 inplace_op<op_subview_elem_equ>(eT(1));
|
max@0
|
338 }
|
max@0
|
339
|
max@0
|
340
|
max@0
|
341
|
max@0
|
342 template<typename eT, typename T1>
|
max@0
|
343 inline
|
max@0
|
344 void
|
max@0
|
345 subview_elem1<eT,T1>::operator+= (const eT val)
|
max@0
|
346 {
|
max@0
|
347 arma_extra_debug_sigprint();
|
max@0
|
348
|
max@0
|
349 inplace_op<op_subview_elem_inplace_plus>(val);
|
max@0
|
350 }
|
max@0
|
351
|
max@0
|
352
|
max@0
|
353
|
max@0
|
354 template<typename eT, typename T1>
|
max@0
|
355 inline
|
max@0
|
356 void
|
max@0
|
357 subview_elem1<eT,T1>::operator-= (const eT val)
|
max@0
|
358 {
|
max@0
|
359 arma_extra_debug_sigprint();
|
max@0
|
360
|
max@0
|
361 inplace_op<op_subview_elem_inplace_minus>(val);
|
max@0
|
362 }
|
max@0
|
363
|
max@0
|
364
|
max@0
|
365
|
max@0
|
366 template<typename eT, typename T1>
|
max@0
|
367 inline
|
max@0
|
368 void
|
max@0
|
369 subview_elem1<eT,T1>::operator*= (const eT val)
|
max@0
|
370 {
|
max@0
|
371 arma_extra_debug_sigprint();
|
max@0
|
372
|
max@0
|
373 inplace_op<op_subview_elem_inplace_schur>(val);
|
max@0
|
374 }
|
max@0
|
375
|
max@0
|
376
|
max@0
|
377
|
max@0
|
378 template<typename eT, typename T1>
|
max@0
|
379 inline
|
max@0
|
380 void
|
max@0
|
381 subview_elem1<eT,T1>::operator/= (const eT val)
|
max@0
|
382 {
|
max@0
|
383 arma_extra_debug_sigprint();
|
max@0
|
384
|
max@0
|
385 inplace_op<op_subview_elem_inplace_div>(val);
|
max@0
|
386 }
|
max@0
|
387
|
max@0
|
388
|
max@0
|
389
|
max@0
|
390 //
|
max@0
|
391 //
|
max@0
|
392
|
max@0
|
393
|
max@0
|
394
|
max@0
|
395 template<typename eT, typename T1>
|
max@0
|
396 template<typename T2>
|
max@0
|
397 inline
|
max@0
|
398 void
|
max@0
|
399 subview_elem1<eT,T1>::operator_equ(const subview_elem1<eT,T2>& x)
|
max@0
|
400 {
|
max@0
|
401 arma_extra_debug_sigprint();
|
max@0
|
402
|
max@0
|
403 inplace_op<op_subview_elem_equ>(x);
|
max@0
|
404 }
|
max@0
|
405
|
max@0
|
406
|
max@0
|
407
|
max@0
|
408
|
max@0
|
409 template<typename eT, typename T1>
|
max@0
|
410 template<typename T2>
|
max@0
|
411 inline
|
max@0
|
412 void
|
max@0
|
413 subview_elem1<eT,T1>::operator= (const subview_elem1<eT,T2>& x)
|
max@0
|
414 {
|
max@0
|
415 arma_extra_debug_sigprint();
|
max@0
|
416
|
max@0
|
417 (*this).operator_equ(x);
|
max@0
|
418 }
|
max@0
|
419
|
max@0
|
420
|
max@0
|
421
|
max@0
|
422 //! work around compiler bugs
|
max@0
|
423 template<typename eT, typename T1>
|
max@0
|
424 inline
|
max@0
|
425 void
|
max@0
|
426 subview_elem1<eT,T1>::operator= (const subview_elem1<eT,T1>& x)
|
max@0
|
427 {
|
max@0
|
428 arma_extra_debug_sigprint();
|
max@0
|
429
|
max@0
|
430 (*this).operator_equ(x);
|
max@0
|
431 }
|
max@0
|
432
|
max@0
|
433
|
max@0
|
434
|
max@0
|
435 template<typename eT, typename T1>
|
max@0
|
436 template<typename T2>
|
max@0
|
437 inline
|
max@0
|
438 void
|
max@0
|
439 subview_elem1<eT,T1>::operator+= (const subview_elem1<eT,T2>& x)
|
max@0
|
440 {
|
max@0
|
441 arma_extra_debug_sigprint();
|
max@0
|
442
|
max@0
|
443 inplace_op<op_subview_elem_inplace_plus>(x);
|
max@0
|
444 }
|
max@0
|
445
|
max@0
|
446
|
max@0
|
447
|
max@0
|
448 template<typename eT, typename T1>
|
max@0
|
449 template<typename T2>
|
max@0
|
450 inline
|
max@0
|
451 void
|
max@0
|
452 subview_elem1<eT,T1>::operator-= (const subview_elem1<eT,T2>& x)
|
max@0
|
453 {
|
max@0
|
454 arma_extra_debug_sigprint();
|
max@0
|
455
|
max@0
|
456 inplace_op<op_subview_elem_inplace_minus>(x);
|
max@0
|
457 }
|
max@0
|
458
|
max@0
|
459
|
max@0
|
460
|
max@0
|
461 template<typename eT, typename T1>
|
max@0
|
462 template<typename T2>
|
max@0
|
463 inline
|
max@0
|
464 void
|
max@0
|
465 subview_elem1<eT,T1>::operator%= (const subview_elem1<eT,T2>& x)
|
max@0
|
466 {
|
max@0
|
467 arma_extra_debug_sigprint();
|
max@0
|
468
|
max@0
|
469 inplace_op<op_subview_elem_inplace_schur>(x);
|
max@0
|
470 }
|
max@0
|
471
|
max@0
|
472
|
max@0
|
473
|
max@0
|
474 template<typename eT, typename T1>
|
max@0
|
475 template<typename T2>
|
max@0
|
476 inline
|
max@0
|
477 void
|
max@0
|
478 subview_elem1<eT,T1>::operator/= (const subview_elem1<eT,T2>& x)
|
max@0
|
479 {
|
max@0
|
480 arma_extra_debug_sigprint();
|
max@0
|
481
|
max@0
|
482 inplace_op<op_subview_elem_inplace_div>(x);
|
max@0
|
483 }
|
max@0
|
484
|
max@0
|
485
|
max@0
|
486
|
max@0
|
487 template<typename eT, typename T1>
|
max@0
|
488 template<typename T2>
|
max@0
|
489 inline
|
max@0
|
490 void
|
max@0
|
491 subview_elem1<eT,T1>::operator= (const Base<eT,T2>& x)
|
max@0
|
492 {
|
max@0
|
493 arma_extra_debug_sigprint();
|
max@0
|
494
|
max@0
|
495 inplace_op<op_subview_elem_equ>(x);
|
max@0
|
496 }
|
max@0
|
497
|
max@0
|
498
|
max@0
|
499
|
max@0
|
500 template<typename eT, typename T1>
|
max@0
|
501 template<typename T2>
|
max@0
|
502 inline
|
max@0
|
503 void
|
max@0
|
504 subview_elem1<eT,T1>::operator+= (const Base<eT,T2>& x)
|
max@0
|
505 {
|
max@0
|
506 arma_extra_debug_sigprint();
|
max@0
|
507
|
max@0
|
508 inplace_op<op_subview_elem_inplace_plus>(x);
|
max@0
|
509 }
|
max@0
|
510
|
max@0
|
511
|
max@0
|
512
|
max@0
|
513 template<typename eT, typename T1>
|
max@0
|
514 template<typename T2>
|
max@0
|
515 inline
|
max@0
|
516 void
|
max@0
|
517 subview_elem1<eT,T1>::operator-= (const Base<eT,T2>& x)
|
max@0
|
518 {
|
max@0
|
519 arma_extra_debug_sigprint();
|
max@0
|
520
|
max@0
|
521 inplace_op<op_subview_elem_inplace_minus>(x);
|
max@0
|
522 }
|
max@0
|
523
|
max@0
|
524
|
max@0
|
525
|
max@0
|
526 template<typename eT, typename T1>
|
max@0
|
527 template<typename T2>
|
max@0
|
528 inline
|
max@0
|
529 void
|
max@0
|
530 subview_elem1<eT,T1>::operator%= (const Base<eT,T2>& x)
|
max@0
|
531 {
|
max@0
|
532 arma_extra_debug_sigprint();
|
max@0
|
533
|
max@0
|
534 inplace_op<op_subview_elem_inplace_schur>(x);
|
max@0
|
535 }
|
max@0
|
536
|
max@0
|
537
|
max@0
|
538
|
max@0
|
539 template<typename eT, typename T1>
|
max@0
|
540 template<typename T2>
|
max@0
|
541 inline
|
max@0
|
542 void
|
max@0
|
543 subview_elem1<eT,T1>::operator/= (const Base<eT,T2>& x)
|
max@0
|
544 {
|
max@0
|
545 arma_extra_debug_sigprint();
|
max@0
|
546
|
max@0
|
547 inplace_op<op_subview_elem_inplace_div>(x);
|
max@0
|
548 }
|
max@0
|
549
|
max@0
|
550
|
max@0
|
551
|
max@0
|
552 //
|
max@0
|
553 //
|
max@0
|
554
|
max@0
|
555
|
max@0
|
556
|
max@0
|
557 template<typename eT, typename T1>
|
max@0
|
558 inline
|
max@0
|
559 void
|
max@0
|
560 subview_elem1<eT,T1>::extract(Mat<eT>& actual_out, const subview_elem1<eT,T1>& in)
|
max@0
|
561 {
|
max@0
|
562 arma_extra_debug_sigprint();
|
max@0
|
563
|
max@0
|
564 const unwrap_check_mixed<T1> tmp1(in.a.get_ref(), actual_out);
|
max@0
|
565 const umat& aa = tmp1.M;
|
max@0
|
566
|
max@0
|
567 arma_debug_check
|
max@0
|
568 (
|
max@0
|
569 ( aa.is_vec() == false ),
|
max@0
|
570 "Mat::elem(): given object is not a vector"
|
max@0
|
571 );
|
max@0
|
572
|
max@0
|
573 const uword* aa_mem = aa.memptr();
|
max@0
|
574 const uword aa_n_elem = aa.n_elem;
|
max@0
|
575
|
max@0
|
576 const Mat<eT>& m_local = in.m;
|
max@0
|
577
|
max@0
|
578 const eT* m_mem = m_local.memptr();
|
max@0
|
579 const uword m_n_elem = m_local.n_elem;
|
max@0
|
580
|
max@0
|
581 const bool alias = (&actual_out == &m_local);
|
max@0
|
582
|
max@0
|
583 arma_extra_debug_warn(alias, "subview_elem1::extract(): aliasing detected");
|
max@0
|
584
|
max@0
|
585 Mat<eT>* tmp_out = alias ? new Mat<eT>() : 0;
|
max@0
|
586 Mat<eT>& out = alias ? *tmp_out : actual_out;
|
max@0
|
587
|
max@0
|
588 out.set_size(aa_n_elem, 1);
|
max@0
|
589
|
max@0
|
590 eT* out_mem = out.memptr();
|
max@0
|
591
|
max@0
|
592 uword i,j;
|
max@0
|
593 for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
|
max@0
|
594 {
|
max@0
|
595 const uword ii = aa_mem[i];
|
max@0
|
596 const uword jj = aa_mem[j];
|
max@0
|
597
|
max@0
|
598 arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
|
max@0
|
599
|
max@0
|
600 out_mem[i] = m_mem[ii];
|
max@0
|
601 out_mem[j] = m_mem[jj];
|
max@0
|
602 }
|
max@0
|
603
|
max@0
|
604 if(i < aa_n_elem)
|
max@0
|
605 {
|
max@0
|
606 const uword ii = aa_mem[i];
|
max@0
|
607
|
max@0
|
608 arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
|
max@0
|
609
|
max@0
|
610 out_mem[i] = m_mem[ii];
|
max@0
|
611 }
|
max@0
|
612
|
max@0
|
613 if(alias == true)
|
max@0
|
614 {
|
max@0
|
615 actual_out = out;
|
max@0
|
616 delete tmp_out;
|
max@0
|
617 }
|
max@0
|
618 }
|
max@0
|
619
|
max@0
|
620
|
max@0
|
621
|
max@0
|
622 template<typename eT, typename T1>
|
max@0
|
623 template<typename op_type>
|
max@0
|
624 inline
|
max@0
|
625 void
|
max@0
|
626 subview_elem1<eT,T1>::mat_inplace_op(Mat<eT>& out, const subview_elem1& in)
|
max@0
|
627 {
|
max@0
|
628 arma_extra_debug_sigprint();
|
max@0
|
629
|
max@0
|
630 const unwrap<T1> tmp1(in.a.get_ref());
|
max@0
|
631 const umat& aa = tmp1.M;
|
max@0
|
632
|
max@0
|
633 arma_debug_check
|
max@0
|
634 (
|
max@0
|
635 ( aa.is_vec() == false ),
|
max@0
|
636 "Mat::elem(): given object is not a vector"
|
max@0
|
637 );
|
max@0
|
638
|
max@0
|
639 const uword* aa_mem = aa.memptr();
|
max@0
|
640 const uword aa_n_elem = aa.n_elem;
|
max@0
|
641
|
max@0
|
642 const unwrap_check< Mat<eT> > tmp2(in.m, out);
|
max@0
|
643 const Mat<eT>& m_local = tmp2.M;
|
max@0
|
644
|
max@0
|
645 const eT* m_mem = m_local.memptr();
|
max@0
|
646 const uword m_n_elem = m_local.n_elem;
|
max@0
|
647
|
max@0
|
648 arma_debug_check( (out.n_elem != aa_n_elem), "Mat::elem(): size mismatch" );
|
max@0
|
649
|
max@0
|
650 eT* out_mem = out.memptr();
|
max@0
|
651
|
max@0
|
652 uword i,j;
|
max@0
|
653 for(i=0, j=1; j<aa_n_elem; i+=2, j+=2)
|
max@0
|
654 {
|
max@0
|
655 const uword ii = aa_mem[i];
|
max@0
|
656 const uword jj = aa_mem[j];
|
max@0
|
657
|
max@0
|
658 arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" );
|
max@0
|
659
|
max@0
|
660 if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { out_mem[i] += m_mem[ii]; out_mem[j] += m_mem[jj]; }
|
max@0
|
661 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { out_mem[i] -= m_mem[ii]; out_mem[j] -= m_mem[jj]; }
|
max@0
|
662 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { out_mem[i] *= m_mem[ii]; out_mem[j] *= m_mem[jj]; }
|
max@0
|
663 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { out_mem[i] /= m_mem[ii]; out_mem[j] /= m_mem[jj]; }
|
max@0
|
664 }
|
max@0
|
665
|
max@0
|
666 if(i < aa_n_elem)
|
max@0
|
667 {
|
max@0
|
668 const uword ii = aa_mem[i];
|
max@0
|
669
|
max@0
|
670 arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" );
|
max@0
|
671
|
max@0
|
672 if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == true) { out_mem[i] += m_mem[ii]; }
|
max@0
|
673 else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == true) { out_mem[i] -= m_mem[ii]; }
|
max@0
|
674 else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == true) { out_mem[i] *= m_mem[ii]; }
|
max@0
|
675 else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == true) { out_mem[i] /= m_mem[ii]; }
|
max@0
|
676 }
|
max@0
|
677 }
|
max@0
|
678
|
max@0
|
679
|
max@0
|
680
|
max@0
|
681 template<typename eT, typename T1>
|
max@0
|
682 inline
|
max@0
|
683 void
|
max@0
|
684 subview_elem1<eT,T1>::plus_inplace(Mat<eT>& out, const subview_elem1& in)
|
max@0
|
685 {
|
max@0
|
686 arma_extra_debug_sigprint();
|
max@0
|
687
|
max@0
|
688 mat_inplace_op<op_subview_elem_inplace_plus>(out, in);
|
max@0
|
689 }
|
max@0
|
690
|
max@0
|
691
|
max@0
|
692
|
max@0
|
693 template<typename eT, typename T1>
|
max@0
|
694 inline
|
max@0
|
695 void
|
max@0
|
696 subview_elem1<eT,T1>::minus_inplace(Mat<eT>& out, const subview_elem1& in)
|
max@0
|
697 {
|
max@0
|
698 arma_extra_debug_sigprint();
|
max@0
|
699
|
max@0
|
700 mat_inplace_op<op_subview_elem_inplace_minus>(out, in);
|
max@0
|
701 }
|
max@0
|
702
|
max@0
|
703
|
max@0
|
704
|
max@0
|
705 template<typename eT, typename T1>
|
max@0
|
706 inline
|
max@0
|
707 void
|
max@0
|
708 subview_elem1<eT,T1>::schur_inplace(Mat<eT>& out, const subview_elem1& in)
|
max@0
|
709 {
|
max@0
|
710 arma_extra_debug_sigprint();
|
max@0
|
711
|
max@0
|
712 mat_inplace_op<op_subview_elem_inplace_schur>(out, in);
|
max@0
|
713 }
|
max@0
|
714
|
max@0
|
715
|
max@0
|
716
|
max@0
|
717 template<typename eT, typename T1>
|
max@0
|
718 inline
|
max@0
|
719 void
|
max@0
|
720 subview_elem1<eT,T1>::div_inplace(Mat<eT>& out, const subview_elem1& in)
|
max@0
|
721 {
|
max@0
|
722 arma_extra_debug_sigprint();
|
max@0
|
723
|
max@0
|
724 mat_inplace_op<op_subview_elem_inplace_div>(out, in);
|
max@0
|
725 }
|
max@0
|
726
|
max@0
|
727
|
max@0
|
728
|
max@0
|
729 //! @}
|