Functions_MatrixComplex.cxx
1 // Copyright (C) 2003-2011 Marc DuruflĂ©
2 // Copyright (C) 2001-2011 Vivien Mallet
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_FUNCTIONS_MATRIX_COMPLEX_CXX
22 
23 /*
24  Functions defined in this file:
25  (storage RowComplexSparse, ArrayRowComplexSparse, etc)
26 
27  alpha.A + B -> B
28  Add(alpha, A, B)
29 
30  alpha.M -> M
31  Mlt(alpha, M)
32 
33  A = A(row_perm, col_perm)
34  ApplyPermutation(A, row_perm, col_perm)
35 
36  A(row_perm, col_perm) = A
37  ApplyInversePermutation(A, row_perm, col_perm)
38 
39  A = Drow * A * Dcol
40  ScaleMatrix(A, Drow, Dcol)
41 
42  A = Drow * A
43  ScaleLeftMatrix(A, Drow)
44 
45  A = A * Dcol
46  ScaleRightMatrix(A, Dcol)
47 
48 */
49 
50 namespace Seldon
51 {
52 
54  template<class T0, class T1, class Allocator1, class T2, class Allocator2>
55  void AddMatrix(const T0& alpha,
56  const Matrix<T1, Symmetric,
57  ArrayRowSymComplexSparse, Allocator1>& A,
59  {
60  int m = B.GetM(), n, ni;
61  Vector<T2> value(2*B.GetN());
62  IVect index(2*B.GetN());
63  for (int i = 0 ; i < m ; i++)
64  {
65  n = A.GetRealRowSize(i);
66  ni = A.GetImagRowSize(i);
67  for (int j = 0; j < n; j++)
68  {
69  value(j) = alpha*T2(A.ValueReal(i, j), 0);
70  index(j) = A.IndexReal(i, j);
71  }
72 
73  for (int j = 0; j < ni; j++)
74  {
75  value(j+n) = alpha*T2(0, A.ValueImag(i, j));
76  index(j+n) = A.IndexImag(i, j);
77  }
78 
79  B.AddInteractionRow(i, n+ni, index, value);
80  }
81  }
82 
83 
85  template<class T0, class T1, class Allocator1, class T2, class Allocator2>
86  void AddMatrix(const T0& alpha, const Matrix<T1, Symmetric,
87  ArrayRowSymComplexSparse, Allocator1>& A,
89  {
90  int m = B.GetM(), n;
91  Vector<T2, VectFull, Allocator2> value(B.GetN());
92  for (int i = 0 ; i < m ; i++)
93  {
94  n = A.GetRealRowSize(i);
95  for (int j = 0; j < n; j++)
96  value(j) = alpha*T1(A.ValueReal(i, j), 0);
97 
98  B.AddInteractionRow(i, n, A.GetRealInd(i), value.GetData());
99 
100  n = A.GetImagRowSize(i);
101  for (int j = 0; j < n; j++)
102  value(j) = alpha*T1(0, A.ValueImag(i, j));
103 
104  B.AddInteractionRow(i, n, A.GetImagInd(i), value.GetData());
105  }
106  }
107 
108 
110  template<class T0, class T1, class Allocator1,
111  class T2, class Allocator2>
112  void AddMatrix(const T0& alpha, const Matrix<T1, General,
113  ArrayRowComplexSparse, Allocator1>& A,
115  {
116  int m = B.GetM(), n;
117  Vector<T2, VectFull, Allocator2> value(B.GetN());
118  for (int i = 0; i < m; i++)
119  {
120  n = A.GetRealRowSize(i);
121  for (int j = 0; j < n; j++)
122  value(j) = alpha*T1(A.ValueReal(i, j), 0);
123 
124  B.AddInteractionRow(i, n, A.GetRealInd(i), value.GetData());
125 
126  n = A.GetImagRowSize(i);
127  for (int j = 0; j < n; j++)
128  value(j) = alpha*T1(0, A.ValueImag(i, j));
129 
130  B.AddInteractionRow(i, n, A.GetImagInd(i), value.GetData());
131  }
132  }
133 
134 
136  template<class T0, class T1, class Allocator1,
137  class T2, class Allocator2>
138  void AddMatrix(const T0& alpha, const Matrix<T1, General,
139  ArrayRowComplexSparse, Allocator1>& A,
141  {
142  int m = B.GetM(), n, ni;
143  Vector<T2> value(2*B.GetN()); IVect index(2*B.GetN());
144  for (int i = 0 ; i < m ; i++)
145  {
146  n = A.GetRealRowSize(i);
147  ni = A.GetImagRowSize(i);
148  for (int j = 0; j < n; j++)
149  {
150  value(j) = alpha*T2(A.ValueReal(i, j), 0);
151  index(j) = A.IndexReal(i, j);
152  }
153 
154  for (int j = 0; j < ni; j++)
155  {
156  value(n+j) = alpha*T2(0, A.ValueImag(i, j));
157  index(n+j) = A.IndexImag(i, j);
158  }
159 
160  B.AddInteractionRow(i, n+ni, index, value);
161  }
162  }
163 
164 
166  template<class T0, class T1, class Prop1, class Allocator1,
167  class T2, class Prop2, class Allocator2,
168  class T3, class Prop3, class Allocator3>
169  void AddMatrix(const T0& alpha,
173  {
174  int m = B.GetM(), n, ni;
175  Vector<T3> value(2*B.GetN()); IVect index(2*B.GetN());
176  for (int i = 0 ; i < m ; i++)
177  {
178  n = A.GetRowSize(i);
179  ni = B.GetRowSize(i);
180  for (int j = 0; j < n; j++)
181  {
182  value(j) = alpha*T3(A.Value(i, j), 0);
183  index(j) = A.Index(i, j);
184  }
185 
186  for (int j = 0; j < ni; j++)
187  {
188  value(n+j) = alpha*T3(0, B.Value(i, j));
189  index(n+j) = B.Index(i, j);
190  }
191 
192  C.AddInteractionRow(i, n+ni, index, value);
193  }
194  }
195 
196 
198  template<class T0, class T1, class Prop1, class Allocator1,
199  class T2, class Prop2, class Allocator2,
200  class T3, class Prop3, class Allocator3>
201  void AddMatrix(const T0& alpha,
205  {
206  int m = B.GetM(), n, ni;
207  Vector<T3> value(2*B.GetN());
208  IVect index(2*B.GetN());
209  for (int i = 0 ; i < m ; i++)
210  {
211  n = A.GetRowSize(i);
212  ni = B.GetRowSize(i);
213  for (int j = 0; j < n; j++)
214  {
215  value(j) = alpha*T3(A.Value(i, j), 0);
216  index(j) = A.Index(i, j);
217  }
218 
219  for (int j = 0; j < ni; j++)
220  {
221  value(n+j) = alpha*T3(0, B.Value(i, j));
222  index(n+j) = B.Index(i, j);
223  }
224 
225  C.AddInteractionRow(i, n+ni, index, value);
226  }
227  }
228 
229 
230  template<class T, class Allocator>
231  void Add_csr_ptr(const T& alpha, long* ptr_A, int* ind_A, T* data_A,
232  long* ptr_B, int* ind_B, T* data_B, int m,
233  Vector<long>& Ptr,
234  Vector<int>& Ind,
235  Vector<T, VectFull, Allocator>& Val)
236  {
237  int i = 0;
238  long j = 0;
239  long k;
240 
241  // A and B might have the same structure
242  // Loop over all non-zeros. If the structures of A and B differ at any
243  // time, the loop is broken and a different strategy is undertaken.
244  for (i = 0; i < m; i++)
245  if (ptr_A[i + 1] == ptr_B[i + 1])
246  {
247  for (j = ptr_A[i]; j < ptr_A[i + 1]; j++)
248  if (ind_A[j] == ind_B[j])
249  data_B[j] += alpha * data_A[j];
250  else
251  break;
252  if (j != ptr_A[i + 1])
253  break;
254  }
255  else
256  break;
257 
258  // Success: A and B have the same structure.
259  if (i == m)
260  return;
261 
262  // The addition is performed row by row in the following lines. Thus the
263  // additions already performed in the current line, if started, should be
264  // canceled.
265  for (k = ptr_A[i]; k < j; k++)
266  if (ind_A[k] == ind_B[k])
267  data_B[k] -= alpha * data_A[k];
268 
269  // Number of non zero entries currently found.
270  long Nnonzero = ptr_A[i];
271 
272  // counting the number of non-zero entries
273  long kb, jb(0), ka, ja(0);
274  for (int i2 = i; i2 < m; i2++)
275  {
276  kb = ptr_B[i2];
277 
278  for (ka = ptr_A[i2]; ka < ptr_A[i2 + 1]; ka++)
279  {
280  ja = ind_A[ka];
281  while (kb < ptr_B[i2 + 1] && ind_B[kb] < ja)
282  {
283  kb++;
284  Nnonzero++;
285  }
286 
287  if (kb < ptr_B[i2 + 1] && ja == ind_B[kb])
288  kb++;
289 
290  Nnonzero++;
291  }
292 
293  while (kb < ptr_B[i2 + 1])
294  {
295  kb++;
296  Nnonzero++;
297  }
298  }
299 
300  // A and B do not have the same structure. An intermediate matrix will be
301  // needed. The first i rows have already been added. These computations
302  // are preserved in arrays Ptr, Ind Val.
303  Ptr.Reallocate(m+1); Ind.Reallocate(Nnonzero);
304  Val.Reallocate(Nnonzero);
305  for (int i2 = 0; i2 <= i; i2++)
306  Ptr(i2) = ptr_B[i2];
307 
308  for (j = 0; j < ptr_B[i]; j++)
309  {
310  Ind(j) = ind_B[j];
311  Val(j) = data_B[j];
312  }
313 
314  // Now deals with the remaining lines.
315  Nnonzero = ptr_A[i];
316  for (; i < m; i++)
317  {
318  kb = ptr_B[i];
319  if (kb < ptr_B[i + 1])
320  jb = ind_B[kb];
321  for (ka = ptr_A[i]; ka < ptr_A[i + 1]; ka++)
322  {
323  ja = ind_A[ka];
324  while (kb < ptr_B[i + 1] && jb < ja)
325  // For all elements in B that are before the ka-th element of A.
326  {
327  Ind(Nnonzero) = jb;
328  Val(Nnonzero) = data_B[kb];
329  kb++;
330  if (kb < ptr_B[i + 1])
331  jb = ind_B[kb];
332  Nnonzero++;
333  }
334 
335  if (kb < ptr_B[i + 1] && ja == jb)
336  // The element in A is also in B.
337  {
338  Ind(Nnonzero) = jb;
339  Val(Nnonzero) = data_B[kb] + alpha * data_A[ka];
340  kb++;
341  if (kb < ptr_B[i + 1])
342  jb = ind_B[kb];
343  }
344  else
345  {
346  Ind(Nnonzero) = ja;
347  Val(Nnonzero) = alpha * data_A[ka];
348  }
349  Nnonzero++;
350  }
351 
352  // The remaining elements from B.
353  while (kb < ptr_B[i + 1])
354  {
355  Ind(Nnonzero) = jb;
356  Val(Nnonzero) = data_B[kb];
357  kb++;
358  if (kb < ptr_B[i + 1])
359  jb = ind_B[kb];
360  Nnonzero++;
361  }
362 
363  Ptr(i + 1) = Nnonzero;
364  }
365  }
366 
367 
369  template<class T0, class T1, class Allocator1,
370  class T2, class Allocator2>
371  void AddMatrix(const T0& alpha,
374  {
375  Vector<int> IndReal, IndImag;
376  Vector<long> PtrReal, PtrImag;
377 
379  VectFull, Allocator2> DataReal, DataImag;
380 
381  Add_csr_ptr(alpha, A.GetRealPtr(), A.GetRealInd(), A.GetRealData(),
382  B.GetRealPtr(), B.GetRealInd(), B.GetRealData(), B.GetM(),
383  PtrReal, IndReal, DataReal);
384 
385  Add_csr_ptr(alpha, A.GetImagPtr(), A.GetImagInd(), A.GetImagData(),
386  B.GetImagPtr(), B.GetImagInd(), B.GetImagData(), B.GetM(),
387  PtrImag, IndImag, DataImag);
388 
389  B.SetData(B.GetM(), B.GetN(), DataReal, PtrReal, IndReal,
390  DataImag, PtrImag, IndImag);
391  }
392 
393 
395  template<class T0, class T1, class Allocator1,
396  class T2, class Allocator2>
397  void AddMatrix(const T0& alpha,
400  {
401  Vector<int> IndReal, IndImag;
402  Vector<long> PtrReal, PtrImag;
403 
405  VectFull, Allocator2> DataReal, DataImag;
406 
407  Add_csr_ptr(alpha, A.GetRealPtr(), A.GetRealInd(), A.GetRealData(),
408  B.GetRealPtr(), B.GetRealInd(), B.GetRealData(), B.GetM(),
409  PtrReal, IndReal, DataReal);
410 
411  Add_csr_ptr(alpha, A.GetImagPtr(), A.GetImagInd(), A.GetImagData(),
412  B.GetImagPtr(), B.GetImagInd(), B.GetImagData(), B.GetM(),
413  PtrImag, IndImag, DataImag);
414 
415  B.SetData(B.GetM(), B.GetN(), DataReal, PtrReal, IndReal,
416  DataImag, PtrImag, IndImag);
417  }
418 
419 
421  template<class T0, class T1, class Allocator1,
422  class T2, class Allocator2>
423  void AddMatrix(const complex<T0>& alpha,
426  {
427  if (imag(alpha) != T0(0))
428  throw Undefined("Add(Matrix<RowSymComplexSparse>)",
429  "Function not implemented for complex scalars");
430 
431  Vector<int> IndReal, IndImag;
432  Vector<long> PtrReal, PtrImag;
433 
435  VectFull, Allocator2> DataReal, DataImag;
436 
437  Add_csr_ptr(real(alpha), A.GetRealPtr(), A.GetRealInd(), A.GetRealData(),
438  B.GetRealPtr(), B.GetRealInd(), B.GetRealData(), B.GetM(),
439  PtrReal, IndReal, DataReal);
440 
441  Add_csr_ptr(real(alpha), A.GetImagPtr(), A.GetImagInd(), A.GetImagData(),
442  B.GetImagPtr(), B.GetImagInd(), B.GetImagData(), B.GetM(),
443  PtrImag, IndImag, DataImag);
444 
445  B.SetData(B.GetM(), B.GetN(), DataReal, PtrReal, IndReal,
446  DataImag, PtrImag, IndImag);
447  }
448 
449 
451  template<class T0, class T1, class Allocator1,
452  class T2, class Allocator2>
453  void AddMatrix(const complex<T0>& alpha,
456  {
457  if (imag(alpha) != T0(0))
458  throw Undefined("Add(Matrix<RowComplexSparse>)",
459  "Function not implemented for complex scalars");
460 
461  Vector<int> IndReal, IndImag;
462  Vector<long> PtrReal, PtrImag;
463 
465  VectFull, Allocator2> DataReal, DataImag;
466 
467  Add_csr_ptr(real(alpha), A.GetRealPtr(), A.GetRealInd(), A.GetRealData(),
468  B.GetRealPtr(), B.GetRealInd(), B.GetRealData(), B.GetM(),
469  PtrReal, IndReal, DataReal);
470 
471  Add_csr_ptr(real(alpha), A.GetImagPtr(), A.GetImagInd(), A.GetImagData(),
472  B.GetImagPtr(), B.GetImagInd(), B.GetImagData(), B.GetM(),
473  PtrImag, IndImag, DataImag);
474 
475  B.SetData(B.GetM(), B.GetN(), DataReal, PtrReal, IndReal,
476  DataImag, PtrImag, IndImag);
477  }
478 
479 
481  template<class T0, class T, class Prop, class Allocator>
482  void MltScalar(const T0& alpha,
484  {
485  for (int i = 0; i < A.GetM(); i++)
486  {
487  for (int j = 0; j < A.GetRealRowSize(i); j++)
488  A.ValueReal(i, j) *= alpha;
489 
490  for (int j = 0; j < A.GetImagRowSize(i); j++)
491  A.ValueImag(i, j) *= alpha;
492 
493  }
494  }
495 
496 
498  template<class T0, class T, class Prop, class Allocator>
499  void MltScalar(const complex<T0>& alpha,
501  {
502  if (imag(alpha) != T0(0))
503  throw Undefined("Mlt(Matrix<ArrayRowComplexSparse>)",
504  "Function not implemented for complex scalars");
505 
506  for (int i = 0; i < A.GetM(); i++)
507  {
508  for (int j = 0; j < A.GetRealRowSize(i); j++)
509  A.ValueReal(i, j) *= real(alpha);
510 
511  for (int j = 0; j < A.GetImagRowSize(i); j++)
512  A.ValueImag(i, j) *= real(alpha);
513  }
514  }
515 
516 
518  template<class T0, class T, class Prop, class Allocator>
519  void MltScalar(const T0& alpha,
521  {
522  for (int i = 0; i < A.GetM(); i++)
523  {
524  for (int j = 0; j < A.GetRealRowSize(i); j++)
525  A.ValueReal(i,j) *= alpha;
526 
527  for (int j = 0; j < A.GetImagRowSize(i); j++)
528  A.ValueImag(i,j) *= alpha;
529  }
530  }
531 
532 
534  template<class T0, class T, class Prop, class Allocator>
535  void MltScalar(const complex<T0>& alpha,
537  {
538  if (imag(alpha) != T0(0))
539  throw Undefined("Mlt(Matrix<ArrayRowComplexSparse>)",
540  "Function not implemented for complex scalars");
541 
542  for (int i = 0; i < A.GetM(); i++)
543  {
544  for (int j = 0; j < A.GetRealRowSize(i); j++)
545  A.ValueReal(i,j) *= real(alpha);
546 
547  for (int j = 0; j < A.GetImagRowSize(i); j++)
548  A.ValueImag(i,j) *= real(alpha);
549  }
550  }
551 
552 
554  template<class T0, class T, class Prop, class Allocator>
555  void MltScalar(const T0& alpha,
557  {
558  typename ClassComplexType<T>::Treal* data_A = A.GetRealData();
559  for (long i = 0; i < A.GetRealDataSize(); i++)
560  data_A[i] *= alpha;
561 
562  data_A = A.GetImagData();
563  for (long i = 0; i < A.GetImagDataSize(); i++)
564  data_A[i] *= alpha;
565  }
566 
567 
569  template<class T0, class T, class Prop, class Allocator>
570  void MltScalar(const complex<T0>& alpha,
572  {
573  if (imag(alpha) != T0(0))
574  throw Undefined("Mlt(Matrix<RowComplexSparse>)",
575  "Function not implemented for complex scalars");
576 
577  typename ClassComplexType<T>::Treal* data_A = A.GetRealData();
578  T0 alpha_r = real(alpha);
579  for (long i = 0; i < A.GetRealDataSize(); i++)
580  data_A[i] *= alpha_r;
581 
582  data_A = A.GetImagData();
583  for (long i = 0; i < A.GetImagDataSize(); i++)
584  data_A[i] *= alpha_r;
585  }
586 
587 
589  template<class T0, class T, class Prop, class Allocator>
590  void MltScalar(const T0& alpha,
592  {
593  typename ClassComplexType<T>::Treal* data_A = A.GetRealData();
594  for (long i = 0; i < A.GetRealDataSize(); i++)
595  data_A[i] *= alpha;
596 
597  data_A = A.GetImagData();
598  for (long i = 0; i < A.GetImagDataSize(); i++)
599  data_A[i] *= alpha;
600  }
601 
602 
604  template<class T0, class T, class Prop, class Allocator>
605  void MltScalar(const complex<T0>& alpha,
607  {
608  if (imag(alpha) != T0(0))
609  throw Undefined("Mlt(Matrix<RowSymComplexSparse>)",
610  "Function not implemented for complex scalars");
611 
612  typename ClassComplexType<T>::Treal* data_A = A.GetRealData();
613  T0 alpha_r = real(alpha);
614  for (long i = 0; i < A.GetRealDataSize(); i++)
615  data_A[i] *= alpha_r;
616 
617  data_A = A.GetImagData();
618  for (long i = 0; i < A.GetImagDataSize(); i++)
619  data_A[i] *= alpha_r;
620  }
621 
622 
624 
628  template<class T, class Prop, class Allocator>
629  void ApplyInversePermutation(Matrix<T, Prop,
630  ArrayRowComplexSparse, Allocator>& A,
631  const IVect& row_perm, const IVect& col_perm)
632  {
633  int m = A.GetM();
634  IVect ind_tmp, iperm(m), rperm(m);
635  for (int i = 0; i < m; i++)
636  {
637  iperm(i) = i;
638  rperm(i) = i;
639  }
640 
641  // A(rperm(i),:) will be the place where is the initial row i.
642 
643  // Algorithm avoiding the allocation of another matrix.
644  for (int i = 0; i < m; i++)
645  {
646  // We get the index of row where the row initially placed on row i is.
647  int i2 = rperm(i);
648  // We get the new index of this row.
649  int i_ = row_perm(i);
650 
651  // We fill ind_tmp of the permuted indices of columns of row i.
652  int nr = A.GetRealRowSize(i2);
653  ind_tmp.Reallocate(nr);
654  for (int j = 0; j < nr; j++)
655  ind_tmp(j) = col_perm(A.IndexReal(i2, j));
656 
657  // We swap the two rows i and its destination row_perm(i).
658  A.SwapRealRow(i2, i_);
659  A.ReplaceRealIndexRow(i_, ind_tmp);
660 
661  int ni = A.GetImagRowSize(i2);
662  ind_tmp.Reallocate(ni);
663  for (int j = 0; j < ni; j++)
664  ind_tmp(j) = col_perm(A.IndexImag(i2, j));
665 
666  A.SwapImagRow(i2, i_);
667  A.ReplaceImagIndexRow(i_, ind_tmp);
668 
669  // We update the indices iperm and rperm in order to keep in memory
670  // the place where the row row_perm(i) is.
671  int i_tmp = iperm(i_);
672  iperm(i_) = iperm(i2);
673  iperm(i2) = i_tmp;
674  rperm(iperm(i_)) = i_;
675  rperm(iperm(i2)) = i2;
676 
677  // We assemble the row i.
678  A.AssembleRealRow(i_);
679  A.AssembleImagRow(i_);
680  }
681  }
682 
683 
685 
689  template<class T, class Prop, class Allocator>
690  void ApplyInversePermutation(Matrix<T, Prop,
691  ArrayRowSymComplexSparse, Allocator>& A,
692  const IVect& row_perm, const IVect& col_perm)
693  {
694  // It is assumed that the permuted matrix is still symmetric! For example,
695  // the user can provide row_perm = col_perm.
696  int m = A.GetM();
697  long nnz_real = A.GetRealDataSize(), nnz_imag = A.GetImagDataSize();
698  IVect IndRow(nnz_real), IndCol(nnz_real);
700  VectFull, Allocator> Val(nnz_real);
701 
702  // First we convert the matrix in coordinate format and we permute the
703  // indices.
704  // IndRow -> indices of the permuted rows
705  // IndCol -> indices of the permuted columns
706  long k = 0;
707  for (int i = 0; i < m; i++)
708  {
709  for (int j = 0; j < A.GetRealRowSize(i); j++)
710  {
711  IndRow(k) = row_perm(i);
712  Val(k) = A.ValueReal(i,j);
713  IndCol(k) = col_perm(A.IndexReal(i, j));
714  if (IndCol(k) <= IndRow(k))
715  {
716  // We store only the superior part of the symmetric matrix.
717  int ind_tmp = IndRow(k);
718  IndRow(k) = IndCol(k);
719  IndCol(k) = ind_tmp;
720  }
721  k++;
722  }
723  }
724 
725  // We sort by row number.
726  Sort(nnz_real, IndRow, IndCol, Val);
727 
728  // A is filled.
729  k = 0;
730  for (int i = 0; i < m; i++)
731  {
732  long first_index = k;
733  // We get the size of the row i.
734  while (k < nnz_real && IndRow(k) <= i)
735  k++;
736 
737  int size_row = k - first_index;
738  // If row not empty.
739  if (size_row > 0)
740  {
741  A.ReallocateRealRow(i, size_row);
742  k = first_index;
743  Sort(k, k+size_row-1, IndCol, Val);
744  for (int j = 0; j < size_row; j++)
745  {
746  A.IndexReal(i,j) = IndCol(k);
747  A.ValueReal(i,j) = Val(k);
748  k++;
749  }
750  }
751  else
752  A.ClearRealRow(i);
753  }
754 
755  // Same procedure for imaginary part.
756 
757  IndRow.Reallocate(nnz_imag);
758  IndCol.Reallocate(nnz_imag);
759  Val.Reallocate(nnz_imag);
760 
761  // First we convert the matrix in coordinate format and we permute the
762  // indices.
763  // IndRow -> indices of the permuted rows
764  // IndCol -> indices of the permuted columns
765  k = 0;
766  for (int i = 0; i < m; i++)
767  {
768  for (int j = 0; j < A.GetImagRowSize(i); j++)
769  {
770  IndRow(k) = row_perm(i);
771  Val(k) = A.ValueImag(i,j);
772  IndCol(k) = col_perm(A.IndexImag(i,j));
773  if (IndCol(k) <= IndRow(k))
774  {
775  // We store only the superior part of the symmetric matrix.
776  int ind_tmp = IndRow(k);
777  IndRow(k) = IndCol(k);
778  IndCol(k) = ind_tmp;
779  }
780  k++;
781  }
782  }
783  // We sort by row number.
784  Sort(nnz_imag, IndRow, IndCol, Val);
785 
786  // A is filled
787  k = 0;
788  for (int i = 0; i < m; i++)
789  {
790  long first_index = k;
791  // We get the size of the row i.
792  while (k < nnz_imag && IndRow(k) <= i)
793  k++;
794  int size_row = k - first_index;
795  // If row not empty.
796  if (size_row > 0)
797  {
798  A.ReallocateImagRow(i, size_row);
799  k = first_index;
800  Sort(k, k+size_row-1, IndCol, Val);
801  for (int j = 0; j < size_row; j++)
802  {
803  A.IndexImag(i,j) = IndCol(k);
804  A.ValueImag(i,j) = Val(k);
805  k++;
806  }
807  }
808  else
809  A.ClearImagRow(i);
810  }
811  }
812 
813 
815 
819  template<class T, class Prop, class Allocator>
821  const Vector<int>& row_perm,
822  const Vector<int>& col_perm)
823  {
824  Vector<int> inv_row_perm(row_perm.GetM());
825  Vector<int> inv_col_perm(col_perm.GetM());
826  for (int i = 0; i < row_perm.GetM(); i++)
827  inv_row_perm(row_perm(i)) = i;
828 
829  for (int i = 0; i < col_perm.GetM(); i++)
830  inv_col_perm(col_perm(i)) = i;
831 
832  ApplyInversePermutation(A, inv_row_perm, inv_col_perm);
833  }
834 
835 
837 
841  template<class T, class Prop, class Allocator> void
843  const Vector<int>& row_perm,
844  const Vector<int>& col_perm)
845  {
846  Vector<int> inv_row_perm(row_perm.GetM());
847  for (int i = 0; i < row_perm.GetM(); i++)
848  inv_row_perm(row_perm(i)) = i;
849 
850  ApplyInversePermutation(A, inv_row_perm, inv_row_perm);
851  }
852 
853 
855 
858  template<class Prop, class T1, class Allocator1,
859  class T2, class Allocator2, class T3, class Allocator3>
860  void ScaleMatrix(Matrix<T1, Prop,
861  ArrayRowSymComplexSparse, Allocator1>& A,
862  const Vector<T2, VectFull, Allocator2>& scale_left,
863  const Vector<T3, VectFull, Allocator3>& scale_right)
864  {
865  int m = A.GetM();
866  for (int i = 0; i < m; i++ )
867  {
868  for (int j = 0; j < A.GetRealRowSize(i); j++ )
869  A.ValueReal(i,j) *= scale_left(i) * scale_right(A.IndexReal(i, j));
870 
871  for (int j = 0; j < A.GetImagRowSize(i); j++ )
872  A.ValueImag(i,j) *= scale_left(i) * scale_right(A.IndexImag(i, j));
873  }
874  }
875 
876 
878 
881  template<class Prop, class T1, class Allocator1,
882  class T2, class Allocator2, class T3, class Allocator3>
884  const Vector<T2, VectFull, Allocator2>& scale_left,
885  const Vector<T3, VectFull, Allocator3>& scale_right)
886  {
887  int m = A.GetM();
888  for (int i = 0; i < m; i++ )
889  {
890  for (int j = 0; j < A.GetRealRowSize(i); j++ )
891  A.ValueReal(i,j) *= scale_left(i) * scale_right(A.IndexReal(i, j));
892 
893  for (int j = 0; j < A.GetImagRowSize(i); j++ )
894  A.ValueImag(i,j) *= scale_left(i) * scale_right(A.IndexImag(i, j));
895  }
896  }
897 
898 
900 
903  template<class T1, class Allocator1,
904  class Prop, class T2, class Allocator2>
907  {
908  int m = A.GetM();
909  for (int i = 0; i < m; i++ )
910  {
911  for (int j = 0; j < A.GetRealRowSize(i); j++ )
912  A.ValueReal(i,j) *= scale(i);
913 
914  for (int j = 0; j < A.GetImagRowSize(i); j++ )
915  A.ValueImag(i,j) *= scale(i);
916  }
917  }
918 
919 
921 
924  template<class T1, class Allocator1,
925  class Prop, class T2, class Allocator2>
926  void ScaleRightMatrix(Matrix<T1, Prop,
927  ArrayRowComplexSparse, Allocator1>& A,
929  {
930  int m = A.GetM();
931  for (int i = 0; i < m; i++ )
932  {
933  for (int j = 0; j < A.GetRealRowSize(i); j++ )
934  A.ValueReal(i,j) *= scale(A.IndexReal(i, j));
935 
936  for (int j = 0; j < A.GetImagRowSize(i); j++ )
937  A.ValueImag(i,j) *= scale(A.IndexImag(i, j));
938  }
939  }
940 
941 
943 
946  template<class Prop, class T1, class Allocator1,
947  class T2, class Allocator2, class T3, class Allocator3>
949  const Vector<T2, VectFull, Allocator2>& scale_left,
950  const Vector<T3, VectFull, Allocator3>& scale_right)
951  {
952  int m = A.GetM();
953  long* ptr_real = A.GetRealPtr();
954  int* ind_real = A.GetRealInd();
955  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
956  long* ptr_imag = A.GetImagPtr();
957  int* ind_imag = A.GetImagInd();
958  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
959  for (int i = 0; i < m; i++ )
960  {
961  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
962  data_real[j] *= scale_left(i) * scale_right(ind_real[j]);
963 
964  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
965  data_imag[j] *= scale_left(i) * scale_right(ind_imag[j]);
966  }
967  }
968 
969 
971 
974  template<class Prop, class T1, class Allocator1,
975  class T2, class Allocator2, class T3, class Allocator3>
977  const Vector<T2, VectFull, Allocator2>& scale_left,
978  const Vector<T3, VectFull, Allocator3>& scale_right)
979  {
980  int m = A.GetM();
981  long* ptr_real = A.GetRealPtr();
982  int* ind_real = A.GetRealInd();
983  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
984  long* ptr_imag = A.GetImagPtr();
985  int* ind_imag = A.GetImagInd();
986  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
987  for (int i = 0; i < m; i++ )
988  {
989  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++ )
990  data_real[j] *= scale_left(i) * scale_right(ind_real[j]);
991 
992  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++ )
993  data_imag[j] *= scale_left(i) * scale_right(ind_imag[j]);
994  }
995  }
996 
997 
999 
1002  template<class T1, class Allocator1,
1003  class Prop, class T2, class Allocator2>
1005  const Vector<T2, VectFull, Allocator2>& scale)
1006  {
1007  int m = A.GetM();
1008  long* ptr_real = A.GetRealPtr();
1009  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
1010  long* ptr_imag = A.GetImagPtr();
1011  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
1012  for (int i = 0; i < m; i++ )
1013  {
1014  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++ )
1015  data_real[j] *= scale(i);
1016 
1017  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++ )
1018  data_imag[j] *= scale(i);
1019  }
1020  }
1021 
1022 
1024 
1027  template<class T1, class Allocator1,
1028  class Prop, class T2, class Allocator2>
1030  const Vector<T2, VectFull, Allocator2>& scale)
1031  {
1032  int m = A.GetM();
1033  long* ptr_real = A.GetRealPtr();
1034  int* ind_real = A.GetRealInd();
1035  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
1036  long* ptr_imag = A.GetImagPtr();
1037  int* ind_imag = A.GetImagInd();
1038  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
1039  for (int i = 0; i < m; i++ )
1040  {
1041  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++ )
1042  data_real[j] *= scale(ind_real[j]);
1043 
1044  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++ )
1045  data_imag[j] *= scale(ind_imag[j]);
1046  }
1047  }
1048 
1049 
1051  template<class T, class Allocator>
1052  void Transpose(const Matrix<T, General,
1053  ArrayRowComplexSparse, Allocator>& A,
1055  {
1056  B.Clear();
1057 
1058  int m = A.GetM();
1059  int n = A.GetN();
1060  Vector<int> ptr_r(n), ptr_i(n);
1061 
1062  B.Reallocate(n, m);
1063 
1064  // For each column j, computes number of its non-zeroes and stores it in
1065  // ptr_T[j].
1066  ptr_r.Zero();
1067  for (int i = 0; i < m; i++)
1068  for (int j = 0; j < A.GetRealRowSize(i); j++)
1069  ptr_r(A.IndexReal(i, j))++;
1070 
1071  ptr_i.Zero();
1072  for (int i = 0; i < m; i++)
1073  for (int j = 0; j < A.GetImagRowSize(i); j++)
1074  ptr_i(A.IndexImag(i, j))++;
1075 
1076  for (int i = 0; i < n; i++)
1077  {
1078  B.ReallocateRealRow(i, ptr_r(i));
1079  B.ReallocateImagRow(i, ptr_i(i));
1080  }
1081 
1082  // filling matrix B
1083  ptr_r.Zero();
1084  ptr_i.Zero();
1085  for (int i = 0; i < m; i++)
1086  {
1087  for (int jp = 0; jp < A.GetRealRowSize(i); jp++)
1088  {
1089  int j = A.IndexReal(i, jp);
1090  int k = ptr_r(j);
1091  ++ptr_r(j);
1092  B.ValueReal(j, k) = A.ValueReal(i, jp);
1093  B.IndexReal(j, k) = i;
1094  }
1095 
1096  for (int jp = 0; jp < A.GetImagRowSize(i); jp++)
1097  {
1098  int j = A.IndexImag(i, jp);
1099  int k = ptr_i(j);
1100  ++ptr_i(j);
1101  B.ValueImag(j, k) = A.ValueImag(i, jp);
1102  B.IndexImag(j, k) = i;
1103  }
1104  }
1105 
1106  // sorting numbers
1107  B.Assemble();
1108  }
1109 
1110 
1112  template<class T, class Allocator>
1115  {
1116  B.Clear();
1117 
1118  int m = A.GetM();
1119  int n = A.GetN();
1120  long* ptr_real = A.GetRealPtr();
1121  int* ind_real = A.GetRealInd();
1122  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1123  long* ptr_imag = A.GetImagPtr();
1124  int* ind_imag = A.GetImagInd();
1125  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1126  Vector<int> ptr_r(n), ptr_i(n);
1127 
1128  // For each column j, computes number of its non-zeroes and stores it in
1129  // ptr_T[j].
1130  ptr_r.Zero();
1131  for (int i = 0; i < m; i++)
1132  for (int j = ptr_real[i]; j < ptr_real[i+1]; j++)
1133  ptr_r(ind_real[j])++;
1134 
1135  ptr_i.Zero();
1136  for (int i = 0; i < m; i++)
1137  for (int j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
1138  ptr_i(ind_imag[j])++;
1139 
1140  typedef typename ClassComplexType<T>::Treal Treal;
1141  Vector<Treal, VectFull, Allocator> ValReal(A.GetRealDataSize());
1142  Vector<Treal, VectFull, Allocator> ValImag(A.GetImagDataSize());
1143  Vector<long> PtrReal(n+1), PtrImag(n+1);
1144  Vector<int> IndReal(A.GetRealDataSize()), IndImag(A.GetImagDataSize());
1145 
1146  PtrReal(0) = 0; PtrImag(0) = 0;
1147  for (int i = 0; i < n; i++)
1148  {
1149  PtrReal(i+1) = PtrReal(i) + ptr_r(i);
1150  PtrImag(i+1) = PtrImag(i) + ptr_i(i);
1151  }
1152 
1153  // filling matrix B
1154  ptr_r.Zero();
1155  ptr_i.Zero();
1156  for (int i = 0; i < m; i++)
1157  {
1158  for (long jp = ptr_real[i]; jp < ptr_real[i+1]; jp++)
1159  {
1160  int j = ind_real[jp];
1161  int k = ptr_r(j);
1162  ValReal(PtrReal(j) + k) = data_real[jp];
1163  IndReal(PtrReal(j) + k) = i;
1164  ++ptr_r(j);
1165  }
1166 
1167  for (long jp = ptr_imag[i]; jp < ptr_imag[i+1]; jp++)
1168  {
1169  int j = ind_imag[jp];
1170  int k = ptr_i(j);
1171  ValImag(PtrImag(j) + k) = data_imag[jp];
1172  IndImag(PtrImag(j) + k) = i;
1173  ++ptr_i(j);
1174  }
1175  }
1176 
1177  // sorting numbers
1178  for (int i = 0; i < n; i++)
1179  {
1180  Sort(PtrReal(i), PtrReal(i+1)-1, IndReal, ValReal);
1181  Sort(PtrImag(i), PtrImag(i+1)-1, IndImag, ValImag);
1182  }
1183 
1184  B.SetData(n, m, ValReal, PtrReal, IndReal, ValImag, PtrImag, IndImag);
1185  }
1186 
1187 
1189 
1193  template <class T, class Prop, class Allocator>
1194  typename ClassComplexType<T>::Treal
1196  {
1197  typename ClassComplexType<T>::Treal res(0);
1198  for (int i = 0; i < A.GetM(); i++)
1199  {
1200  int ji = 0;
1201  int size_imag = A.GetImagRowSize(i);
1202  for (int j = 0; j < A.GetRealRowSize(i); j++)
1203  {
1204  int k = A.IndexReal(i, j);
1205  while ( ji < size_imag && A.IndexImag(i, ji) < k)
1206  {
1207  res = max(res, abs(A.ValueImag(i, ji)));
1208  ji++;
1209  }
1210 
1211  if ( ji < size_imag && (A.IndexImag(i, ji) == k))
1212  {
1213  res = max(res, ComplexAbs(T(A.ValueReal(i, j),
1214  A.ValueImag(i, ji))));
1215  ji++;
1216  }
1217  else
1218  res = max(res, abs(A.ValueReal(i, j)));
1219  }
1220 
1221  while (ji < size_imag)
1222  {
1223  res = max(res, abs(A.ValueImag(i, ji)));
1224  ji++;
1225  }
1226  }
1227 
1228  return res;
1229  }
1230 
1231 
1233 
1237  template <class T, class Prop, class Allocator>
1238  typename ClassComplexType<T>::Treal
1240  {
1241  typename ClassComplexType<T>::Treal res(0);
1242  long* ptr_real = A.GetRealPtr();
1243  int* ind_real = A.GetRealInd();
1244  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1245  long* ptr_imag = A.GetImagPtr();
1246  int* ind_imag = A.GetImagInd();
1247  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1248  for (int i = 0; i < A.GetM(); i++)
1249  {
1250  long ji = ptr_imag[i];
1251  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
1252  {
1253  int k = ind_real[j];
1254  while ( ji < ptr_imag[i+1] && ind_imag[ji] < k)
1255  {
1256  res = max(res, abs(data_imag[ji]));
1257  ji++;
1258  }
1259 
1260  if ( ji < ptr_imag[i+1] && (ind_imag[ji] == k))
1261  {
1262  res = max(res, ComplexAbs(T(data_real[j],
1263  data_imag[ji])));
1264  ji++;
1265  }
1266  else
1267  res = max(res, abs(data_real[j]));
1268  }
1269 
1270  while (ji < ptr_imag[i+1])
1271  {
1272  res = max(res, abs(data_imag[ji]));
1273  ji++;
1274  }
1275  }
1276 
1277  return res;
1278  }
1279 
1280 
1282 
1286  template <class T, class Prop, class Allocator>
1287  typename ClassComplexType<T>::Treal
1289  {
1291  sum.Fill(0);
1292  for (int i = 0; i < A.GetM(); i++)
1293  {
1294  int ji = 0;
1295  int size_imag = A.GetImagRowSize(i);
1296  for (int j = 0; j < A.GetRealRowSize(i); j++)
1297  {
1298  int k = A.IndexReal(i, j);
1299  while ( ji < size_imag && A.IndexImag(i, ji) < k)
1300  {
1301  sum(A.IndexImag(i, ji)) += abs(A.ValueImag(i, ji));
1302  ji++;
1303  }
1304 
1305  if ( ji < size_imag && (A.IndexImag(i, ji) == k))
1306  {
1307  sum(k) += ComplexAbs(T(A.ValueReal(i, j),
1308  A.ValueImag(i, ji)));
1309  ji++;
1310  }
1311  else
1312  sum(k) += abs(A.ValueReal(i, j));
1313  }
1314 
1315  while (ji < size_imag)
1316  {
1317  sum(A.IndexImag(i, ji)) += abs(A.ValueImag(i, ji));
1318  ji++;
1319  }
1320  }
1321 
1322  return sum.GetNormInf();
1323  }
1324 
1325 
1327 
1331  template <class T, class Prop, class Allocator>
1332  typename ClassComplexType<T>::Treal
1334  {
1336  long* ptr_real = A.GetRealPtr();
1337  int* ind_real = A.GetRealInd();
1338  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1339  long* ptr_imag = A.GetImagPtr();
1340  int* ind_imag = A.GetImagInd();
1341  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1342  sum.Fill(0);
1343  for (int i = 0; i < A.GetM(); i++)
1344  {
1345  long ji = ptr_imag[i];
1346  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
1347  {
1348  int k = ind_real[j];
1349  while ( ji < ptr_imag[i+1] && ind_imag[ji] < k)
1350  {
1351  sum(ind_imag[ji]) += abs(data_imag[ji]);
1352  ji++;
1353  }
1354 
1355  if ( ji < ptr_imag[i+1] && (ind_imag[ji] == k))
1356  {
1357  sum(k) += ComplexAbs(T(data_real[j],
1358  data_imag[ji]));
1359  ji++;
1360  }
1361  else
1362  sum(k) += abs(data_real[j]);
1363  }
1364 
1365  while (ji < ptr_imag[i+1])
1366  {
1367  sum(ind_imag[ji]) += abs(data_imag[ji]);
1368  ji++;
1369  }
1370  }
1371 
1372  return sum.GetNormInf();
1373  }
1374 
1375 
1377 
1381  template <class T, class Prop, class Allocator>
1382  typename ClassComplexType<T>::Treal
1384  {
1385  typename ClassComplexType<T>::Treal res(0), sum;
1386  for (int i = 0; i < A.GetM(); i++)
1387  {
1388  sum = 0;
1389  int ji = 0;
1390  int size_imag = A.GetImagRowSize(i);
1391  for (int j = 0; j < A.GetRealRowSize(i); j++)
1392  {
1393  int k = A.IndexReal(i, j);
1394  while ( ji < size_imag && A.IndexImag(i, ji) < k)
1395  {
1396  sum += abs(A.ValueImag(i, ji));
1397  ji++;
1398  }
1399 
1400  if ( ji < size_imag && (A.IndexImag(i, ji) == k))
1401  {
1402  sum += ComplexAbs(T(A.ValueReal(i, j),
1403  A.ValueImag(i, ji)));
1404  ji++;
1405  }
1406  else
1407  sum += abs(A.ValueReal(i, j));
1408  }
1409 
1410  while (ji < size_imag)
1411  {
1412  sum += abs(A.ValueImag(i, ji));
1413  ji++;
1414  }
1415 
1416  res = max(res, sum);
1417  }
1418 
1419  return res;
1420  }
1421 
1422 
1424 
1428  template <class T, class Prop, class Allocator>
1429  typename ClassComplexType<T>::Treal
1431  {
1432  typename ClassComplexType<T>::Treal res(0), sum;
1433  long* ptr_real = A.GetRealPtr();
1434  int* ind_real = A.GetRealInd();
1435  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1436  long* ptr_imag = A.GetImagPtr();
1437  int* ind_imag = A.GetImagInd();
1438  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1439  for (int i = 0; i < A.GetM(); i++)
1440  {
1441  sum = 0;
1442  long ji = ptr_imag[i];
1443  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
1444  {
1445  int k = ind_real[j];
1446  while ( ji < ptr_imag[i+1] && ind_imag[ji] < k)
1447  {
1448  sum += abs(data_imag[ji]);
1449  ji++;
1450  }
1451 
1452  if ( ji < ptr_imag[i+1] && (ind_imag[ji] == k))
1453  {
1454  sum += ComplexAbs(T(data_real[j],
1455  data_imag[ji]));
1456  ji++;
1457  }
1458  else
1459  sum += abs(data_real[j]);
1460  }
1461 
1462  while (ji < ptr_imag[i+1])
1463  {
1464  sum += abs(data_imag[ji]);
1465  ji++;
1466  }
1467 
1468  res = max(res, sum);
1469  }
1470 
1471  return res;
1472  }
1473 
1474 
1476 
1480  template <class T, class Prop, class Allocator>
1481  typename ClassComplexType<T>::Treal
1483  {
1484  typename ClassComplexType<T>::Treal res(0);
1485  for (int i = 0; i < A.GetM(); i++)
1486  {
1487  int ji = 0;
1488  int size_imag = A.GetImagRowSize(i);
1489  for (int j = 0; j < A.GetRealRowSize(i); j++)
1490  {
1491  int k = A.IndexReal(i, j);
1492  while ( ji < size_imag && A.IndexImag(i, ji) < k)
1493  {
1494  res = max(res, abs(A.ValueImag(i, ji)));
1495  ji++;
1496  }
1497 
1498  if ( ji < size_imag && (A.IndexImag(i, ji) == k))
1499  {
1500  res = max(res, ComplexAbs(T(A.ValueReal(i, j),
1501  A.ValueImag(i, ji))));
1502  ji++;
1503  }
1504  else
1505  res = max(res, abs(A.ValueReal(i, j)));
1506  }
1507 
1508  while (ji < size_imag)
1509  {
1510  res = max(res, abs(A.ValueImag(i, ji)));
1511  ji++;
1512  }
1513  }
1514 
1515  return res;
1516  }
1517 
1518 
1520 
1524  template <class T, class Prop, class Allocator>
1525  typename ClassComplexType<T>::Treal
1527  {
1528  typename ClassComplexType<T>::Treal res(0);
1529  long* ptr_real = A.GetRealPtr();
1530  int* ind_real = A.GetRealInd();
1531  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1532  long* ptr_imag = A.GetImagPtr();
1533  int* ind_imag = A.GetImagInd();
1534  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1535  for (int i = 0; i < A.GetM(); i++)
1536  {
1537  long ji = ptr_imag[i];
1538  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
1539  {
1540  int k = ind_real[j];
1541  while ( ji < ptr_imag[i+1] && ind_imag[ji] < k)
1542  {
1543  res = max(res, abs(data_imag[ji]));
1544  ji++;
1545  }
1546 
1547  if ( ji < ptr_imag[i+1] && (ind_imag[ji] == k))
1548  {
1549  res = max(res, ComplexAbs(T(data_real[j],
1550  data_imag[ji])));
1551  ji++;
1552  }
1553  else
1554  res = max(res, abs(data_real[j]));
1555  }
1556 
1557  while (ji < ptr_imag[i+1])
1558  {
1559  res = max(res, abs(data_imag[ji]));
1560  ji++;
1561  }
1562  }
1563 
1564  return res;
1565  }
1566 
1567 
1569 
1573  template <class T, class Prop, class Allocator>
1574  typename ClassComplexType<T>::Treal
1576  {
1577  typename ClassComplexType<T>::Treal val;
1579  sum.Fill(0);
1580  for (int i = 0; i < A.GetM(); i++)
1581  {
1582  int ji = 0;
1583  int size_imag = A.GetImagRowSize(i);
1584  for (int j = 0; j < A.GetRealRowSize(i); j++)
1585  {
1586  int k = A.IndexReal(i, j);
1587  while ( ji < size_imag && A.IndexImag(i, ji) < k)
1588  {
1589  val = abs(A.ValueImag(i, ji));
1590  sum(A.IndexImag(i, ji)) += val;
1591  if (A.IndexImag(i, ji) != i)
1592  sum(i) += val;
1593 
1594  ji++;
1595  }
1596 
1597  if ( ji < size_imag && (A.IndexImag(i, ji) == k))
1598  {
1599  val = ComplexAbs(T(A.ValueReal(i, j),
1600  A.ValueImag(i, ji)));
1601  sum(k) += val;
1602  if (k != i)
1603  sum(i) += val;
1604 
1605  ji++;
1606  }
1607  else
1608  {
1609  val = abs(A.ValueReal(i, j));
1610  sum(k) += val;
1611  if (k != i)
1612  sum(i) += val;
1613  }
1614  }
1615 
1616  while (ji < size_imag)
1617  {
1618  val = abs(A.ValueImag(i, ji));
1619  sum(A.IndexImag(i, ji)) += val;
1620  if (A.IndexImag(i, ji) != i)
1621  sum(i) += val;
1622 
1623  ji++;
1624  }
1625  }
1626 
1627  return sum.GetNormInf();
1628  }
1629 
1630 
1632 
1636  template <class T, class Prop, class Allocator>
1637  typename ClassComplexType<T>::Treal
1639  {
1641  long* ptr_real = A.GetRealPtr();
1642  int* ind_real = A.GetRealInd();
1643  typename ClassComplexType<T>::Treal* data_real = A.GetRealData();
1644  long* ptr_imag = A.GetImagPtr();
1645  int* ind_imag = A.GetImagInd();
1646  typename ClassComplexType<T>::Treal* data_imag = A.GetImagData();
1647  sum.Fill(0);
1648  typename ClassComplexType<T>::Treal val;
1649  for (int i = 0; i < A.GetM(); i++)
1650  {
1651  long ji = ptr_imag[i];
1652  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
1653  {
1654  int k = ind_real[j];
1655  while ( ji < ptr_imag[i+1] && ind_imag[ji] < k)
1656  {
1657  val = abs(data_imag[ji]);
1658  sum(ind_imag[ji]) += val;
1659  if (ind_imag[ji] != i)
1660  sum(i) += val;
1661 
1662  ji++;
1663  }
1664 
1665  if ( ji < ptr_imag[i+1] && (ind_imag[ji] == k))
1666  {
1667  val = ComplexAbs(T(data_real[j],
1668  data_imag[ji]));
1669  sum(k) += val;
1670  if (k != i)
1671  sum(i) += val;
1672 
1673  ji++;
1674  }
1675  else
1676  {
1677  val = abs(data_real[j]);
1678  sum(k) += val;
1679  if (k != i)
1680  sum(i) += val;
1681  }
1682  }
1683 
1684  while (ji < ptr_imag[i+1])
1685  {
1686  val = abs(data_imag[ji]);
1687  sum(ind_imag[ji]) += val;
1688  if (ind_imag[ji] != i)
1689  sum(i) += val;
1690 
1691  ji++;
1692  }
1693  }
1694 
1695  return sum.GetNormInf();
1696  }
1697 
1698 
1700 
1704  template <class T, class Prop, class Allocator>
1705  typename ClassComplexType<T>::Treal
1707  {
1708  return Norm1(A);
1709  }
1710 
1711 
1713 
1717  template <class T, class Prop, class Allocator>
1718  typename ClassComplexType<T>::Treal
1720  {
1721  return Norm1(A);
1722  }
1723 
1724 
1726  template<class T, class Prop, class Allocator>
1727  typename ClassComplexType<T>::Treal
1729  {
1730  typename ClassComplexType<T>::Treal res(0);
1731  for (int i = 0; i < A.GetM(); i++)
1732  {
1733  for (int j = 0; j < A.GetRealRowSize(i); j++)
1734  res += A.ValueReal(i, j)*A.ValueReal(i, j);
1735 
1736  for (int j = 0; j < A.GetImagRowSize(i); j++)
1737  res += A.ValueImag(i, j)*A.ValueImag(i, j);
1738  }
1739 
1740  res = sqrt(res);
1741  return res;
1742  }
1743 
1744 
1746  template<class T, class Prop, class Allocator>
1747  typename ClassComplexType<T>::Treal
1749  {
1750  typename ClassComplexType<T>::Treal res(0);
1751  for (int i = 0; i < A.GetM(); i++)
1752  {
1753  for (int j = 0; j < A.GetRealRowSize(i); j++)
1754  {
1755  if (i == A.IndexReal(i, j))
1756  res += A.ValueReal(i, j)*A.ValueReal(i, j);
1757  else
1758  res += 2.0*A.ValueReal(i, j)*A.ValueReal(i, j);
1759  }
1760 
1761  for (int j = 0; j < A.GetImagRowSize(i); j++)
1762  {
1763  if (i == A.IndexImag(i, j))
1764  res += A.ValueImag(i, j)*A.ValueImag(i, j);
1765  else
1766  res += 2.0*A.ValueImag(i, j)*A.ValueImag(i, j);
1767  }
1768  }
1769 
1770  res = sqrt(res);
1771  return res;
1772  }
1773 
1774 
1776  template<class T, class Prop, class Allocator>
1778  {
1779  for (int i = 0; i < A.GetM(); i++)
1780  for (int j = 0; j < A.GetImagRowSize(i); j++)
1781  A.ValueImag(i, j) = -A.ValueImag(i, j);
1782  }
1783 
1784 
1786  template<class T, class Prop, class Allocator>
1788  {
1789  for (int i = 0; i < A.GetM(); i++)
1790  for (int j = 0; j < A.GetImagRowSize(i); j++)
1791  A.ValueImag(i, j) = -A.ValueImag(i, j);
1792  }
1793 
1794 
1796  template<class T, class Prop, class Allocator>
1798  {
1799  typename ClassComplexType<T>::Treal* data = A.GetImagData();
1800  for (long i = 0; i < A.GetImagDataSize(); i++)
1801  data[i] = -data[i];
1802  }
1803 
1804 
1806  template<class T, class Prop, class Allocator>
1808  {
1809  typename ClassComplexType<T>::Treal* data = A.GetImagData();
1810  for (long i = 0; i < A.GetImagDataSize(); i++)
1811  data[i] = -data[i];
1812  }
1813 
1814 
1816  template<class T, class Allocator>
1817  void Transpose(const Matrix<T, Symmetric,
1818  ArrayRowSymComplexSparse, Allocator>& A,
1819  Matrix<T, Symmetric,
1820  ArrayRowSymComplexSparse, Allocator>& B)
1821  {
1822  B = A;
1823  }
1824 
1825 
1827  template<class T, class Allocator>
1829  {
1831  Transpose(B, A);
1832  }
1833 
1834 
1836  template<class T, class Allocator>
1838  {
1839  }
1840 
1841 
1843  template<class T, class Allocator>
1844  void Transpose(const Matrix<T, Symmetric,
1845  RowSymComplexSparse, Allocator>& A,
1846  Matrix<T, Symmetric,
1847  RowSymComplexSparse, Allocator>& B)
1848  {
1849  B = A;
1850  }
1851 
1852 
1854  template<class T, class Allocator>
1856  {
1858  Transpose(B, A);
1859  }
1860 
1861 
1863  template<class T, class Allocator>
1865  {
1866  }
1867 
1868 
1870  template<class T, class Prop, class Allocator, class T0>
1872  const T0& epsilon)
1873  {
1874  // TO BE DONE
1875  }
1876 
1877 
1879  template<class T, class Prop, class Allocator, class T0>
1881  const T0& epsilon)
1882  {
1883  // TO BE DONE
1884  }
1885 
1886 
1888 
1892  template<class T1, class Prop, class Allocator>
1893  void EraseCol(const IVect& col_number,
1895  {
1896  int m = col_number.GetM();
1897  // index array to know fastly if it is a column to erase
1898  IVect index(A.GetM()); index.Fill(-1);
1899  for (int i = 0; i < m; i++)
1900  index(col_number(i)) = i;
1901 
1902  // first, we remove rows
1903  for (int i = 0; i < A.GetM(); i++)
1904  {
1905  if (index(i) != -1)
1906  {
1907  A.ClearRealRow(i);
1908  A.ClearImagRow(i);
1909  }
1910  }
1911 
1912 
1913  // then columns
1914  for (int i = 0; i < A.GetM(); i++)
1915  {
1916  bool something_to_remove = false;
1917  for (int j = 0; j < A.GetRealRowSize(i); j++)
1918  if (index(A.IndexReal(i,j)) != -1)
1919  something_to_remove = true;
1920 
1921  if (something_to_remove)
1922  {
1923  int nb = 0;
1924  for (int j = 0; j < A.GetRealRowSize(i); j++)
1925  if (index(A.IndexReal(i,j)) == -1)
1926  {
1927  A.IndexReal(i, nb) = A.IndexReal(i, j);
1928  A.ValueReal(i, nb) = A.ValueReal(i, j);
1929  nb++;
1930  }
1931 
1932  A.ResizeRealRow(i, nb);
1933  }
1934 
1935  something_to_remove = false;
1936  for (int j = 0; j < A.GetImagRowSize(i); j++)
1937  if (index(A.IndexImag(i,j)) != -1)
1938  something_to_remove = true;
1939 
1940  if (something_to_remove)
1941  {
1942  int nb = 0;
1943  for (int j = 0; j < A.GetImagRowSize(i); j++)
1944  if (index(A.IndexImag(i,j)) == -1)
1945  {
1946  A.IndexImag(i, nb) = A.IndexImag(i, j);
1947  A.ValueImag(i, nb) = A.ValueImag(i, j);
1948  nb++;
1949  }
1950 
1951  A.ResizeImagRow(i, nb);
1952  }
1953  }
1954  }
1955 
1956 
1958 
1962  template<class T1, class Prop, class Allocator>
1963  void EraseCol(const IVect& col_number,
1965  {
1966  int m = col_number.GetM();
1967  // index array to know fastly if it is a column to erase
1968  IVect index(A.GetM()); index.Fill(-1);
1969  for (int i = 0; i < m; i++)
1970  index(col_number(i)) = i;
1971 
1972  for (int i = 0; i < A.GetM(); i++)
1973  {
1974  bool something_to_remove = false;
1975  for (int j = 0; j < A.GetRealRowSize(i); j++)
1976  if (index(A.IndexReal(i,j)) != -1)
1977  something_to_remove = true;
1978 
1979  if (something_to_remove)
1980  {
1981  int nb = 0;
1982  for (int j = 0; j < A.GetRealRowSize(i); j++)
1983  if (index(A.IndexReal(i,j)) == -1)
1984  {
1985  A.IndexReal(i, nb) = A.IndexReal(i, j);
1986  A.ValueReal(i, nb) = A.ValueReal(i, j);
1987  nb++;
1988  }
1989 
1990  A.ResizeRealRow(i, nb);
1991  }
1992 
1993  something_to_remove = false;
1994  for (int j = 0; j < A.GetImagRowSize(i); j++)
1995  if (index(A.IndexImag(i,j)) != -1)
1996  something_to_remove = true;
1997 
1998  if (something_to_remove)
1999  {
2000  int nb = 0;
2001  for (int j = 0; j < A.GetImagRowSize(i); j++)
2002  if (index(A.IndexImag(i,j)) == -1)
2003  {
2004  A.IndexImag(i, nb) = A.IndexImag(i, j);
2005  A.ValueImag(i, nb) = A.ValueImag(i, j);
2006  nb++;
2007  }
2008 
2009  A.ResizeImagRow(i, nb);
2010  }
2011  }
2012  }
2013 
2014 
2016 
2020  template<class T1, class Prop, class Allocator>
2021  void EraseCol(const IVect& col_number,
2023  {
2024  int m = A.GetM(), n = A.GetN();
2025  long nnz_real = A.GetRealIndSize();
2026  long nnz_imag = A.GetImagIndSize();
2027  long* ptr_real = A.GetRealPtr();
2028  int* ind_real = A.GetRealInd();
2029  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
2030  long* ptr_imag = A.GetImagPtr();
2031  int* ind_imag = A.GetImagInd();
2032  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
2033  Vector<bool> ColToKeep(n);
2034  ColToKeep.Fill(true);
2035  for (int i = 0; i < col_number.GetM(); i++)
2036  ColToKeep(col_number(i)) = false;
2037 
2038  for (long i = 0; i < A.GetRealIndSize(); i++)
2039  if (!ColToKeep(ind_real[i]))
2040  nnz_real--;
2041 
2042  for (long i = 0; i < A.GetImagIndSize(); i++)
2043  if (!ColToKeep(ind_imag[i]))
2044  nnz_imag--;
2045 
2046  if ((nnz_real == A.GetRealIndSize()) && (nnz_imag == A.GetImagIndSize()))
2047  return;
2048 
2049  Vector<long> PtrReal(m+1), PtrImag(m+1);
2050  Vector<int> IndReal(m+1), IndImag(nnz_imag);
2052  VectFull, Allocator> ValReal(nnz_real), ValImag(nnz_imag);
2053 
2054  PtrReal(0) = 0; PtrImag(0) = 0;
2055  for (int i = 0; i < m; i++)
2056  {
2057  long jA = PtrReal(i); int size_row = 0;
2058  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2059  if (ColToKeep(ind_real[j]))
2060  {
2061  IndReal(jA) = ind_real[j];
2062  ValReal(jA) = data_real[j];
2063  size_row++; jA++;
2064  }
2065 
2066  PtrReal(i+1) = PtrReal(i) + size_row;
2067 
2068  jA = PtrImag(i); size_row = 0;
2069  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2070  if (ColToKeep(ind_imag[j]))
2071  {
2072  IndImag(jA) = ind_imag[j];
2073  ValImag(jA) = data_imag[j];
2074  size_row++; jA++;
2075  }
2076 
2077  PtrImag(i+1) = PtrImag(i) + size_row;
2078  }
2079 
2080  A.SetData(m, n, ValReal, PtrReal, IndReal, ValImag, PtrImag, IndImag);
2081  }
2082 
2083 
2085 
2089  template<class T1, class Prop, class Allocator>
2090  void EraseCol(const IVect& col_number,
2092  {
2093  int m = A.GetM(), n = A.GetN();
2094  long nnz_real = A.GetRealIndSize();
2095  long* ptr_real = A.GetRealPtr();
2096  int* ind_real = A.GetRealInd();
2097  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
2098  long nnz_imag = A.GetImagIndSize();
2099  long* ptr_imag = A.GetImagPtr();
2100  int* ind_imag = A.GetImagInd();
2101  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
2102  Vector<bool> ColToKeep(n);
2103  ColToKeep.Fill(true);
2104  for (int i = 0; i < col_number.GetM(); i++)
2105  ColToKeep(col_number(i)) = false;
2106 
2107  for (int i = 0; i < m; i++)
2108  {
2109  if (!ColToKeep(i))
2110  {
2111  nnz_real -= ptr_real[i+1] - ptr_real[i];
2112  nnz_imag -= ptr_imag[i+1] - ptr_imag[i];
2113  }
2114  else
2115  {
2116  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2117  if (!ColToKeep(ind_real[j]))
2118  nnz_real--;
2119 
2120  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2121  if (!ColToKeep(ind_imag[j]))
2122  nnz_imag--;
2123  }
2124  }
2125 
2126  if ((nnz_real == A.GetRealIndSize()) && (nnz_imag == A.GetImagIndSize()))
2127  return;
2128 
2129  Vector<long> PtrReal(m+1), PtrImag(m+1);
2130  Vector<int> IndReal(nnz_real), IndImag(nnz_imag);
2132  VectFull, Allocator> ValReal(nnz_real), ValImag(nnz_imag);
2133 
2134  PtrReal(0) = 0; PtrImag(0) = 0;
2135  for (int i = 0; i < m; i++)
2136  {
2137  long jA = PtrReal(i), size_row = 0;
2138  if (ColToKeep(i))
2139  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2140  if (ColToKeep(ind_real[j]))
2141  {
2142  IndReal(jA) = ind_real[j];
2143  ValReal(jA) = data_real[j];
2144  size_row++; jA++;
2145  }
2146 
2147  PtrReal(i+1) = PtrReal(i) + size_row;
2148 
2149  jA = PtrImag(i); size_row = 0;
2150  if (ColToKeep(i))
2151  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2152  if (ColToKeep(ind_imag[j]))
2153  {
2154  IndImag(jA) = ind_imag[j];
2155  ValImag(jA) = data_imag[j];
2156  size_row++; jA++;
2157  }
2158 
2159  PtrImag(i+1) = PtrImag(i) + size_row;
2160  }
2161 
2162  A.SetData(m, n, ValReal, PtrReal, IndReal, ValImag, PtrImag, IndImag);
2163  }
2164 
2165 
2167 
2171  template<class T1, class Prop, class Allocator>
2172  void EraseRow(const IVect& col_number,
2174  {
2175  EraseCol(col_number, A);
2176  }
2177 
2178 
2180 
2184  template<class T1, class Prop, class Allocator>
2185  void EraseRow(const IVect& col_number,
2187  {
2188  for (int i = 0; i < col_number.GetM(); i++)
2189  {
2190  A.ClearRealRow(col_number(i));
2191  A.ClearImagRow(col_number(i));
2192  }
2193  }
2194 
2195 
2197 
2201  template<class T1, class Prop, class Allocator>
2202  void EraseRow(const IVect& col_number,
2204  {
2205  int m = A.GetM(), n = A.GetN();
2206  long nnz_real = A.GetRealIndSize();
2207  long* ptr_real = A.GetRealPtr();
2208  int* ind_real = A.GetRealInd();
2209  typename ClassComplexType<T1>::Treal* data_real = A.GetRealData();
2210  long nnz_imag = A.GetImagIndSize();
2211  long* ptr_imag = A.GetImagPtr();
2212  int* ind_imag = A.GetImagInd();
2213  typename ClassComplexType<T1>::Treal* data_imag = A.GetImagData();
2214  Vector<bool> RowToKeep(m);
2215  RowToKeep.Fill(true);
2216  for (int i = 0; i < col_number.GetM(); i++)
2217  RowToKeep(col_number(i)) = false;
2218 
2219  for (int i = 0; i < m; i++)
2220  if (!RowToKeep(i))
2221  {
2222  nnz_real -= ptr_real[i+1] - ptr_real[i];
2223  nnz_imag -= ptr_imag[i+1] - ptr_imag[i];
2224  }
2225 
2226  Vector<long> PtrReal(m+1), PtrImag(m+1);
2227  Vector<int> IndReal(nnz_real), IndImag(nnz_imag);
2229  VectFull, Allocator> ValReal(nnz_real), ValImag(nnz_imag);
2230 
2231  PtrReal(0) = 0; PtrImag(0) = 0;
2232  for (int i = 0; i < m; i++)
2233  {
2234  if (RowToKeep(i))
2235  {
2236  int size_row = ptr_real[i+1] - ptr_real[i];
2237  for (int j = 0; j < size_row; j++)
2238  {
2239  IndReal(PtrReal(i) + j) = ind_real[ptr_real[i] + j];
2240  ValReal(PtrReal(i) + j) = data_real[ptr_real[i] + j];
2241  }
2242 
2243  PtrReal(i+1) = PtrReal(i) + size_row;
2244 
2245  size_row = ptr_imag[i+1] - ptr_imag[i];
2246  for (int j = 0; j < size_row; j++)
2247  {
2248  IndImag(PtrImag(i) + j) = ind_imag[ptr_imag[i] + j];
2249  ValImag(PtrImag(i) + j) = data_imag[ptr_imag[i] + j];
2250  }
2251 
2252  PtrImag(i+1) = PtrImag(i) + size_row;
2253  }
2254  else
2255  {
2256  PtrReal(i+1) = PtrReal(i);
2257  PtrImag(i+1) = PtrImag(i);
2258  }
2259  }
2260 
2261  A.SetData(m, n, ValReal, PtrReal, IndReal, ValImag, PtrImag, IndImag);
2262  }
2263 
2264 
2266 
2270  template<class T1, class Prop, class Allocator>
2271  void EraseRow(const IVect& col_number,
2273  {
2274  EraseCol(col_number, A);
2275  }
2276 
2277 
2279 
2284  template<class T>
2285  void GetRowSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale_left,
2287  {
2288  int n = mat.GetM();
2289  diagonal_scale_left.Reallocate(n);
2290  diagonal_scale_left.Fill(0);
2291  for (int i = 0; i < n; i++)
2292  {
2293  for (int j = 0; j < mat.GetRealRowSize(i); j++)
2294  {
2295  diagonal_scale_left(i) += abs(mat.ValueReal(i,j));
2296  if (i != mat.IndexReal(i,j))
2297  diagonal_scale_left(mat.IndexReal(i,j))
2298  += abs(mat.ValueReal(i,j));
2299  }
2300 
2301  for (int j = 0; j < mat.GetImagRowSize(i); j++)
2302  {
2303  diagonal_scale_left(i) += abs(mat.ValueImag(i,j));
2304  if (i != mat.IndexImag(i,j))
2305  diagonal_scale_left(mat.IndexImag(i,j))
2306  += abs(mat.ValueImag(i,j));
2307  }
2308  }
2309  }
2310 
2311 
2313 
2318  template<class T>
2319  void GetRowSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale_left,
2321  {
2322  int n = mat.GetM();
2323  diagonal_scale_left.Reallocate(n);
2324  diagonal_scale_left.Fill(0);
2325  for (int i = 0; i < n; i++)
2326  {
2327  for (int j = 0; j < mat.GetRealRowSize(i); j++)
2328  diagonal_scale_left(i) += abs(mat.ValueReal(i,j));
2329 
2330  for (int j = 0; j < mat.GetImagRowSize(i); j++)
2331  diagonal_scale_left(i) += abs(mat.ValueImag(i,j));
2332  }
2333  }
2334 
2335 
2337 
2342  template<class T>
2343  void GetRowSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale_left,
2345  {
2346  int n = mat.GetM();
2347  diagonal_scale_left.Reallocate(n);
2348  diagonal_scale_left.Fill(0);
2349  long* ptr_real = mat.GetRealPtr();
2350  int* ind_real = mat.GetRealInd();
2351  typename ClassComplexType<T>::Treal* data_real = mat.GetRealData();
2352  long* ptr_imag = mat.GetImagPtr();
2353  int* ind_imag = mat.GetImagInd();
2354  typename ClassComplexType<T>::Treal* data_imag = mat.GetImagData();
2355  for (int i = 0; i < n; i++)
2356  {
2357  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2358  {
2359  diagonal_scale_left(i) += abs(data_real[j]);
2360  if (i != ind_real[j])
2361  diagonal_scale_left(ind_real[j]) += abs(data_real[j]);
2362  }
2363 
2364  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2365  {
2366  diagonal_scale_left(i) += abs(data_imag[j]);
2367  if (i != ind_imag[j])
2368  diagonal_scale_left(ind_imag[j]) += abs(data_imag[j]);
2369  }
2370  }
2371  }
2372 
2373 
2375 
2380  template<class T>
2381  void GetRowSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale_left,
2383  {
2384  int n = mat.GetM();
2385  diagonal_scale_left.Reallocate(n);
2386  diagonal_scale_left.Fill(0);
2387  long* ptr_real = mat.GetRealPtr();
2388  typename ClassComplexType<T>::Treal* data_real = mat.GetRealData();
2389  long* ptr_imag = mat.GetImagPtr();
2390  typename ClassComplexType<T>::Treal* data_imag = mat.GetImagData();
2391  for (int i = 0; i < n; i++)
2392  {
2393  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2394  diagonal_scale_left(i) += abs(data_real[j]);
2395 
2396  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2397  diagonal_scale_left(i) += abs(data_imag[j]);
2398  }
2399  }
2400 
2401 
2403 
2408  template<class T>
2409  void GetColSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale,
2411  {
2412  GetRowSum(diagonal_scale, mat);
2413  }
2414 
2415 
2417 
2422  template<class T>
2423  void GetColSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale,
2425  {
2426  int n = mat.GetM();
2427  diagonal_scale.Reallocate(mat.GetN());
2428  diagonal_scale.Fill(0);
2429  for (int i = 0; i < n; i++)
2430  {
2431  for (int j = 0; j < mat.GetRealRowSize(i); j++)
2432  diagonal_scale(mat.IndexReal(i, j)) += abs(mat.ValueReal(i,j));
2433 
2434  for (int j = 0; j < mat.GetImagRowSize(i); j++)
2435  diagonal_scale(mat.IndexImag(i, j)) += abs(mat.ValueImag(i,j));
2436  }
2437  }
2438 
2439 
2441 
2446  template<class T>
2447  void GetColSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale,
2449  {
2450  GetRowSum(diagonal_scale, mat);
2451  }
2452 
2453 
2455 
2460  template<class T>
2461  void GetColSum(Vector<typename ClassComplexType<T>::Treal>& diagonal_scale,
2463  {
2464  int n = mat.GetM();
2465  diagonal_scale.Reallocate(mat.GetN());
2466  diagonal_scale.Fill(0);
2467  long* ptr_real = mat.GetRealPtr();
2468  int* ind_real = mat.GetRealInd();
2469  typename ClassComplexType<T>::Treal* data_real = mat.GetRealData();
2470  long* ptr_imag = mat.GetImagPtr();
2471  int* ind_imag = mat.GetImagInd();
2472  typename ClassComplexType<T>::Treal* data_imag = mat.GetImagData();
2473  for (int i = 0; i < n; i++)
2474  {
2475  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2476  diagonal_scale(ind_real[j]) += abs(data_real[j]);
2477 
2478  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2479  diagonal_scale(ind_imag[j]) += abs(data_imag[j]);
2480  }
2481  }
2482 
2483 
2486 
2493  template<class T>
2494  void GetRowColSum(Vector<typename ClassComplexType<T>::Treal>& sum_row,
2495  Vector<typename ClassComplexType<T>::Treal>& sum_col,
2497  {
2498  GetRowSum(sum_row, mat);
2499  sum_col = sum_row;
2500  }
2501 
2502 
2505 
2512  template<class T>
2513  void GetRowColSum(Vector<typename ClassComplexType<T>::Treal>& sum_row,
2514  Vector<typename ClassComplexType<T>::Treal>& sum_col,
2516  {
2517  int n = mat.GetM();
2518  sum_row.Reallocate(n);
2519  sum_col.Reallocate(mat.GetN());
2520  sum_row.Fill(0);
2521  sum_col.Fill(0);
2522  for (int i = 0; i < n; i++)
2523  {
2524  for (int j = 0; j < mat.GetRealRowSize(i); j++)
2525  {
2526  sum_row(i) += abs(mat.ValueReal(i,j));
2527  sum_col(mat.IndexReal(i, j)) += abs(mat.ValueReal(i,j));
2528  }
2529 
2530  for (int j = 0; j < mat.GetImagRowSize(i); j++)
2531  {
2532  sum_row(i) += abs(mat.ValueImag(i,j));
2533  sum_col(mat.IndexImag(i, j)) += abs(mat.ValueImag(i,j));
2534  }
2535  }
2536  }
2537 
2538 
2541 
2548  template<class T>
2549  void GetRowColSum(Vector<typename ClassComplexType<T>::Treal>& sum_row,
2550  Vector<typename ClassComplexType<T>::Treal>& sum_col,
2552  {
2553  GetRowSum(sum_row, mat);
2554  sum_col = sum_row;
2555  }
2556 
2557 
2560 
2567  template<class T>
2568  void GetRowColSum(Vector<typename ClassComplexType<T>::Treal>& sum_row,
2569  Vector<typename ClassComplexType<T>::Treal>& sum_col,
2571  {
2572  int n = mat.GetM();
2573  sum_row.Reallocate(n);
2574  sum_col.Reallocate(mat.GetN());
2575  sum_row.Fill(0);
2576  sum_col.Fill(0);
2577  long* ptr_real = mat.GetRealPtr();
2578  int* ind_real = mat.GetRealInd();
2579  typename ClassComplexType<T>::Treal* data_real = mat.GetRealData();
2580  long* ptr_imag = mat.GetImagPtr();
2581  int* ind_imag = mat.GetImagInd();
2582  typename ClassComplexType<T>::Treal* data_imag = mat.GetImagData();
2583  for (int i = 0; i < n; i++)
2584  {
2585  for (long j = ptr_real[i]; j < ptr_real[i+1]; j++)
2586  {
2587  sum_row(i) += abs(data_real[j]);
2588  sum_col(ind_real[j]) += abs(data_real[j]);
2589  }
2590 
2591  for (long j = ptr_imag[i]; j < ptr_imag[i+1]; j++)
2592  {
2593  sum_row(i) += abs(data_imag[j]);
2594  sum_col(ind_imag[j]) += abs(data_imag[j]);
2595  }
2596  }
2597  }
2598 
2599 
2601  template<class T0, class Prop0, class Allocator0,
2602  class T1, class Allocator1>
2603  void CopySubMatrix(const Matrix<T0, Prop0,
2604  ArrayRowComplexSparse, Allocator0>& A,
2605  const IVect& row, const IVect& col,
2606  Vector<int>& RowNum,
2607  Vector<int>& ColNum,
2608  Vector<complex<T1>, VectFull, Allocator1>& Value)
2609  {
2610  int m = A.GetM(), n = A.GetN();
2611  if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
2612  {
2613  RowNum.Clear(); ColNum.Clear(); Value.Clear();
2614  return;
2615  }
2616 
2617  Vector<bool> RowKept(m), ColKept(n);
2618  RowKept.Fill(false); ColKept.Fill(false);
2619  for (int i = 0; i < row.GetM(); i++)
2620  RowKept(row(i)) = true;
2621 
2622  for (int i = 0; i < col.GetM(); i++)
2623  ColKept(col(i)) = true;
2624 
2625  // counting the number of non-zero elements to keep
2626  long nnz = 0;
2627  for (int i = 0; i < A.GetM(); i++)
2628  if (RowKept(i))
2629  {
2630  int ji = 0;
2631  int size_imag = A.GetImagRowSize(i);
2632  for (int jr = 0; jr < A.GetRealRowSize(i); jr++)
2633  {
2634  int jcol = A.IndexReal(i, jr);
2635  while ((ji < size_imag) && (A.IndexImag(i, ji) < jcol))
2636  {
2637  if (ColKept(A.IndexImag(i, ji)))
2638  nnz++;
2639 
2640  ji++;
2641  }
2642 
2643  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2644  ji++;
2645 
2646  if (ColKept(jcol))
2647  nnz++;
2648  }
2649 
2650  while (ji < size_imag)
2651  {
2652  if (ColKept(A.IndexImag(i, ji)))
2653  nnz++;
2654 
2655  ji++;
2656  }
2657  }
2658 
2659  RowNum.Reallocate(nnz);
2660  ColNum.Reallocate(nnz);
2661  Value.Reallocate(nnz);
2662  nnz = 0;
2663  // then filling the arrays RowNum, ColNum, Value
2664  for (int i = 0; i < A.GetM(); i++)
2665  if (RowKept(i))
2666  {
2667  int ji = 0;
2668  int size_imag = A.GetImagRowSize(i);
2669  for (int jr = 0; jr < A.GetRealRowSize(i); jr++)
2670  {
2671  int jcol = A.IndexReal(i, jr);
2672  while ((ji < size_imag) && (A.IndexImag(i, ji) < jcol))
2673  {
2674  if (ColKept(A.IndexImag(i, ji)))
2675  {
2676  RowNum(nnz) = i;
2677  ColNum(nnz) = A.IndexImag(i, ji);
2678  Value(nnz) = T0(0, A.ValueImag(i, ji));
2679  nnz++;
2680  }
2681 
2682  ji++;
2683  }
2684 
2685  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2686  {
2687  if (ColKept(jcol))
2688  {
2689  RowNum(nnz) = i;
2690  ColNum(nnz) = jcol;
2691  Value(nnz)
2692  = T0(A.ValueReal(i, jr), A.ValueImag(i, ji));
2693  nnz++;
2694  }
2695 
2696  ji++;
2697  }
2698  else
2699  {
2700  if (ColKept(jcol))
2701  {
2702  RowNum(nnz) = i;
2703  ColNum(nnz) = jcol;
2704  Value(nnz) = T0(A.ValueReal(i, jr), 0);
2705  nnz++;
2706  }
2707  }
2708  }
2709 
2710  while (ji < size_imag)
2711  {
2712  if (ColKept(A.IndexImag(i, ji)))
2713  {
2714  RowNum(nnz) = i;
2715  ColNum(nnz) = A.IndexImag(i, ji);
2716  Value(nnz) = T0(0, A.ValueImag(i, ji));
2717  nnz++;
2718  }
2719 
2720  ji++;
2721  }
2722  }
2723  }
2724 
2725 
2727  template<class T0, class Prop0, class Allocator0,
2728  class T1, class Allocator1>
2729  void CopySubMatrix(const Matrix<T0, Prop0,
2730  ArrayRowSymComplexSparse, Allocator0>& A,
2731  const IVect& row, const IVect& col,
2732  Vector<int>& RowNum,
2733  Vector<int>& ColNum,
2734  Vector<complex<T1>, VectFull, Allocator1>& Value)
2735  {
2736  int m = A.GetM(), n = A.GetN();
2737  if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
2738  {
2739  RowNum.Clear(); ColNum.Clear(); Value.Clear();
2740  return;
2741  }
2742 
2743  Vector<bool> RowKept(m), ColKept(n);
2744  RowKept.Fill(false); ColKept.Fill(false);
2745  for (int i = 0; i < row.GetM(); i++)
2746  RowKept(row(i)) = true;
2747 
2748  for (int i = 0; i < col.GetM(); i++)
2749  ColKept(col(i)) = true;
2750 
2751  // counting the number of non-zero elements to keep
2752  long nnz = 0;
2753  for (int i = 0; i < A.GetM(); i++)
2754  {
2755  int ji = 0;
2756  int size_imag = A.GetImagRowSize(i);
2757  for (int jr = 0; jr < A.GetRealRowSize(i); jr++)
2758  {
2759  int jcol = A.IndexReal(i, jr);
2760  while ((ji < size_imag) && (A.IndexImag(i, ji) < jcol))
2761  {
2762  if (ColKept(A.IndexImag(i, ji)) && RowKept(i))
2763  nnz++;
2764 
2765  if (A.IndexImag(i, ji) != i)
2766  if (RowKept(A.IndexImag(i, ji)) && ColKept(i))
2767  nnz++;
2768 
2769  ji++;
2770  }
2771 
2772  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2773  ji++;
2774 
2775  if (ColKept(jcol) && RowKept(i))
2776  nnz++;
2777 
2778  if (jcol != i)
2779  if (RowKept(jcol) && ColKept(i))
2780  nnz++;
2781  }
2782 
2783  while (ji < size_imag)
2784  {
2785  if (ColKept(A.IndexImag(i, ji)) && RowKept(i))
2786  nnz++;
2787 
2788  if (A.IndexImag(i, ji) != i)
2789  if (RowKept(A.IndexImag(i, ji)) && ColKept(i))
2790  nnz++;
2791 
2792  ji++;
2793  }
2794  }
2795 
2796  RowNum.Reallocate(nnz);
2797  ColNum.Reallocate(nnz);
2798  Value.Reallocate(nnz);
2799  nnz = 0;
2800  for (int i = 0; i < A.GetM(); i++)
2801  {
2802  int ji = 0;
2803  int size_imag = A.GetImagRowSize(i);
2804  for (int jr = 0; jr < A.GetRealRowSize(i); jr++)
2805  {
2806  int jcol = A.IndexReal(i, jr);
2807  while ((ji < size_imag) && (A.IndexImag(i, ji) < jcol))
2808  {
2809  if (ColKept(A.IndexImag(i, ji)) && RowKept(i))
2810  {
2811  RowNum(nnz) = i;
2812  ColNum(nnz) = A.IndexImag(i, ji);
2813  Value(nnz) = T0(0, A.ValueImag(i, ji));
2814  nnz++;
2815  }
2816 
2817  if (A.IndexImag(i, ji) != i)
2818  if (RowKept(A.IndexImag(i, ji)) && ColKept(i))
2819  {
2820  RowNum(nnz) = A.IndexImag(i, ji);
2821  ColNum(nnz) = i;
2822  Value(nnz) = T0(0, A.ValueImag(i, ji));
2823  nnz++;
2824  }
2825 
2826  ji++;
2827  }
2828 
2829  if (ColKept(jcol) && RowKept(i))
2830  {
2831  RowNum(nnz) = i;
2832  ColNum(nnz) = jcol;
2833  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2834  Value(nnz)
2835  = T0(A.ValueReal(i, jr), A.ValueImag(i, ji));
2836  else
2837  Value(nnz) = T0(A.ValueReal(i, jr), 0);
2838 
2839  nnz++;
2840  }
2841 
2842  if (jcol != i)
2843  if (RowKept(jcol) && ColKept(i))
2844  {
2845  RowNum(nnz) = jcol;
2846  ColNum(nnz) = i;
2847  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2848  Value(nnz)
2849  = T0(A.ValueReal(i, jr), A.ValueImag(i, ji));
2850  else
2851  Value(nnz) = T0(A.ValueReal(i, jr), 0);
2852 
2853  nnz++;
2854  }
2855 
2856  if ((ji < size_imag) && (A.IndexImag(i, ji) == jcol))
2857  ji++;
2858  }
2859 
2860  while (ji < size_imag)
2861  {
2862  if (ColKept(A.IndexImag(i, ji)) && RowKept(i))
2863  {
2864  RowNum(nnz) = i;
2865  ColNum(nnz) = A.IndexImag(i, ji);
2866  Value(nnz) = T0(0, A.ValueImag(i, ji));
2867  nnz++;
2868  }
2869 
2870  if (A.IndexImag(i, ji) != i)
2871  if (RowKept(A.IndexImag(i, ji)) && ColKept(i))
2872  {
2873  RowNum(nnz) = A.IndexImag(i, ji);
2874  ColNum(nnz) = i;
2875  Value(nnz) = T0(0, A.ValueImag(i, ji));
2876  nnz++;
2877  }
2878 
2879  ji++;
2880  }
2881  }
2882  }
2883 
2884 
2886  template<class T0, class Prop0, class Allocator0,
2887  class T1, class Allocator1>
2889  const IVect& row, const IVect& col,
2890  Vector<int>& RowNum,
2891  Vector<int>& ColNum,
2892  Vector<complex<T1>, VectFull, Allocator1>& Value)
2893  {
2894  int m = A.GetM(), n = A.GetN();
2895  if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
2896  {
2897  RowNum.Clear(); ColNum.Clear(); Value.Clear();
2898  return;
2899  }
2900 
2901  long* ptr_real = A.GetRealPtr();
2902  int* ind_real = A.GetRealInd();
2903  typename ClassComplexType<T0>::Treal* data_real = A.GetRealData();
2904  long* ptr_imag = A.GetImagPtr();
2905  int* ind_imag = A.GetImagInd();
2906  typename ClassComplexType<T0>::Treal* data_imag = A.GetImagData();
2907 
2908  Vector<bool> RowKept(m), ColKept(n);
2909  RowKept.Fill(false); ColKept.Fill(false);
2910  for (int i = 0; i < row.GetM(); i++)
2911  RowKept(row(i)) = true;
2912 
2913  for (int i = 0; i < col.GetM(); i++)
2914  ColKept(col(i)) = true;
2915 
2916  // counting the number of non-zero elements to keep
2917  long nnz = 0;
2918  for (int i = 0; i < m; i++)
2919  if (RowKept(i))
2920  {
2921  long ji = ptr_imag[i];
2922  for (long jr = ptr_real[i]; jr < ptr_real[i+1]; jr++)
2923  {
2924  int jcol = ind_real[jr];
2925  while ((ji < ptr_imag[i+1]) && (ind_imag[ji] < jcol))
2926  {
2927  if (ColKept(ind_imag[ji]))
2928  nnz++;
2929 
2930  ji++;
2931  }
2932 
2933  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
2934  ji++;
2935 
2936  if (ColKept(jcol))
2937  nnz++;
2938  }
2939 
2940  while (ji < ptr_imag[i+1])
2941  {
2942  if (ColKept(ind_imag[ji]))
2943  nnz++;
2944 
2945  ji++;
2946  }
2947  }
2948 
2949  RowNum.Reallocate(nnz);
2950  ColNum.Reallocate(nnz);
2951  Value.Reallocate(nnz);
2952  nnz = 0;
2953  // then filling the arrays RowNum, ColNum, Value
2954  for (int i = 0; i < A.GetM(); i++)
2955  if (RowKept(i))
2956  {
2957  long ji = ptr_imag[i];
2958  for (long jr = ptr_real[i]; jr < ptr_real[i+1]; jr++)
2959  {
2960  int jcol = ind_real[jr];
2961  while ((ji < ptr_imag[i+1]) && (ind_imag[ji] < jcol))
2962  {
2963  if (ColKept(ind_imag[ji]))
2964  {
2965  RowNum(nnz) = i;
2966  ColNum(nnz) = ind_imag[ji];
2967  Value(nnz) = T0(0, data_imag[ji]);
2968  nnz++;
2969  }
2970 
2971  ji++;
2972  }
2973 
2974  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
2975  {
2976  if (ColKept(jcol))
2977  {
2978  RowNum(nnz) = i;
2979  ColNum(nnz) = jcol;
2980  Value(nnz) = T0(data_real[jr], data_imag[ji]);
2981  nnz++;
2982  }
2983 
2984  ji++;
2985  }
2986  else
2987  {
2988  if (ColKept(jcol))
2989  {
2990  RowNum(nnz) = i;
2991  ColNum(nnz) = jcol;
2992  Value(nnz) = T0(data_real[jr], 0);
2993  nnz++;
2994  }
2995  }
2996  }
2997 
2998  while (ji < ptr_imag[i+1])
2999  {
3000  if (ColKept(ind_imag[ji]))
3001  {
3002  RowNum(nnz) = i;
3003  ColNum(nnz) = ind_imag[ji];
3004  Value(nnz) = T0(0, data_imag[ji]);
3005  nnz++;
3006  }
3007 
3008  ji++;
3009  }
3010  }
3011  }
3012 
3013 
3015  template<class T0, class Prop0, class Allocator0,
3016  class T1, class Allocator1>
3017  void CopySubMatrix(const Matrix<T0, Prop0,
3018  RowSymComplexSparse, Allocator0>& A,
3019  const IVect& row, const IVect& col,
3020  Vector<int>& RowNum,
3021  Vector<int>& ColNum,
3022  Vector<complex<T1>, VectFull, Allocator1>& Value)
3023  {
3024  int m = A.GetM(), n = A.GetN();
3025  if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
3026  {
3027  RowNum.Clear(); ColNum.Clear(); Value.Clear();
3028  return;
3029  }
3030 
3031  long* ptr_real = A.GetRealPtr();
3032  int* ind_real = A.GetRealInd();
3033  typename ClassComplexType<T0>::Treal* data_real = A.GetRealData();
3034  long* ptr_imag = A.GetImagPtr();
3035  int* ind_imag = A.GetImagInd();
3036  typename ClassComplexType<T0>::Treal* data_imag = A.GetImagData();
3037 
3038  Vector<bool> RowKept(m), ColKept(n);
3039  RowKept.Fill(false); ColKept.Fill(false);
3040  for (int i = 0; i < row.GetM(); i++)
3041  RowKept(row(i)) = true;
3042 
3043  for (int i = 0; i < col.GetM(); i++)
3044  ColKept(col(i)) = true;
3045 
3046  // counting the number of non-zero elements to keep
3047  long nnz = 0;
3048  for (int i = 0; i < m; i++)
3049  {
3050  long ji = ptr_imag[i];
3051  for (long jr = ptr_real[i]; jr < ptr_real[i+1]; jr++)
3052  {
3053  int jcol = ind_real[jr];
3054  while ((ji < ptr_imag[i+1]) && (ind_imag[ji] < jcol))
3055  {
3056  if (ColKept(ind_imag[ji]) && RowKept(i))
3057  nnz++;
3058 
3059  if (ind_imag[ji] != i)
3060  if (RowKept(ind_imag[ji]) && ColKept(i))
3061  nnz++;
3062 
3063  ji++;
3064  }
3065 
3066  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
3067  ji++;
3068 
3069  if (ColKept(jcol) && RowKept(i))
3070  nnz++;
3071 
3072  if (jcol != i)
3073  if (RowKept(jcol) && ColKept(i))
3074  nnz++;
3075  }
3076 
3077  while (ji < ptr_imag[i+1])
3078  {
3079  if (ColKept(ind_imag[ji]) && RowKept(i))
3080  nnz++;
3081 
3082  if (ind_imag[ji] != i)
3083  if (RowKept(ind_imag[ji]) && ColKept(i))
3084  nnz++;
3085 
3086  ji++;
3087  }
3088  }
3089 
3090  RowNum.Reallocate(nnz);
3091  ColNum.Reallocate(nnz);
3092  Value.Reallocate(nnz);
3093  nnz = 0;
3094  for (int i = 0; i < m; i++)
3095  {
3096  long ji = ptr_imag[i];
3097  for (long jr = ptr_real[i]; jr < ptr_real[i+1]; jr++)
3098  {
3099  int jcol = ind_real[jr];
3100  while ((ji < ptr_imag[i+1]) && (ind_imag[ji] < jcol))
3101  {
3102  if (ColKept(ind_imag[ji]) && RowKept(i))
3103  {
3104  RowNum(nnz) = i;
3105  ColNum(nnz) = ind_imag[ji];
3106  Value(nnz) = T0(0, data_imag[ji]);
3107  nnz++;
3108  }
3109 
3110  if (ind_imag[ji] != i)
3111  if (RowKept(ind_imag[ji]) && ColKept(i))
3112  {
3113  RowNum(nnz) = ind_imag[ji];
3114  ColNum(nnz) = i;
3115  Value(nnz) = T0(0, data_imag[ji]);
3116  nnz++;
3117  }
3118 
3119  ji++;
3120  }
3121 
3122  if (ColKept(jcol) && RowKept(i))
3123  {
3124  RowNum(nnz) = i;
3125  ColNum(nnz) = jcol;
3126  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
3127  Value(nnz) = T0(data_real[jr], data_imag[ji]);
3128  else
3129  Value(nnz) = T0(data_real[jr], 0);
3130 
3131  nnz++;
3132  }
3133 
3134  if (jcol != i)
3135  if (RowKept(jcol) && ColKept(i))
3136  {
3137  RowNum(nnz) = jcol;
3138  ColNum(nnz) = i;
3139  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
3140  Value(nnz) = T0(data_real[jr], data_imag[ji]);
3141  else
3142  Value(nnz) = T0(data_real[jr], 0);
3143 
3144  nnz++;
3145  }
3146 
3147  if ((ji < ptr_imag[i+1]) && (ind_imag[ji] == jcol))
3148  ji++;
3149  }
3150 
3151  while (ji < ptr_imag[i+1])
3152  {
3153  if (ColKept(ind_imag[ji]) && RowKept(i))
3154  {
3155  RowNum(nnz) = i;
3156  ColNum(nnz) = ind_imag[ji];
3157  Value(nnz) = T0(0, data_imag[ji]);
3158  nnz++;
3159  }
3160 
3161  if (ind_imag[ji] != i)
3162  if (RowKept(ind_imag[ji]) && ColKept(i))
3163  {
3164  RowNum(nnz) = ind_imag[ji];
3165  ColNum(nnz) = i;
3166  Value(nnz) = T0(0, data_imag[ji]);
3167  nnz++;
3168  }
3169 
3170  ji++;
3171  }
3172  }
3173  }
3174 
3175 }
3176 
3177 #define SELDON_FILE_FUNCTIONS_MATRIX_COMPLEX_CXX
3178 #endif
3179 
Seldon::Matrix_ArrayComplexSparse::IndexReal
int IndexReal(int num_row, int i) const
Returns column number of j-th non-zero value of row i (real part).
Definition: Matrix_ArrayComplexSparseInline.cxx:473
Seldon::Matrix_ArrayComplexSparse::IndexImag
int IndexImag(int num_row, int i) const
Returns column number of j-th non-zero value of row i (imaginary part).
Definition: Matrix_ArrayComplexSparseInline.cxx:555
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::Norm1
ClassComplexType< T >::Treal Norm1(const VectorExpression< T, E > &X)
returns 1-norm of an expression with vectors
Definition: Functions_BaseInline.cxx:140
Seldon::Matrix_SymComplexSparse::GetRealInd
int * GetRealInd() const
Returns (row or column) indices of non-zero entries for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:113
Seldon::Matrix_ComplexSparse::GetImagInd
int * GetImagInd() const
Returns (row or column) indices of non-zero entries for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:124
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Matrix_ComplexSparse::GetImagData
value_type * GetImagData() const
Returns the array of values of the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:248
Seldon::Matrix_SymComplexSparse::GetRealPtr
long * GetRealPtr() const
Returns (row or column) start indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:84
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix< T, Prop, ArrayRowComplexSparse, Allocator >::GetRealRowSize
int GetRealRowSize(int i) const
Returns the number of non-zero entries of a row.
Definition: Matrix_ArrayComplexSparseInline.cxx:1225
Seldon::RowSymComplexSparse
Definition: Storage.hxx:436
Seldon::ArrayRowComplexSparse
Definition: Storage.hxx:446
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::Matrix_ComplexSparse::GetImagPtr
long * GetImagPtr() const
Returns (row or column) start indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:93
Seldon::Matrix_ComplexSparse::GetRealDataSize
long GetRealDataSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:205
Seldon::Conjugate
void Conjugate(Matrix< T, Prop, Storage, Allocator > &A)
A is replaced by its conjugate.
Definition: Functions_Matrix.cxx:2915
Seldon::VirtualMatrix::GetN
int GetN() const
Returns the number of columns.
Definition: Matrix_BaseInline.cxx:80
Seldon::VirtualMatrix::GetM
int GetM() const
Returns the number of rows.
Definition: Matrix_BaseInline.cxx:69
Seldon::Undefined
Definition: Errors.hxx:62
Seldon::Matrix_SymComplexSparse::GetImagPtr
long * GetImagPtr() const
Returns (row or column) start indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:97
Seldon::General
Definition: Properties.hxx:26
Seldon::Matrix< T, Prop, ArrayRowComplexSparse, Allocator >::GetImagRowSize
int GetImagRowSize(int i) const
Returns the number of non-zero entries of a row.
Definition: Matrix_ArrayComplexSparseInline.cxx:1238
Seldon::Matrix< T, Prop, ArrayRowSymComplexSparse, Allocator >
Row-major symmetric sparse-matrix class.
Definition: Matrix_ArrayComplexSparse.hxx:492
Seldon::Matrix< T, Prop, ArrayRowComplexSparse, Allocator >
Row-major sparse-matrix class.
Definition: Matrix_ArrayComplexSparse.hxx:380
Seldon::ArrayRowSymComplexSparse
Definition: Storage.hxx:450
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::Transpose
void Transpose(Matrix< T, Prop, Storage, Allocator > &A)
Matrix transposition.
Definition: Functions_Matrix.cxx:2699
Seldon::Matrix_ComplexSparse::GetRealData
value_type * GetRealData() const
Returns the array of values of the real part.
Definition: Matrix_ComplexSparseInline.cxx:236
Seldon::Matrix_ComplexSparse::GetRealPtr
long * GetRealPtr() const
Returns (row or column) start indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:81
Seldon::Matrix_SymComplexSparse::GetImagData
value_type * GetImagData() const
Returns the array of values of the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:258
Seldon::Symmetric
Definition: Properties.hxx:30
Seldon::Matrix< T, Prop, RowComplexSparse, Allocator >
Row-major sparse-matrix class.
Definition: Matrix_ComplexSparse.hxx:319
Seldon::MaxAbs
ClassComplexType< T >::Treal MaxAbs(const Matrix< T, Prop, Storage, Allocator > &A)
Returns the maximum (in absolute value) of a matrix.
Definition: Functions_Matrix.cxx:2386
Seldon::Matrix_SymComplexSparse::GetImagInd
int * GetImagInd() const
Returns (row or column) indices of non-zero entries for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:130
Seldon::Matrix< T, Prop, ArrayRowSymComplexSparse, Allocator >::GetImagRowSize
int GetImagRowSize(int i) const
Returns the number of non-zero entries of a row.
Definition: Matrix_ArrayComplexSparseInline.cxx:2126
Seldon::Matrix_ComplexSparse::GetRealInd
int * GetRealInd() const
Returns (row or column) indices of non-zero entries for the real part.
Definition: Matrix_ComplexSparseInline.cxx:108
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_ComplexSparse::GetImagDataSize
long GetImagDataSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:224
Seldon::Matrix< T, Prop, ArrayRowSymComplexSparse, Allocator >::GetRealRowSize
int GetRealRowSize(int i) const
Returns the number of non-zero entries of a row.
Definition: Matrix_ArrayComplexSparseInline.cxx:2112
Seldon::Matrix_SymComplexSparse::GetRealDataSize
long GetRealDataSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:214
Seldon::AddMatrix
void AddMatrix(const T0 &alpha, const Matrix< T1, Prop1, Storage1, Allocator1 > &A, Matrix< T2, Prop2, Storage2, Allocator2 > &B)
Adds two matrices.
Definition: Functions_Matrix.cxx:1619
Seldon::Matrix_SymComplexSparse::GetRealData
value_type * GetRealData() const
Returns the array of values of the real part.
Definition: Matrix_SymComplexSparseInline.cxx:246
Seldon::Matrix_ArrayComplexSparse::ValueReal
const value_type & ValueReal(int num_row, int i) const
Returns j-th non-zero value of row i (real part).
Definition: Matrix_ArrayComplexSparseInline.cxx:432
Seldon::Matrix< T, Prop, RowSymComplexSparse, Allocator >
Row-major complex sparse-matrix class.
Definition: Matrix_SymComplexSparse.hxx:317
Seldon::ComplexAbs
T ComplexAbs(const T &val)
returns absolute value of val
Definition: CommonInline.cxx:309
Seldon::Matrix_SymComplexSparse::GetImagDataSize
long GetImagDataSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:234
Seldon::Matrix_ArrayComplexSparse::ValueImag
const value_type & ValueImag(int num_row, int i) const
Returns j-th non-zero value of row i (imaginary part).
Definition: Matrix_ArrayComplexSparseInline.cxx:514