1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17
18
19 //! \addtogroup operator_cube_plus
20 //! @{
21
22
23
24 //! unary plus operation (does nothing, but is required for completeness)
25 template<typename T1>
26 arma_inline
27 const BaseCube<typename T1::elem_type,T1>&
operator +(const BaseCube<typename T1::elem_type,T1> & X)28 operator+
29 (
30 const BaseCube<typename T1::elem_type,T1>& X
31 )
32 {
33 arma_extra_debug_sigprint();
34
35 return X;
36 }
37
38
39
40 //! BaseCube + scalar
41 template<typename T1>
42 arma_inline
43 const eOpCube<T1, eop_scalar_plus>
operator +(const BaseCube<typename T1::elem_type,T1> & X,const typename T1::elem_type k)44 operator+
45 (
46 const BaseCube<typename T1::elem_type,T1>& X,
47 const typename T1::elem_type k
48 )
49 {
50 arma_extra_debug_sigprint();
51
52 return eOpCube<T1, eop_scalar_plus>(X.get_ref(), k);
53 }
54
55
56
57 //! scalar + BaseCube
58 template<typename T1>
59 arma_inline
60 const eOpCube<T1, eop_scalar_plus>
operator +(const typename T1::elem_type k,const BaseCube<typename T1::elem_type,T1> & X)61 operator+
62 (
63 const typename T1::elem_type k,
64 const BaseCube<typename T1::elem_type,T1>& X
65 )
66 {
67 arma_extra_debug_sigprint();
68
69 return eOpCube<T1, eop_scalar_plus>(X.get_ref(), k);
70 }
71
72
73
74 //! non-complex BaseCube + complex scalar (experimental)
75 template<typename T1>
76 arma_inline
77 const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
operator +(const BaseCube<typename T1::pod_type,T1> & X,const std::complex<typename T1::pod_type> & k)78 operator+
79 (
80 const BaseCube<typename T1::pod_type, T1>& X,
81 const std::complex<typename T1::pod_type>& k
82 )
83 {
84 arma_extra_debug_sigprint();
85
86 return mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X.get_ref(), k);
87 }
88
89
90
91 //! complex scalar + non-complex BaseCube (experimental)
92 template<typename T1>
93 arma_inline
94 const mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>
operator +(const std::complex<typename T1::pod_type> & k,const BaseCube<typename T1::pod_type,T1> & X)95 operator+
96 (
97 const std::complex<typename T1::pod_type>& k,
98 const BaseCube<typename T1::pod_type, T1>& X
99 )
100 {
101 arma_extra_debug_sigprint();
102
103 return mtOpCube<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_plus>('j', X.get_ref(), k); // NOTE: order is swapped
104 }
105
106
107
108 //! addition of BaseCube objects with same element type
109 template<typename T1, typename T2>
110 arma_inline
111 const eGlueCube<T1, T2, eglue_plus>
operator +(const BaseCube<typename T1::elem_type,T1> & X,const BaseCube<typename T1::elem_type,T2> & Y)112 operator+
113 (
114 const BaseCube<typename T1::elem_type,T1>& X,
115 const BaseCube<typename T1::elem_type,T2>& Y
116 )
117 {
118 arma_extra_debug_sigprint();
119
120 return eGlueCube<T1, T2, eglue_plus>(X.get_ref(), Y.get_ref());
121 }
122
123
124
125 //! addition of BaseCube objects with different element types
126 template<typename T1, typename T2>
127 inline
128 const mtGlueCube<typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_plus>
operator +(const BaseCube<typename force_different_type<typename T1::elem_type,typename T2::elem_type>::T1_result,T1> & X,const BaseCube<typename force_different_type<typename T1::elem_type,typename T2::elem_type>::T2_result,T2> & Y)129 operator+
130 (
131 const BaseCube< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T1_result, T1>& X,
132 const BaseCube< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T2_result, T2>& Y
133 )
134 {
135 arma_extra_debug_sigprint();
136
137 typedef typename T1::elem_type eT1;
138 typedef typename T2::elem_type eT2;
139
140 typedef typename promote_type<eT1,eT2>::result out_eT;
141
142 promote_type<eT1,eT2>::check();
143
144 return mtGlueCube<out_eT, T1, T2, glue_mixed_plus>( X.get_ref(), Y.get_ref() );
145 }
146
147
148
149 template<typename eT, typename T2>
150 arma_inline
151 Cube<eT>
operator +(const subview_cube_each1<eT> & X,const Base<eT,T2> & Y)152 operator+
153 (
154 const subview_cube_each1<eT>& X,
155 const Base<eT,T2>& Y
156 )
157 {
158 arma_extra_debug_sigprint();
159
160 return subview_cube_each1_aux::operator_plus(X, Y.get_ref());
161 }
162
163
164
165 template<typename T1, typename eT>
166 arma_inline
167 Cube<eT>
operator +(const Base<eT,T1> & X,const subview_cube_each1<eT> & Y)168 operator+
169 (
170 const Base<eT,T1>& X,
171 const subview_cube_each1<eT>& Y
172 )
173 {
174 arma_extra_debug_sigprint();
175
176 return subview_cube_each1_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order
177 }
178
179
180
181 template<typename eT, typename TB, typename T2>
182 arma_inline
183 Cube<eT>
operator +(const subview_cube_each2<eT,TB> & X,const Base<eT,T2> & Y)184 operator+
185 (
186 const subview_cube_each2<eT,TB>& X,
187 const Base<eT,T2>& Y
188 )
189 {
190 arma_extra_debug_sigprint();
191
192 return subview_cube_each2_aux::operator_plus(X, Y.get_ref());
193 }
194
195
196
197 template<typename T1, typename eT, typename TB>
198 arma_inline
199 Cube<eT>
operator +(const Base<eT,T1> & X,const subview_cube_each2<eT,TB> & Y)200 operator+
201 (
202 const Base<eT,T1>& X,
203 const subview_cube_each2<eT,TB>& Y
204 )
205 {
206 arma_extra_debug_sigprint();
207
208 return subview_cube_each2_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order
209 }
210
211
212
213 //! @}
214