00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SELDON_FILE_MATRIX_ARRAY_COMPLEX_SPARSE_CXX
00022
00023 #include "Matrix_ArrayComplexSparse.hxx"
00024
00025 namespace Seldon
00026 {
00027
00028
00029
00030
00031
00032
00033
00035
00038 template <class T, class Prop, class Storage, class Allocator>
00039 inline Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00040 Matrix_ArrayComplexSparse()
00041 : val_real_(), val_imag_()
00042 {
00043 this->m_ = 0;
00044 this->n_ = 0;
00045 }
00046
00047
00049
00054 template <class T, class Prop, class Storage, class Allocator>
00055 inline Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00056 Matrix_ArrayComplexSparse(int i, int j):
00057 val_real_(Storage::GetFirst(i, j)), val_imag_(Storage::GetFirst(i, j))
00058 {
00059 this->m_ = i;
00060 this->n_ = j;
00061 }
00062
00063
00064
00065
00066
00067
00068
00070 template <class T, class Prop, class Storage, class Allocator>
00071 inline Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00072 ~Matrix_ArrayComplexSparse()
00073 {
00074 Clear();
00075 }
00076
00077
00079
00082 template <class T, class Prop, class Storage, class Allocator>
00083 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::Clear()
00084 {
00085 this->m_ = 0;
00086 this->n_ = 0;
00087 val_real_.Clear();
00088 val_imag_.Clear();
00089 }
00090
00091
00092
00093
00094
00095
00096
00098
00104 template <class T, class Prop, class Storage, class Allocator>
00105 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00106 Reallocate(int i, int j)
00107 {
00108
00109 Clear();
00110
00111 this->m_ = i;
00112 this->n_ = j;
00113
00114 int n = Storage::GetFirst(i,j);
00115 val_real_.Reallocate(n);
00116 val_imag_.Reallocate(n);
00117 }
00118
00119
00121
00127 template <class T, class Prop, class Storage, class Allocator>
00128 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00129 Resize(int i, int j)
00130 {
00131 int n = Storage::GetFirst(this->m_, n_);
00132 int new_n = Storage::GetFirst(i, j);
00133 if (n != new_n)
00134 {
00135 Vector<Vector<T, VectSparse, Allocator>, VectFull,
00136 NewAlloc<Vector<T, VectSparse, Allocator> > > new_val_real;
00137
00138 Vector<Vector<T, VectSparse, Allocator>, VectFull,
00139 NewAlloc<Vector<T, VectSparse, Allocator> > > new_val_imag;
00140
00141 new_val_real.Reallocate(new_n);
00142 new_val_imag.Reallocate(new_n);
00143
00144 for (int k = 0 ; k < min(n, new_n) ; k++)
00145 {
00146 Swap(new_val_real(k), this->val_real_(k));
00147 Swap(new_val_imag(k), this->val_imag_(k));
00148 }
00149
00150 val_real_.SetData(new_n, new_val_real.GetData());
00151 val_imag_.SetData(new_n, new_val_imag.GetData());
00152 new_val_real.Nullify();
00153 new_val_imag.Nullify();
00154
00155 }
00156
00157 this->m_ = i;
00158 this->n_ = j;
00159 }
00160
00161
00162
00163
00164
00165
00166
00168
00171 template <class T, class Prop, class Storage, class Allocator>
00172 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00173 ::GetM() const
00174 {
00175 return m_;
00176 }
00177
00178
00180
00183 template <class T, class Prop, class Storage, class Allocator>
00184 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00185 ::GetN() const
00186 {
00187 return n_;
00188 }
00189
00190
00192
00196 template <class T, class Prop, class Storage, class Allocator>
00197 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00198 ::GetM(const SeldonTranspose& status) const
00199 {
00200 if (status.NoTrans())
00201 return m_;
00202 else
00203 return n_;
00204 }
00205
00206
00208
00212 template <class T, class Prop, class Storage, class Allocator>
00213 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00214 ::GetN(const SeldonTranspose& status) const
00215 {
00216 if (status.NoTrans())
00217 return n_;
00218 else
00219 return m_;
00220 }
00221
00222
00224
00227 template <class T, class Prop, class Storage, class Allocator>
00228 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00229 GetRealNonZeros() const
00230 {
00231 int nnz = 0;
00232 for (int i = 0; i < this->val_real_.GetM(); i++)
00233 nnz += this->val_real_(i).GetM();
00234
00235 return nnz;
00236 }
00237
00238
00240
00243 template <class T, class Prop, class Storage, class Allocator>
00244 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00245 GetImagNonZeros() const
00246 {
00247 int nnz = 0;
00248 for (int i = 0; i < this->val_imag_.GetM(); i++)
00249 nnz += this->val_imag_(i).GetM();
00250
00251 return nnz;
00252 }
00253
00254
00256
00261 template <class T, class Prop, class Storage, class Allocator>
00262 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00263 GetRealDataSize() const
00264 {
00265 return GetRealNonZeros();
00266 }
00267
00268
00270
00275 template <class T, class Prop, class Storage, class Allocator>
00276 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00277 GetImagDataSize() const
00278 {
00279 return GetImagNonZeros();
00280 }
00281
00282
00284
00289 template <class T, class Prop, class Storage, class Allocator>
00290 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00291 GetDataSize() const
00292 {
00293 return (GetRealNonZeros()+GetImagNonZeros());
00294 }
00295
00296
00298
00303 template <class T, class Prop, class Storage, class Allocator>
00304 inline int* Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00305 GetRealInd(int i) const
00306 {
00307 return val_real_(i).GetIndex();
00308 }
00309
00310
00312
00316 template <class T, class Prop, class Storage, class Allocator> inline T*
00317 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::GetRealData(int i)
00318 const
00319 {
00320 return val_real_(i).GetData();
00321 }
00322
00323
00325
00330 template <class T, class Prop, class Storage, class Allocator>
00331 inline int* Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00332 GetImagInd(int i) const
00333 {
00334 return val_imag_(i).GetIndex();
00335 }
00336
00337
00339
00343 template <class T, class Prop, class Storage, class Allocator> inline T*
00344 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::GetImagData(int i)
00345 const
00346 {
00347 return val_imag_(i).GetData();
00348 }
00349
00350
00351
00352
00353
00354
00355
00357
00363 template <class T, class Prop, class Storage, class Allocator>
00364 inline complex<T>
00365 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::operator()
00366 (int i, int j) const
00367 {
00368
00369 #ifdef SELDON_CHECK_BOUNDS
00370 if (i < 0 || i >= this->m_)
00371 throw WrongRow("Matrix::operator()", "Index should be in [0, "
00372 + to_str(this->m_-1) + "], but is equal to "
00373 + to_str(i) + ".");
00374
00375 if (j < 0 || j >= this->n_)
00376 throw WrongCol("Matrix::operator()", "Index should be in [0, "
00377 + to_str(this->n_-1) + "], but is equal to "
00378 + to_str(j) + ".");
00379 #endif
00380
00381 return complex<T>(this->val_real_(Storage::GetFirst(i, j))
00382 (Storage::GetSecond(i, j)),
00383 this->val_imag_(Storage::GetFirst(i, j))
00384 (Storage::GetSecond(i, j)) );
00385 }
00386
00387
00389
00395 template <class T, class Prop, class Storage, class Allocator>
00396 inline complex<T>&
00397 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00398 ::Val(int i, int j)
00399 {
00400 throw Undefined("Matrix_ArrayComplexSparse::Val(int i, int j)");
00401 }
00402
00403
00405
00411 template <class T, class Prop, class Storage, class Allocator>
00412 inline const complex<T>&
00413 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00414 ::Val(int i, int j) const
00415 {
00416 throw Undefined("Matrix_ArrayComplexSparse::Val(int i, int j)");
00417 }
00418
00419
00421
00427 template <class T, class Prop, class Storage, class Allocator>
00428 inline complex<T>&
00429 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00430 ::Get(int i, int j)
00431 {
00432 throw Undefined("Matrix_ArrayComplexSparse::Get(int i, int j)");
00433 }
00434
00435
00437
00443 template <class T, class Prop, class Storage, class Allocator>
00444 inline const complex<T>&
00445 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00446 ::Get(int i, int j) const
00447 {
00448 throw Undefined("Matrix_ArrayComplexSparse::Get(int i, int j)");
00449 }
00450
00451
00453
00458 template <class T, class Prop, class Storage, class Allocator>
00459 inline T&
00460 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00461 ::ValReal(int i, int j)
00462 {
00463 return val_real_(Storage::GetFirst(i, j)).Val(Storage::GetSecond(i, j));
00464 }
00465
00466
00468
00473 template <class T, class Prop, class Storage, class Allocator>
00474 inline const T&
00475 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00476 ::ValReal(int i, int j) const
00477 {
00478 return val_real_(Storage::GetFirst(i, j)).Val(Storage::GetSecond(i, j));
00479 }
00480
00481
00483
00488 template <class T, class Prop, class Storage, class Allocator>
00489 inline T&
00490 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00491 ::ValImag(int i, int j)
00492 {
00493 return val_imag_(Storage::GetFirst(i, j)).Val(Storage::GetSecond(i, j));
00494 }
00495
00496
00498
00503 template <class T, class Prop, class Storage, class Allocator>
00504 inline const T&
00505 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00506 ::ValImag(int i, int j) const
00507 {
00508 return val_imag_(Storage::GetFirst(i, j)).Val(Storage::GetSecond(i, j));
00509 }
00510
00511
00513
00518 template <class T, class Prop, class Storage, class Allocator>
00519 inline T&
00520 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00521 ::GetReal(int i, int j)
00522 {
00523 return val_real_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j));
00524 }
00525
00526
00528
00533 template <class T, class Prop, class Storage, class Allocator>
00534 inline const T&
00535 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00536 ::GetReal(int i, int j) const
00537 {
00538 return val_real_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j));
00539 }
00540
00541
00543
00548 template <class T, class Prop, class Storage, class Allocator>
00549 inline T&
00550 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00551 ::GetImag(int i, int j)
00552 {
00553 return val_imag_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j));
00554 }
00555
00556
00558
00563 template <class T, class Prop, class Storage, class Allocator>
00564 inline const T&
00565 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00566 ::GetImag(int i, int j) const
00567 {
00568 return val_imag_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j));
00569 }
00570
00571
00573
00578 template <class T, class Prop, class Storage, class Allocator>
00579 inline void
00580 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00581 ::Set(int i, int j, const complex<T>& x)
00582 {
00583 if (real(x) != T(0))
00584 val_real_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j)) = real(x);
00585 else
00586 {
00587 if (val_real_(Storage::GetFirst(i, j))(Storage::GetSecond(i, j)) != T(0))
00588 val_real_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j)) = T(0);
00589 }
00590
00591 if (imag(x) != T(0))
00592 val_imag_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j)) = imag(x);
00593 else
00594 {
00595 if (val_imag_(Storage::GetFirst(i, j))(Storage::GetSecond(i, j)) != T(0))
00596 val_imag_(Storage::GetFirst(i, j)).Get(Storage::GetSecond(i, j)) = T(0);
00597 }
00598
00599 }
00600
00601
00603
00608 template <class T, class Prop, class Storage, class Allocator>
00609 inline const T& Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00610 ValueReal(int i, int j) const
00611 {
00612
00613 #ifdef SELDON_CHECK_BOUNDS
00614 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00615 throw WrongRow("Matrix_ArraySparse::value", "Index should be in [0, "
00616 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00617 + "], but is equal to " + to_str(i) + ".");
00618
00619 if (j < 0 || j >= this->val_real_(i).GetM())
00620 throw WrongCol("Matrix_ArraySparse::value", "Index should be in [0, " +
00621 to_str(this->val_real_(i).GetM()-1) + "], but is equal to "
00622 + to_str(j) + ".");
00623 #endif
00624
00625 return val_real_(i).Value(j);
00626 }
00627
00628
00630
00635 template <class T, class Prop, class Storage, class Allocator>
00636 inline T&
00637 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00638 ValueReal(int i, int j)
00639 {
00640
00641 #ifdef SELDON_CHECK_BOUNDS
00642 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00643 throw WrongRow("Matrix_ArraySparse::value", "Index should be in [0, "
00644 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00645 + "], but is equal to " + to_str(i) + ".");
00646 if (j < 0 || j >= this->val_real_(i).GetM())
00647 throw WrongCol("Matrix_ArraySparse::value", "Index should be in [0, " +
00648 to_str(this->val_real_(i).GetM()-1) + "], but is equal to "
00649 + to_str(j) + ".");
00650 #endif
00651
00652 return val_real_(i).Value(j);
00653 }
00654
00655
00657
00662 template <class T, class Prop, class Storage, class Allocator>
00663 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00664 IndexReal(int i, int j) const
00665 {
00666
00667 #ifdef SELDON_CHECK_BOUNDS
00668 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00669 throw WrongRow("Matrix_ArraySparse::index", "Index should be in [0, "
00670 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00671 + "], but is equal to " + to_str(i) + ".");
00672
00673 if (j < 0 || j >= this->val_real_(i).GetM())
00674 throw WrongCol("Matrix_ArraySparse::index", "Index should be in [0, " +
00675 to_str(this->val_real_(i).GetM()-1) + "], but is equal to "
00676 + to_str(j) + ".");
00677 #endif
00678
00679 return val_real_(i).Index(j);
00680 }
00681
00682
00684
00689 template <class T, class Prop, class Storage, class Allocator>
00690 inline int& Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00691 IndexReal(int i, int j)
00692 {
00693
00694 #ifdef SELDON_CHECK_BOUNDS
00695 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00696 throw WrongRow("Matrix_ArraySparse::index", "Index should be in [0, "
00697 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00698 + "], but is equal to " + to_str(i) + ".");
00699
00700 if (j < 0 || j >= this->val_real_(i).GetM())
00701 throw WrongCol("Matrix_ArraySparse::index", "Index should be in [0, "
00702 + to_str(this->val_real_(i).GetM()-1)
00703 + "], but is equal to " + to_str(j) + ".");
00704 #endif
00705
00706 return val_real_(i).Index(j);
00707 }
00708
00709
00711
00716 template <class T, class Prop, class Storage, class Allocator>
00717 inline const T& Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00718 ValueImag(int i, int j) const
00719 {
00720
00721 #ifdef SELDON_CHECK_BOUNDS
00722 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00723 throw WrongRow("Matrix_ArraySparse::value", "Index should be in [0, "
00724 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00725 + "], but is equal to " + to_str(i) + ".");
00726
00727 if (j < 0 || j >= this->val_imag_(i).GetM())
00728 throw WrongCol("Matrix_ArraySparse::value", "Index should be in [0, " +
00729 to_str(this->val_imag_(i).GetM()-1) + "], but is equal to "
00730 + to_str(j) + ".");
00731 #endif
00732
00733 return val_imag_(i).Value(j);
00734 }
00735
00736
00738
00743 template <class T, class Prop, class Storage, class Allocator>
00744 inline T& Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00745 ValueImag (int i, int j)
00746 {
00747
00748 #ifdef SELDON_CHECK_BOUNDS
00749 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00750 throw WrongRow("Matrix_ArraySparse::value", "Index should be in [0, "
00751 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00752 + "], but is equal to " + to_str(i) + ".");
00753
00754 if (j < 0 || j >= this->val_imag_(i).GetM())
00755 throw WrongCol("Matrix_ArraySparse::value", "Index should be in [0, " +
00756 to_str(this->val_imag_(i).GetM()-1) + "], but is equal to "
00757 + to_str(j) + ".");
00758 #endif
00759
00760 return val_imag_(i).Value(j);
00761 }
00762
00763
00765
00770 template <class T, class Prop, class Storage, class Allocator>
00771 inline int Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00772 IndexImag(int i, int j) const
00773 {
00774
00775 #ifdef SELDON_CHECK_BOUNDS
00776 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00777 throw WrongRow("Matrix_ArraySparse::index", "Index should be in [0, "
00778 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00779 + "], but is equal to " + to_str(i) + ".");
00780
00781 if (j < 0 || j >= this->val_imag_(i).GetM())
00782 throw WrongCol("Matrix_ArraySparse::index", "Index should be in [0, " +
00783 to_str(this->val_imag_(i).GetM()-1) + "], but is equal to "
00784 + to_str(j) + ".");
00785 #endif
00786
00787 return val_imag_(i).Index(j);
00788 }
00789
00790
00792
00797 template <class T, class Prop, class Storage, class Allocator>
00798 inline int& Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00799 IndexImag(int i, int j)
00800 {
00801
00802 #ifdef SELDON_CHECK_BOUNDS
00803 if (i < 0 || i >= Storage::GetFirst(this->m_, this->n_))
00804 throw WrongRow("Matrix_ArrayComplexSparse::index",
00805 "Index should be in [0, "
00806 + to_str(Storage::GetFirst(this->m_, this->n_)-1)
00807 + "], but is equal to " + to_str(i) + ".");
00808
00809 if (j < 0 || j >= this->val_imag_(i).GetM())
00810 throw WrongCol("Matrix_ArraySparse::index", "Index should be in [0, " +
00811 to_str(this->val_imag_(i).GetM()-1) + "], but is equal to "
00812 + to_str(j) + ".");
00813 #endif
00814
00815 return val_imag_(i).Index(j);
00816 }
00817
00818
00820
00826 template <class T, class Prop, class Storage, class Allocator>
00827 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00828 SetRealData(int i, int n, T* val, int* ind)
00829 {
00830 val_real_(i).SetData(n, val, ind);
00831 }
00832
00833
00835
00841 template <class T, class Prop, class Storage, class Allocator>
00842 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00843 SetImagData(int i, int n, T* val, int* ind)
00844 {
00845 val_imag_(i).SetData(n, val, ind);
00846 }
00847
00848
00850
00854 template <class T, class Prop, class Storage, class Allocator>
00855 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::NullifyReal(int i)
00856 {
00857 val_real_(i).Nullify();
00858 }
00859
00860
00862
00866 template <class T, class Prop, class Storage, class Allocator>
00867 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::NullifyImag(int i)
00868 {
00869 val_imag_(i).Nullify();
00870 }
00871
00872
00874
00879 template <class T, class Prop, class Storage, class Allocator>
00880 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00881 SetRealData(int m, int n, Vector<T, VectSparse, Allocator>* val)
00882 {
00883 m_ = m;
00884 n_ = n;
00885 val_real_.SetData(Storage::GetFirst(m, n), val);
00886 }
00887
00888
00890
00895 template <class T, class Prop, class Storage, class Allocator>
00896 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
00897 SetImagData(int m, int n, Vector<T, VectSparse, Allocator>* val)
00898 {
00899 m_ = m;
00900 n_ = n;
00901 val_imag_.SetData(Storage::GetFirst(m, n), val);
00902 }
00903
00904
00906
00910 template <class T, class Prop, class Storage, class Allocator>
00911 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::NullifyReal()
00912 {
00913 m_ = 0;
00914 n_ = 0;
00915 val_real_.Nullify();
00916 }
00917
00918
00920
00924 template <class T, class Prop, class Storage, class Allocator>
00925 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::NullifyImag()
00926 {
00927 m_ = 0;
00928 n_ = 0;
00929 val_imag_.Nullify();
00930 }
00931
00932
00933
00934
00935
00936
00937
00939
00944 template <class T, class Prop, class Storage, class Allocator>
00945 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::Print() const
00946 {
00947 if (Storage::GetFirst(1, 0) == 1)
00948 for (int i = 0; i < this->m_; i++)
00949 {
00950 for (int j = 0; j < this->val_real_(i).GetM(); j++)
00951 cout << (i+1) << " " << this->val_real_(i).Index(j)+1
00952 << " " << this->val_real_(i).Value(j) << endl;
00953
00954 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
00955 cout << (i+1) << " " << this->val_imag_(i).Index(j)+1
00956 << " (0, " << this->val_imag_(i).Value(j) << ")"<<endl;
00957 }
00958 else
00959 for (int i = 0; i < this->n_; i++)
00960 {
00961 for (int j = 0; j < this->val_real_(i).GetM(); j++)
00962 cout << this->val_real_(i).Index(j)+1 << " " << i+1
00963 << " " << this->val_real_(i).Value(j) << endl;
00964
00965 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
00966 cout << this->val_imag_(i).Index(j)+1 << " " << i+1
00967 << " (0, " << this->val_imag_(i).Value(j) << ")"<<endl;
00968 }
00969 }
00970
00971
00973
00980 template <class T, class Prop, class Storage, class Allocator>
00981 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
00982 ::Write(string FileName) const
00983 {
00984 ofstream FileStream;
00985 FileStream.open(FileName.c_str());
00986
00987 #ifdef SELDON_CHECK_IO
00988
00989 if (!FileStream.is_open())
00990 throw IOError("Matrix_ArrayComplexSparse::Write(string FileName)",
00991 string("Unable to open file \"") + FileName + "\".");
00992 #endif
00993
00994 this->Write(FileStream);
00995
00996 FileStream.close();
00997 }
00998
00999
01001
01008 template <class T, class Prop, class Storage, class Allocator>
01009 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01010 ::Write(ostream& FileStream) const
01011 {
01012
01013 #ifdef SELDON_CHECK_IO
01014
01015 if (!FileStream.good())
01016 throw IOError("Matrix_ArrayComplexSparse::Write(ofstream& FileStream)",
01017 "Stream is not ready.");
01018 #endif
01019
01020 FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->m_)),
01021 sizeof(int));
01022
01023 FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->n_)),
01024 sizeof(int));
01025
01026 for (int i = 0; i < val_real_.GetM(); i++)
01027 {
01028 val_real_(i).Write(FileStream);
01029 val_imag_(i).Write(FileStream);
01030 }
01031 }
01032
01033
01035
01039 template <class T, class Prop, class Storage, class Allocator>
01040 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01041 ::WriteText(string FileName) const
01042 {
01043 ofstream FileStream; FileStream.precision(14);
01044 FileStream.open(FileName.c_str());
01045
01046 #ifdef SELDON_CHECK_IO
01047
01048 if (!FileStream.is_open())
01049 throw IOError("Matrix_ArrayComplexSparse::WriteText(string FileName)",
01050 string("Unable to open file \"") + FileName + "\".");
01051 #endif
01052
01053 this->WriteText(FileStream);
01054
01055 FileStream.close();
01056 }
01057
01058
01060
01064 template <class T, class Prop, class Storage, class Allocator>
01065 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01066 ::WriteText(ostream& FileStream) const
01067 {
01068
01069 #ifdef SELDON_CHECK_IO
01070
01071 if (!FileStream.good())
01072 throw IOError("Matrix_ArrayComplexSparse::"
01073 "WriteText(ofstream& FileStream)",
01074 "Stream is not ready.");
01075 #endif
01076
01077
01078 IVect IndRow, IndCol; Vector<complex<T> > Value;
01079 const Matrix<T, Prop, Storage, Allocator>& leaf_class =
01080 static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this);
01081
01082 ConvertMatrix_to_Coordinates(leaf_class, IndRow, IndCol,
01083 Value, 1, true);
01084
01085 for (int i = 0; i < IndRow.GetM(); i++)
01086 FileStream << IndRow(i) << " " << IndCol(i) << " " << Value(i) << '\n';
01087
01088
01089 int m = Storage::GetFirst(this->m_, this->n_);
01090 int n = Storage::GetSecond(this->m_, this->n_);
01091 bool presence_last_elt = false;
01092 if (m > 0 && n > 0)
01093 {
01094 if (this->val_real_(m-1).GetM() > 0)
01095 {
01096 int p = this->val_real_(m-1).GetM();
01097 if (this->val_real_(m-1).Index(p-1) == n-1)
01098 presence_last_elt = true;
01099 }
01100
01101 if (this->val_imag_(m-1).GetM() > 0)
01102 {
01103 int p = this->val_imag_(m-1).GetM();
01104 if (this->val_imag_(m-1).Index(p-1) == n-1)
01105 presence_last_elt = true;
01106 }
01107
01108 if (!presence_last_elt)
01109 {
01110 complex<T> zero;
01111 SetComplexZero(zero);
01112 FileStream << this->m_ << " " << this->n_ << " " << zero << '\n';
01113 }
01114 }
01115 }
01116
01117
01119
01123 template <class T, class Prop, class Storage, class Allocator>
01124 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01125 ::Read(string FileName)
01126 {
01127 ifstream FileStream;
01128 FileStream.open(FileName.c_str());
01129
01130 #ifdef SELDON_CHECK_IO
01131
01132 if (!FileStream.is_open())
01133 throw IOError("Matrix_ArrayComplexSparse::Read(string FileName)",
01134 string("Unable to open file \"") + FileName + "\".");
01135 #endif
01136
01137 this->Read(FileStream);
01138
01139 FileStream.close();
01140 }
01141
01142
01144
01148 template <class T, class Prop, class Storage, class Allocator>
01149 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01150 ::Read(istream& FileStream)
01151 {
01152
01153 #ifdef SELDON_CHECK_IO
01154
01155 if (!FileStream.good())
01156 throw IOError("Matrix_ArraySparse::Read(ofstream& FileStream)",
01157 "Stream is not ready.");
01158 #endif
01159
01160 FileStream.read(reinterpret_cast<char*>(const_cast<int*>(&this->m_)),
01161 sizeof(int));
01162
01163 FileStream.read(reinterpret_cast<char*>(const_cast<int*>(&this->n_)),
01164 sizeof(int));
01165
01166 val_real_.Reallocate(Storage::GetFirst(this->m_, this->n_));
01167 val_imag_.Reallocate(Storage::GetFirst(this->m_, this->n_));
01168 for (int i = 0; i < val_real_.GetM(); i++)
01169 {
01170 val_real_(i).Read(FileStream);
01171 val_imag_(i).Read(FileStream);
01172 }
01173
01174 #ifdef SELDON_CHECK_IO
01175
01176 if (!FileStream.good())
01177 throw IOError("Matrix_ArraySparse::Read(istream& FileStream)",
01178 string("Input operation failed.")
01179 + string(" The input file may have been removed")
01180 + " or may not contain enough data.");
01181 #endif
01182
01183 }
01184
01185
01187
01191 template <class T, class Prop, class Storage, class Allocator>
01192 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01193 ::ReadText(string FileName)
01194 {
01195 ifstream FileStream;
01196 FileStream.open(FileName.c_str());
01197
01198 #ifdef SELDON_CHECK_IO
01199
01200 if (!FileStream.is_open())
01201 throw IOError("Matrix_ArraySparse::ReadText(string FileName)",
01202 string("Unable to open file \"") + FileName + "\".");
01203 #endif
01204
01205 this->ReadText(FileStream);
01206
01207 FileStream.close();
01208 }
01209
01210
01212
01216 template <class T, class Prop, class Storage, class Allocator>
01217 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>
01218 ::ReadText(istream& FileStream)
01219 {
01220 Matrix<T, Prop, Storage, Allocator>& leaf_class =
01221 static_cast<Matrix<T, Prop, Storage, Allocator>& >(*this);
01222
01223 complex<T> zero; int index = 1;
01224 ReadCoordinateMatrix(leaf_class, FileStream, zero, index);
01225 }
01226
01227
01229
01235 template <class T, class Prop, class Storage, class Allocator>
01236 void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::Assemble()
01237 {
01238 for (int i = 0; i < Storage::GetFirst(this->m_, this->n_); i++)
01239 {
01240 val_real_(i).Assemble();
01241 val_imag_(i).Assemble();
01242 }
01243 }
01244
01245
01247 template <class T, class Prop, class Storage, class Allocator>
01248 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
01249 SetIdentity()
01250 {
01251 this->n_ = this->m_;
01252 for (int i = 0; i < this->m_; i++)
01253 {
01254 val_real_(i).Reallocate(1);
01255 val_real_(i).Index(0) = i;
01256 val_real_(i).Value(0) = T(1);
01257 }
01258 }
01259
01260
01262 template <class T, class Prop, class Storage, class Allocator>
01263 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::Zero()
01264 {
01265 for (int i = 0; i < Storage::GetFirst(this->m_, this->n_); i++)
01266 {
01267 val_real_(i).Zero();
01268 val_imag_(i).Zero();
01269 }
01270 }
01271
01272
01274 template <class T, class Prop, class Storage, class Allocator>
01275 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::Fill()
01276 {
01277 int value = 0;
01278 for (int i = 0; i < Storage::GetFirst(this->m_, this->n_); i++)
01279 {
01280 for (int j = 0; j < val_real_(i).GetM(); j++)
01281 val_real_(i).Value(j) = value++;
01282
01283 for (int j = 0; j < val_imag_(i).GetM(); j++)
01284 val_imag_(i).Value(j) = value++;
01285 }
01286 }
01287
01288
01290
01294 template <class T, class Prop, class Storage, class Allo> template<class T0>
01295 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allo>::
01296 Fill(const complex<T0>& x)
01297 {
01298 for (int i = 0; i < Storage::GetFirst(this->m_, this->n_); i++)
01299 {
01300 val_real_(i).Fill(real(x));
01301 val_imag_(i).Fill(imag(x));
01302 }
01303 }
01304
01305
01307 template <class T, class Prop, class Storage, class Allocator>
01308 template <class T0>
01309 inline Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>&
01310 Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::operator=
01311 (const complex<T0>& x)
01312 {
01313 this->Fill(x);
01314 }
01315
01316
01318 template <class T, class Prop, class Storage, class Allocator>
01319 inline void Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>::
01320 FillRand()
01321 {
01322 for (int i = 0; i < Storage::GetFirst(this->m_, this->n_); i++)
01323 {
01324 val_real_(i).FillRand();
01325 val_imag_(i).FillRand();
01326 }
01327 }
01328
01329
01331
01333
01334
01336
01339 template <class T, class Prop, class Allocator>
01340 inline Matrix<T, Prop, ArrayColComplexSparse, Allocator>::Matrix():
01341 Matrix_ArrayComplexSparse<T, Prop, ArrayColComplexSparse, Allocator>()
01342 {
01343 }
01344
01345
01347
01352 template <class T, class Prop, class Allocator>
01353 inline Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01354 ::Matrix(int i, int j) :
01355 Matrix_ArrayComplexSparse<T, Prop, ArrayColComplexSparse, Allocator>(i, j)
01356 {
01357 }
01358
01359
01361 template <class T, class Prop, class Allocator>
01362 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01363 ::ClearRealColumn(int i)
01364 {
01365 this->val_real_(i).Clear();
01366 }
01367
01368
01370 template <class T, class Prop, class Allocator>
01371 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01372 ::ClearImagColumn(int i)
01373 {
01374 this->val_imag_(i).Clear();
01375 }
01376
01377
01379
01383 template <class T, class Prop, class Alloc> inline
01384 void Matrix<T, Prop, ArrayColComplexSparse, Alloc>
01385 ::ReallocateRealColumn(int i, int j)
01386 {
01387 this->val_real_(i).Reallocate(j);
01388 }
01389
01390
01392
01396 template <class T, class Prop, class Alloc> inline
01397 void Matrix<T, Prop, ArrayColComplexSparse, Alloc>
01398 ::ReallocateImagColumn(int i, int j)
01399 {
01400 this->val_imag_(i).Reallocate(j);
01401 }
01402
01403
01405
01409 template <class T, class Prop, class Allocator> inline
01410 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01411 ::ResizeRealColumn(int i, int j)
01412 {
01413 this->val_real_(i).Resize(j);
01414 }
01415
01416
01418
01422 template <class T, class Prop, class Allocator> inline
01423 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01424 ::ResizeImagColumn(int i, int j)
01425 {
01426 this->val_imag_(i).Resize(j);
01427 }
01428
01429
01431
01435 template <class T, class Prop, class Allocator> inline
01436 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01437 ::SwapRealColumn(int i, int j)
01438 {
01439 Swap(this->val_real_(i), this->val_real_(j));
01440 }
01441
01442
01444
01448 template <class T, class Prop, class Allocator> inline
01449 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01450 ::SwapImagColumn(int i, int j)
01451 {
01452 Swap(this->val_imag_(i), this->val_imag_(j));
01453 }
01454
01455
01457
01461 template <class T, class Prop, class Allocator>
01462 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01463 ReplaceRealIndexColumn(int i, IVect& new_index)
01464 {
01465 for (int j = 0; j < this->val_real_(i).GetM(); j++)
01466 this->val_real_(i).Index(j) = new_index(j);
01467 }
01468
01469
01471
01475 template <class T, class Prop, class Allocator>
01476 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01477 ReplaceImagIndexColumn(int i, IVect& new_index)
01478 {
01479 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
01480 this->val_imag_(i).Index(j) = new_index(j);
01481 }
01482
01483
01485
01489 template <class T, class Prop, class Allocator>
01490 inline int Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01491 GetRealColumnSize(int i) const
01492 {
01493 return this->val_real_(i).GetSize();
01494 }
01495
01496
01498
01502 template <class T, class Prop, class Allocator>
01503 inline int Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01504 GetImagColumnSize(int i) const
01505 {
01506 return this->val_imag_(i).GetSize();
01507 }
01508
01509
01511 template <class T, class Prop, class Allocator> inline
01512 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01513 ::PrintRealColumn(int i) const
01514 {
01515 this->val_real_(i).Print();
01516 }
01517
01518
01520 template <class T, class Prop, class Allocator> inline
01521 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01522 ::PrintImagColumn(int i) const
01523 {
01524 this->val_imag_(i).Print();
01525 }
01526
01527
01529
01534 template <class T, class Prop, class Allocator> inline
01535 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01536 ::AssembleRealColumn(int i)
01537 {
01538 this->val_real_(i).Assemble();
01539 }
01540
01541
01543
01548 template <class T, class Prop, class Allocator> inline
01549 void Matrix<T, Prop, ArrayColComplexSparse, Allocator>
01550 ::AssembleImagColumn(int i)
01551 {
01552 this->val_imag_(i).Assemble();
01553 }
01554
01555
01557
01562 template <class T, class Prop, class Allocator>
01563 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01564 AddInteraction(int i, int j, const complex<T>& val)
01565 {
01566 if (real(val) != T(0))
01567 this->val_real_(j).AddInteraction(i, real(val));
01568
01569 if (imag(val) != T(0))
01570 this->val_imag_(j).AddInteraction(i, imag(val));
01571 }
01572
01573
01575
01581 template <class T, class Prop, class Allocator> template <class Alloc1>
01582 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01583 AddInteractionRow(int i, int nb, const IVect& col,
01584 const Vector<complex<T>, VectFull, Alloc1>& val)
01585 {
01586 for (int j = 0; j < nb; j++)
01587 AddInteraction(i, col(j), val(j));
01588 }
01589
01590
01592
01598 template <class T, class Prop, class Allocator> template <class Alloc1>
01599 inline void Matrix<T, Prop, ArrayColComplexSparse, Allocator>::
01600 AddInteractionColumn(int i, int nb, const IVect& row,
01601 const Vector<complex<T>, VectFull, Alloc1>& val)
01602 {
01603 int nb_real = 0;
01604 int nb_imag = 0;
01605 IVect row_real(nb), row_imag(nb);
01606 Vector<T> val_real(nb), val_imag(nb);
01607 for (int j = 0; j < nb; j++)
01608 {
01609 if (real(val(j)) != T(0))
01610 {
01611 row_real(nb_real) = row(j);
01612 val_real(nb_real) = real(val(j));
01613 nb_real++;
01614 }
01615
01616 if (imag(val(j)) != T(0))
01617 {
01618 row_imag(nb_imag) = row(j);
01619 val_imag(nb_imag) = imag(val(j));
01620 nb_imag++;
01621 }
01622 }
01623
01624 this->val_real_(i).AddInteractionRow(nb_real, row_real, val_real);
01625 this->val_imag_(i).AddInteractionRow(nb_imag, row_imag, val_imag);
01626 }
01627
01628
01630
01632
01633
01635
01638 template <class T, class Prop, class Allocator>
01639 inline Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::Matrix():
01640 Matrix_ArrayComplexSparse<T, Prop, ArrayRowComplexSparse, Allocator>()
01641 {
01642 }
01643
01644
01646
01651 template <class T, class Prop, class Allocator>
01652 inline Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01653 ::Matrix(int i, int j):
01654 Matrix_ArrayComplexSparse<T, Prop, ArrayRowComplexSparse, Allocator>(i, j)
01655 {
01656 }
01657
01658
01660 template <class T, class Prop, class Allocator>
01661 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01662 ::ClearRealRow(int i)
01663 {
01664 this->val_real_(i).Clear();
01665 }
01666
01667
01669 template <class T, class Prop, class Allocator>
01670 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01671 ::ClearImagRow(int i)
01672 {
01673 this->val_imag_(i).Clear();
01674 }
01675
01676
01678
01683 template <class T, class Prop, class Allocator>
01684 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01685 ReallocateRealRow(int i, int j)
01686 {
01687 this->val_real_(i).Reallocate(j);
01688 }
01689
01690
01692
01697 template <class T, class Prop, class Allocator>
01698 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01699 ReallocateImagRow(int i, int j)
01700 {
01701 this->val_imag_(i).Reallocate(j);
01702 }
01703
01704
01706
01711 template <class T, class Prop, class Allocator> inline
01712 void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01713 ::ResizeRealRow(int i, int j)
01714 {
01715 this->val_real_(i).Resize(j);
01716 }
01717
01718
01720
01725 template <class T, class Prop, class Allocator> inline
01726 void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01727 ::ResizeImagRow(int i, int j)
01728 {
01729 this->val_imag_(i).Resize(j);
01730 }
01731
01732
01734
01738 template <class T, class Prop, class Allocator>
01739 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01740 ::SwapRealRow(int i,int j)
01741 {
01742 Swap(this->val_real_(i), this->val_real_(j));
01743 }
01744
01745
01747
01751 template <class T, class Prop, class Allocator>
01752 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01753 ::SwapImagRow(int i, int j)
01754 {
01755 Swap(this->val_imag_(i), this->val_imag_(j));
01756 }
01757
01758
01760
01764 template <class T, class Prop, class Allocator>
01765 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01766 ReplaceRealIndexRow(int i, IVect& new_index)
01767 {
01768 for (int j = 0; j < this->val_real_(i).GetM(); j++)
01769 this->val_real_(i).Index(j) = new_index(j);
01770 }
01771
01772
01774
01778 template <class T, class Prop, class Allocator>
01779 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01780 ReplaceImagIndexRow(int i, IVect& new_index)
01781 {
01782 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
01783 this->val_imag_(i).Index(j) = new_index(j);
01784 }
01785
01786
01788
01792 template <class T, class Prop, class Allocator> inline
01793 int Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01794 ::GetRealRowSize(int i) const
01795 {
01796 return this->val_real_(i).GetSize();
01797 }
01798
01799
01801
01805 template <class T, class Prop, class Allocator> inline
01806 int Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01807 ::GetImagRowSize(int i) const
01808 {
01809 return this->val_imag_(i).GetSize();
01810 }
01811
01812
01814 template <class T, class Prop, class Allocator> inline
01815 void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01816 ::PrintRealRow(int i) const
01817 {
01818 this->val_real_(i).Print();
01819 }
01820
01821
01823 template <class T, class Prop, class Allocator> inline
01824 void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01825 ::PrintImagRow(int i) const
01826 {
01827 this->val_imag_(i).Print();
01828 }
01829
01830
01832
01837 template <class T, class Prop, class Allocator>
01838 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01839 ::AssembleRealRow(int i)
01840 {
01841 this->val_real_(i).Assemble();
01842 }
01843
01844
01846
01851 template <class T, class Prop, class Allocator>
01852 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>
01853 ::AssembleImagRow(int i)
01854 {
01855 this->val_imag_(i).Assemble();
01856 }
01857
01858
01860
01865 template <class T, class Prop, class Allocator>
01866 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01867 AddInteraction(int i, int j, const complex<T>& val)
01868 {
01869 if (real(val) != T(0))
01870 this->val_real_(i).AddInteraction(j, real(val));
01871
01872 if (imag(val) != T(0))
01873 this->val_imag_(i).AddInteraction(j, imag(val));
01874 }
01875
01876
01878
01884 template <class T, class Prop, class Allocator> template <class Alloc1>
01885 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01886 AddInteractionRow(int i, int nb, const IVect& col,
01887 const Vector<complex<T>, VectFull, Alloc1>& val)
01888 {
01889 if (nb <= 0)
01890 return;
01891
01892 int nb_real = 0;
01893 int nb_imag = 0;
01894 IVect col_real(nb), col_imag(nb);
01895 Vector<T> val_real(nb), val_imag(nb);
01896 for (int j = 0; j < nb; j++)
01897 {
01898 if (real(val(j)) != T(0))
01899 {
01900 col_real(nb_real) = col(j);
01901 val_real(nb_real) = real(val(j));
01902 nb_real++;
01903 }
01904
01905 if (imag(val(j)) != T(0))
01906 {
01907 col_imag(nb_imag) = col(j);
01908 val_imag(nb_imag) = imag(val(j));
01909 nb_imag++;
01910 }
01911 }
01912
01913 this->val_real_(i).AddInteractionRow(nb_real, col_real, val_real);
01914 this->val_imag_(i).AddInteractionRow(nb_imag, col_imag, val_imag);
01915 }
01916
01917
01919
01925 template <class T, class Prop, class Allocator> template <class Alloc1>
01926 inline void Matrix<T, Prop, ArrayRowComplexSparse, Allocator>::
01927 AddInteractionColumn(int i, int nb, const IVect& row,
01928 const Vector<complex<T>, VectFull, Alloc1>& val)
01929 {
01930 for (int j = 0; j < nb; j++)
01931 AddInteraction(row(j), i, val(j));
01932 }
01933
01934
01936
01938
01939
01941
01944 template <class T, class Prop, class Allocator>
01945 inline Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::Matrix():
01946 Matrix_ArrayComplexSparse<T, Prop, ArrayColSymComplexSparse, Allocator>()
01947 {
01948 }
01949
01950
01952
01957 template <class T, class Prop, class Allocator>
01958 inline Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::Matrix(int i, int j):
01959 Matrix_ArrayComplexSparse<T, Prop, ArrayColSymComplexSparse, Allocator>(i, j)
01960 {
01961 }
01962
01963
01964
01965
01966
01967
01968
01970
01976 template <class T, class Prop, class Allocator>
01977 inline complex<T>
01978 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::operator() (int i, int j)
01979 const
01980 {
01981 #ifdef SELDON_CHECK_BOUNDS
01982 if (i < 0 || i >= this->m_)
01983 throw WrongRow("Matrix::operator()", "Index should be in [0, "
01984 + to_str(this->m_-1) + "], but is equal to "
01985 + to_str(i) + ".");
01986 if (j < 0 || j >= this->n_)
01987 throw WrongCol("Matrix::operator()", "Index should be in [0, "
01988 + to_str(this->n_-1) + "], but is equal to "
01989 + to_str(j) + ".");
01990 #endif
01991
01992 if (i <= j)
01993 return complex<T>(this->val_real_(j)(i), this->val_imag_(j)(i));
01994
01995 return complex<T>(this->val_real_(i)(j), this->val_imag_(i)(j));
01996 }
01997
01998
02000
02005 template <class T, class Prop, class Allocator>
02006 inline T&
02007 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::ValReal(int i, int j)
02008 {
02009 #ifdef SELDON_CHECK_BOUNDS
02010 if (i < 0 || i >= this->m_)
02011 throw WrongRow("Matrix::ValReal", "Index should be in [0, "
02012 + to_str(this->m_-1) + "], but is equal to "
02013 + to_str(i) + ".");
02014 if (j < 0 || j >= this->n_)
02015 throw WrongCol("Matrix::ValReal", "Index should be in [0, "
02016 + to_str(this->n_-1) + "], but is equal to "
02017 + to_str(j) + ".");
02018 if (i > j)
02019 throw WrongArgument("Matrix::ValReal()",
02020 string("With this function, you ")
02021 + "can only access upper part of matrix.");
02022 #endif
02023
02024 return this->val_real_(j).Val(i);
02025 }
02026
02027
02029
02035 template <class T, class Prop, class Allocator>
02036 inline const T&
02037 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>
02038 ::ValReal(int i, int j) const
02039 {
02040 #ifdef SELDON_CHECK_BOUNDS
02041 if (i < 0 || i >= this->m_)
02042 throw WrongRow("Matrix::ValReal", "Index should be in [0, "
02043 + to_str(this->m_-1) + "], but is equal to "
02044 + to_str(i) + ".");
02045 if (j < 0 || j >= this->n_)
02046 throw WrongCol("Matrix::ValReal", "Index should be in [0, "
02047 + to_str(this->n_-1) + "], but is equal to "
02048 + to_str(j) + ".");
02049 if (i > j)
02050 throw WrongArgument("Matrix::ValReal()",
02051 string("With this function, you ")
02052 + "can only access upper part of matrix.");
02053 #endif
02054
02055 return this->val_real_(j).Val(i);
02056 }
02057
02058
02060
02066 template <class T, class Prop, class Allocator>
02067 inline T&
02068 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::GetReal(int i, int j)
02069 {
02070 #ifdef SELDON_CHECK_BOUNDS
02071 if (i < 0 || i >= this->m_)
02072 throw WrongRow("Matrix::GetReal", "Index should be in [0, "
02073 + to_str(this->m_-1) + "], but is equal to "
02074 + to_str(i) + ".");
02075 if (j < 0 || j >= this->n_)
02076 throw WrongCol("Matrix::GetReal", "Index should be in [0, "
02077 + to_str(this->n_-1) + "], but is equal to "
02078 + to_str(j) + ".");
02079 #endif
02080
02081 if (i <= j)
02082 return this->val_real_(j).Get(i);
02083
02084 return this->val_real_(i).Get(j);
02085 }
02086
02087
02089
02095 template <class T, class Prop, class Allocator>
02096 inline const T&
02097 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>
02098 ::GetReal(int i, int j) const
02099 {
02100 #ifdef SELDON_CHECK_BOUNDS
02101 if (i < 0 || i >= this->m_)
02102 throw WrongRow("Matrix::GetReal", "Index should be in [0, "
02103 + to_str(this->m_-1) + "], but is equal to "
02104 + to_str(i) + ".");
02105 if (j < 0 || j >= this->n_)
02106 throw WrongCol("Matrix::GetReal", "Index should be in [0, "
02107 + to_str(this->n_-1) + "], but is equal to "
02108 + to_str(j) + ".");
02109 #endif
02110
02111 if (i <= j)
02112 return this->val_real_(j).Get(i);
02113
02114 return this->val_real_(i).Get(j);
02115 }
02116
02117
02119
02125 template <class T, class Prop, class Allocator>
02126 inline T&
02127 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::ValImag(int i, int j)
02128 {
02129 #ifdef SELDON_CHECK_BOUNDS
02130 if (i < 0 || i >= this->m_)
02131 throw WrongRow("Matrix::ValImag", "Index should be in [0, "
02132 + to_str(this->m_-1) + "], but is equal to "
02133 + to_str(i) + ".");
02134 if (j < 0 || j >= this->n_)
02135 throw WrongCol("Matrix::ValImag", "Index should be in [0, "
02136 + to_str(this->n_-1) + "], but is equal to "
02137 + to_str(j) + ".");
02138 if (i > j)
02139 throw WrongArgument("Matrix::ValImag()",
02140 string("With this function, you ")
02141 + "can only access upper part of matrix.");
02142 #endif
02143
02144 return this->val_imag_(j).Val(i);
02145 }
02146
02147
02149
02154 template <class T, class Prop, class Allocator>
02155 inline const T&
02156 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>
02157 ::ValImag(int i, int j) const
02158 {
02159 #ifdef SELDON_CHECK_BOUNDS
02160 if (i < 0 || i >= this->m_)
02161 throw WrongRow("Matrix::ValImag", "Index should be in [0, "
02162 + to_str(this->m_-1) + "], but is equal to "
02163 + to_str(i) + ".");
02164 if (j < 0 || j >= this->n_)
02165 throw WrongCol("Matrix::ValImag", "Index should be in [0, "
02166 + to_str(this->n_-1) + "], but is equal to "
02167 + to_str(j) + ".");
02168 if (i > j)
02169 throw WrongArgument("Matrix::ValImag()",
02170 string("With this function, you ")
02171 + "can only access upper part of matrix.");
02172 #endif
02173
02174 return this->val_imag_(j).Val(i);
02175 }
02176
02177
02179
02184 template <class T, class Prop, class Allocator>
02185 inline T&
02186 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::GetImag(int i, int j)
02187 {
02188 #ifdef SELDON_CHECK_BOUNDS
02189 if (i < 0 || i >= this->m_)
02190 throw WrongRow("Matrix::GetImag", "Index should be in [0, "
02191 + to_str(this->m_-1) + "], but is equal to "
02192 + to_str(i) + ".");
02193 if (j < 0 || j >= this->n_)
02194 throw WrongCol("Matrix::GetImag", "Index should be in [0, "
02195 + to_str(this->n_-1) + "], but is equal to "
02196 + to_str(j) + ".");
02197 #endif
02198
02199 if (i <= j)
02200 return this->val_imag_(j).Get(i);
02201
02202 return this->val_imag_(i).Get(j);
02203 }
02204
02205
02207
02212 template <class T, class Prop, class Allocator>
02213 inline const T&
02214 Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>
02215 ::GetImag(int i, int j) const
02216 {
02217 #ifdef SELDON_CHECK_BOUNDS
02218 if (i < 0 || i >= this->m_)
02219 throw WrongRow("Matrix::GetImag", "Index should be in [0, "
02220 + to_str(this->m_-1) + "], but is equal to "
02221 + to_str(i) + ".");
02222 if (j < 0 || j >= this->n_)
02223 throw WrongCol("Matrix::GetImag", "Index should be in [0, "
02224 + to_str(this->n_-1) + "], but is equal to "
02225 + to_str(j) + ".");
02226 #endif
02227
02228 if (i <= j)
02229 return this->val_imag_(j).Val(i);
02230
02231 return this->val_imag_(i).Val(j);
02232 }
02233
02234
02236
02241 template <class T, class Prop, class Allocator>
02242 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>
02243 ::Set(int i, int j, const complex<T>& x)
02244 {
02245 if (i <= j)
02246 {
02247 if (real(x) != T(0))
02248 this->val_real_(j).Get(i) = real(x);
02249 else
02250 {
02251 if (this->val_real_(j)(i) != T(0))
02252 this->val_real_(j).Get(i) = T(0);
02253 }
02254
02255 if (imag(x) != T(0))
02256 this->val_imag_(j).Get(i) = imag(x);
02257 else
02258 {
02259 if (this->val_imag_(j)(i) != T(0))
02260 this->val_imag_(j).Get(i) = T(0);
02261 }
02262 }
02263 else
02264 {
02265 if (real(x) != T(0))
02266 this->val_real_(i).Get(j) = real(x);
02267 else
02268 {
02269 if (this->val_real_(i)(j) != T(0))
02270 this->val_real_(i).Get(j) = T(0);
02271 }
02272
02273 if (imag(x) != T(0))
02274 this->val_imag_(i).Get(j) = imag(x);
02275 else
02276 {
02277 if (this->val_imag_(i)(j) != T(0))
02278 this->val_imag_(i).Get(j) = T(0);
02279 }
02280 }
02281 }
02282
02283
02285 template <class T, class Prop, class Allocator> inline
02286 void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::ClearRealColumn(int i)
02287 {
02288 this->val_real_(i).Clear();
02289 }
02290
02291
02293 template <class T, class Prop, class Allocator> inline
02294 void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::ClearImagColumn(int i)
02295 {
02296 this->val_imag_(i).Clear();
02297 }
02298
02299
02301
02306 template <class T, class Prop, class Allocator>
02307 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02308 ReallocateRealColumn(int i, int j)
02309 {
02310 this->val_real_(i).Reallocate(j);
02311 }
02312
02313
02315
02320 template <class T, class Prop, class Allocator>
02321 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02322 ReallocateImagColumn(int i, int j)
02323 {
02324 this->val_imag_(i).Reallocate(j);
02325 }
02326
02327
02329
02333 template <class T, class Prop, class Allocator>
02334 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02335 ResizeRealColumn(int i, int j)
02336 {
02337 this->val_real_(i).Resize(j);
02338 }
02339
02340
02342
02346 template <class T, class Prop, class Allocator>
02347 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02348 ResizeImagColumn(int i, int j)
02349 {
02350 this->val_imag_(i).Resize(j);
02351 }
02352
02353
02355
02359 template <class T, class Prop, class Allocator>
02360 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02361 SwapRealColumn(int i, int j)
02362 {
02363 Swap(this->val_real_(i), this->val_real_(j));
02364 }
02365
02366
02368
02372 template <class T, class Prop, class Allocator>
02373 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02374 SwapImagColumn(int i, int j)
02375 {
02376 Swap(this->val_imag_(i), this->val_imag_(j));
02377 }
02378
02379
02381
02385 template <class T, class Prop, class Allocator>
02386 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02387 ReplaceRealIndexColumn(int i, IVect& new_index)
02388 {
02389 for (int j = 0; j < this->val_real_(i).GetM(); j++)
02390 this->val_real_(i).Index(j) = new_index(j);
02391 }
02392
02393
02395
02399 template <class T, class Prop, class Allocator>
02400 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02401 ReplaceImagIndexColumn(int i, IVect& new_index)
02402 {
02403 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
02404 this->val_imag_(i).Index(j) = new_index(j);
02405 }
02406
02407
02409
02413 template <class T, class Prop, class Allocator>
02414 inline int Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02415 GetRealColumnSize(int i) const
02416 {
02417 return this->val_real_(i).GetSize();
02418 }
02419
02420
02422
02426 template <class T, class Prop, class Allocator>
02427 inline int Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02428 GetImagColumnSize(int i) const
02429 {
02430 return this->val_imag_(i).GetSize();
02431 }
02432
02433
02435 template <class T, class Prop, class Allocator>
02436 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02437 PrintRealColumn(int i) const
02438 {
02439 this->val_real_(i).Print();
02440 }
02441
02442
02444 template <class T, class Prop, class Allocator>
02445 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02446 PrintImagColumn(int i) const
02447 {
02448 this->val_imag_(i).Print();
02449 }
02450
02451
02453
02458 template <class T, class Prop, class Allocator>
02459 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02460 AssembleRealColumn(int i)
02461 {
02462 this->val_real_(i).Assemble();
02463 }
02464
02465
02467
02472 template <class T, class Prop, class Allocator>
02473 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02474 AssembleImagColumn(int i)
02475 {
02476 this->val_imag_(i).Assemble();
02477 }
02478
02479
02481
02486 template <class T, class Prop, class Allocator>
02487 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02488 AddInteraction(int i, int j, const complex<T>& val)
02489 {
02490 if (i <= j)
02491 {
02492 if (real(val) != T(0))
02493 this->val_real_(j).AddInteraction(i, real(val));
02494
02495 if (imag(val) != T(0))
02496 this->val_imag_(j).AddInteraction(i, imag(val));
02497 }
02498 }
02499
02500
02502
02508 template <class T, class Prop, class Allocator> template <class Alloc1>
02509 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02510 AddInteractionRow(int i, int nb, const IVect& col,
02511 const Vector<complex<T>, VectFull, Alloc1>& val)
02512 {
02513 for (int j = 0; j < nb; j++)
02514 AddInteraction(i, col(j), val(j));
02515 }
02516
02517
02519
02525 template <class T, class Prop, class Allocator> template <class Alloc1>
02526 inline void Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>::
02527 AddInteractionColumn(int i, int nb, const IVect& row,
02528 const Vector<complex<T>, VectFull, Alloc1>& val)
02529 {
02530 int nb_real = 0;
02531 int nb_imag = 0;
02532 IVect row_real(nb), row_imag(nb);
02533 Vector<T> val_real(nb), val_imag(nb);
02534 for (int j = 0; j < nb; j++)
02535 if (row(j) <= i)
02536 {
02537 if (real(val(j)) != T(0))
02538 {
02539 row_real(nb_real) = row(j);
02540 val_real(nb_real) = real(val(j));
02541 nb_real++;
02542 }
02543
02544 if (imag(val(j)) != T(0))
02545 {
02546 row_imag(nb_imag) = row(j);
02547 val_imag(nb_imag) = imag(val(j));
02548 nb_imag++;
02549 }
02550 }
02551
02552 this->val_real_(i).AddInteractionRow(nb_real, row_real, val_real);
02553 this->val_imag_(i).AddInteractionRow(nb_imag, row_imag, val_imag);
02554 }
02555
02556
02558
02560
02561
02563
02566 template <class T, class Prop, class Allocator>
02567 inline Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::Matrix():
02568 Matrix_ArrayComplexSparse<T, Prop, ArrayRowSymComplexSparse, Allocator>()
02569 {
02570 }
02571
02572
02574
02579 template <class T, class Prop, class Allocator>
02580 inline Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02581 ::Matrix(int i, int j):
02582 Matrix_ArrayComplexSparse<T, Prop, ArrayRowSymComplexSparse, Allocator>(i, j)
02583 {
02584 }
02585
02586
02587
02588
02589
02590
02591
02593
02599 template <class T, class Prop, class Allocator>
02600 inline complex<T>
02601 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::operator() (int i, int j)
02602 const
02603 {
02604
02605 #ifdef SELDON_CHECK_BOUNDS
02606 if (i < 0 || i >= this->m_)
02607 throw WrongRow("Matrix_ArraySparse::operator()", "Index should be in [0, "
02608 + to_str(this->m_-1) + "], but is equal to "
02609 + to_str(i) + ".");
02610 if (j < 0 || j >= this->n_)
02611 throw WrongCol("Matrix_ArraySparse::operator()", "Index should be in [0, "
02612 + to_str(this->n_-1) + "], but is equal to "
02613 + to_str(j) + ".");
02614 #endif
02615
02616 if (i <= j)
02617 return complex<T>(this->val_real_(i)(j), this->val_imag_(i)(j));
02618
02619 return complex<T>(this->val_real_(j)(i), this->val_imag_(j)(i));
02620 }
02621
02622
02624
02629 template <class T, class Prop, class Allocator>
02630 inline T&
02631 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::ValReal(int i, int j)
02632 {
02633 #ifdef SELDON_CHECK_BOUNDS
02634 if (i < 0 || i >= this->m_)
02635 throw WrongRow("Matrix::ValReal", "Index should be in [0, "
02636 + to_str(this->m_-1) + "], but is equal to "
02637 + to_str(i) + ".");
02638 if (j < 0 || j >= this->n_)
02639 throw WrongCol("Matrix::ValReal", "Index should be in [0, "
02640 + to_str(this->n_-1) + "], but is equal to "
02641 + to_str(j) + ".");
02642 if (i > j)
02643 throw WrongArgument("Matrix::ValReal()",
02644 string("With this function, you ")
02645 + "can only access upper part of matrix.");
02646 #endif
02647
02648 return this->val_real_(i).Val(j);
02649 }
02650
02651
02653
02659 template <class T, class Prop, class Allocator>
02660 inline const T&
02661 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02662 ::ValReal(int i, int j) const
02663 {
02664 #ifdef SELDON_CHECK_BOUNDS
02665 if (i < 0 || i >= this->m_)
02666 throw WrongRow("Matrix::ValReal", "Index should be in [0, "
02667 + to_str(this->m_-1) + "], but is equal to "
02668 + to_str(i) + ".");
02669 if (j < 0 || j >= this->n_)
02670 throw WrongCol("Matrix::ValReal", "Index should be in [0, "
02671 + to_str(this->n_-1) + "], but is equal to "
02672 + to_str(j) + ".");
02673 if (i > j)
02674 throw WrongArgument("Matrix::ValReal()",
02675 string("With this function, you ")
02676 + "can only access upper part of matrix.");
02677 #endif
02678
02679 return this->val_real_(i).Val(j);
02680 }
02681
02682
02684
02690 template <class T, class Prop, class Allocator>
02691 inline T&
02692 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::GetReal(int i, int j)
02693 {
02694 #ifdef SELDON_CHECK_BOUNDS
02695 if (i < 0 || i >= this->m_)
02696 throw WrongRow("Matrix::GetReal", "Index should be in [0, "
02697 + to_str(this->m_-1) + "], but is equal to "
02698 + to_str(i) + ".");
02699 if (j < 0 || j >= this->n_)
02700 throw WrongCol("Matrix::GetReal", "Index should be in [0, "
02701 + to_str(this->n_-1) + "], but is equal to "
02702 + to_str(j) + ".");
02703 #endif
02704
02705 if (i <= j)
02706 return this->val_real_(i).Get(j);
02707
02708 return this->val_real_(j).Get(i);
02709 }
02710
02711
02713
02719 template <class T, class Prop, class Allocator>
02720 inline const T&
02721 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02722 ::GetReal(int i, int j) const
02723 {
02724 #ifdef SELDON_CHECK_BOUNDS
02725 if (i < 0 || i >= this->m_)
02726 throw WrongRow("Matrix::GetReal", "Index should be in [0, "
02727 + to_str(this->m_-1) + "], but is equal to "
02728 + to_str(i) + ".");
02729 if (j < 0 || j >= this->n_)
02730 throw WrongCol("Matrix::GetReal", "Index should be in [0, "
02731 + to_str(this->n_-1) + "], but is equal to "
02732 + to_str(j) + ".");
02733 #endif
02734
02735 if (i <= j)
02736 return this->val_real_(i).Get(j);
02737
02738 return this->val_real_(j).Get(i);
02739 }
02740
02741
02743
02749 template <class T, class Prop, class Allocator>
02750 inline T&
02751 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::ValImag(int i, int j)
02752 {
02753 #ifdef SELDON_CHECK_BOUNDS
02754 if (i < 0 || i >= this->m_)
02755 throw WrongRow("Matrix::ValImag", "Index should be in [0, "
02756 + to_str(this->m_-1) + "], but is equal to "
02757 + to_str(i) + ".");
02758 if (j < 0 || j >= this->n_)
02759 throw WrongCol("Matrix::ValImag", "Index should be in [0, "
02760 + to_str(this->n_-1) + "], but is equal to "
02761 + to_str(j) + ".");
02762 if (i > j)
02763 throw WrongArgument("Matrix::ValImag()",
02764 string("With this function, you ")
02765 + "can only access upper part of matrix.");
02766 #endif
02767
02768 return this->val_imag_(i).Val(j);
02769 }
02770
02771
02773
02778 template <class T, class Prop, class Allocator>
02779 inline const T&
02780 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02781 ::ValImag(int i, int j) const
02782 {
02783 #ifdef SELDON_CHECK_BOUNDS
02784 if (i < 0 || i >= this->m_)
02785 throw WrongRow("Matrix::ValImag", "Index should be in [0, "
02786 + to_str(this->m_-1) + "], but is equal to "
02787 + to_str(i) + ".");
02788 if (j < 0 || j >= this->n_)
02789 throw WrongCol("Matrix::ValImag", "Index should be in [0, "
02790 + to_str(this->n_-1) + "], but is equal to "
02791 + to_str(j) + ".");
02792 if (i > j)
02793 throw WrongArgument("Matrix::ValImag()",
02794 string("With this function, you ")
02795 + "can only access upper part of matrix.");
02796 #endif
02797
02798 return this->val_imag_(i).Val(j);
02799 }
02800
02801
02803
02808 template <class T, class Prop, class Allocator>
02809 inline T&
02810 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::GetImag(int i, int j)
02811 {
02812 #ifdef SELDON_CHECK_BOUNDS
02813 if (i < 0 || i >= this->m_)
02814 throw WrongRow("Matrix::GetImag", "Index should be in [0, "
02815 + to_str(this->m_-1) + "], but is equal to "
02816 + to_str(i) + ".");
02817 if (j < 0 || j >= this->n_)
02818 throw WrongCol("Matrix::GetImag", "Index should be in [0, "
02819 + to_str(this->n_-1) + "], but is equal to "
02820 + to_str(j) + ".");
02821 #endif
02822
02823 if (i <= j)
02824 return this->val_imag_(i).Get(j);
02825
02826 return this->val_imag_(j).Get(i);
02827 }
02828
02829
02831
02836 template <class T, class Prop, class Allocator>
02837 inline const T&
02838 Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02839 ::GetImag(int i, int j) const
02840 {
02841 #ifdef SELDON_CHECK_BOUNDS
02842 if (i < 0 || i >= this->m_)
02843 throw WrongRow("Matrix::GetImag", "Index should be in [0, "
02844 + to_str(this->m_-1) + "], but is equal to "
02845 + to_str(i) + ".");
02846 if (j < 0 || j >= this->n_)
02847 throw WrongCol("Matrix::GetImag", "Index should be in [0, "
02848 + to_str(this->n_-1) + "], but is equal to "
02849 + to_str(j) + ".");
02850 #endif
02851
02852 if (i <= j)
02853 return this->val_imag_(i).Val(j);
02854
02855 return this->val_imag_(j).Val(i);
02856 }
02857
02858
02860
02865 template <class T, class Prop, class Allocator>
02866 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
02867 ::Set(int i, int j, const complex<T>& x)
02868 {
02869 if (i <= j)
02870 {
02871 if (real(x) != T(0))
02872 this->val_real_(i).Get(j) = real(x);
02873 else
02874 {
02875 if (this->val_real_(i)(j) != T(0))
02876 this->val_real_(i).Get(j) = T(0);
02877 }
02878
02879 if (imag(x) != T(0))
02880 this->val_imag_(i).Get(j) = imag(x);
02881 else
02882 {
02883 if (this->val_imag_(i)(j) != T(0))
02884 this->val_imag_(i).Get(j) = T(0);
02885 }
02886 }
02887 else
02888 {
02889 if (real(x) != T(0))
02890 this->val_real_(j).Get(i) = real(x);
02891 else
02892 {
02893 if (this->val_real_(j)(i) != T(0))
02894 this->val_real_(j).Get(i) = T(0);
02895 }
02896
02897 if (imag(x) != T(0))
02898 this->val_imag_(j).Get(i) = imag(x);
02899 else
02900 {
02901 if (this->val_imag_(j)(i) != T(0))
02902 this->val_imag_(j).Get(i) = T(0);
02903 }
02904 }
02905 }
02906
02907
02909 template <class T, class Prop, class Allocator>
02910 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::ClearRealRow(int i)
02911 {
02912 this->val_real_(i).Clear();
02913 }
02914
02915
02917 template <class T, class Prop, class Allocator>
02918 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::ClearImagRow(int i)
02919 {
02920 this->val_imag_(i).Clear();
02921 }
02922
02923
02925
02930 template <class T, class Prop, class Allocator>
02931 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02932 ReallocateRealRow(int i,int j)
02933 {
02934 this->val_real_(i).Reallocate(j);
02935 }
02936
02937
02939
02944 template <class T, class Prop, class Allocator>
02945 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02946 ReallocateImagRow(int i,int j)
02947 {
02948 this->val_imag_(i).Reallocate(j);
02949 }
02950
02951
02953
02957 template <class T, class Prop, class Allocator>
02958 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02959 ResizeRealRow(int i,int j)
02960 {
02961 this->val_real_(i).Resize(j);
02962 }
02963
02964
02966
02970 template <class T, class Prop, class Allocator>
02971 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02972 ResizeImagRow(int i,int j)
02973 {
02974 this->val_imag_(i).Resize(j);
02975 }
02976
02977
02979
02983 template <class T, class Prop, class Allocator>
02984 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02985 SwapRealRow(int i,int j)
02986 {
02987 Swap(this->val_real_(i), this->val_real_(j));
02988 }
02989
02990
02992
02996 template <class T, class Prop, class Allocator>
02997 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
02998 SwapImagRow(int i,int j)
02999 {
03000 Swap(this->val_imag_(i), this->val_imag_(j));
03001 }
03002
03003
03005
03009 template <class T, class Prop, class Allocator>
03010 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
03011 ReplaceRealIndexRow(int i, IVect& new_index)
03012 {
03013 for (int j = 0; j < this->val_real_(i).GetM(); j++)
03014 this->val_real_(i).Index(j) = new_index(j);
03015 }
03016
03017
03019
03023 template <class T, class Prop, class Allocator>
03024 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
03025 ReplaceImagIndexRow(int i,IVect& new_index)
03026 {
03027 for (int j = 0; j < this->val_imag_(i).GetM(); j++)
03028 this->val_imag_(i).Index(j) = new_index(j);
03029 }
03030
03031
03033
03037 template <class T, class Prop, class Allocator>
03038 inline int Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03039 ::GetRealRowSize(int i)
03040 const
03041 {
03042 return this->val_real_(i).GetSize();
03043 }
03044
03045
03047
03051 template <class T, class Prop, class Allocator>
03052 inline int Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03053 ::GetImagRowSize(int i) const
03054 {
03055 return this->val_imag_(i).GetSize();
03056 }
03057
03058
03060 template <class T, class Prop, class Allocator>
03061 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03062 ::PrintRealRow(int i) const
03063 {
03064 this->val_real_(i).Print();
03065 }
03066
03067
03069 template <class T, class Prop, class Allocator>
03070 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03071 ::PrintImagRow(int i) const
03072 {
03073 this->val_imag_(i).Print();
03074 }
03075
03076
03078
03083 template <class T, class Prop, class Allocator>
03084 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03085 ::AssembleRealRow(int i)
03086 {
03087 this->val_real_(i).Assemble();
03088 }
03089
03090
03092
03097 template <class T, class Prop, class Allocator>
03098 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>
03099 ::AssembleImagRow(int i)
03100 {
03101 this->val_imag_(i).Assemble();
03102 }
03103
03104
03106
03111 template <class T, class Prop, class Allocator>
03112 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
03113 AddInteraction(int i, int j, const complex<T>& val)
03114 {
03115 if (i <= j)
03116 {
03117 if (real(val) != T(0))
03118 this->val_real_(i).AddInteraction(j, real(val));
03119
03120 if (imag(val) != T(0))
03121 this->val_imag_(i).AddInteraction(j, imag(val));
03122 }
03123 }
03124
03125
03127
03133 template <class T, class Prop, class Allocator> template <class Alloc1>
03134 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
03135 AddInteractionRow(int i, int nb, const IVect& col,
03136 const Vector<complex<T>, VectFull, Alloc1>& val)
03137 {
03138 int nb_real = 0;
03139 int nb_imag = 0;
03140 IVect col_real(nb), col_imag(nb);
03141 Vector<T> val_real(nb), val_imag(nb);
03142 for (int j = 0; j < nb; j++)
03143 if (i <= col(j))
03144 {
03145 if (real(val(j)) != T(0))
03146 {
03147 col_real(nb_real) = col(j);
03148 val_real(nb_real) = real(val(j));
03149 nb_real++;
03150 }
03151
03152 if (imag(val(j)) != T(0))
03153 {
03154 col_imag(nb_imag) = col(j);
03155 val_imag(nb_imag) = imag(val(j));
03156 nb_imag++;
03157 }
03158 }
03159
03160 this->val_real_(i).AddInteractionRow(nb_real, col_real, val_real);
03161 this->val_imag_(i).AddInteractionRow(nb_imag, col_imag, val_imag);
03162 }
03163
03164
03166
03172 template <class T, class Prop, class Allocator> template <class Alloc1>
03173 inline void Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>::
03174 AddInteractionColumn(int i, int nb, const IVect& row,
03175 const Vector<complex<T>, VectFull, Alloc1>& val)
03176 {
03177 for (int j = 0; j < nb; j++)
03178 AddInteraction(row(j), i, val(j));
03179 }
03180
03181 }
03182
03183 #define SELDON_FILE_MATRIX_ARRAY_COMPLEX_SPARSE_CXX
03184 #endif