Functions_Vector.cxx
1 // Copyright (C) 2003-2009 Marc DuruflĂ©
2 // Copyright (C) 2001-2009 Vivien Mallet
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_CXX
24 #define SELDON_FILE_FUNCTIONS_VECTOR_CXX
25 
26 
27 #include "Functions_Vector.hxx"
28 
29 
30 /*
31  Functions defined in this file:
32 
33  alpha X -> X
34  Mlt(alpha, X)
35 
36  alpha X + Y -> Y
37  Add(alpha, X, Y)
38 
39  alpha X + beta Y -> Y
40  Add(alpha, X, beta, Y)
41 
42  X -> Y
43  Copy(X, Y)
44 
45  X <-> Y
46  Swap(X, Y)
47 
48  X.Y
49  DotProd(X, Y)
50  DotProdConj(X, Y)
51 
52  ||X||
53  Norm1(X)
54  Norm2(X)
55  GetMaxAbsIndex(X)
56 
57  Omega X
58  GenRot(x, y, cos, sin)
59  ApplyRot(x, y, cos, sin)
60 
61 */
62 
63 
64 namespace Seldon
65 {
66 
67 
69  // MLT //
70 
71 
73  template <class T0,
74  class T1, class Storage1, class Allocator1>
75  void MltScalar(const T0& alpha,
77  {
78  X *= alpha;
79  }
80 
81 
82  // MLT //
84 
85 
87  // ADD //
88 
89 
91  template <class T0,
92  class T1, class Storage1, class Allocator1,
93  class T2, class Storage2, class Allocator2>
94  void AddVector(const T0& alpha,
97  {
98  T0 zero; SetComplexZero(zero);
99  if (alpha != zero)
100  {
101  long ma = X.GetM();
102 
103 #ifdef SELDON_CHECK_DIMENSIONS
104  CheckDim(X, Y, "Add(alpha, X, Y)");
105 #endif
106 
107  for (long i = 0; i < ma; i++)
108  Y(i) += alpha * X(i);
109  }
110  }
111 
112 
114  template <class T0,
115  class T1, class Storage1, class Allocator1,
116  class T2, class Storage2, class Allocator2>
117  void AddVector(const T0& alpha,
119  const T0& beta,
121  {
122  T0 zero; SetComplexZero(zero);
123  if (alpha != zero)
124  {
125  long ma = X.GetM();
126 
127 #ifdef SELDON_CHECK_DIMENSIONS
128  CheckDim(X, Y, "Add(alpha, X, Y)");
129 #endif
130 
131  for (long i = 0; i < ma; i++)
132  Y(i) = beta*Y(i) + alpha * X(i);
133  }
134  else
135  Mlt(beta, Y);
136  }
137 
138 
140  template <class T0,
141  class T1, class Allocator1,
142  class T2, class Allocator2>
143  void AddVector(const T0 alpha,
146  {
147  if (alpha != T0(0))
148  {
149  T1 alpha_ = alpha;
150 
151 #ifdef SELDON_CHECK_DIMENSIONS
152  CheckDim(X, Y, "Add(alpha, X, Y)");
153 #endif
154 
155  VecAXPY(Y.GetPetscVector(), alpha_, X.GetPetscVector());
156  }
157  }
158 
159 
160  template <class T0,
161  class T1, class Allocator1,
162  class T2, class Allocator2>
163  void AddVector(const T0 alpha,
164  const Vector<T1, PETScPar, Allocator1>& X,
165  Vector<T2, PETScPar, Allocator2>& Y)
166  {
167  if (alpha != T0(0))
168  {
169  T1 alpha_ = alpha;
170 
171 #ifdef SELDON_CHECK_DIMENSIONS
172  CheckDim(X, Y, "Add(alpha, X, Y)");
173 #endif
174 
175  VecAXPY(Y.GetPetscVector(), alpha_, X.GetPetscVector());
176  }
177  }
178 
179 
181  template <class T0,
182  class T1, class Allocator1,
183  class T2, class Allocator2>
184  void AddVector(const T0& alpha,
187  {
188  T0 zero;
189  SetComplexZero(zero);
190  if (alpha != zero)
191  {
193  Xalpha *= alpha;
194  Y.AddInteractionRow(Xalpha.GetSize(),
195  Xalpha.GetIndex(), Xalpha.GetData(), true);
196  }
197  }
198 
199 
201  template <class T0,
202  class T1, class Allocator1,
203  class T2, class Allocator2>
204  void AddVector(const T0& alpha,
207  {
208  T0 zero;
209  SetComplexZero(zero);
210  if (alpha != zero)
211  {
212  for (int i = 0; i < X.GetM(); i++)
213  Y(X.Index(i)) += alpha * X.Value(i);
214  }
215  }
216 
217 
219  template <class T0,
220  class T1, class Allocator1,
221  class T2, class Allocator2>
222  void AddVector(const T0& alpha,
225  {
226 
227 #ifdef SELDON_CHECK_DIMENSIONS
228  CheckDim(X, Y, "Add(X, Y)", "X + Y");
229 #endif
230 
231  for (int i = 0; i < X.GetNvector(); i++)
232  Add(alpha, X.GetVector(i), Y.GetVector(i));
233  }
234 
235 
236  template <class T0,
237  class T1, template <class U1> class Allocator1,
238  class T2, template <class U2> class Allocator2>
239  void AddVector(const T0& alpha,
240  const
241  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
242  Vector<FloatDouble, DenseSparseCollection, Allocator2<T2> >& Y)
243  {
244 
245 #ifdef SELDON_CHECK_DIMENSIONS
246  CheckDim(X, Y, "Add(X, Y)");
247 #endif
248 
249  AddVector(alpha, X.GetFloatDense(), Y.GetFloatDense());
250  AdVectord(alpha, X.GetFloatSparse(), Y.GetFloatSparse());
251  AddVector(alpha, X.GetDoubleDense(), Y.GetDoubleDense());
252  AddVector(alpha, X.GetDoubleSparse(), Y.GetDoubleSparse());
253  }
254 
255 
257  template <class T0,
258  class T1, template <class U1> class Allocator1,
259  class T2, class Storage2, class Allocator2>
260  void AddVector(const T0& alpha,
261  const
262  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
264  {
265  if (alpha != T0(0))
266  {
267  double alpha_ = alpha;
268 
269  int ma = X.GetM();
270 
271 #ifdef SELDON_CHECK_DIMENSIONS
272  CheckDim(X, Y, "Add(alpha, X, Y)");
273 #endif
274 
275  for (int i = 0; i < ma; i++)
276  Y(i) += alpha_ * X(i);
277 
278  }
279  }
280 
281 
282  // ADD //
284 
285 
287  // COPY //
288 
289 
291  template <class T1, class Storage1, class Allocator1,
292  class T2, class Storage2, class Allocator2>
295  {
296  Y.Copy(X);
297  }
298 
299 
301  template <class T1, class Allocator1,
302  class T2, class Allocator2>
305  {
306  Y.Clear();
307  for (int i = 0; i < X.GetNvector(); i++)
308  Y.PushBack(X.GetVector(i));
309  }
310 
311 
312  template<class T, class Alloc1, class Alloc2>
313  void CopyVector(const Vector<T, PETScPar, Alloc1>& A,
314  Vector<T, VectFull, Alloc2>& B)
315  {
316  B.Reallocate(A.GetLocalM());
317  T *local_data;
318  VecGetArray(A.GetPetscVector(), &local_data);
319  for (int i = 0; i < A.GetLocalM(); i++)
320  B(i) = local_data[i];
321  VecRestoreArray(A.GetPetscVector(), &local_data);
322  }
323 
324 
325  template<class T, class Alloc1, class Alloc2>
326  void CopyVector(const Vector<T, VectFull, Alloc1>& A,
327  Vector<T, PETScPar, Alloc2>& B)
328  {
329  T *local_data;
330  VecGetArray(B.GetPetscVector(), &local_data);
331  for (int i = 0; i < A.GetM(); i++)
332  local_data[i] = A(i);
333  VecRestoreArray(B.GetPetscVector(), &local_data);
334  }
335 
336 
337 
338  // COPY //
340 
341 
343  // SWAP //
344 
345 
347  template <class T, class Storage, class Allocator>
350  {
351  long nx = X.GetM();
352  T* data = X.GetData();
353  X.Nullify();
354  X.SetData(Y.GetM(), Y.GetData());
355  Y.Nullify();
356  Y.SetData(nx, data);
357  }
358 
359 
361  template <class T, class Allocator>
364  {
365  long nx = X.GetM();
366  T* data = X.GetData();
367  int* index = X.GetIndex();
368  X.Nullify();
369  X.SetData(Y.GetM(), Y.GetData(), Y.GetIndex());
370  Y.Nullify();
371  Y.SetData(nx, data, index);
372  }
373 
374 
376  template <class T>
378  {
379  long nx = X.GetM();
380  T* data = X.GetData();
381  X.Nullify();
382  X.SetData(Y.GetM(), Y.GetData());
383  Y.Nullify();
384  Y.SetData(nx, data);
385  }
386 
387 
388  // SWAP //
390 
391 
393  // DOTPROD //
394 
395 
397  template<class T1, class Storage1, class Allocator1,
398  class T2, class Storage2, class Allocator2>
401  {
402  T1 value;
403  SetComplexZero(value);
404 
405 #ifdef SELDON_CHECK_DIMENSIONS
406  CheckDim(X, Y, "DotProd(X, Y)");
407 #endif
408 
409  for (long i = 0; i < X.GetM(); i++)
410  value += X(i) * Y(i);
411 
412  return value;
413  }
414 
415 
417  template<class T1, class Allocator1,
418  class T2, class Allocator2>
419  typename T1::value_type
422  {
423  typename T1::value_type value(0);
424 
425 #ifdef SELDON_CHECK_DIMENSIONS
426  CheckDim(X, Y, "DotProd(X, Y)", "<X, Y>");
427 #endif
428 
429  for (int i = 0; i < X.GetNvector(); i++)
430  value += DotProdVector(X.GetVector(i), Y.GetVector(i));
431  return value;
432  }
433 
434 
436  template<class T1, template <class U1> class Allocator1,
437  class T2, template <class U2> class Allocator2>
438  double
440  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& X,
441  const
442  Vector<FloatDouble, DenseSparseCollection, Allocator2<T2> >& Y)
443  {
444 
445 #ifdef SELDON_CHECK_DIMENSIONS
446  CheckDim(X, Y, "DotProd(X, Y)");
447 #endif
448 
449  double value(0.);
450  value += DotProdVector(X.GetFloatDense(), Y.GetFloatDense());
451  value += DotProdVector(X.GetFloatSparse(), Y.GetFloatSparse());
452  value += DotProdVector(X.GetDoubleDense(), Y.GetDoubleDense());
453  value += DotProdVector(X.GetDoubleSparse(), Y.GetDoubleSparse());
454  return value;
455  }
456 
457 
459  template<class T1, class Storage1, class Allocator1,
460  class T2, class Storage2, class Allocator2>
463  {
464  T1 value;
465  SetComplexZero(value);
466 
467 #ifdef SELDON_CHECK_DIMENSIONS
468  CheckDim(X, Y, "DotProdConj(X, Y)");
469 #endif
470 
471  for (long i = 0; i < X.GetM(); i++)
472  value += conjugate(X(i)) * Y(i);
473 
474  return value;
475  }
476 
477 
479  template<class T1, class Allocator1,
480  class T2, class Allocator2>
483  {
484  T1 value;
485  SetComplexZero(value);
486 
487  int size_x = X.GetSize();
488  int size_y = Y.GetSize();
489  int kx = 0, ky = 0, pos_x;
490  while (kx < size_x)
491  {
492  pos_x = X.Index(kx);
493  while (ky < size_y && Y.Index(ky) < pos_x)
494  ky++;
495 
496  if (ky < size_y && Y.Index(ky) == pos_x)
497  value += X.Value(kx) * Y.Value(ky);
498 
499  kx++;
500  }
501 
502  return value;
503  }
504 
505 
507  template<class T1, class Allocator1,
508  class T2, class Allocator2>
511  {
512  T1 value;
513  SetComplexZero(value);
514  for (int i = 0; i < X.GetM(); i++)
515  value += X.Value(i)*Y(X.Index(i));
516 
517  return value;
518  }
519 
520 
522  template<class T1, class Allocator1,
523  class T2, class Allocator2>
526  {
527  return DotProdVector(Y, X);
528  }
529 
530 
532  template<class T1, class Allocator1,
533  class T2, class Allocator2>
534  T1
537  {
538  T1 value;
539  SetComplexZero(value);
540 
541  int size_x = X.GetSize();
542  int size_y = Y.GetSize();
543  int kx = 0, ky = 0, pos_x;
544  while (kx < size_x)
545  {
546  pos_x = X.Index(kx);
547  while (ky < size_y && Y.Index(ky) < pos_x)
548  ky++;
549 
550  if (ky < size_y && Y.Index(ky) == pos_x)
551  value += conjugate(X.Value(kx)) * Y.Value(ky);
552 
553  kx++;
554  }
555 
556  return value;
557  }
558 
559 
561  template<class T1, class Allocator1,
562  class T2, class Allocator2>
563  T1
566  {
567  T1 value;
568  SetComplexZero(value);
569 
570  for (int i = 0; i < X.GetM(); i++)
571  value += conjugate(X.Value(i))*Y(X.Index(i));
572 
573  return value;
574  }
575 
576 
577  // DOTPROD //
579 
580 
582  // NORM1 //
583 
584 
586 
590  template<class T1, class Storage1, class Allocator1>
591  typename ClassComplexType<T1>::Treal
593  {
594  typename ClassComplexType<T1>::Treal value(0);
595 
596  for (long i = 0; i < X.GetM(); i++)
597  value += ComplexAbs(X(i));
598 
599  return value;
600  }
601 
602 
604 
608  template<class T1, class Allocator1>
609  typename ClassComplexType<T1>::Treal
611  {
612  typename ClassComplexType<T1>::Treal value(0);
613 
614  for (int i = 0; i < X.GetM(); i++)
615  value += ComplexAbs(X.Value(i));
616 
617  return value;
618  }
619 
620 
621  // NORM1 //
623 
624 
626  // NORM2 //
627 
628 
630  template<class T1, class Storage1, class Allocator1>
632  {
633  T1 value(0);
634 
635  for (long i = 0; i < X.GetM(); i++)
636  value += X(i) * X(i);
637 
638  return sqrt(value);
639  }
640 
641 
643  template<class T1, class Storage1, class Allocator1>
644  T1 Norm2(const Vector<complex<T1>, Storage1, Allocator1>& X)
645  {
646  T1 value(0);
647 
648  for (size_t i = 0; i < X.GetSize(); i++)
649  value += absSquare(X(i));
650 
651  return sqrt(value);
652  }
653 
654 
656  template<class T1, class Allocator1>
658  {
659  T1 value(0);
660 
661  for (size_t i = 0; i < X.GetSize(); i++)
662  value += X.Value(i) * X.Value(i);
663 
664  return sqrt(value);
665  }
666 
667 
669  template<class T1, class Allocator1>
670  T1 Norm2(const Vector<complex<T1>, VectSparse, Allocator1>& X)
671  {
672  T1 value(0);
673 
674  for (size_t i = 0; i < X.GetSize(); i++)
675  value += absSquare(X.Value(i));
676 
677  return sqrt(value);
678  }
679 
680 
681  // NORM2 //
683 
684 
686  // GETMAXABSINDEX //
687 
688 
690  template<class T, class Storage, class Allocator>
692  {
693  return X.GetNormInfIndex();
694  }
695 
696 
697  // GETMAXABSINDEX //
699 
700 
702  // APPLYROT //
703 
704 
706  template<class T>
707  void GenRot(T& a_in, T& b_in, T& c_, T& s_)
708  {
709  // Old BLAS version.
710  T roe;
711  if (abs(a_in) > abs(b_in))
712  roe = a_in;
713  else
714  roe = b_in;
715 
716  T scal = abs(a_in) + abs(b_in);
717  T r, z;
718  if (scal != T(0))
719  {
720  T a_scl = a_in / scal;
721  T b_scl = b_in / scal;
722  r = scal * sqrt(a_scl * a_scl + b_scl * b_scl);
723  if (roe < T(0))
724  r *= T(-1);
725 
726  c_ = a_in / r;
727  s_ = b_in / r;
728  z = T(1);
729  if (abs(a_in) > abs(b_in))
730  z = s_;
731  else if (abs(b_in) >= abs(a_in) && c_ != T(0))
732  z = T(1) / c_;
733  }
734  else
735  {
736  c_ = T(1);
737  s_ = T(0);
738  r = T(0);
739  z = T(0);
740  }
741  a_in = r;
742  b_in = z;
743  }
744 
745 
747  template<class T>
748  void GenRot(complex<T>& a_in, complex<T>& b_in, T& c_, complex<T>& s_)
749  {
750 
751  T a = abs(a_in), b = abs(b_in);
752  if (a == T(0))
753  {
754  c_ = T(0);
755  s_ = complex<T>(1, 0);
756  a_in = b_in;
757  }
758  else
759  {
760  T scale = a + b;
761  T a_scal = abs(a_in / scale);
762  T b_scal = abs(b_in / scale);
763  T norm = sqrt(a_scal * a_scal + b_scal * b_scal) * scale;
764 
765  c_ = a / norm;
766  complex<T> alpha = a_in / a;
767  s_ = alpha * conjugate(b_in) / norm;
768  a_in = alpha * norm;
769  }
770  b_in = complex<T>(0, 0);
771  }
772 
773 
775  template<class T>
776  void ApplyRot(T& x, T& y, const T& c_, const T& s_)
777  {
778  T temp = c_ * x + s_ * y;
779  y = c_ * y - s_ * x;
780  x = temp;
781  }
782 
783 
785  template<class T>
786  void ApplyRot(complex<T>& x, complex<T>& y,
787  const T& c_, const complex<T>& s_)
788  {
789  complex<T> temp = s_ * y + c_ * x;
790  y = -conjugate(s_) * x + c_ * y;
791  x = temp;
792  }
793 
794 
796  template<class T, class Allocator1, class Allocator2>
799  const T& c, const T& s)
800  {
801  T tmp;
802  for (long i = 0; i < X.GetM(); i++)
803  {
804  tmp = c*X(i) + s*Y(i);
805  Y(i) = c*Y(i) - s*X(i);
806  X(i) = tmp;
807  }
808  }
809 
810 
812  template<class T, class Allocator1, class Allocator2>
815  const T& c, const T& s)
816  {
817  T tmp;
818  for (int i = 0; i < X.GetM(); i++)
819  {
820  tmp = c*X.Value(i) + s*Y(X.Index(i));
821  Y(X.Index(i)) = c*Y(X.Index(i)) - s*X.Value(i);
822  X.Value(i) = tmp;
823  }
824  }
825 
826 
827  // APPLYROT //
829 
830 
832  // CHECKDIM //
833 
834 
836 
846  template <class T0, class Storage0, class Allocator0,
847  class T1, class Storage1, class Allocator1>
850  string function, string op)
851  {
852 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
853  string Xchar = to_str(&X), Ychar = to_str(&Y);
854 #else
855  string Xchar("X"), Ychar("Y");
856 #endif
857 
858  if (X.GetLength() != Y.GetLength())
859  throw WrongDim(function, string("Operation ") + op
860  + string(" not permitted:")
861  + string("\n X (") + Xchar + string(") is a ")
862  + string("vector of length ") + to_str(X.GetLength())
863  + string(";\n Y (") + Ychar + string(") is a ")
864  + string("vector of length ") + to_str(Y.GetLength())
865  + string("."));
866  }
867 
868 
870 
880  template <class T0, class Allocator0,
881  class T1, class Allocator1>
884  string function, string op)
885  {
886  // The dimension of a Vector<VectSparse> is infinite,
887  // so no vector dimension checking has to be done.
888  }
889 
890 
892 
902  template <class T0, class Allocator0,
903  class T1, class Allocator1>
906  string function, string op)
907  {
908  if (X.GetLength() != Y.GetLength())
909  throw WrongDim(function, string("Operation ") + op
910  + string(" not permitted:")
911  + string("\n X (") + to_str(&X) + string(") is a ")
912  + string("vector of length ") + to_str(X.GetLength())
913  + string(";\n Y (") + to_str(&Y) + string(") is a ")
914  + string("vector of length ") + to_str(Y.GetLength())
915  + string("."));
916 
917  if (X.GetNvector() != Y.GetNvector())
918  throw WrongDim(function, string("Operation ") + op
919  + string(" not permitted:")
920  + string("\n X (") + to_str(&X) + string(") is a ")
921  + string("vector of length ") + to_str(X.GetNvector())
922  + string(";\n Y (") + to_str(&Y) + string(") is a ")
923  + string("vector of length ") + to_str(Y.GetNvector())
924  + string("."));
925  }
926 
927 
929 
939  template <class T0, class Allocator0, class Allocator00,
940  class T1, class Allocator1, class Allocator11>
942  Collection, Allocator00>& X,
944  Collection, Allocator11>& Y,
945  string function, string op)
946  {
947 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
948  string Xchar = to_str(&X), Ychar = to_str(&Y);
949 #else
950  string Xchar("X"), Ychar("Y");
951 #endif
952 
953  if (X.GetNvector() != Y.GetNvector())
954  throw WrongDim(function, string("Operation ") + op
955  + string(" not permitted:")
956  + string("\n X (") + Xchar + string(") is a ")
957  + string("vector of length ") + to_str(X.GetNvector())
958  + string(";\n Y (") + Ychar + string(") is a ")
959  + string("vector of length ") + to_str(Y.GetNvector())
960  + string("."));
961  }
962 
963 
965 
975  template <class T0, class Allocator0,
976  class T1, class Allocator1>
979  string function, string op)
980  {
981 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
982  string Xchar = to_str(&X), Ychar = to_str(&Y);
983 #else
984  string Xchar("X"), Ychar("Y");
985 #endif
986 
987  if (X.GetLength() != Y.GetM())
988  throw WrongDim(function, string("Operation ") + op
989  + string(" not permitted:")
990  + string("\n X (") + Xchar + string(") is a ")
991  + string("vector of length ") + to_str(X.GetLength())
992  + string(";\n Y (") + Ychar + string(") is a ")
993  + string("vector of length ") + to_str(Y.GetM())
994  + string("."));
995  }
996 
997 
999 
1009  template <class T0, template <class U0> class Allocator0,
1010  class T1, template <class U1> class Allocator1>
1011  void
1012  CheckDim(const
1013  Vector<FloatDouble, DenseSparseCollection, Allocator0<T0> >& X,
1014  const
1015  Vector<FloatDouble, DenseSparseCollection, Allocator1<T1> >& Y,
1016  string function, string op)
1017  {
1018 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
1019  string Xchar = to_str(&X), Ychar = to_str(&Y);
1020 #else
1021  string Xchar("X"), Ychar("Y");
1022 #endif
1023 
1024  if (X.GetNvector() != Y.GetNvector())
1025  throw WrongDim(function, string("Operation ") + op
1026  + string(" not permitted:")
1027  + string("\n X (") + Xchar + string(") is a ")
1028  + string("vector of length ") + to_str(X.GetNvector())
1029  + string(";\n Y (") + Ychar + string(") is a ")
1030  + string("vector of length ") + to_str(Y.GetNvector())
1031  + string("."));
1032  }
1033 
1034 
1035  // CHECKDIM //
1037 
1038 
1040  // GATHER/SCATTER //
1041 
1042 
1043  template<class T, class Allocator1, class Allocator2>
1044  void GatherSparseEntry(const Vector<T, VectFull, Allocator1>& Y,
1045  Vector<T, VectSparse, Allocator2>& X)
1046  {
1047  for (int i = 0; i < X.GetM(); i++)
1048  X.Value(i) = Y(X.Index(i));
1049  }
1050 
1051  template<class T, class Allocator1, class Allocator2>
1052  void GatherSparseEntryZero(Vector<T, VectFull, Allocator1>& Y,
1053  Vector<T, VectSparse, Allocator2>& X)
1054  {
1055  T zero; SetComplexZero(zero);
1056  for (int i = 0; i < X.GetM(); i++)
1057  {
1058  X.Value(i) = Y(X.Index(i));
1059  Y(X.Index(i)) = zero;
1060  }
1061  }
1062 
1063 
1064  template<class T, class Allocator1, class Allocator2>
1065  void ScatterSparseEntry(const Vector<T, VectSparse, Allocator1>& X,
1066  Vector<T, VectFull, Allocator2>& Y)
1067  {
1068  for (int i = 0; i < X.GetM(); i++)
1069  Y(X.Index(i)) = X.Value(i);
1070  }
1071 
1072 
1073  // GATHER/SCATTER //
1075 
1076 
1078  // CONJUGATE //
1079 
1080 
1082  template<class T, class Prop, class Allocator>
1084  {
1085  for (long i = 0; i < X.GetM(); i++)
1086  X(i) = conjugate(X(i));
1087  }
1088 
1089 
1091  template<class T, class Allocator>
1093  {
1094  for (size_t i = 0; i < X.GetSize(); i++)
1095  X.Value(i) = conjugate(X.Value(i));
1096  }
1097 
1098 
1099  // CONJUGATE //
1101 
1102 
1103 } // namespace Seldon.
1104 
1105 
1106 #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::Vector< T, VectSparse, Allocator >::SetData
void SetData(size_t nz, T *data, int *index)
Changes the length of the vector and sets its data array (low level method).
Definition: SparseVector.cxx:224
Seldon::FloatDouble
Definition: Storage.hxx:365
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::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
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::DenseSparseCollection
Definition: StorageInline.cxx:89
Seldon::Vector< T, VectSparse, Allocator >::Nullify
void Nullify()
Clears the vector without releasing memory.
Definition: SparseVector.cxx:294
Seldon::Vector_Base::GetM
long GetM() const
Returns the number of elements.
Definition: VectorInline.cxx:131
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::SwapPointer
void SwapPointer(Vector< T > &X, Vector< T > &Y)
Swaps X and Y with pointers.
Definition: Functions_Vector.cxx:377
Seldon::Collection
Definition: StorageInline.cxx:84
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::Vector_Base::GetSize
size_t GetSize() const
Returns the number of elements stored.
Definition: VectorInline.cxx:153
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::absSquare
T absSquare(const T &x)
returns the square modulus of z
Definition: CommonInline.cxx:340
Seldon::Vector< T, VectSparse, Allocator >
Sparse vector class.
Definition: SparseVector.hxx:29
Seldon::VectSparse
Definition: StorageInline.cxx:79
Seldon::WrongDim
Definition: Errors.hxx:102
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::Vector< T, VectSparse, Allocator >::GetIndex
int * GetIndex() const
Returns a pointer to the array containing the indices of the non-zero entries.
Definition: SparseVectorInline.cxx:189
Seldon::ComplexAbs
T ComplexAbs(const T &val)
returns absolute value of val
Definition: CommonInline.cxx:309
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::Vector< T, VectSparse, Allocator >::Value
reference Value(int i)
Access operator.
Definition: SparseVectorInline.cxx:99
Seldon::Vector_Base::GetData
pointer GetData() const
Returns a pointer to data_ (stored data).
Definition: VectorInline.cxx:177