TinyVector.hxx
1 #ifndef SELDON_FILE_TINY_VECTOR_HXX
2 
3 #include "TinyVectorExpression.hxx"
4 
5 namespace Seldon
6 {
7 
8  /**********************
9  * TinyVector classes *
10  **********************/
11 
12 
13  template<int n>
15 
16  template<class T, int m>
17  class TinyVector;
18 
20  template <class T, int m_>
21  class TinyVector_Base : public TinyVectorExpression<T, m_, TinyVector<T, m_> >
22  {
23  public :
24  typedef T value_type;
25 
26  template<int n>
27  friend class TinyVectorLoop;
28 
29  protected:
30  // pointer data_;
31  T data_[m_];
32 
33  public :
35 
36  explicit TinyVector_Base(const T& a);
37  explicit TinyVector_Base(const T& a, const T& b);
38  TinyVector_Base(const T& a, const T& b, const T& c);
39  TinyVector_Base(const T& a, const T& b, const T& c, const T& d);
40  TinyVector_Base(const T& a, const T& b, const T& c, const T& d, const T& e);
41 
42  void Init(const T & a);
43  void Init(const T & a, const T& b);
44  void Init(const T & a, const T& b, const T& c);
45  void Init(const T & a, const T& b, const T& c, const T& d);
46  void Init(const T & a, const T& b, const T& c, const T& d, const T& e);
47 
48  // Basic Functions
49  int GetM() const;
50  int GetLength() const;
51  int GetSize() const;
52  size_t GetMemorySize() const;
53 
55  const TinyVector<T, m_>& GetLeafClass() const;
56 
57  // Element access and affection
58  const T& operator()(int i) const;
59  T& operator()(int i);
60 
61  // Convenient Functions
62  void Print() const; // we display the coordinates
63  void Print(ostream&) const; // we display the coordinates
64  void Zero() ; // we put zero on coordinates
65  void Fill();
66 
67  template<class T0>
68  void Fill(const T0& x);
69  void FillRand();
70  bool IsZero() const;
71 
72  // Norms
73  typename ClassComplexType<T>::Treal DistanceSquare(const TinyVector<T, m_> & p) const;
74  typename ClassComplexType<T>::Treal Distance(const TinyVector<T, m_> & p) const;
75 
76  };
77 
78 
80  template <class T, int m_>
81  class TinyVector : public TinyVector_Base<T, m_>
82  {
83  public :
84  static typename ClassComplexType<T>::Treal threshold;
85 
86  TinyVector();
87 
88  explicit TinyVector(const T& a);
89  explicit TinyVector(const T& a, const T& b);
90  TinyVector(const T& a, const T& b, const T& c);
91  TinyVector(const T& a, const T& b, const T& c, const T& d);
92  TinyVector(const T& a, const T& b, const T& c, const T& d, const T& e);
93 
94  template<class E>
96 
97  // operation this = u
98  template<class T1, class E>
100 
101  // this += u
102  template<class T1, class E>
104 
105  // this -= u
106  template<class T1, class E>
108 
109  // fills vector with x
110  TinyVector<T, m_>& operator =(const T& x);
111 
112  // operation this = a*this where a is scalar
113  template<class T1>
114  TinyVector<T, m_>& operator *=( const T1& a );
115 
116  // operation this = 1/a*this where a is scalar
117  template<class T1>
118  TinyVector<T, m_>& operator /=( const T1& a );
119 
120  };
121 
122 
124  template<int m_>
125  class TinyVector<int, m_> : public TinyVector_Base<int, m_>
126  {
127  public :
128  TinyVector();
129 
130  explicit TinyVector(const int& a);
131  explicit TinyVector(const int& a, const int& b);
132  TinyVector(const int& a, const int& b, const int& c);
133  TinyVector(const int& a, const int& b, const int& c, const int& d);
134  TinyVector(const int& a, const int& b, const int& c, const int& d, const int& e);
135 
136  };
137 
138 
139  /*************
140  * Operators *
141  *************/
142 
143 
144  // Operators to compare expressions
145  template<int m>
146  bool operator==(const TinyVector<int, m>& u, const TinyVector<int, m>& v);
147 
148  template<int m>
149  bool operator!=(const TinyVector<int, m> & u, const TinyVector<int, m>& v);
150 
151  template<int m>
152  bool operator<=(const TinyVector<int, m> & u, const TinyVector<int, m>& v);
153 
154  template<int m>
155  bool operator<(const TinyVector<int, m> & u, const TinyVector<int, m>& v);
156 
157  template<int m>
158  bool operator>=(const TinyVector<int, m> & u, const TinyVector<int, m>& v);
159 
160  template<int m>
161  bool operator>(const TinyVector<int, m> & u, const TinyVector<int, m>& v);
162 
163  template<class T, int m, class E1, class E2>
166 
167  template<class T, int m, class E1, class E2>
170 
171  template<class T, int m, class E1, class E2>
174 
175  template<class T, int m, class E1, class E2>
178 
179  template<class T, int m, class E1, class E2>
182 
183  template<class T, int m, class E1, class E2>
186 
187  template <class T, int m>
188  ostream& operator <<(ostream& out,const TinyVector<T,m>& V);
189 
190  template <class T, int m>
191  istream& operator >>(istream& out, TinyVector<T,m>& V);
192 
193  // threshold for comparing vectors
194 #ifdef MONTJOIE_WITH_MPFR
195  template<class T, int m>
196  typename ClassComplexType<T>::Treal TinyVector<T, m>::threshold(0, MONTJOIE_DEFAULT_PRECISION);
197 #else
198  template<class T, int m>
199  typename ClassComplexType<T>::Treal TinyVector<T, m>::threshold(0);
200 #endif
201 
202 
203  /**************************
204  * TinyVectorLoop classes *
205  **************************/
206 
207 
209  template<int n>
210  class TinyVectorLoop
211  {
212  public :
213  template<int m, class T0>
214  static void Zero(TinyVector<T0, m>& x);
215 
216  template<int m, class T0>
217  static void FillGreater(TinyVector<T0, m>& x, const T0& a);
218 
219  template<int m, class T0>
220  static void InitValue(TinyVector<T0, m>& x, const T0& a);
221 
222  template<int m, class T0, class T1>
223  static void Fill(TinyVector<T0, m>& x, const T1& a);
224 
225  template<int m, class T0>
226  static void Fill(TinyVector<T0, m>& x);
227 
228  template<int m, class T0>
229  static void FillRand(TinyVector<T0, m>& x);
230 
231  template<int m, class T0, class E0>
232  static bool IsZero(const TinyVectorExpression<T0, m, E0>& x);
233 
234  template<int m, class T1, class E, class T0>
235  static void Copy(const TinyVectorExpression<T1, m, E>& x, TinyVector<T0, m>& y);
236 
237  template<int m, class T1, class E, class T0>
238  static void AddCopy(const TinyVectorExpression<T1, m, E>& x, TinyVector<T0, m>& y);
239 
240  template<int m, class T1, class E, class T0>
242 
243  template<int m, class T0, class T1>
244  static void
245  CopyVector(const TinyVector<Vector<T0>, m>& uvec, int j, TinyVector<T1, m>& u);
246 
247  template<int m, class T0, class T1>
248  static void
249  CopyVector(const TinyVector<T1, m>& u, int j, TinyVector<Vector<T0>, m>& uvec);
250 
251  template<int m, class T0, class T1>
252  static void CopyVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp);
253 
254  template<int m, class T>
255  static void CopyVector(const Vector<complex<T> >& Vh, int j, TinyVector<T, m>& vr, TinyVector<T, m>& vi);
256 
257  template<int m, class T0, class T1>
258  static void CopyVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh);
259 
260  template<int m, class T0, class T1>
261  static void AddVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp);
262 
263  template<int m, class T0, class T1>
264  static void AddVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh);
265 
266  template<int m, class T0, class T1>
267  static void ExtractVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp);
268 
269  template<int m, class T0, class T1>
270  static void ExtractVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh);
271 
272  template<int m, class T0, class T1>
273  static void ExtractVector(const Vector<Vector<T0> >& u,
274  int j, int offset, TinyVector<T1, m>& v);
275 
276  template<int m, class T0, class T1>
277  static void CopyVector(const TinyVector<T1, m>& v,
278  int j, int offset, Vector<Vector<T0> >& u);
279 
280  template<int p, int m, class T0, class T1>
281  static void ExtractVector(const Vector<Vector<TinyVector<T0, p> > >& u,
282  int j, int k, int offset, TinyVector<T1, m>& v);
283 
284  template<int m, class T0, class T1>
285  static void ExtractVector(const Vector<T0>& Vh, const IVect& row_num,
286  int j, TinyVector<T1, m>& tmp);
287 
288  template<int m, class T0, class T1>
289  static void ExtractVector(const TinyVector<T1, m>& tmp,
290  const IVect& row_num, int j, Vector<T0>& Vh);
291 
292  template<class T0, class T1>
293  static void ExtractVector(const Vector<T0>& x_src, int offset_source,
294  Vector<T1>& x_dest, int offset_dest);
295 
296  template<int m, class T0, class T1>
297  static void AddVector(const T0& alpha, const TinyVector<T1, m>& tmp,
298  const IVect& row_num, int j, Vector<T0>& Vh);
299 
300  template<int m, class T0, class T1>
301  static void ExtractVectorConj(const Vector<T0>& Vh, const IVect& row_num,
302  int j, TinyVector<T1, m>& tmp);
303 
304  template<int m, class T0, class T1>
305  static void ExtractVectorConj(const TinyVector<T1, m>& tmp,
306  const IVect& row_num, int j, Vector<T0>& Vh);
307 
308  template<int m, class T0, class T1>
309  static void AddVectorConj(const T0& alpha, const TinyVector<T1, m>& tmp,
310  const IVect& row_num, int j, Vector<T0>& Vh);
311 
312  template<int m, class T0, class T1>
313  static void MltVector(const T1& alpha, int j, TinyVector<Vector<T0>, m>& uvec);
314 
315  template<int m, class T0, class T1, class E0, class E1>
316  static bool Equal(const TinyVectorExpression<T0, m, E0>& x,
318 
319  template<int m, class T0, class T1, class E0, class E1>
320  static bool LessOrEqual(const TinyVectorExpression<T0, m, E0>& x,
322 
323  template<int m, class T0, class T1, class E0, class E1>
324  static bool Less(const TinyVectorExpression<T0, m, E0>& x,
326 
327  template<int m, class T0, class T1>
328  static bool EqualInt(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y);
329 
330  template<int m, class T0, class T1>
331  static bool LessOrEqualInt(const TinyVector<T0, m>& x,
332  const TinyVector<T1, m>& y);
333 
334  template<int m, class T0, class T1>
335  static bool LessInt(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y);
336 
337  template<int m, class T0, class T1>
338  static void Mlt(const T1& alpha, TinyVector<T0, m>& x);
339 
340  template<int m, class T0, class T1, class T2, class E0, class E1>
341  static void DotProd(const TinyVectorExpression<T0, m, E0>& u,
342  const TinyVectorExpression<T1, m, E1>& v, T2& scal);
343 
344  template<int m, class T0, class T1, class T2, class E0, class E1>
345  static void DotProdConj(const TinyVectorExpression<T0, m, E0>& u,
346  const TinyVectorExpression<T1, m, E1>& v, T2& scal);
347 
348  template<int m, class T0, class T1, class E0>
349  static void Abs(const TinyVectorExpression<T0, m, E0>& u, T1& scal);
350 
351  template<int m, class T0, class T1, class E0>
352  static void NormInf(const TinyVectorExpression<T0, m, E0>& u, T1& scal);
353 
354  template<int m, class T0, class T1, class E0>
355  static void AbsSquare(const TinyVectorExpression<T0, m, E0>& u, T1& scal);
356 
357  template<int m, class T>
358  static void Print(const TinyVector<T, m>& V, ostream& out);
359 
360  template<int m, class T>
361  static ostream& WriteText(const TinyVector<T, m>& V, ostream& out);
362 
363  template<int m, class T>
364  static istream& ReadText(TinyVector<T, m>& V, istream& in);
365 
366  template<class T, int m>
367  static void UpdateMinimum(const TinyVector<T, m>& u, TinyVector<T, m>& v);
368 
369  template<class T, int m>
370  static void UpdateMaximum(const TinyVector<T, m>& u, TinyVector<T, m>& v);
371 
372  };
373 
375  template<>
376  class TinyVectorLoop<0>
377  {
378  public :
379  template<int m, class T0>
380  static inline void Zero(TinyVector<T0, m>& x) {}
381 
382  template<int m, class T0, class E0>
383  static inline bool IsZero(const TinyVectorExpression<T0, m, E0>& x) { return true; }
384 
385  template<int m, class T0>
386  static inline void FillGreater(TinyVector<T0, m>& x, const T0& a){}
387 
388  template<int m, class T0>
389  static inline void InitValue(TinyVector<T0, m>& x, const T0& a){}
390 
391  template<int m, class T0, class T1>
392  static inline void Fill(TinyVector<T0, m>& x, const T1& a){}
393 
394  template<int m, class T0>
395  static inline void Fill(TinyVector<T0, m>& x){}
396 
397  template<int m, class T0>
398  static inline void FillRand(TinyVector<T0, m>& x){}
399 
400  template<int m, class T1, class E, class T0>
401  static inline void Copy(const TinyVectorExpression<T1, m, E>& x, TinyVector<T0, m>& y) {}
402 
403  template<int m, class T1, class E, class T0>
404  static inline void AddCopy(const TinyVectorExpression<T1, m, E>& x, TinyVector<T0, m>& y) {}
405 
406  template<int m, class T1, class E, class T0>
407  static inline void DiffCopy(const TinyVectorExpression<T1, m, E>& x, TinyVector<T0, m>& y) {}
408 
409  template<int m, class T0, class T1>
410  static inline void CopyVector(const TinyVector<Vector<T0>, m>& uvec,
411  int j, TinyVector<T1, m>& u) { }
412 
413  template<int m, class T0, class T1>
414  static inline void CopyVector(const TinyVector<T1, m>& u, int j,
415  TinyVector<Vector<T0>, m>& uvec) {}
416 
417  template<int m, class T0, class T1>
418  static inline void CopyVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp) {}
419 
420  template<int m, class T>
421  static inline void CopyVector(const Vector<complex<T> >& Vh, int j,
423 
424  template<int m, class T0, class T1>
425  static inline void CopyVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh) {}
426 
427  template<int m, class T0, class T1>
428  static inline void AddVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp) {}
429 
430  template<int m, class T0, class T1>
431  static inline void AddVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh) {}
432 
433  template<int m, class T0, class T1>
434  static inline void ExtractVector(const Vector<T0>& Vh, int j, TinyVector<T1, m>& tmp) {}
435 
436  template<int m, class T0, class T1>
437  static inline void ExtractVector(const TinyVector<T1, m>& tmp, int j, Vector<T0>& Vh) {}
438 
439  template<int m, class T0, class T1>
440  static inline void ExtractVector(const Vector<T0>& Vh, const IVect& row_num,
441  int j, TinyVector<T1, m>& tmp) {}
442 
443  template<int m, class T0, class T1>
444  static inline void ExtractVector(const Vector<Vector<T0> >& u,
445  int j, int offset, TinyVector<T1, m>& v) {}
446 
447  template<int m, class T0, class T1>
448  static inline void CopyVector(const TinyVector<T1, m>& v,
449  int j, int offset, Vector<Vector<T0> >& u) {}
450 
451  template<int p, int m, class T0, class T1>
452  static inline void ExtractVector(const Vector<Vector<TinyVector<T0, p> > >& u,
453  int j, int k, int offset, TinyVector<T1, m>& v) {}
454 
455  template<int m, class T0, class T1>
456  static inline void ExtractVector(const TinyVector<T1, m>& tmp,
457  const IVect& row_num, int j, Vector<T0>& Vh) {}
458 
459  template<class T0, class T1>
460  static inline void ExtractVector(const Vector<T0>& x_src, int offset_source,
461  Vector<T1>& x_dest, int offset_dest) {}
462 
463  template<int m, class T0, class T1>
464  static inline void AddVector(const T0& alpha, const TinyVector<T1, m>& tmp,
465  const IVect& row_num, int j, Vector<T0>& Vh) {}
466 
467  template<int m, class T0, class T1>
468  static inline void ExtractVectorConj(const Vector<T0>& Vh, const IVect& row_num,
469  int j, TinyVector<T1, m>& tmp) {}
470 
471  template<int m, class T0, class T1>
472  static inline void ExtractVectorConj(const TinyVector<T1, m>& tmp,
473  const IVect& row_num, int j, Vector<T0>& Vh) {}
474 
475  template<int m, class T0, class T1>
476  static inline void AddVectorConj(const T0& alpha, const TinyVector<T1, m>& tmp,
477  const IVect& row_num, int j, Vector<T0>& Vh) {}
478 
479  template<int m, class T0, class T1>
480  static inline void MltVector(const T1& alpha, int j, TinyVector<Vector<T0>, m>& uvec) {}
481 
482  template<int m, class T0, class T1, class E0, class E1>
483  static inline bool Equal(const TinyVectorExpression<T0, m, E0>& x,
485  {
486  return true;
487  }
488 
489  template<int m, class T0, class T1, class E0, class E1>
490  static inline bool LessOrEqual(const TinyVectorExpression<T0, m, E0>& x,
492  {
493  return true;
494  }
495 
496  template<int m, class T0, class T1, class E0, class E1>
497  static inline bool Less(const TinyVectorExpression<T0, m, E0>& x,
499  {
500  return false;
501  }
502 
503  template<int m, class T0, class T1>
504  static inline bool EqualInt(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y)
505  {
506  return true;
507  }
508 
509  template<int m, class T0, class T1>
510  static inline bool LessOrEqualInt(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y)
511  {
512  return true;
513  }
514 
515  template<int m, class T0, class T1>
516  static inline bool LessInt(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y)
517  {
518  return false;
519  }
520 
521  template<int m, class T0, class T1>
522  static inline void Mlt(const T1& alpha, TinyVector<T0, m>& x) {}
523 
524  template<int m, class T0, class T1, class T2, class E0, class E1>
525  static inline void DotProd(const TinyVectorExpression<T0, m, E0>& u,
526  const TinyVectorExpression<T1, m, E1>& v, T2& scal) {}
527 
528  template<int m, class T0, class T1, class E0, class E1, class T2>
529  static inline void DotProdConj(const TinyVectorExpression<T0, m, E0>& u,
530  const TinyVectorExpression<T1, m, E1>& v, T2& scal) {}
531 
532  template<int m, class T0, class T1, class E0>
533  static inline void Abs(const TinyVectorExpression<T0, m, E0>& u, T1& scal) {}
534 
535  template<int m, class T0, class T1, class E0>
536  static inline void NormInf(const TinyVectorExpression<T0, m, E0>& u, T1& scal) {}
537 
538  template<int m, class T0, class T1, class E0>
539  static inline void AbsSquare(const TinyVectorExpression<T0, m, E0>& u, T1& scal) {}
540 
541  template<int m, class T>
542  static inline void Print(const TinyVector<T, m>& V, ostream& out) { }
543 
544  template<int m, class T>
545  static inline ostream& WriteText(const TinyVector<T, m>& V, ostream& out) { return out; }
546 
547  template<int m, class T>
548  static inline istream& ReadText(const TinyVector<T, m>& V, istream& in) { return in; }
549 
550  template<class T, int m>
551  static inline void UpdateMinimum(const TinyVector<T, m>& u, TinyVector<T, m>& v) {}
552 
553  template<class T, int m>
554  static inline void UpdateMaximum(const TinyVector<T, m>& u, TinyVector<T, m>& v) {}
555 
556  };
557 
558 
559  /***********************
560  * Blas-like functions *
561  ***********************/
562 
563  // returns (u,v)
564  template<class T, int m, class E1, class E2>
565  T DotProd(const TinyVectorExpression<T, m, E1> & u,
567 
568  // returns (u,v) where v is complex and u real
569  template<class T, int m, class E1, class E2>
570  complex<T> DotProd(const TinyVectorExpression<T, m, E1> & u,
571  const TinyVectorExpression<complex<T>, m, E2> & v);
572 
573  template<class T, int m, class E1, class E2>
574  complex<T> DotProd(const TinyVectorExpression<complex<T>, m, E1> & u,
576 
577  // returns (conj(u), v) where u and v are complex
578  template<class T, int m, class E1, class E2>
579  complex<T> DotProdConj(const TinyVectorExpression<complex<T>, m, E1> & u,
580  const TinyVectorExpression<complex<T>, m, E2> & v);
581 
582  // returns || u ||^2
583  template<class T, int m, class E>
584  typename ClassComplexType<T>::Treal AbsSquare(const TinyVectorExpression<T, m, E> & u);
585 
586  // returns || u ||_1
587  template<class T, int m, class E>
588  typename ClassComplexType<T>::Treal Norm1(const TinyVectorExpression<T, m, E> & u);
589 
590  // returns || u ||_inf
591  template<class T, int m, class E>
592  typename ClassComplexType<T>::Treal NormInf(const TinyVectorExpression<T, m, E> & u);
593 
594  template <class T, int m>
595  T Distance(const TinyVector<T, m>& u, const TinyVector<T, m> & v);
596 
597  // returns || u ||_2
598  template<class T, int m, class E>
599  typename ClassComplexType<T>::Treal Norm2(const TinyVectorExpression<T, m, E> & u);
600 
601  template<class T0, class T1, class T2, int m>
602  void Add(const TinyVector<T0, m>& x, const TinyVector<T1, m>& y, TinyVector<T2, m>& z);
603 
604  template<class T0, class T1, class T2, int m>
605  void Add(const T0& alpha, const TinyVector<T1, m>& y, TinyVector<T2, m>& x);
606 
607  template<class T0, class T, int m>
608  void Mlt(const T0& alpha, TinyVector<T, m>& p);
609 
610 
611  /***********************
612  * Extractions functions *
613  ***********************/
614 
615 
616  template<int p, int m, class T0, class T1>
617  void ExtractVector(const Vector<Vector<TinyVector<T0, p> > >& u,
618  int j, int k, int offset, TinyVector<T1, m>& v);
619 
620  template<int m, class T0, class T1>
621  void ExtractVector(const Vector<Vector<T0> >& u,
622  int j, int offset, TinyVector<T1, m>& v);
623 
624  template<int m, class T0, class T1>
625  void CopyVector(const TinyVector<T1, m>& v,
626  int j, int offset, Vector<Vector<T0> >& u);
627 
628  template<int m, class T0, class T1>
629  void ExtractVector(const Vector<T0>& Vh, const IVect& row_num,
630  int nb, TinyVector<T1, m>& tmp);
631 
632  template<int m, class T0, class T1>
633  void ExtractVector(const TinyVector<T1, m>& tmp,
634  const IVect& row_num, int nb, Vector<T0>& Vh);
635 
636  template<int m, class T0, class T1>
637  void AddVector(const T0& alpha, const TinyVector<T1, m>& tmp,
638  const IVect& row_num, int nb, Vector<T0>& Vh);
639 
640  template<int m, class T0, class T1>
641  void ExtractVectorConj(const Vector<T0>& Vh, const IVect& row_num,
642  int nb, TinyVector<T1, m>& tmp);
643 
644  template<int m, class T0, class T1>
645  void ExtractVectorConj(const TinyVector<T1, m>& tmp,
646  const IVect& row_num, int nb, Vector<T0>& Vh);
647 
648  template<int m, class T0, class T1>
649  void AddVectorConj(const T0& alpha, const TinyVector<T1, m>& tmp,
650  const IVect& row_num, int nb, Vector<T0>& Vh);
651 
652 
653  template<int m, class T0, class T1>
654  void CopyVector(const TinyVector<Vector<T0>, m>& uvec,
655  int j, TinyVector<T1, m>& u);
656 
657  template<int m, class T0, class T1>
658  void CopyVector(const TinyVector<T1, m>& u,
659  int j, TinyVector<Vector<T0>, m>& uvec);
660 
661  template<int m, class T0, class T1>
662  void CopyVector(const TinyVector<T1, m>& u, int j, Vector<T0>& uvec);
663 
664  template<int m, class T0, class T1>
665  void CopyVector(const Vector<T0>& uvec, int j, TinyVector<T1, m>& u);
666 
667  template<int m, class T>
668  void CopyVector(const Vector<complex<T> >& Vh, int j, TinyVector<T, m>& vr, TinyVector<T, m>& vi);
669 
670  template<int m, class T0, class T1>
671  void AddVector(const TinyVector<T1, m>& u, int offset, Vector<T0>& uvec);
672 
673  template<int m, class T0, class T1>
674  void AddVector(const Vector<T0>& uvec, int offset, TinyVector<T1, m>& u);
675 
676  template<int m, class T0, class T1>
677  void ExtractVector(const TinyVector<T1, m>& u, int offset, Vector<T0>& uvec);
678 
679  template<int m, class T0, class T1>
680  void ExtractVector(const Vector<T0>& uvec, int offset, TinyVector<T1, m>& u);
681 
682 
683  /*******************
684  * Other functions *
685  *******************/
686 
687 
688  template<class T0, int m>
689  void SymmetrizePointPlane(const TinyVector<T0, m>& u, const TinyVector<T0, m>& normale,
690  const T0& d, TinyVector<T0, m>& v);
691 
692  template<class T, int m>
694 
695  template<class T, int m>
697 
698  template<int m, class T0, class T1>
699  void MltVector(const T1& alpha, int j, TinyVector<Vector<T0>, m>& uvec);
700 
701  template<class T>
702  int IntersectionEdges(const TinyVector<T,2>& pointA, const TinyVector<T,2>& pointB,
703  const TinyVector<T,2>& pt1, const TinyVector<T,2>& pt2,
704  TinyVector<T,2>& res, const T& threshold);
705 
706  template<class T>
707  int IntersectionDroites(const TinyVector<T,2>& pointA, const TinyVector<T,2>& pointB,
708  const TinyVector<T,2>& pt1, const TinyVector<T,2>& pt2,
709  TinyVector<T,2>& res, const T& threshold);
710 
711  template<class T, int p>
712  void Mlt(const T& alpha, Vector<TinyVector<T, p> >& X);
713 
714  template<class T, class Prop, class Storage, int p>
715  void Mlt(const SeldonTranspose&, const Matrix<T, Prop, Storage>& A,
717 
718  template<class T, class Prop, class Storage, int p>
719  void Mlt(const Matrix<T, Prop, Storage>& A,
721 
722 
723  /************************************
724  * Functions for 2-D or 3-D vectors *
725  ************************************/
726 
727  // res = u^v where u,v and res are vectors
728  template<class T1, class T2, class T3>
729  void TimesProd(const TinyVector<T1, 3> & u, const TinyVector<T2, 3> & v, TinyVector<T3, 3>& res);
730 
731  template<class T>
732  void ForceZeroVdotN(const TinyVector<T, 2>& normale, TinyVector<T, 2>& v0);
733 
734  template<class T>
735  void ForceZeroVdotN(const TinyVector<T, 3>& normale, TinyVector<T, 3>& v0);
736 
737  template<class T>
739 
740  template<class T>
742 
744  template<class T0, class T1, class T2, class T3>
747 
748  // res = (u^v) . w = det(u,v,w) where u,v and w are vectors
749  template<class T>
750  T Determinant(const TinyVector<T,3> & u, const TinyVector<T,3> & v, const TinyVector<T,3>& w);
751 
753  template<class T>
754  void GetVectorPlane(const TinyVector<T,3>& normale,
756 
757  void FillZero(double& X);
758  void FillZero(complex<double>& X);
759  void FillZero(int& X);
760  void FillZero(float& X);
761  void FillZero(complex<float>& X);
762  void FillZero(bool& X);
763 
764  template<class T, class Storage, class Allocator>
765  void FillZero(Vector<T, Storage, Allocator>& X);
766 
767  template<class T, class Prop, class Storage, class Allocator>
768  void FillZero(Matrix<T, Prop, Storage, Allocator>& X);
769 
770  template<class T, class Prop, class Allocator>
771  void FillZero(Matrix<T, Prop, RowSparse, Allocator>& X);
772 
773  template<class T, int m>
774  void FillZero(TinyVector<T, m>& X);
775 
776  template<class T>
777  void FillZero(T& x);
778 
779  template<class T>
780  void FillZero(complex<T>& x);
781 
782  template<class T, int p>
783  void SetComplexZero(TinyVector<T, p>& x);
784 
785  template<class T>
786  bool IsComplexZero(const T& x);
787 
788  template<class T>
789  bool IsComplexZero(const complex<T>& x);
790 
791 } // end namespace
792 
793 #define SELDON_FILE_TINY_VECTOR_HXX
794 #endif
795 
796 
Seldon::GenerateSymPts
void GenerateSymPts(const TinyVector< T0, 3 > &u, TinyVector< T1, 3 > &v, TinyVector< T2, 3 > &w, TinyVector< T3, 3 > &t)
generates four points respecting the symmetry of the reference pyramid with one point
Definition: TinyVectorInline.cxx:1524
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::operator==
bool operator==(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns true if *this == u
Definition: TinyMatrixInline.cxx:1245
Seldon::TimesProd
void TimesProd(const TinyVector< T1, 3 > &u, const TinyVector< T2, 3 > &v, TinyVector< T3, 3 > &res)
cross product res = u^v where u,v and res are vectors
Definition: TinyVectorInline.cxx:1455
Seldon::TinyVectorLoop::ExtractVectorConj
static void ExtractVectorConj(const Vector< T0 > &Vh, const IVect &row_num, int j, TinyVector< T1, m > &tmp)
tmp = conj(Vh(row_num(nb+:)))
Definition: TinyVectorInline.cxx:860
Seldon::TinyVectorLoop::ExtractVector
static void ExtractVector(const Vector< T0 > &Vh, int j, TinyVector< T1, m > &tmp)
tmp(:) = Vh(offset + :)
Definition: TinyVectorInline.cxx:763
Seldon::TinyVectorLoop::DiffCopy
static void DiffCopy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y -= x
Definition: TinyVectorInline.cxx:682
Seldon::TinyVectorLoop::FillRand
static void FillRand(TinyVector< T0, m > &x)
sets randomly the components with function rand()
Definition: TinyVectorInline.cxx:644
Seldon::TinyVector_Base
Class storing a tiny vector whose size is known at compilation time.
Definition: TinyVector.hxx:21
Seldon::Norm2
ClassComplexType< T >::Treal Norm2(const VectorExpression< T, E > &X)
returns 2-norm of an expression with vectors
Definition: Functions_BaseInline.cxx:153
Seldon::TinyVectorExpression
Expression between vectors.
Definition: TinyVectorExpression.hxx:8
Seldon::Norm1
ClassComplexType< T >::Treal Norm1(const VectorExpression< T, E > &X)
returns 1-norm of an expression with vectors
Definition: Functions_BaseInline.cxx:140
Seldon::TinyVector::TinyVector
TinyVector()
Sets all components to 0.
Definition: TinyVectorInline.cxx:312
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::TinyVectorLoop::Zero
static void Zero(TinyVector< T0, m > &x)
Sets all components to 0.
Definition: TinyVectorInline.cxx:600
Seldon::TinyVectorLoop::WriteText
static ostream & WriteText(const TinyVector< T, m > &V, ostream &out)
displays V
Definition: TinyVectorInline.cxx:1053
Seldon::TinyVectorLoop::Copy
static void Copy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y = x
Definition: TinyVectorInline.cxx:664
Seldon::TinyVectorLoop::AddCopy
static void AddCopy(const TinyVectorExpression< T1, m, E > &x, TinyVector< T0, m > &y)
y += x
Definition: TinyVectorInline.cxx:673
Seldon::TinyVector_Base::FillRand
void FillRand()
sets randomly the components with function rand()
Definition: TinyVectorInline.cxx:275
Seldon::Matrix< T, Prop, Storage >
Seldon::TinyVectorLoop::UpdateMaximum
static void UpdateMaximum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = max(v, u)
Definition: TinyVectorInline.cxx:1084
Seldon::TinyVectorLoop
class used for unrolling loops for operators/functions of TinyVector
Definition: TinyVector.hxx:14
Seldon::TinyVectorLoop::CopyVector
static void CopyVector(const TinyVector< Vector< T0 >, m > &uvec, int j, TinyVector< T1, m > &u)
u(:) = uvec(:)(j)
Definition: TinyVectorInline.cxx:692
Seldon::TinyVector_Base::DistanceSquare
ClassComplexType< T >::Treal DistanceSquare(const TinyVector< T, m_ > &p) const
returns |u-v|^2 (usual euclidian norm)
Definition: TinyVectorInline.cxx:291
Seldon::TinyVector
vector with real/complex components
Definition: TinyVector.hxx:17
Seldon::TinyVectorLoop::Mlt
static void Mlt(const T1 &alpha, TinyVector< T0, m > &x)
Multiplies x by alpha.
Definition: TinyVectorInline.cxx:982
Seldon::Matrix< T, Prop, RowSparse, Allocator >
Row-major sparse-matrix class.
Definition: Matrix_Sparse.hxx:223
Seldon::TinyVectorLoop::Abs
static void Abs(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = \sum |u_i|^2
Definition: TinyVectorInline.cxx:1013
Seldon::AddVectorConj
void AddVectorConj(const T0 &alpha, const TinyVector< T1, m > &tmp, const IVect &row_num, int nb, Vector< T0 > &Vh)
Vh(row_num(nb+:)) += alpha * conj(tmp)
Definition: TinyVectorInline.cxx:1296
Seldon::TinyVectorLoop::IsZero
static bool IsZero(const TinyVectorExpression< T0, m, E0 > &x)
returns true if all components are 0
Definition: TinyVectorInline.cxx:653
Seldon::TinyVector_Base::Distance
ClassComplexType< T >::Treal Distance(const TinyVector< T, m_ > &p) const
returns |u-v| (usual euclidian norm)
Definition: TinyVectorInline.cxx:299
Seldon::operator<=
bool operator<=(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u <= v, false otherwise
Definition: TinyVectorInline.cxx:494
Seldon::TinyVector_Base::Init
void Init(const T &a)
sets first component to a
Definition: TinyVectorInline.cxx:77
Seldon::ExtractVector
void ExtractVector(const Vector< Vector< TinyVector< T0, p > > > &u, int j, int k, int offset, TinyVector< T1, m > &v)
v(:) = u(offset+:)(j)(k)
Definition: TinyVectorInline.cxx:1224
Seldon::TinyVector_Base::GetSize
int GetSize() const
Returns the number of stored elements.
Definition: TinyVectorInline.cxx:179
Seldon::TinyVectorLoop::Less
static bool Less(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x < y
Definition: TinyVectorInline.cxx:929
Seldon::ForceZeroVdotN
void ForceZeroVdotN(const TinyVector< T, 2 > &normale, TinyVector< T, 2 > &v0)
modifies v0 such that v0 \cdot normale = 0
Definition: TinyVectorInline.cxx:1474
Seldon::TinyVector_Base::TinyVector_Base
TinyVector_Base()
all components are set to 0
Definition: TinyVectorInline.cxx:15
Seldon::UpdateMinimum
void UpdateMinimum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = min(v, u) elementwise
Definition: TinyVectorInline.cxx:1397
Seldon::UpdateMaximum
void UpdateMaximum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = max(v, u) elementwise
Definition: TinyVectorInline.cxx:1405
Seldon::TinyVectorLoop::NormInf
static void NormInf(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = max |u_i|^2
Definition: TinyVectorInline.cxx:1022
Seldon::CopyVector
void CopyVector(const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Y = X.
Definition: Functions_Vector.cxx:293
Seldon::PointInsideBoundingBox
bool PointInsideBoundingBox(const TinyVector< T, 2 > &, const TinyVector< TinyVector< T, 2 >, 2 > &)
returns true if x is inside the bounding box s
Definition: TinyVectorInline.cxx:1498
Seldon::operator>>
istream & operator>>(istream &out, TinyVector< T, m > &V)
reads V
Definition: TinyVectorInline.cxx:587
Seldon::TinyVectorLoop::Print
static void Print(const TinyVector< T, m > &V, ostream &out)
displays V without brackets
Definition: TinyVectorInline.cxx:1040
Seldon::TinyVector_Base::Print
void Print() const
displays the vector without brackets
Definition: TinyVectorInline.cxx:235
Seldon::TinyVector_Base::GetLength
int GetLength() const
Returns the number of stored elements.
Definition: TinyVectorInline.cxx:171
Seldon::TinyVectorLoop::LessInt
static bool LessInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x < y
Definition: TinyVectorInline.cxx:969
Seldon::TinyVector_Base::IsZero
bool IsZero() const
returns true if all components are 0
Definition: TinyVectorInline.cxx:283
Seldon::TinyVector_Base::Zero
void Zero()
Sets all components to 0.
Definition: TinyVectorInline.cxx:251
Seldon::TinyVectorLoop::LessOrEqualInt
static bool LessOrEqualInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x <= y
Definition: TinyVectorInline.cxx:955
Seldon::TinyVector_Base::Fill
void Fill()
Sets the vector to [0, 1, 2, 3, ..., n-1].
Definition: TinyVectorInline.cxx:259
Seldon::TinyVector::operator+=
TinyVector< T, m_ > & operator+=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this += expression with vectors.
Definition: TinyVectorInline.cxx:374
Seldon::operator>=
bool operator>=(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u >= v, false otherwise
Definition: TinyVectorInline.cxx:509
Seldon::TinyVectorLoop::Fill
static void Fill(TinyVector< T0, m > &x, const T1 &a)
Sets all components to a given value.
Definition: TinyVectorInline.cxx:626
Seldon::NormInf
ClassComplexType< T >::Treal NormInf(const Matrix< T, Prop, Storage, Allocator > &A)
Returns the infinity-norm of a matrix.
Definition: Functions_Matrix.cxx:2435
Seldon::TinyVector::operator=
TinyVector< T, m_ > & operator=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this = expression with vectors.
Definition: TinyVectorInline.cxx:364
Seldon::TinyVector_Base::GetLeafClass
TinyVector< T, m_ > & GetLeafClass()
returns leaf class
Definition: TinyVectorInline.cxx:195
Seldon::TinyVectorLoop::DotProd
static void DotProd(const TinyVectorExpression< T0, m, E0 > &u, const TinyVectorExpression< T1, m, E1 > &v, T2 &scal)
scal = u.v
Definition: TinyVectorInline.cxx:992
Seldon::operator!=
bool operator!=(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns true if *this != u
Definition: TinyMatrixInline.cxx:1254
Seldon::TinyVectorLoop::FillGreater
static void FillGreater(TinyVector< T0, m > &x, const T0 &a)
Fills with a in ascendant order (instead of descendant order for Fill)
Definition: TinyVectorInline.cxx:609
Seldon::TinyVectorLoop::AddVectorConj
static void AddVectorConj(const T0 &alpha, const TinyVector< T1, m > &tmp, const IVect &row_num, int j, Vector< T0 > &Vh)
Vh(row_num(nb+:)) += alpha * conj(tmp)
Definition: TinyVectorInline.cxx:882
Seldon::TinyVectorLoop::AddVector
static void AddVector(const Vector< T0 > &Vh, int j, TinyVector< T1, m > &tmp)
tmp(:) += Vh(offset + :)
Definition: TinyVectorInline.cxx:743
Seldon::TinyVectorLoop::UpdateMinimum
static void UpdateMinimum(const TinyVector< T, m > &u, TinyVector< T, m > &v)
sets v = min(v, u)
Definition: TinyVectorInline.cxx:1075
Seldon::TinyVector::operator-=
TinyVector< T, m_ > & operator-=(const TinyVectorExpression< T1, m_, E > &u)
Operator *this -= expression with vectors.
Definition: TinyVectorInline.cxx:384
Seldon::AbsSquare
ClassComplexType< T >::Treal AbsSquare(const TinyVectorExpression< T, m, E > &u)
returns || u ||^2
Definition: TinyVectorInline.cxx:1146
Seldon::Distance
T Distance(const TinyVector< T, m > &u, const TinyVector< T, m > &v)
returns || u-v ||
Definition: TinyVectorInline.cxx:1179
Seldon::SymmetrizePointPlane
void SymmetrizePointPlane(const TinyVector< T0, m > &u, const TinyVector< T0, m > &normale, const T0 &d, TinyVector< T0, m > &v)
Applies the symmetry with respect to the hyperplane a x + b y + c z + .. + d = 0 v = S(u) where S is ...
Definition: TinyVectorInline.cxx:1386
Seldon::TinyVectorLoop::InitValue
static void InitValue(TinyVector< T0, m > &x, const T0 &a)
initializes a single value
Definition: TinyVectorInline.cxx:618
Seldon::ExtractVectorConj
void ExtractVectorConj(const Vector< T0 > &Vh, const IVect &row_num, int nb, TinyVector< T1, m > &tmp)
tmp = conj(Vh(row_num(nb+:)))
Definition: TinyVectorInline.cxx:1278
Seldon::TinyVector_Base::GetMemorySize
size_t GetMemorySize() const
returns the size used by the object in bytes
Definition: TinyVectorInline.cxx:187
Seldon::Determinant
T Determinant(const TinyVector< T, 3 > &u, const TinyVector< T, 3 > &v, const TinyVector< T, 3 > &w)
res = (u^v) . w = det(u,v,w) where u,v and w are vectors
Definition: TinyVectorInline.cxx:1535
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::operator<<
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
Definition: Array.cxx:1617
Seldon::TinyVectorLoop::AbsSquare
static void AbsSquare(const TinyVectorExpression< T0, m, E0 > &u, T1 &scal)
computes scal = \sum |u_i|^2
Definition: TinyVectorInline.cxx:1031
Seldon::TinyVector_Base::operator()
const T & operator()(int i) const
returns x(i)
Definition: TinyVectorInline.cxx:211
Seldon::TinyVectorLoop::MltVector
static void MltVector(const T1 &alpha, int j, TinyVector< Vector< T0 >, m > &uvec)
u(:)(j) *= alpha
Definition: TinyVectorInline.cxx:893
Seldon::TinyVectorLoop::ReadText
static istream & ReadText(TinyVector< T, m > &V, istream &in)
reads V
Definition: TinyVectorInline.cxx:1066
Seldon::TinyVectorLoop::DotProdConj
static void DotProdConj(const TinyVectorExpression< T0, m, E0 > &u, const TinyVectorExpression< T1, m, E1 > &v, T2 &scal)
returns (conj(u), v)
Definition: TinyVectorInline.cxx:1003
Seldon::operator>
bool operator>(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns true if u > v, false otherwise
Definition: TinyVectorInline.cxx:517
Seldon::operator<
bool operator<(const TinyVector< int, m > &u, const TinyVector< int, m > &v)
returns *this < u
Definition: TinyVectorInline.cxx:501
Seldon::TinyVector_Base::GetM
int GetM() const
Returns the number of stored elements.
Definition: TinyVectorInline.cxx:163
Seldon::AddVector
void AddVector(const T0 &alpha, const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Adds two vectors Y = Y + alpha X.
Definition: Functions_Vector.cxx:94
Seldon::TinyVectorLoop::LessOrEqual
static bool LessOrEqual(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x <= y
Definition: TinyVectorInline.cxx:915
Seldon::TinyVectorLoop::Equal
static bool Equal(const TinyVectorExpression< T0, m, E0 > &x, const TinyVectorExpression< T1, m, E1 > &y)
returns x == y
Definition: TinyVectorInline.cxx:903
Seldon::TinyVectorLoop::EqualInt
static bool EqualInt(const TinyVector< T0, m > &x, const TinyVector< T1, m > &y)
returns x == y
Definition: TinyVectorInline.cxx:944