comparison armadillo-2.4.4/include/armadillo_bits/operator_times.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) 2008-2010 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2010 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
15 //! \addtogroup operator_times
16 //! @{
17
18
19
20 //! Base * scalar
21 template<typename T1>
22 arma_inline
23 const eOp<T1, eop_scalar_times>
24 operator*
25 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k)
26 {
27 arma_extra_debug_sigprint();
28
29 return eOp<T1, eop_scalar_times>(X.get_ref(),k);
30 }
31
32
33
34 //! scalar * Base
35 template<typename T1>
36 arma_inline
37 const eOp<T1, eop_scalar_times>
38 operator*
39 (const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
40 {
41 arma_extra_debug_sigprint();
42
43 return eOp<T1, eop_scalar_times>(X.get_ref(),k); // NOTE: order is swapped
44 }
45
46
47
48 //! non-complex Base * complex scalar (experimental)
49 template<typename T1>
50 arma_inline
51 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>
52 operator*
53 (
54 const Base<typename T1::pod_type, T1>& X,
55 const std::complex<typename T1::pod_type>& k
56 )
57 {
58 arma_extra_debug_sigprint();
59
60 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>('j', X.get_ref(), k);
61 }
62
63
64
65 //! complex scalar * non-complex Base (experimental)
66 template<typename T1>
67 arma_inline
68 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>
69 operator*
70 (
71 const std::complex<typename T1::pod_type>& k,
72 const Base<typename T1::pod_type, T1>& X
73 )
74 {
75 arma_extra_debug_sigprint();
76
77 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>('j', X.get_ref(), k);
78 }
79
80
81
82 //! scalar * trans(T1)
83 template<typename T1>
84 arma_inline
85 const Op<T1, op_htrans2>
86 operator*
87 (const typename T1::elem_type k, const Op<T1, op_htrans>& X)
88 {
89 arma_extra_debug_sigprint();
90
91 return Op<T1, op_htrans2>(X.m, k);
92 }
93
94
95
96 //! trans(T1) * scalar
97 template<typename T1>
98 arma_inline
99 const Op<T1, op_htrans2>
100 operator*
101 (const Op<T1, op_htrans>& X, const typename T1::elem_type k)
102 {
103 arma_extra_debug_sigprint();
104
105 return Op<T1, op_htrans2>(X.m, k);
106 }
107
108
109
110 //! Base * diagmat
111 template<typename T1, typename T2>
112 arma_inline
113 const Glue<T1, Op<T2, op_diagmat>, glue_times_diag>
114 operator*
115 (const Base<typename T2::elem_type,T1>& X, const Op<T2, op_diagmat>& Y)
116 {
117 arma_extra_debug_sigprint();
118
119 return Glue<T1, Op<T2, op_diagmat>, glue_times_diag>(X.get_ref(), Y);
120 }
121
122
123
124 //! diagmat * Base
125 template<typename T1, typename T2>
126 arma_inline
127 const Glue<Op<T1, op_diagmat>, T2, glue_times_diag>
128 operator*
129 (const Op<T1, op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y)
130 {
131 arma_extra_debug_sigprint();
132
133 return Glue<Op<T1, op_diagmat>, T2, glue_times_diag>(X, Y.get_ref());
134 }
135
136
137
138 //! diagmat * diagmat
139 template<typename T1, typename T2>
140 arma_inline
141 Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>::result >
142 operator*
143 (const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
144 {
145 arma_extra_debug_sigprint();
146
147 typedef typename T1::elem_type eT1;
148 typedef typename T2::elem_type eT2;
149
150 typedef typename promote_type<eT1,eT2>::result out_eT;
151
152 promote_type<eT1,eT2>::check();
153
154 const diagmat_proxy<T1> A(X.m);
155 const diagmat_proxy<T2> B(Y.m);
156
157 arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "matrix multiply");
158
159 const uword N = A.n_elem;
160
161 Mat<out_eT> out(N,N);
162
163 out.zeros();
164
165 for(uword i=0; i<N; ++i)
166 {
167 out.at(i,i) = upgrade_val<eT1,eT2>::apply( A[i] ) * upgrade_val<eT1,eT2>::apply( B[i] );
168 }
169
170 return out;
171 }
172
173
174
175 //! multiplication of Base objects with same element type
176 template<typename T1, typename T2>
177 arma_inline
178 const Glue<T1, T2, glue_times>
179 operator*
180 (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y)
181 {
182 arma_extra_debug_sigprint();
183
184 return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
185 }
186
187
188
189 //! multiplication of Base objects with different element types
190 template<typename T1, typename T2>
191 inline
192 const mtGlue< typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_times >
193 operator*
194 (
195 const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T1_result, T1>& X,
196 const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T2_result, T2>& Y
197 )
198 {
199 arma_extra_debug_sigprint();
200
201 typedef typename T1::elem_type eT1;
202 typedef typename T2::elem_type eT2;
203
204 typedef typename promote_type<eT1,eT2>::result out_eT;
205
206 promote_type<eT1,eT2>::check();
207
208 return mtGlue<out_eT, T1, T2, glue_mixed_times>( X.get_ref(), Y.get_ref() );
209 }
210
211
212
213 //! @}