softsusy is hosted by Hepforge, IPPP Durham
SOFTSUSY  4.1
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 {
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 {
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,
118  OpAdd<T> > >
119 operator+( const Xpr<T,A>& a, const Xpr<T,B>& b )
120 {
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,
138  OpSubtract<T> > >
140 {
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,
156  OpSubtract<T> > >
157 operator-( const Indexable<T,A>& a, const Xpr<T,B>& b )
158 {
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,
174  OpSubtract<T> > >
175 operator-( const Xpr<T,A>& a, const Indexable<T,B>& b )
176 {
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,
192  OpSubtract<T> > >
193 operator-( const Xpr<T,A>& a, const Xpr<T,B>& b )
194 {
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,
211  OpMultiply<T> > >
213 {
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,
229  OpMultiply<T> > >
230 operator*( const Indexable<T,A>& a, const Xpr<T,B>& b )
231 {
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,
247  OpMultiply<T> > >
248 operator*( const Xpr<T,A>& a, const Indexable<T,B>& b )
249 {
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,
265  OpMultiply<T> > >
266 operator*( const Xpr<T,A>& a, const Xpr<T,B>& b )
267 {
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,
283  OpMultiply<T> > >
284 operator*( T a, const Indexable<T,B>& b )
285 {
286  typedef XprScalOp< T,
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,
300  OpMultiply<T> > >
301 operator*( const Indexable<T,B>& b, T a )
302 {
303  typedef XprScalOp< T,
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,
317  OpMultiply<T> > >
318 operator*( T a, const Xpr<T,B>& b )
319 {
320  typedef XprScalOp< T,
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,
334  OpMultiply<T> > >
335 operator*( const Xpr<T,B>& b, T a )
336 {
337  typedef XprScalOp< T,
339  OpMultiply<T> > ExprT;
340 
341  return Xpr< T, ExprT >(
342  ExprT( a,
343  ConstRef<T,Xpr<T,B> >(b) ));
344 }
345 
346 #endif
const version of under-object for speed upgrade of linear algebra
Definition: xpr-base.h:36
provides indexing of xpr type objects
Definition: xpr-base.h:79
Add two xpr objects.
Definition: xpr-base.h:149
multiply two xpr objects
Definition: xpr-base.h:169
subtract two xpr objects
Definition: xpr-base.h:159
binary operator on two xpr objects
Definition: xpr-base.h:47
scalar operator between two xpr object
Definition: xpr-base.h:63
Under-object for speed upgrade of linear algebra.
Definition: xpr-base.h:25
Symbolic under-object for vectors/matrices for speed upgrade. The linear algebra operations are often...
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
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
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