Functions_Vector.hxx
1 // Copyright (C) 2001-2011 Vivien Mallet
2 // Copyright (C) 2003-2009 Marc DuruflĂ©
3 // Copyright (C) 2010 INRIA
4 // Author(s): Marc Fragu
5 //
6 // This file is part of the linear-algebra library Seldon,
7 // http://seldon.sourceforge.net/.
8 //
9 // Seldon is free software; you can redistribute it and/or modify it under the
10 // terms of the GNU Lesser General Public License as published by the Free
11 // Software Foundation; either version 2.1 of the License, or (at your option)
12 // any later version.
13 //
14 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
15 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 // more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with Seldon. If not, see http://www.gnu.org/licenses/.
21 
22 
23 #ifndef SELDON_FILE_FUNCTIONS_VECTOR_HXX
24 
25 #define SELDON_FILE_FUNCTIONS_VECTOR_HXX
26 
27 
28 /*
29  Functions defined in this file:
30 
31  alpha X -> X
32  Mlt(alpha, X)
33 
34  alpha X + Y -> Y
35  Add(alpha, X, Y)
36 
37  alpha X + beta Y -> Y
38  Add(alpha, X, beta, Y)
39 
40  X -> Y
41  Copy(X, Y)
42 
43  X <-> Y
44  Swap(X, Y)
45 
46  X.Y
47  DotProd(X, Y)
48  DotProdConj(X, Y)
49 
50  ||X||
51  Norm1(X)
52  Norm2(X)
53  GetMaxAbsIndex(X)
54 
55  Omega X
56  GenRot(x, y, cos, sin)
57  ApplyRot(x, y, cos, sin)
58 
59 */
60 
61 namespace Seldon
62 {
63 
65  // MLT //
66 
67 
68  template <class T0,
69  class T1, class Storage1, class Allocator1>
70  void MltScalar(const T0& alpha,
71  Vector<T1, Storage1, Allocator1>& X) throw();
72 
73 
74  // MLT //
76 
77 
79  // ADD //
80 
81 
82  template <class T0,
83  class T1, class Storage1, class Allocator1,
84  class T2, class Storage2, class Allocator2>
85  void AddVector(const T0& alpha,
86  const Vector<T1, Storage1, Allocator1>& X,
87  Vector<T2, Storage2, Allocator2>& Y);
88 
89  template <class T0,
90  class T1, class Storage1, class Allocator1,
91  class T2, class Storage2, class Allocator2>
92  void AddVector(const T0& alpha,
93  const Vector<T1, Storage1, Allocator1>& X,
94  const T0& beta,
95  Vector<T2, Storage2, Allocator2>& Y);
96 
97  template <class T0,
98  class T1, class Allocator1,
99  class T2, class Allocator2>
100  void AddVector(const T0 alpha,
101  const Vector<T1, PETScSeq, Allocator1>& X,
102  Vector<T2, PETScSeq, Allocator2>& Y);
103 
104  template <class T0,
105  class T1, class Allocator1,
106  class T2, class Allocator2>
107  void AddVector(const T0 alpha,
108  const Vector<T1, PETScPar, Allocator1>& X,
109  Vector<T2, PETScPar, Allocator2>& Y);
110 
111  template <class T0,
112  class T1, class Allocator1,
113  class T2, class Allocator2>
114  void AddVector(const T0& alpha,
115  const Vector<T1, VectSparse, Allocator1>& X,
116  Vector<T2, VectSparse, Allocator2>& Y);
117 
118  template <class T0,
119  class T1, class Allocator1,
120  class T2, class Allocator2>
121  void AddVector(const T0& alpha,
122  const Vector<T1, VectSparse, Allocator1>& X,
123  Vector<T2, VectFull, Allocator2>& Y);
124 
125  template <class T0,
126  class T1, class Allocator1,
127  class T2, class Allocator2>
128  void AddVector(const T0& alpha,
129  const Vector<T1, Collection, Allocator1>& X,
130  Vector<T2, Collection, Allocator2>& Y);
131 
132  template <class T0,
133  class T1, template <class U1> class Allocator1,
134  class T2, template <class U2> class Allocator2>
135  void AddVector(const T0& alpha,
136  const
137  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
138  Vector<FloatDouble, DenseSparseCollection, Allocator2<T2> >& Y);
139 
140  template <class T0,
141  class T1, template <class U1> class Allocator1,
142  class T2, class Storage2, class Allocator2>
143  void AddVector(const T0& alpha,
144  const
145  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
146  Vector<T2, Storage2, Allocator2>& Y);
147 
148  // ADD //
150 
151 
153  // COPY //
154 
155 
156  template <class T1, class Storage1, class Allocator1,
157  class T2, class Storage2, class Allocator2>
158  void CopyVector(const Vector<T1, Storage1, Allocator1>& X,
159  Vector<T2, Storage2, Allocator2>& Y);
160 
161  template <class T1, class Allocator1,
162  class T2, class Allocator2>
163  void CopyVector(const Vector<T1, Collection, Allocator1>& X,
164  Vector<T2, VectFull, Allocator2>& Y);
165 
166  template<class T, class Alloc1, class Alloc2>
167  void CopyVector(const Vector<T, PETScPar, Alloc1>& A,
168  Vector<T, VectFull, Alloc2>& B);
169 
170  template<class T, class Alloc1, class Alloc2>
171  void CopyVector(const Vector<T, VectFull, Alloc1>& A,
172  Vector<T, PETScPar, Alloc2>& B);
173 
174 
175  // COPY //
177 
178 
180  // SWAP //
181 
182 
183  template <class T, class Storage, class Allocator>
184  void Swap(Vector<T, Storage, Allocator>& X,
185  Vector<T, Storage, Allocator>& Y);
186 
187  template <class T, class Allocator>
188  void Swap(Vector<T, VectSparse, Allocator>& X,
189  Vector<T, VectSparse, Allocator>& Y);
190 
191  template<class T>
192  void SwapPointer(Vector<T>& X, Vector<T>& Y);
193 
194 
195  // SWAP //
197 
198 
200  // DOTPROD //
201 
202 
203  template<class T1, class Storage1, class Allocator1,
204  class T2, class Storage2, class Allocator2>
205  T1 DotProdVector(const Vector<T1, Storage1, Allocator1>& X,
206  const Vector<T2, Storage2, Allocator2>& Y);
207 
208  template<class T1, class Allocator1,
209  class T2, class Allocator2>
210  typename T1::value_type
211  DotProdVector(const Vector<T1, Collection, Allocator1>& X,
212  const Vector<T2, Collection, Allocator2>& Y);
213 
214  template<class T1, template <class U1> class Allocator1,
215  class T2, template <class U2> class Allocator2>
216  double
217  DotProdVector(const
218  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
219  const
220  Vector<FloatDouble, DenseSparseCollection, Allocator2<T2> >& Y);
221 
222  template<class T1, class Storage1, class Allocator1,
223  class T2, class Storage2, class Allocator2>
224  T1 DotProdConjVector(const Vector<T1, Storage1, Allocator1>& X,
225  const Vector<T2, Storage2, Allocator2>& Y);
226 
227  template<class T1, class Allocator1,
228  class T2, class Allocator2>
229  T1 DotProdVector(const Vector<T1, VectSparse, Allocator1>& X,
230  const Vector<T2, VectSparse, Allocator2>& Y);
231 
232  template<class T1, class Allocator1,
233  class T2, class Allocator2>
234  T1 DotProdVector(const Vector<T1, VectSparse, Allocator1>& X,
235  const Vector<T2, VectFull, Allocator2>& Y);
236 
237  template<class T1, class Allocator1,
238  class T2, class Allocator2>
239  T1 DotProdVector(const Vector<T1, VectFull, Allocator1>& X,
240  const Vector<T2, VectSparse, Allocator2>& Y);
241 
242  template<class T1, class Allocator1,
243  class T2, class Allocator2>
244  T1
245  DotProdConjVector(const Vector<T1, VectSparse, Allocator1>& X,
246  const Vector<T2, VectSparse, Allocator2>& Y);
247 
248  template<class T1, class Allocator1,
249  class T2, class Allocator2>
250  T1
251  DotProdConjVector(const Vector<T1, VectSparse, Allocator1>& X,
252  const Vector<T2, VectFull, Allocator2>& Y);
253 
254 
255  // DOTPROD //
257 
258 
260  // NORM1 //
261 
262 
263  template<class T1, class Storage1, class Allocator1>
264  typename ClassComplexType<T1>::Treal
265  Norm1(const Vector<T1, Storage1, Allocator1>& X);
266 
267  template<class T1, class Allocator1>
268  typename ClassComplexType<T1>::Treal
269  Norm1(const Vector<T1, VectSparse, Allocator1>& X);
270 
271 
272  // NORM1 //
274 
275 
277  // NORM2 //
278 
279 
280  template<class T1, class Storage1, class Allocator1>
281  T1 Norm2(const Vector<T1, Storage1, Allocator1>& X);
282 
283  template<class T1, class Storage1, class Allocator1>
284  T1 Norm2(const Vector<complex<T1>, Storage1, Allocator1>& X);
285 
286  template<class T1, class Allocator1>
287  T1 Norm2(const Vector<T1, VectSparse, Allocator1>& X);
288 
289  template<class T1, class Allocator1>
290  T1 Norm2(const Vector<complex<T1>, VectSparse, Allocator1>& X);
291 
292 
293  // NORM2 //
295 
296 
298  // GETMAXABSINDEX //
299 
300 
301  template<class T, class Storage, class Allocator>
302  long GetMaxAbsIndex(const Vector<T, Storage, Allocator>& X);
303 
304 
305  // GETMAXABSINDEX //
307 
308 
310  // APPLYROT //
311 
312 
313  template<class T>
314  void GenRot(T& a_in, T& b_in, T& c_, T& s_);
315 
316  template<class T>
317  void GenRot(complex<T>& a_in, complex<T>& b_in, T& c_, complex<T>& s_);
318 
319  template<class T>
320  void ApplyRot(T& x, T& y, const T& c_, const T& s_);
321 
322  template<class T>
323  void ApplyRot(complex<T>& x, complex<T>& y,
324  const T& c_, const complex<T>& s_);
325 
326  template<class T, class Allocator1, class Allocator2>
327  void ApplyRot(Vector<T, VectFull, Allocator1>& X,
328  Vector<T, VectFull, Allocator2>& Y,
329  const T& c, const T& s);
330 
331  template<class T, class Allocator1, class Allocator2>
332  void ApplyRot(Vector<T, VectSparse, Allocator1>& X,
333  Vector<T, VectFull, Allocator2>& Y,
334  const T& c, const T& s);
335 
336 
337  // APPLYROT //
339 
340 
342  // CHECKDIM //
343 
344 
345  template <class T0, class Storage0, class Allocator0,
346  class T1, class Storage1, class Allocator1>
347  void CheckDim(const Vector<T0, Storage0, Allocator0>& X,
348  const Vector<T1, Storage1, Allocator1>& Y,
349  string function = "", string op = "X + Y");
350 
351  template <class T0, class Allocator0,
352  class T1, class Allocator1>
353  void CheckDim(const Vector<T0, VectSparse, Allocator0>& X,
354  const Vector<T1, VectSparse, Allocator1>& Y,
355  string function = "", string op = "X + Y");
356 
357  template <class T0, class Allocator0,
358  class T1, class Allocator1>
359  void CheckDim(const Vector<T0, Collection, Allocator0>& X,
360  const Vector<T1, Collection, Allocator1>& Y,
361  string function = "", string op = "X + Y");
362 
363  template <class T0, class Allocator0, class Allocator00,
364  class T1, class Allocator1, class Allocator11>
365  void CheckDim(const Vector<Vector<T0, VectSparse, Allocator0>,
366  Collection, Allocator00>& X,
367  const Vector<Vector<T1, VectSparse, Allocator1>,
368  Collection, Allocator11>& Y,
369  string function = "", string op = "X + Y");
370 
371  template <class T0, class Allocator0,
372  class T1, class Allocator1>
373  void CheckDim(const Vector<T0, VectFull, Allocator0>& X,
374  Vector<T1, Collection, Allocator1>& Y,
375  string function = "", string op = "X + Y");
376 
377  template <class T0, template <class U0> class Allocator0,
378  class T1, template <class U1> class Allocator1>
379  void
380  CheckDim(const
381  Vector<FloatDouble, DenseSparseCollection, Allocator0<T0> >& X,
382  const
383  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& Y,
384  string function = "", string op = "X + Y");
385 
386 
387  // CHECKDIM //
389 
390 
392  // GATHER/SCATTER //
393 
394 
395  template<class T, class Allocator1, class Allocator2>
396  void GatherSparseEntry(const Vector<T, VectFull, Allocator1>& y,
397  Vector<T, VectSparse, Allocator2>& x);
398 
399  template<class T, class Allocator1, class Allocator2>
400  void GatherSparseEntryZero(Vector<T, VectFull, Allocator1>& y,
401  Vector<T, VectSparse, Allocator2>& x);
402 
403  template<class T, class Allocator1, class Allocator2>
404  void ScatterSparseEntry(const Vector<T, VectSparse, Allocator1>& x,
405  Vector<T, VectFull, Allocator2>& y);
406 
407 
408  // GATHER/SCATTER //
410 
411 
413  // CONJUGATE //
414 
415 
416  template<class T, class Prop, class Allocator>
417  void Conjugate(Vector<T, Prop, Allocator>& X);
418 
419  template<class T, class Allocator>
420  void Conjugate(Vector<T, VectSparse, Allocator>& X);
421 
422 
423  // CONJUGATE //
425 
426 
427 } // namespace Seldon.
428 
429 #endif
Seldon::ApplyRot
void ApplyRot(T &x, T &y, const T &c_, const T &s_)
Rotation of a point in 2-D.
Definition: Functions_Vector.cxx:776
Seldon::MltScalar
void MltScalar(const T0 &alpha, Array3D< T, Allocator > &A)
Multiplication of all elements of a 3D array by a scalar.
Definition: Array3D.cxx:539
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::Norm1
ClassComplexType< T >::Treal Norm1(const VectorExpression< T, E > &X)
returns 1-norm of an expression with vectors
Definition: Functions_BaseInline.cxx:140
Seldon::SwapPointer
void SwapPointer(Vector< T > &X, Vector< T > &Y)
Swaps X and Y with pointers.
Definition: Functions_Vector.cxx:377
Seldon::DotProdVector
T1 DotProdVector(const Vector< T1, Storage1, Allocator1 > &X, const Vector< T2, Storage2, Allocator2 > &Y)
Scalar product between two vectors.
Definition: Functions_Vector.cxx:399
Seldon::Conjugate
void Conjugate(Matrix< T, Prop, Storage, Allocator > &A)
A is replaced by its conjugate.
Definition: Functions_Matrix.cxx:2915
Seldon::CopyVector
void CopyVector(const Vector< T1, Storage1, Allocator1 > &X, Vector< T2, Storage2, Allocator2 > &Y)
Y = X.
Definition: Functions_Vector.cxx:293
Seldon::CheckDim
void CheckDim(const Matrix< T0, Prop0, Storage0, Allocator0 > &A, const Matrix< T1, Prop1, Storage1, Allocator1 > &B, const Matrix< T2, Prop2, Storage2, Allocator2 > &C, string function)
Checks the compatibility of the dimensions.
Definition: Functions_Matrix.cxx:2132
Seldon::GetMaxAbsIndex
long GetMaxAbsIndex(const Vector< T, Storage, Allocator > &X)
returns index for which X(i) is maximal
Definition: Functions_Vector.cxx:691
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::DotProdConjVector
T1 DotProdConjVector(const Vector< T1, Storage1, Allocator1 > &X, const Vector< T2, Storage2, Allocator2 > &Y)
Scalar product between two vectors conj(X).Y .
Definition: Functions_Vector.cxx:461
Seldon::Swap
void Swap(Vector< T, Storage, Allocator > &X, Vector< T, Storage, Allocator > &Y)
Swaps X and Y without copying all elements.
Definition: Functions_Vector.cxx:348
Seldon::GenRot
void GenRot(T &a_in, T &b_in, T &c_, T &s_)
Computation of rotation between two points.
Definition: Functions_Vector.cxx:707
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