comparison armadillo-2.4.4/include/armadillo_bits/operator_plus.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 //! \addtogroup operator_plus
15 //! @{
16
17
18
19 //! unary plus operation (does nothing, but is required for completeness)
20 template<typename T1>
21 arma_inline
22 const Base<typename T1::elem_type,T1>&
23 operator+
24 (const Base<typename T1::elem_type,T1>& X)
25 {
26 arma_extra_debug_sigprint();
27
28 return X;
29 }
30
31
32
33 //! Base + scalar
34 template<typename T1>
35 arma_inline
36 const eOp<T1, eop_scalar_plus>
37 operator+
38 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k)
39 {
40 arma_extra_debug_sigprint();
41
42 return eOp<T1, eop_scalar_plus>(X.get_ref(), k);
43 }
44
45
46
47 //! scalar + Base
48 template<typename T1>
49 arma_inline
50 const eOp<T1, eop_scalar_plus>
51 operator+
52 (const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
53 {
54 arma_extra_debug_sigprint();
55
56 return eOp<T1, eop_scalar_plus>(X.get_ref(), k); // NOTE: order is swapped
57 }
58
59
60
61 //! non-complex Base + complex scalar (experimental)
62 template<typename T1>
63 arma_inline
64 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
65 operator+
66 (
67 const Base<typename T1::pod_type, T1>& X,
68 const std::complex<typename T1::pod_type>& k
69 )
70 {
71 arma_extra_debug_sigprint();
72
73 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X.get_ref(), k);
74 }
75
76
77
78 //! complex scalar + non-complex Base (experimental)
79 template<typename T1>
80 arma_inline
81 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
82 operator+
83 (
84 const std::complex<typename T1::pod_type>& k,
85 const Base<typename T1::pod_type, T1>& X
86 )
87 {
88 arma_extra_debug_sigprint();
89
90 return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X.get_ref(), k); // NOTE: order is swapped
91 }
92
93
94
95 //! addition of Base objects with same element type
96 template<typename T1, typename T2>
97 arma_inline
98 const eGlue<T1, T2, eglue_plus>
99 operator+
100 (
101 const Base<typename T1::elem_type,T1>& X,
102 const Base<typename T1::elem_type,T2>& Y
103 )
104 {
105 arma_extra_debug_sigprint();
106
107 return eGlue<T1, T2, eglue_plus>(X.get_ref(), Y.get_ref());
108 }
109
110
111
112 //! addition of Base objects with different element types
113 template<typename T1, typename T2>
114 inline
115 const mtGlue<typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_plus>
116 operator+
117 (
118 const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T1_result, T1>& X,
119 const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T2_result, T2>& Y
120 )
121 {
122 arma_extra_debug_sigprint();
123
124 typedef typename T1::elem_type eT1;
125 typedef typename T2::elem_type eT2;
126
127 typedef typename promote_type<eT1,eT2>::result out_eT;
128
129 promote_type<eT1,eT2>::check();
130
131 return mtGlue<out_eT, T1, T2, glue_mixed_plus>( X.get_ref(), Y.get_ref() );
132 }
133
134
135
136 //! @}