comparison armadillo-3.900.4/include/armadillo_bits/operator_plus.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) 2008-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2012 Conrad Sanderson
3 // Copyright (C) 2012 Ryan Curtin
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9
10 //! \addtogroup operator_plus
11 //! @{
12
13
14
15 //! unary plus operation (does nothing, but is required for completeness)
16 template<typename T1>
17 arma_inline
18 typename enable_if2< is_arma_type<T1>::value, const T1& >::result
19 operator+
20 (const T1& X)
21 {
22 arma_extra_debug_sigprint();
23
24 return X;
25 }
26
27
28
29 //! Base + scalar
30 template<typename T1>
31 arma_inline
32 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_scalar_plus> >::result
33 operator+
34 (const T1& X, const typename T1::elem_type k)
35 {
36 arma_extra_debug_sigprint();
37
38 return eOp<T1, eop_scalar_plus>(X, k);
39 }
40
41
42
43 //! scalar + Base
44 template<typename T1>
45 arma_inline
46 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_scalar_plus> >::result
47 operator+
48 (const typename T1::elem_type k, const T1& X)
49 {
50 arma_extra_debug_sigprint();
51
52 return eOp<T1, eop_scalar_plus>(X, k); // NOTE: order is swapped
53 }
54
55
56
57 //! non-complex Base + complex scalar
58 template<typename T1>
59 arma_inline
60 typename
61 enable_if2
62 <
63 (is_arma_type<T1>::value && is_complex<typename T1::elem_type>::value == false),
64 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
65 >::result
66 operator+
67 (
68 const T1& X,
69 const std::complex<typename T1::pod_type>& k
70 )
71 {
72 arma_extra_debug_sigprint();
73
74 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X, k);
75 }
76
77
78
79 //! complex scalar + non-complex Base
80 template<typename T1>
81 arma_inline
82 typename
83 enable_if2
84 <
85 (is_arma_type<T1>::value && is_complex<typename T1::elem_type>::value == false),
86 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
87 >::result
88 operator+
89 (
90 const std::complex<typename T1::pod_type>& k,
91 const T1& X
92 )
93 {
94 arma_extra_debug_sigprint();
95
96 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X, k); // NOTE: order is swapped
97 }
98
99
100
101 //! addition of user-accessible Armadillo objects with same element type
102 template<typename T1, typename T2>
103 arma_inline
104 typename
105 enable_if2
106 <
107 is_arma_type<T1>::value && is_arma_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value,
108 const eGlue<T1, T2, eglue_plus>
109 >::result
110 operator+
111 (
112 const T1& X,
113 const T2& Y
114 )
115 {
116 arma_extra_debug_sigprint();
117
118 return eGlue<T1, T2, eglue_plus>(X, Y);
119 }
120
121
122
123 //! addition of user-accessible Armadillo objects with different element types
124 template<typename T1, typename T2>
125 inline
126 typename
127 enable_if2
128 <
129 (is_arma_type<T1>::value && is_arma_type<T2>::value && (is_same_type<typename T1::elem_type, typename T2::elem_type>::value == false)),
130 const mtGlue<typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_plus>
131 >::result
132 operator+
133 (
134 const T1& X,
135 const T2& Y
136 )
137 {
138 arma_extra_debug_sigprint();
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
145 promote_type<eT1,eT2>::check();
146
147 return mtGlue<out_eT, T1, T2, glue_mixed_plus>( X, Y );
148 }
149
150
151
152 //! addition of two sparse objects
153 template<typename T1, typename T2>
154 inline
155 arma_hot
156 typename
157 enable_if2
158 <
159 (is_arma_sparse_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
160 SpGlue<T1,T2,spglue_plus>
161 >::result
162 operator+
163 (
164 const T1& x,
165 const T2& y
166 )
167 {
168 arma_extra_debug_sigprint();
169
170 return SpGlue<T1,T2,spglue_plus>(x, y);
171 }
172
173
174
175 //! addition of sparse and non-sparse object
176 template<typename T1, typename T2>
177 inline
178 typename
179 enable_if2
180 <
181 (is_arma_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
182 Mat<typename T1::elem_type>
183 >::result
184 operator+
185 (
186 const T1& x,
187 const T2& y
188 )
189 {
190 arma_extra_debug_sigprint();
191
192 Mat<typename T1::elem_type> result(x);
193
194 const SpProxy<T2> pb(y);
195
196 arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "addition" );
197
198 typename SpProxy<T2>::const_iterator_type it = pb.begin();
199 typename SpProxy<T2>::const_iterator_type it_end = pb.end();
200
201 while(it != it_end)
202 {
203 result.at(it.row(), it.col()) += (*it);
204 ++it;
205 }
206
207 return result;
208 }
209
210
211
212 //! addition of sparse and non-sparse object
213 template<typename T1, typename T2>
214 inline
215 typename
216 enable_if2
217 <
218 (is_arma_sparse_type<T1>::value && is_arma_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
219 Mat<typename T1::elem_type>
220 >::result
221 operator+
222 (
223 const T1& x,
224 const T2& y
225 )
226 {
227 arma_extra_debug_sigprint();
228
229 // Just call the other order (these operations are commutative)
230 return (y + x);
231 }
232
233
234
235 //! @}