softsusy
is hosted by
Hepforge
,
IPPP Durham
SOFTSUSY
4.1
src
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,
62
ConstRef<T,Indexable<T,A>
>,
63
ConstRef<T,Indexable<T,B>
>,
64
OpAdd<T>
> >
65
operator+
(
const
Indexable<T,A>
& a,
const
Indexable<T,B>
& b )
66
{
67
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
68
ConstRef<T,Indexable<T,B>
>,
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,
80
ConstRef<T,Indexable<T,A>
>,
81
ConstRef<T,Xpr<T,B>
>,
82
OpAdd<T>
> >
83
operator+
(
const
Indexable<T,A>
& a,
const
Xpr<T,B>
& b )
84
{
85
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
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,
98
ConstRef<T,Xpr<T,A>
>,
99
ConstRef<T,Indexable<T,B>
>,
100
OpAdd<T>
> >
101
operator+
(
const
Xpr<T,A>
& a,
const
Indexable<T,B>
& b )
102
{
103
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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
{
121
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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>
> >
139
operator-
(
const
Indexable<T,A>
& a,
const
Indexable<T,B>
& b )
140
{
141
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
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
{
159
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
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
{
177
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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
{
195
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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>
> >
212
operator*
(
const
Indexable<T,A>
& a,
const
Indexable<T,B>
& b )
213
{
214
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
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
{
232
typedef
XprBinOp< T, ConstRef<T,Indexable<T,A>
>,
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
{
250
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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
{
268
typedef
XprBinOp< T, ConstRef<T,Xpr<T,A>
>,
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
ConstRef
const version of under-object for speed upgrade of linear algebra
Definition:
xpr-base.h:36
Indexable
provides indexing of xpr type objects
Definition:
xpr-base.h:79
OpAdd
Add two xpr objects.
Definition:
xpr-base.h:149
OpMultiply
multiply two xpr objects
Definition:
xpr-base.h:169
OpSubtract
subtract two xpr objects
Definition:
xpr-base.h:159
XprBinOp
binary operator on two xpr objects
Definition:
xpr-base.h:47
XprScalOp
scalar operator between two xpr object
Definition:
xpr-base.h:63
Xpr
Under-object for speed upgrade of linear algebra.
Definition:
xpr-base.h:25
xpr-base.h
Symbolic under-object for vectors/matrices for speed upgrade. The linear algebra operations are often...
operator-
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
dot
T dot(const Indexable< T, A > &a, const Indexable< T, B > &b)
temporary xpr A.B
Definition:
xpr-vector.h:18
operator*
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
operator+
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
Generated by
1.9.1