SoftSUSY is hosted by Hepforge, IPPP Durham
SOFTSUSY  4.0
xpr-vector.h
Go to the documentation of this file.
1 
10 #ifndef XPR_VECTOR_H
11 #define XPR_VECTOR_H
12 
13 #include "xpr-base.h"
14 
15 /****** DOT PRODUCT *** temporary *****/
17 template<typename T, typename A, typename B >
18 T dot(const Indexable<T,A>& a, const Indexable<T,B>& b )
19 {
20  T retval = T();
21  for (int i = a.displayStart(); i <= a.displayEnd(); ++i)
22  retval += a(i) * b(i);
23  return retval;
24 }
25 
27 template<typename T, typename A, typename B >
28 T dot(const Indexable<T,A>& a, const Xpr<T,B>& b )
29 {
30  T retval = T();
31  for (int i = a.displayStart(); i <= a.displayEnd(); ++i)
32  retval += a(i) * b(i);
33  return retval;
34 }
35 
37 template<typename T, typename A, typename B >
38 T dot(const Xpr<T,A>& a, const Indexable<T,B>& b )
39 {
40  T retval = T();
41  for (int i = b.displayStart(); i <= b.displayEnd(); ++i)
42  retval += a(i) * b(i);
43  return retval;
44 }
45 
47 template<typename T, typename A, typename B >
48 T dot(const Xpr<T,A>& a, const Xpr<T,B>& b )
49 {
50  T retval = T();
51  for (int i = b.displayStart(); i <= b.displayEnd(); ++i)
52  retval += a(i) * b(i);
53  return retval;
54 }
55 
56 /******************* ADDITION ******************************/
57 
59 template<typename T, typename A, typename B>
60 Xpr< T,
61  XprBinOp<T,
64  OpAdd<T> > >
66 {
69  OpAdd<T> > ExprT;
70 
71  return Xpr< T, ExprT >(
72  ExprT( ConstRef<T,Indexable<T,A> >(a),
73  ConstRef<T,Indexable<T,B> >(b) ));
74 }
75 
77 template<typename T, typename A, typename B>
78 Xpr< T,
79  XprBinOp<T,
82  OpAdd<T> > >
83 operator+( const Indexable<T,A>& a, const Xpr<T,B>& b )
84 {
86  ConstRef<T,Xpr<T,B> >,
87  OpAdd<T> > ExprT;
88 
89  return Xpr< T, ExprT >(
90  ExprT( ConstRef<T,Indexable<T,A> >(a),
91  ConstRef<T,Xpr<T,B> >(b) ));
92 }
93 
95 template<typename T, typename A, typename B>
96 Xpr< T,
97  XprBinOp<T,
100  OpAdd<T> > >
101 operator+( const Xpr<T,A>& a, const Indexable<T,B>& b )
102 {
104  ConstRef<T,Indexable<T,B> >,
105  OpAdd<T> > ExprT;
106 
107  return Xpr< T, ExprT >(
108  ExprT( ConstRef<T,Xpr<T,A> >(a),
109  ConstRef<T,Indexable<T,B> >(b) ));
110 }
111 
113 template<typename T, typename A, typename B>
114 Xpr< T,
115  XprBinOp<T,
116  ConstRef<T,Xpr<T,A> >,
117  ConstRef<T,Xpr<T,B> >,
118  OpAdd<T> > >
119 operator+( const Xpr<T,A>& a, const Xpr<T,B>& b )
120 {
122  ConstRef<T,Xpr<T,B> >,
123  OpAdd<T> > ExprT;
124 
125  return Xpr< T, ExprT >(
126  ExprT( ConstRef<T,Xpr<T,A> >(a),
127  ConstRef<T,Xpr<T,B> >(b) ));
128 }
129 
130 /**************************** SUBTRACTION ***************************/
131 
133 template<typename T, typename A, typename B>
134 Xpr< T,
135  XprBinOp<T,
136  ConstRef<T,Indexable<T,A> >,
137  ConstRef<T,Indexable<T,B> >,
138  OpSubtract<T> > >
140 {
142  ConstRef<T,Indexable<T,B> >,
143  OpSubtract<T> > ExprT;
144 
145  return Xpr< T, ExprT >(
146  ExprT( ConstRef<T,Indexable<T,A> >(a),
147  ConstRef<T,Indexable<T,B> >(b) ));
148 }
149 
151 template<typename T, typename A, typename B>
152 Xpr< T,
153  XprBinOp<T,
154  ConstRef<T,Indexable<T,A> >,
155  ConstRef<T,Xpr<T,B> >,
156  OpSubtract<T> > >
157 operator-( const Indexable<T,A>& a, const Xpr<T,B>& b )
158 {
160  ConstRef<T,Xpr<T,B> >,
161  OpSubtract<T> > ExprT;
162 
163  return Xpr< T, ExprT >(
164  ExprT( ConstRef<T,Indexable<T,A> >(a),
165  ConstRef<T,Xpr<T,B> >(b) ));
166 }
167 
169 template<typename T, typename A, typename B>
170 Xpr< T,
171  XprBinOp<T,
172  ConstRef<T,Xpr<T,A> >,
173  ConstRef<T,Indexable<T,B> >,
174  OpSubtract<T> > >
175 operator-( const Xpr<T,A>& a, const Indexable<T,B>& b )
176 {
178  ConstRef<T,Indexable<T,B> >,
179  OpSubtract<T> > ExprT;
180 
181  return Xpr< T, ExprT >(
182  ExprT( ConstRef<T,Xpr<T,A> >(a),
183  ConstRef<T,Indexable<T,B> >(b) ));
184 }
185 
187 template<typename T, typename A, typename B>
188 Xpr< T,
189  XprBinOp<T,
190  ConstRef<T,Xpr<T,A> >,
191  ConstRef<T,Xpr<T,B> >,
192  OpSubtract<T> > >
193 operator-( const Xpr<T,A>& a, const Xpr<T,B>& b )
194 {
196  ConstRef<T,Xpr<T,B> >,
197  OpSubtract<T> > ExprT;
198 
199  return Xpr< T, ExprT >(
200  ExprT( ConstRef<T,Xpr<T,A> >(a),
201  ConstRef<T,Xpr<T,B> >(b) ));
202 }
203 
204 /*********** ELEMENT WISE MULTIPLY ***************************/
206 template<typename T, typename A, typename B>
207 Xpr< T,
208  XprBinOp<T,
209  ConstRef<T,Indexable<T,A> >,
210  ConstRef<T,Indexable<T,B> >,
211  OpMultiply<T> > >
213 {
215  ConstRef<T,Indexable<T,B> >,
216  OpMultiply<T> > ExprT;
217 
218  return Xpr< T, ExprT >(
219  ExprT( ConstRef<T,Indexable<T,A> >(a),
220  ConstRef<T,Indexable<T,B> >(b) ));
221 }
222 
224 template<typename T, typename A, typename B>
225 Xpr< T,
226  XprBinOp<T,
227  ConstRef<T,Indexable<T,A> >,
228  ConstRef<T,Xpr<T,B> >,
229  OpMultiply<T> > >
230 operator*( const Indexable<T,A>& a, const Xpr<T,B>& b )
231 {
233  ConstRef<T,Xpr<T,B> >,
234  OpMultiply<T> > ExprT;
235 
236  return Xpr< T, ExprT >(
237  ExprT( ConstRef<T,Indexable<T,A> >(a),
238  ConstRef<T,Xpr<T,B> >(b) ));
239 }
240 
242 template<typename T, typename A, typename B>
243 Xpr< T,
244  XprBinOp<T,
245  ConstRef<T,Xpr<T,A> >,
246  ConstRef<T,Indexable<T,B> >,
247  OpMultiply<T> > >
248 operator*( const Xpr<T,A>& a, const Indexable<T,B>& b )
249 {
251  ConstRef<T,Indexable<T,B> >,
252  OpMultiply<T> > ExprT;
253 
254  return Xpr< T, ExprT >(
255  ExprT( ConstRef<T,Xpr<T,A> >(a),
256  ConstRef<T,Indexable<T,B> >(b) ));
257 }
258 
260 template<typename T, typename A, typename B>
261 Xpr< T,
262  XprBinOp<T,
263  ConstRef<T,Xpr<T,A> >,
264  ConstRef<T,Xpr<T,B> >,
265  OpMultiply<T> > >
266 operator*( const Xpr<T,A>& a, const Xpr<T,B>& b )
267 {
269  ConstRef<T,Xpr<T,B> >,
270  OpMultiply<T> > ExprT;
271 
272  return Xpr< T, ExprT >(
273  ExprT( ConstRef<T,Xpr<T,A> >(a),
274  ConstRef<T,Xpr<T,B> >(b) ));
275 }
276 
277 /********* SCALAR MULTIPLY ***************/
279 template<typename T, typename B>
280 Xpr< T,
281  XprScalOp<T,
282  ConstRef<T,Indexable<T,B> >,
283  OpMultiply<T> > >
284 operator*( T a, const Indexable<T,B>& b )
285 {
286  typedef XprScalOp< T,
287  ConstRef<T,Indexable<T,B> >,
288  OpMultiply<T> > ExprT;
289 
290  return Xpr< T, ExprT >(
291  ExprT( a,
292  ConstRef<T,Indexable<T,B> >(b) ));
293 }
294 
296 template<typename T, typename B>
297 Xpr< T,
298  XprScalOp<T,
299  ConstRef<T,Indexable<T,B> >,
300  OpMultiply<T> > >
301 operator*( const Indexable<T,B>& b, T a )
302 {
303  typedef XprScalOp< T,
304  ConstRef<T,Indexable<T,B> >,
305  OpMultiply<T> > ExprT;
306 
307  return Xpr< T, ExprT >(
308  ExprT( a,
309  ConstRef<T,Indexable<T,B> >(b) ));
310 }
311 
313 template<typename T, typename B>
314 Xpr< T,
315  XprScalOp<T,
316  ConstRef<T,Xpr<T,B> >,
317  OpMultiply<T> > >
318 operator*( T a, const Xpr<T,B>& b )
319 {
320  typedef XprScalOp< T,
321  ConstRef<T,Xpr<T,B> >,
322  OpMultiply<T> > ExprT;
323 
324  return Xpr< T, ExprT >(
325  ExprT( a,
326  ConstRef<T,Xpr<T,B> >(b) ));
327 }
328 
330 template<typename T, typename B>
331 Xpr< T,
332  XprScalOp<T,
333  ConstRef<T,Xpr<T,B> >,
334  OpMultiply<T> > >
335 operator*( const Xpr<T,B>& b, T a )
336 {
337  typedef XprScalOp< T,
338  ConstRef<T,Xpr<T,B> >,
339  OpMultiply<T> > ExprT;
340 
341  return Xpr< T, ExprT >(
342  ExprT( a,
343  ConstRef<T,Xpr<T,B> >(b) ));
344 }
345 
346 #endif
subtract two xpr objects
Definition: xpr-base.h:159
Under-object for speed upgrade of linear algebra.
Definition: xpr-base.h:24
Symbolic under-object for vectors/matrices for speed upgrade. The linear algebra operations are often...
multiply two xpr objects
Definition: xpr-base.h:169
provides indexing of xpr type objects
Definition: xpr-base.h:79
binary operator on two xpr objects
Definition: xpr-base.h:47
Xpr< T, XprBinOp< T, ConstRef< T, Indexable< T, A > >, ConstRef< T, Indexable< T, B > >, OpAdd< T > > > operator+(const Indexable< T, A > &a, const Indexable< T, B > &b)
temporary xpr A+B
Definition: xpr-vector.h:65
const version of under-object for speed upgrade of linear algebra
Definition: xpr-base.h:36
Add two xpr objects.
Definition: xpr-base.h:149
T dot(const Indexable< T, A > &a, const Indexable< T, B > &b)
temporary xpr A.B
Definition: xpr-vector.h:18
Xpr< T, XprBinOp< T, ConstRef< T, Indexable< T, A > >, ConstRef< T, Indexable< T, B > >, OpMultiply< T > > > operator*(const Indexable< T, A > &a, const Indexable< T, B > &b)
xpr A*x, for each element
Definition: xpr-vector.h:212
scalar operator between two xpr object
Definition: xpr-base.h:63
Xpr< T, XprBinOp< T, ConstRef< T, Indexable< T, A > >, ConstRef< T, Indexable< T, B > >, OpSubtract< T > > > operator-(const Indexable< T, A > &a, const Indexable< T, B > &b)
temporary xpr A-B
Definition: xpr-vector.h:139