VectorExpressionInline.cxx
1 #ifndef SELDON_FILE_VECTOR_EXPRESSION_INLINE_CXX
2 
3 namespace Seldon
4 {
5 
7  template<class T, class E>
8  inline long VectorExpression<T, E>::GetSize() const
9  {
10  return static_cast<const E&>(*this).GetSize();
11  }
12 
13 
15  template<class T, class E>
16  inline const T VectorExpression<T, E>::operator()(long i) const
17  {
18  return static_cast<const E&>(*this)(i);
19  }
20 
21 
23  template<class T, class E1, class E2> template<class T1, class T2>
26  const VectorExpression<T2, E2>& v)
27  : u_(u), v_(v)
28  {
29 #ifdef SELDON_CHECK_DIMENSIONS
30  if (u_.GetSize() != v_.GetSize())
31  throw WrongDim("VectorDifference",
32  string("Cannot subtract u and v because the sizes ")
33  +to_str(u.GetSize()) + " and " + to_str(v.GetSize())
34  + " are different");
35 #endif
36  }
37 
38 
40  template<class T, class E1, class E2>
42  {
43  return u_.GetSize();
44  }
45 
46 
48  template<class T, class E1, class E2>
49  inline const T VectorDifference<T, E1, E2>::operator()(long i) const
50  {
51  return u_(i) - v_(i);
52  }
53 
54 
56  template<class T, class E1, class E2> template<class T1, class T2>
58  const VectorExpression<T2, E2>& v)
59  : u_(u), v_(v)
60  {
61 #ifdef SELDON_CHECK_DIMENSIONS
62  if (long(u_.GetSize()) != long(v_.GetSize()))
63  throw WrongDim("VectorDifference",
64  string("Cannot Add u and v because the sizes ")
65  +to_str(u.GetSize()) + " and " + to_str(v.GetSize())
66  + " are different");
67 #endif
68  }
69 
70 
72  template<class T, class E1, class E2>
73  inline long VectorSum<T, E1, E2>::GetSize() const
74  {
75  return u_.GetSize();
76  }
77 
78 
80  template<class T, class E1, class E2>
81  inline const T VectorSum<T, E1, E2>::operator()(long i) const
82  {
83  return u_(i) + v_(i);
84  }
85 
86 
88  template<class T, class E1, class E2> template<class T1, class T2>
91  const VectorExpression<T2, E2>& v)
92  : u_(u), v_(v)
93  {
94 #ifdef SELDON_CHECK_DIMENSIONS
95  if (u_.GetSize() != v_.GetSize())
96  throw WrongDim("VectorDifference",
97  string("Cannot multiply u and v because the sizes ")
98  +to_str(u.GetSize()) + " and " + to_str(v.GetSize())
99  + " are different");
100 #endif
101  }
102 
103 
105  template<class T, class E1, class E2>
107  {
108  return u_.GetSize();
109  }
110 
111 
113  template<class T, class E1, class E2>
114  inline const T VectorProduct<T, E1, E2>::operator()(long i) const
115  {
116  return u_(i) * v_(i);
117  }
118 
119 
121  template<class T, class E1, class E2> template<class T1, class T2>
124  const VectorExpression<T2, E2>& v)
125  : u_(u), v_(v)
126  {
127 #ifdef SELDON_CHECK_DIMENSIONS
128  if (u_.GetSize() != v_.GetSize())
129  throw WrongDim("VectorDifference",
130  string("Cannot divide u and v because the sizes ")
131  +to_str(u.GetSize()) + " and " + to_str(v.GetSize())
132  + " are different");
133 #endif
134  }
135 
136 
138  template<class T, class E1, class E2>
140  {
141  return u_.GetSize();
142  }
143 
144 
146  template<class T, class E1, class E2>
147  inline const T VectorDivision<T, E1, E2>::operator()(long i) const
148  {
149  return u_(i) / v_(i);
150  }
151 
152 
154  template<class T, class T0, class E> template<class T1>
155  inline VectorScaled<T, T0, E>::VectorScaled(const T0& alpha,
156  const VectorExpression<T1, E>& u)
157  : alpha_(alpha), u_(u)
158  {
159  }
160 
161 
163  template<class T, class T0, class E>
165  {
166  return u_.GetSize();
167  }
168 
169 
171  template<class T, class T0, class E>
172  inline const T VectorScaled<T, T0, E>::operator()(long i) const
173  {
174  return alpha_*u_(i);
175  }
176 
177 
179  template<class T, class T0, class E> template<class T1>
181  const VectorExpression<T1, E>& u)
182  : alpha_(alpha), u_(u)
183  {
184  }
185 
186 
188  template<class T, class T0, class E>
190  {
191  return u_.GetSize();
192  }
193 
194 
196  template<class T, class T0, class E>
197  inline const T VectorScalDiv<T, T0, E>::operator()(long i) const
198  {
199  return alpha_ / u_(i);
200  }
201 
202 
204  template<class T, class T0, class E> template<class T1>
206  const VectorExpression<T1, E>& u)
207  : alpha_(alpha), u_(u)
208  {
209  }
210 
211 
213  template<class T, class T0, class E>
215  {
216  return u_.GetSize();
217  }
218 
219 
221  template<class T, class T0, class E>
222  inline const T VectorScalSum<T, T0, E>::operator()(long i) const
223  {
224  return alpha_ + u_(i);
225  }
226 
227 
229  template<class T, class T0, class E> template<class T1>
231  const VectorExpression<T1, E>& u)
232  : alpha_(alpha), u_(u)
233  {
234  }
235 
236 
238  template<class T, class T0, class E>
240  {
241  return u_.GetSize();
242  }
243 
244 
246  template<class T, class T0, class E>
247  inline const T VectorScalDiff<T, T0, E>::operator()(long i) const
248  {
249  return alpha_ - u_(i);
250  }
251 
252 
254  template<class T, class E>
256  : u_(u)
257  {
258  }
259 
260 
262  template<class T, class E>
263  inline long VectorOpposite<T, E>::GetSize() const
264  {
265  return u_.GetSize();
266  }
267 
268 
270  template<class T, class E>
271  inline const T VectorOpposite<T, E>::operator()(long i) const
272  {
273  return -u_(i);
274  }
275 
276 
277  /*************
278  * Operators *
279  *************/
280 
281 
283  template<class T, class E1, class E2>
284  inline const VectorSum<T, E1, E2>
286  const VectorExpression<T, E2>& v)
287  {
288  return VectorSum<T, E1, E2>(u, v);
289  }
290 
291 
293  template<class T, class E1, class E2>
294  inline const VectorSum<complex<T>, E1, E2>
295  operator +(const VectorExpression<complex<T>, E1>& u,
296  const VectorExpression<T, E2>& v)
297  {
298  return VectorSum<complex<T>, E1, E2>(u, v);
299  }
300 
301 
303  template<class T, class E1, class E2>
304  inline const VectorSum<complex<T>, E1, E2>
306  const VectorExpression<complex<T>, E2>& v)
307  {
308  return VectorSum<complex<T>, E1, E2>(u, v);
309  }
310 
311 
313  template<class T, class E1, class E2>
314  inline const VectorDifference<T, E1, E2>
316  const VectorExpression<T, E2>& v)
317  {
318  return VectorDifference<T, E1, E2>(u, v);
319  }
320 
321 
323  template<class T, class E1, class E2>
324  inline const VectorDifference<complex<T>, E1, E2>
325  operator -(const VectorExpression<complex<T>, E1>& u,
326  const VectorExpression<T, E2>& v)
327  {
328  return VectorDifference<complex<T>, E1, E2>(u, v);
329  }
330 
331 
333  template<class T, class E1, class E2>
334  inline const VectorDifference<complex<T>, E1, E2>
336  const VectorExpression<complex<T>, E2>& v)
337  {
338  return VectorDifference<complex<T>, E1, E2>(u, v);
339  }
340 
341 
343  template<class T, class E1, class E2>
344  inline const VectorProduct<T, E1, E2>
346  const VectorExpression<T, E2>& v)
347  {
348  return VectorProduct<T, E1, E2>(u, v);
349  }
350 
351 
353  template<class T, class E1, class E2>
354  inline const VectorProduct<complex<T>, E1, E2>
355  operator *(const VectorExpression<complex<T>, E1>& u,
356  const VectorExpression<T, E2>& v)
357  {
358  return VectorProduct<complex<T>, E1, E2>(u, v);
359  }
360 
361 
363  template<class T, class E1, class E2>
364  inline const VectorProduct<complex<T>, E1, E2>
366  const VectorExpression<complex<T>, E2>& v)
367  {
368  return VectorProduct<complex<T>, E1, E2>(u, v);
369  }
370 
371 
373  template<class T, class E1, class E2>
374  inline const VectorDivision<T, E1, E2>
376  const VectorExpression<T, E2>& v)
377  {
378  return VectorDivision<T, E1, E2>(u, v);
379  }
380 
381 
383  template<class T, class E1, class E2>
384  inline const VectorDivision<complex<T>, E1, E2>
385  operator /(const VectorExpression<complex<T>, E1>& u,
386  const VectorExpression<T, E2>& v)
387  {
388  return VectorDivision<complex<T>, E1, E2>(u, v);
389  }
390 
391 
393  template<class T, class E1, class E2>
394  inline const VectorDivision<complex<T>, E1, E2>
396  const VectorExpression<complex<T>, E2>& v)
397  {
398  return VectorDivision<complex<T>, E1, E2>(u, v);
399  }
400 
401 
403  template<class T, class E>
404  inline const VectorScaled<T, T, E>
405  operator *(const T& alpha,
406  const VectorExpression<T, E>& u)
407  {
408  return VectorScaled<T, T, E>(alpha, u);
409  }
410 
411 
413  template<class T, class E>
414  inline const VectorScaled<complex<T>, complex<T>, E>
415  operator *(const complex<T>& alpha,
416  const VectorExpression<T, E>& u)
417  {
418  return VectorScaled<complex<T>, complex<T>, E>(alpha, u);
419  }
420 
421 
423  template<class T, class E>
424  inline const VectorScaled<complex<T>, T, E>
425  operator *(const T& alpha,
426  const VectorExpression<complex<T>, E>& u)
427  {
428  return VectorScaled<complex<T>, T, E>(alpha, u);
429  }
430 
431 
433  template<class T, class E>
435  const T& alpha)
436  {
437  return VectorScaled<T, T, E>(alpha, u);
438  }
439 
440 
442  template<class T, class E>
443  inline const VectorScaled<complex<T>, complex<T>, E>
445  const complex<T>& alpha)
446  {
447  return VectorScaled<complex<T>, complex<T>, E>(alpha, u);
448  }
449 
450 
452  template<class T, class E>
453  inline const VectorScaled<complex<T>, T, E>
454  operator *(const VectorExpression<complex<T>, E>& u,
455  const T& alpha)
456  {
457  return VectorScaled<complex<T>, T, E>(alpha, u);
458  }
459 
460 
462  template<class T, class E>
463  inline const VectorScalDiv<T, T, E> operator /(const T& alpha,
464  const VectorExpression<T, E>& u)
465  {
466  return VectorScalDiv<T, T, E>(alpha, u);
467  }
468 
469 
471  template<class T, class E>
472  inline const VectorScalDiv<complex<T>, complex<T>, E>
473  operator /(const complex<T>& alpha,
474  const VectorExpression<T, E>& u)
475  {
476  return VectorScalDiv<complex<T>, complex<T>, E>(alpha, u);
477  }
478 
479 
481  template<class T, class E>
482  inline const VectorScalDiv<complex<T>, T, E>
483  operator /(const T& alpha,
484  const VectorExpression<complex<T>, E>& u)
485  {
486  return VectorScalDiv<complex<T>, T, E>(alpha, u);
487  }
488 
489 
491  template<class T, class E>
493  const T& alpha)
494  {
495  T one; SetComplexOne(one);
496  return VectorScaled<T, T, E>(one/alpha, u);
497  }
498 
499 
501  template<class T, class E>
502  inline const VectorScaled<complex<T>, complex<T>, E>
504  const complex<T>& alpha)
505  {
506  T one; SetComplexOne(one);
507  return VectorScaled<complex<T>, complex<T>, E>(one/alpha, u);
508  }
509 
510 
512  template<class T, class E>
513  inline const VectorScaled<complex<T>, T, E>
514  operator /(const VectorExpression<complex<T>, E>& u,
515  const T& alpha)
516  {
517  T one; SetComplexOne(one);
518  return VectorScaled<complex<T>, T, E>(one/alpha, u);
519  }
520 
521 
523  template<class T, class E>
524  inline const VectorScalSum<T, T, E> operator +(const T& alpha,
525  const VectorExpression<T, E>& u)
526  {
527  return VectorScalSum<T, T, E>(alpha, u);
528  }
529 
530 
532  template<class T, class E>
533  inline const VectorScalSum<complex<T>, complex<T>, E>
534  operator +(const complex<T>& alpha,
535  const VectorExpression<T, E>& u)
536  {
537  return VectorScalSum<complex<T>, complex<T>, E>(alpha, u);
538  }
539 
540 
542  template<class T, class E>
543  inline const VectorScalSum<complex<T>, T, E>
544  operator +(const T& alpha,
545  const VectorExpression<complex<T>, E>& u)
546  {
547  return VectorScalSum<complex<T>, T, E>(alpha, u);
548  }
549 
550 
552  template<class T, class E>
554  const T& alpha)
555  {
556  return VectorScalSum<T, T, E>(alpha, u);
557  }
558 
559 
561  template<class T, class E>
562  inline const VectorScalSum<complex<T>, complex<T>, E>
564  const complex<T>& alpha)
565  {
566  return VectorScalSum<complex<T>, complex<T>, E>(alpha, u);
567  }
568 
569 
571  template<class T, class E>
572  inline const VectorScalSum<complex<T>, T, E>
573  operator +(const VectorExpression<complex<T>, E>& u,
574  const T& alpha)
575  {
576  return VectorScalSum<complex<T>, T, E>(alpha, u);
577  }
578 
579 
581  template<class T, class E>
583  const T& alpha)
584  {
585  return VectorScalSum<T, T, E>(-alpha, u);
586  }
587 
588 
590  template<class T, class E>
591  inline const VectorScalSum<complex<T>, complex<T>, E>
593  const complex<T>& alpha)
594  {
595  return VectorScalSum<complex<T>, complex<T>, E>(-alpha, u);
596  }
597 
598 
600  template<class T, class E>
601  inline const VectorScalSum<complex<T>, T, E>
602  operator -(const VectorExpression<complex<T>, E>& u,
603  const T& alpha)
604  {
605  return VectorScalSum<complex<T>, T, E>(-alpha, u);
606  }
607 
608 
610  template<class T, class E>
611  inline const VectorScalDiff<T, T, E> operator -(const T& alpha,
612  const VectorExpression<T, E>& u)
613  {
614  return VectorScalDiff<T, T, E>(alpha, u);
615  }
616 
617 
619  template<class T, class E>
620  inline const VectorScalDiff<complex<T>, complex<T>, E>
621  operator -(const complex<T>& alpha,
622  const VectorExpression<T, E>& u)
623  {
624  return VectorScalDiff<complex<T>, complex<T>, E>(alpha, u);
625  }
626 
627 
629  template<class T, class E>
630  inline const VectorScalDiff<complex<T>, T, E>
631  operator -(const T& alpha,
632  const VectorExpression<complex<T>, E>& u)
633  {
634  return VectorScalDiff<complex<T>, T, E>(alpha, u);
635  }
636 
637 
639  template<class T, class E>
641  {
642  return VectorOpposite<T, E>(u);
643  }
644 
645 }
646 
647 #define SELDON_FILE_VECTOR_EXPRESSION_INLINE_CXX
648 #endif
Seldon::VectorScalSum::VectorScalSum
VectorScalSum(const T0 &, const VectorExpression< T1, E > &)
Constructor alpha + u with a scalar alpha and an expression u.
Definition: VectorExpressionInline.cxx:205
Seldon::operator*
const TinyMatrixProduct< T, m, n, E1, E2 > operator*(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u*v element-wise
Definition: TinyMatrixExpressionInline.cxx:257
Seldon::operator+
const TinyMatrixSum< T, m, n, E1, E2 > operator+(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u+v
Definition: TinyMatrixExpressionInline.cxx:197
Seldon::VectorExpression::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:8
Seldon::VectorScalSum
Addition between a scalar and a vector.
Definition: VectorExpression.hxx:124
Seldon::VectorScaled::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:164
Seldon::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
Seldon::VectorExpression
Expression between vectors.
Definition: VectorExpression.hxx:8
Seldon::VectorScaled::VectorScaled
VectorScaled(const T0 &, const VectorExpression< T1, E > &)
Constructor alpha * u with a scalar alpha and an expression u.
Definition: VectorExpressionInline.cxx:155
Seldon::VectorScalDiff::VectorScalDiff
VectorScalDiff(const T0 &, const VectorExpression< T1, E > &)
Constructor alpha - u with a scalar alpha and an expression u.
Definition: VectorExpressionInline.cxx:230
Seldon::VectorDivision::VectorDivision
VectorDivision(const VectorExpression< T1, E1 > &, const VectorExpression< T2, E2 > &)
Constructor u / v with two expressions u and v.
Definition: VectorExpressionInline.cxx:123
Seldon::VectorScalDiv
Division between a scalar and a vector.
Definition: VectorExpression.hxx:107
Seldon::VectorSum::operator()
const T operator()(long) const
returns the i-th element of the sum
Definition: VectorExpressionInline.cxx:81
Seldon::VectorDivision::operator()
const T operator()(long) const
returns the i-th element of the element-wise division
Definition: VectorExpressionInline.cxx:147
Seldon::VectorExpression::operator()
const T operator()(long) const
returns the element i of expression
Definition: VectorExpressionInline.cxx:16
Seldon::VectorScalDiff::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:239
Seldon::VectorDifference::GetSize
long GetSize() const
returns the size of the associated vectors
Definition: VectorExpressionInline.cxx:41
Seldon::VectorDifference::operator()
const T operator()(long) const
returns the i-th element of the difference
Definition: VectorExpressionInline.cxx:49
Seldon::operator/
const TinyMatrixDivision< T, m, n, E1, E2 > operator/(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u/v element-wise
Definition: TinyMatrixExpressionInline.cxx:287
Seldon::VectorSum
Sum between two expressions.
Definition: VectorExpression.hxx:39
Seldon::VectorScaled::operator()
const T operator()(long) const
returns the i-th element of alpha*u
Definition: VectorExpressionInline.cxx:172
Seldon::VectorScalDiff
Subtraction between a scalar and a vector.
Definition: VectorExpression.hxx:141
Seldon::VectorDivision
Division between two expressions (elementwise)
Definition: VectorExpression.hxx:73
Seldon::VectorScalDiff::operator()
const T operator()(long) const
returns the i-th element of alpha - u
Definition: VectorExpressionInline.cxx:247
Seldon::VectorDivision::GetSize
long GetSize() const
returns the size of the associated vectors
Definition: VectorExpressionInline.cxx:139
Seldon::VectorSum::VectorSum
VectorSum(const VectorExpression< T1, E1 > &, const VectorExpression< T2, E2 > &)
Constructor u+v with two expressions u and v.
Definition: VectorExpressionInline.cxx:57
Seldon::VectorOpposite::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:263
Seldon::VectorProduct::operator()
const T operator()(long) const
returns the i-th element of the element-wise product
Definition: VectorExpressionInline.cxx:114
Seldon::operator-
const TinyMatrixDifference< T, m, n, E1, E2 > operator-(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u-v
Definition: TinyMatrixExpressionInline.cxx:227
Seldon::VectorScalDiv::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:189
Seldon::VectorOpposite
Opposite of a vector.
Definition: VectorExpression.hxx:158
Seldon::VectorDifference::VectorDifference
VectorDifference(const VectorExpression< T1, E1 > &, const VectorExpression< T2, E2 > &)
Constructor u-v with two expressions u and v.
Definition: VectorExpressionInline.cxx:25
Seldon::VectorSum::GetSize
long GetSize() const
returns the size of the associated vectors
Definition: VectorExpressionInline.cxx:73
Seldon::VectorProduct::GetSize
long GetSize() const
returns the size of the associated vectors
Definition: VectorExpressionInline.cxx:106
Seldon::VectorOpposite::VectorOpposite
VectorOpposite(const VectorExpression< T, E > &)
Constructor -u with an expression u.
Definition: VectorExpressionInline.cxx:255
Seldon::VectorProduct
Product between two expressions (elementwise)
Definition: VectorExpression.hxx:56
Seldon::VectorScalDiv::VectorScalDiv
VectorScalDiv(const T0 &, const VectorExpression< T1, E > &)
Constructor alpha / u with a scalar alpha and an expression u.
Definition: VectorExpressionInline.cxx:180
Seldon::VectorProduct::VectorProduct
VectorProduct(const VectorExpression< T1, E1 > &, const VectorExpression< T2, E2 > &)
Constructor u*v with two expressions u and v.
Definition: VectorExpressionInline.cxx:90
Seldon::WrongDim
Definition: Errors.hxx:102
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::VectorOpposite::operator()
const T operator()(long) const
returns the i-th element of -u
Definition: VectorExpressionInline.cxx:271
Seldon::VectorScalSum::operator()
const T operator()(long) const
returns the i-th element of alpha + u
Definition: VectorExpressionInline.cxx:222
Seldon::VectorScalDiv::operator()
const T operator()(long) const
returns the i-th element of alpha / u
Definition: VectorExpressionInline.cxx:197
Seldon::VectorScaled
Multiplication between a scalar and a vector.
Definition: VectorExpression.hxx:90
Seldon::VectorScalSum::GetSize
long GetSize() const
returns the size of the associated vector
Definition: VectorExpressionInline.cxx:214
Seldon::VectorDifference
Difference between two expressions.
Definition: VectorExpression.hxx:22