comparison armadillo-3.900.4/include/armadillo_bits/operator_minus.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_minus
11 //! @{
12
13
14
15 //! unary -
16 template<typename T1>
17 arma_inline
18 typename
19 enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_neg> >::result
20 operator-
21 (const T1& X)
22 {
23 arma_extra_debug_sigprint();
24
25 return eOp<T1,eop_neg>(X);
26 }
27
28
29
30 //! cancellation of two consecutive negations: -(-T1)
31 template<typename T1>
32 arma_inline
33 const T1&
34 operator-
35 (const eOp<T1, eop_neg>& X)
36 {
37 arma_extra_debug_sigprint();
38
39 return X.m;
40 }
41
42
43
44 //! Base - scalar
45 template<typename T1>
46 arma_inline
47 typename
48 enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_scalar_minus_post> >::result
49 operator-
50 (
51 const T1& X,
52 const typename T1::elem_type k
53 )
54 {
55 arma_extra_debug_sigprint();
56
57 return eOp<T1, eop_scalar_minus_post>(X, k);
58 }
59
60
61
62 //! scalar - Base
63 template<typename T1>
64 arma_inline
65 typename
66 enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_scalar_minus_pre> >::result
67 operator-
68 (
69 const typename T1::elem_type k,
70 const T1& X
71 )
72 {
73 arma_extra_debug_sigprint();
74
75 return eOp<T1, eop_scalar_minus_pre>(X, k);
76 }
77
78
79
80 //! complex scalar - non-complex Base
81 template<typename T1>
82 arma_inline
83 typename
84 enable_if2
85 <
86 (is_arma_type<T1>::value && is_complex<typename T1::elem_type>::value == false),
87 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_minus_pre>
88 >::result
89 operator-
90 (
91 const std::complex<typename T1::pod_type>& k,
92 const T1& X
93 )
94 {
95 arma_extra_debug_sigprint();
96
97 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_minus_pre>('j', X, k);
98 }
99
100
101
102 //! non-complex Base - complex scalar
103 template<typename T1>
104 arma_inline
105 typename
106 enable_if2
107 <
108 (is_arma_type<T1>::value && is_complex<typename T1::elem_type>::value == false),
109 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_minus_post>
110 >::result
111 operator-
112 (
113 const T1& X,
114 const std::complex<typename T1::pod_type>& k
115 )
116 {
117 arma_extra_debug_sigprint();
118
119 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_minus_post>('j', X, k);
120 }
121
122
123
124 //! subtraction of Base objects with same element type
125 template<typename T1, typename T2>
126 arma_inline
127 typename
128 enable_if2
129 <
130 is_arma_type<T1>::value && is_arma_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value,
131 const eGlue<T1, T2, eglue_minus>
132 >::result
133 operator-
134 (
135 const T1& X,
136 const T2& Y
137 )
138 {
139 arma_extra_debug_sigprint();
140
141 return eGlue<T1, T2, eglue_minus>(X, Y);
142 }
143
144
145
146 //! subtraction of Base objects with different element types
147 template<typename T1, typename T2>
148 inline
149 typename
150 enable_if2
151 <
152 (is_arma_type<T1>::value && is_arma_type<T2>::value && (is_same_type<typename T1::elem_type, typename T2::elem_type>::value == false)),
153 const mtGlue<typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_minus>
154 >::result
155 operator-
156 (
157 const T1& X,
158 const T2& Y
159 )
160 {
161 arma_extra_debug_sigprint();
162
163 typedef typename T1::elem_type eT1;
164 typedef typename T2::elem_type eT2;
165
166 typedef typename promote_type<eT1,eT2>::result out_eT;
167
168 promote_type<eT1,eT2>::check();
169
170 return mtGlue<out_eT, T1, T2, glue_mixed_minus>( X, Y );
171 }
172
173
174
175 //! subtraction of two sparse objects
176 template<typename T1, typename T2>
177 inline
178 typename
179 enable_if2
180 <
181 (is_arma_sparse_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
182 const SpGlue<T1,T2,spglue_minus>
183 >::result
184 operator-
185 (
186 const T1& X,
187 const T2& Y
188 )
189 {
190 arma_extra_debug_sigprint();
191
192 return SpGlue<T1,T2,spglue_minus>(X,Y);
193 }
194
195
196
197 //! subtraction of one sparse and one dense object
198 template<typename T1, typename T2>
199 inline
200 typename
201 enable_if2
202 <
203 (is_arma_sparse_type<T1>::value && is_arma_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
204 Mat<typename T1::elem_type>
205 >::result
206 operator-
207 (
208 const T1& x,
209 const T2& y
210 )
211 {
212 arma_extra_debug_sigprint();
213
214 const SpProxy<T1> pa(x);
215
216 Mat<typename T1::elem_type> result(-y);
217
218 arma_debug_assert_same_size( pa.get_n_rows(), pa.get_n_cols(), result.n_rows, result.n_cols, "subtraction" );
219
220 typename SpProxy<T1>::const_iterator_type it = pa.begin();
221 typename SpProxy<T1>::const_iterator_type it_end = pa.end();
222
223 while(it != it_end)
224 {
225 result.at(it.row(), it.col()) += (*it);
226 ++it;
227 }
228
229 return result;
230 }
231
232
233
234 //! subtraction of one dense and one sparse object
235 template<typename T1, typename T2>
236 inline
237 typename
238 enable_if2
239 <
240 (is_arma_type<T1>::value && is_arma_sparse_type<T2>::value && is_same_type<typename T1::elem_type, typename T2::elem_type>::value),
241 Mat<typename T1::elem_type>
242 >::result
243 operator-
244 (
245 const T1& x,
246 const T2& y
247 )
248 {
249 arma_extra_debug_sigprint();
250
251 Mat<typename T1::elem_type> result(x);
252
253 const SpProxy<T2> pb(y.get_ref());
254
255 arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "subtraction" );
256
257 typename SpProxy<T2>::const_iterator_type it = pb.begin();
258 typename SpProxy<T2>::const_iterator_type it_end = pb.end();
259
260 while(it != it_end)
261 {
262 result.at(it.row(), it.col()) -= (*it);
263 ++it;
264 }
265
266 return result;
267 }
268
269
270
271 //! @}