glue_mixed_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-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 
16 
17 
18 
20 template<typename T1, typename T2>
21 inline
22 void
24  {
26 
27  typedef typename T1::elem_type eT1;
28  typedef typename T2::elem_type eT2;
29 
30  // TODO: extend the unwrap_check framework to handle mixed matrix types
31 
32  const unwrap<T1> tmp1(X.A);
33  const unwrap<T2> tmp2(X.B);
34 
35  const Mat<eT1>& A = tmp1.M;
36  const Mat<eT2>& B = tmp2.M;
37 
38  const bool A_is_alias = ( ((void *)&out) == ((void *)&A) );
39  const bool B_is_alias = ( ((void *)&out) == ((void *)&B) );
40 
41  const Mat<eT1>* AA_ptr = A_is_alias ? new Mat<eT1>(A) : 0;
42  const Mat<eT2>* BB_ptr = B_is_alias ? new Mat<eT2>(B) : 0;
43 
44  const Mat<eT1>& AA = A_is_alias ? *AA_ptr : A;
45  const Mat<eT2>& BB = B_is_alias ? *BB_ptr : B;
46 
47  arma_debug_assert_mul_size(AA, BB, "multiplication");
48 
49  out.set_size(AA.n_rows, BB.n_cols);
50 
51  gemm_mixed<>::apply(out, AA, BB);
52 
53  if(A_is_alias == true)
54  {
55  delete AA_ptr;
56  }
57 
58  if(B_is_alias == true)
59  {
60  delete BB_ptr;
61  }
62  }
63 
64 
65 
67 template<typename T1, typename T2>
68 inline
69 void
71  {
73 
74  typedef typename T1::elem_type eT1;
75  typedef typename T2::elem_type eT2;
76 
77  typedef typename promote_type<eT1,eT2>::result out_eT;
78 
80 
81  const Proxy<T1> A(X.A);
82  const Proxy<T2> B(X.B);
83 
84  arma_debug_assert_same_size(A, B, "addition");
85 
86  out.set_size(A.get_n_rows(), A.get_n_cols());
87 
88  out_eT* out_mem = out.memptr();
89  const uword n_elem = out.n_elem;
90 
91  for(uword i=0; i<n_elem; ++i)
92  {
94  }
95  }
96 
97 
98 
100 template<typename T1, typename T2>
101 inline
102 void
104  {
106 
107  typedef typename T1::elem_type eT1;
108  typedef typename T2::elem_type eT2;
109 
110  typedef typename promote_type<eT1,eT2>::result out_eT;
111 
113 
114  const Proxy<T1> A(X.A);
115  const Proxy<T2> B(X.B);
116 
117  arma_debug_assert_same_size(A, B, "subtraction");
118 
119  out.set_size(A.get_n_rows(), A.get_n_cols());
120 
121  out_eT* out_mem = out.memptr();
122  const uword n_elem = out.n_elem;
123 
124  for(uword i=0; i<n_elem; ++i)
125  {
126  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>::apply(B[i]);
127  }
128  }
129 
130 
131 
133 template<typename T1, typename T2>
134 inline
135 void
137  {
139 
140  typedef typename T1::elem_type eT1;
141  typedef typename T2::elem_type eT2;
142 
143  typedef typename promote_type<eT1,eT2>::result out_eT;
144 
146 
147  const Proxy<T1> A(X.A);
148  const Proxy<T2> B(X.B);
149 
150  arma_debug_assert_same_size(A, B, "element-wise division");
151 
152  out.set_size(A.get_n_rows(), A.get_n_cols());
153 
154  out_eT* out_mem = out.memptr();
155  const uword n_elem = out.n_elem;
156 
157  for(uword i=0; i<n_elem; ++i)
158  {
159  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::apply(B[i]);
160  }
161  }
162 
163 
164 
166 template<typename T1, typename T2>
167 inline
168 void
170  {
172 
173  typedef typename T1::elem_type eT1;
174  typedef typename T2::elem_type eT2;
175 
176  typedef typename promote_type<eT1,eT2>::result out_eT;
177 
179 
180  const Proxy<T1> A(X.A);
181  const Proxy<T2> B(X.B);
182 
183  arma_debug_assert_same_size(A, B, "element-wise multiplication");
184 
185  out.set_size(A.get_n_rows(), A.get_n_cols());
186 
187  out_eT* out_mem = out.memptr();
188  const uword n_elem = out.n_elem;
189 
190  for(uword i=0; i<n_elem; ++i)
191  {
192  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::apply(B[i]);
193  }
194  }
195 
196 
197 
198 //
199 //
200 //
201 
202 
203 
205 template<typename T1, typename T2>
206 inline
207 void
209  {
211 
212  typedef typename T1::elem_type eT1;
213  typedef typename T2::elem_type eT2;
214 
215  typedef typename promote_type<eT1,eT2>::result out_eT;
216 
218 
219  const ProxyCube<T1> A(X.A);
220  const ProxyCube<T2> B(X.B);
221 
222  arma_debug_assert_same_size(A, B, "addition");
223 
224  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
225 
226  out_eT* out_mem = out.memptr();
227  const uword n_elem = out.n_elem;
228 
229  for(uword i=0; i<n_elem; ++i)
230  {
231  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) + upgrade_val<eT1,eT2>::apply(B[i]);
232  }
233  }
234 
235 
236 
238 template<typename T1, typename T2>
239 inline
240 void
242  {
244 
245  typedef typename T1::elem_type eT1;
246  typedef typename T2::elem_type eT2;
247 
248  typedef typename promote_type<eT1,eT2>::result out_eT;
249 
251 
252  const ProxyCube<T1> A(X.A);
253  const ProxyCube<T2> B(X.B);
254 
255  arma_debug_assert_same_size(A, B, "subtraction");
256 
257  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
258 
259  out_eT* out_mem = out.memptr();
260  const uword n_elem = out.n_elem;
261 
262  for(uword i=0; i<n_elem; ++i)
263  {
264  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) - upgrade_val<eT1,eT2>::apply(B[i]);
265  }
266  }
267 
268 
269 
271 template<typename T1, typename T2>
272 inline
273 void
275  {
277 
278  typedef typename T1::elem_type eT1;
279  typedef typename T2::elem_type eT2;
280 
281  typedef typename promote_type<eT1,eT2>::result out_eT;
282 
284 
285  const ProxyCube<T1> A(X.A);
286  const ProxyCube<T2> B(X.B);
287 
288  arma_debug_assert_same_size(A, B, "element-wise division");
289 
290  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
291 
292  out_eT* out_mem = out.memptr();
293  const uword n_elem = out.n_elem;
294 
295  for(uword i=0; i<n_elem; ++i)
296  {
297  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) / upgrade_val<eT1,eT2>::apply(B[i]);
298  }
299  }
300 
301 
302 
304 template<typename T1, typename T2>
305 inline
306 void
308  {
310 
311  typedef typename T1::elem_type eT1;
312  typedef typename T2::elem_type eT2;
313 
314  typedef typename promote_type<eT1,eT2>::result out_eT;
315 
317 
318  const ProxyCube<T1> A(X.A);
319  const ProxyCube<T2> B(X.B);
320 
321  arma_debug_assert_same_size(A, B, "element-wise multiplication");
322 
323  out.set_size(A.get_n_rows(), A.get_n_cols(), A.get_n_slices());
324 
325  out_eT* out_mem = out.memptr();
326  const uword n_elem = out.n_elem;
327 
328  for(uword i=0; i<n_elem; ++i)
329  {
330  out_mem[i] = upgrade_val<eT1,eT2>::apply(A[i]) * upgrade_val<eT1,eT2>::apply(B[i]);
331  }
332  }
333 
334 
335 
is_promotable< T1, T2 >::result result
static void check()
static void apply(Mat< typename eT_promoter< T1, T2 >::eT > &out, const mtGlue< typename eT_promoter< T1, T2 >::eT, T1, T2, glue_mixed_plus > &X)
matrix addition with different element types
static void apply(Mat< typename eT_promoter< T1, T2 >::eT > &out, const mtGlue< typename eT_promoter< T1, T2 >::eT, T1, T2, glue_mixed_div > &X)
element-wise matrix division with different element types
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
#define arma_debug_assert_same_size
Definition: debug.hpp:1086
static void apply(Mat< typename eT_promoter< T1, T2 >::eT > &out, const mtGlue< typename eT_promoter< T1, T2 >::eT, T1, T2, glue_mixed_times > &X)
matrix multiplication with different element types
u32 uword
Definition: typedef.hpp:85
const Mat< eT > M
Definition: unwrap.hpp:32
Dense cube class.
Definition: Cube_bones.hpp:30
static void apply(Mat< typename eT_promoter< T1, T2 >::eT > &out, const mtGlue< typename eT_promoter< T1, T2 >::eT, T1, T2, glue_mixed_minus > &X)
matrix subtraction with different element types
promote_type< typename T1::elem_type, typename T2::elem_type >::result eT
static arma_inline promote_type< T1, T2 >::result apply(const T1 x)
Definition: upgrade_val.hpp:31
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
static void apply(Mat< typename eT_promoter< T1, T2 >::eT > &out, const mtGlue< typename eT_promoter< T1, T2 >::eT, T1, T2, glue_mixed_schur > &X)
element-wise matrix multiplication with different element types
#define arma_debug_assert_mul_size
Definition: debug.hpp:1087
Dense matrix class.
static void apply(Mat< out_eT > &C, const Mat< in_eT1 > &A, const Mat< in_eT2 > &B, const out_eT alpha=out_eT(1), const out_eT beta=out_eT(0))
immediate multiplication of matrices A and B, storing the result in C
Definition: gemm_mixed.hpp:409


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57