Warning: this documentation for the development version is under construction.

/home/vivien/public_html/.src_seldon/matrix/Matrix_HermPacked.cxx

00001 // Copyright (C) 2001-2009 Vivien Mallet
00002 // Copyright (C) 2003-2009 Marc Duruflé
00003 //
00004 // This file is part of the linear-algebra library Seldon,
00005 // http://seldon.sourceforge.net/.
00006 //
00007 // Seldon is free software; you can redistribute it and/or modify it under the
00008 // terms of the GNU Lesser General Public License as published by the Free
00009 // Software Foundation; either version 2.1 of the License, or (at your option)
00010 // any later version.
00011 //
00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00015 // more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00019 
00020 
00021 #ifndef SELDON_FILE_MATRIX_HERMPACKED_CXX
00022 
00023 #include "Matrix_HermPacked.hxx"
00024 
00025 namespace Seldon
00026 {
00027 
00028 
00029   /****************
00030    * CONSTRUCTORS *
00031    ****************/
00032 
00033 
00035 
00038   template <class T, class Prop, class Storage, class Allocator>
00039   inline Matrix_HermPacked<T, Prop, Storage, Allocator>::Matrix_HermPacked():
00040     Matrix_Base<T, Allocator>()
00041   {
00042   }
00043 
00044 
00046 
00051   template <class T, class Prop, class Storage, class Allocator>
00052   inline Matrix_HermPacked<T, Prop, Storage, Allocator>
00053   ::Matrix_HermPacked(int i, int j):
00054     Matrix_Base<T, Allocator>(i, i)
00055   {
00056 
00057 #ifdef SELDON_CHECK_MEMORY
00058     try
00059       {
00060 #endif
00061 
00062         this->data_ = this->allocator_.allocate((i * (i + 1)) / 2, this);
00063 
00064 #ifdef SELDON_CHECK_MEMORY
00065       }
00066     catch (...)
00067       {
00068         this->m_ = 0;
00069         this->n_ = 0;
00070         this->data_ = NULL;
00071         return;
00072       }
00073     if (this->data_ == NULL)
00074       {
00075         this->m_ = 0;
00076         this->n_ = 0;
00077         return;
00078       }
00079 #endif
00080 
00081   }
00082 
00083 
00085   template <class T, class Prop, class Storage, class Allocator>
00086   inline Matrix_HermPacked<T, Prop, Storage, Allocator>
00087   ::Matrix_HermPacked(const Matrix_HermPacked<T, Prop,
00088                       Storage, Allocator>& A):
00089     Matrix_Base<T, Allocator>()
00090   {
00091     this->m_ = 0;
00092     this->n_ = 0;
00093     this->data_ = NULL;
00094 
00095     this->Copy(A);
00096   }
00097 
00098 
00099   /**************
00100    * DESTRUCTOR *
00101    **************/
00102 
00103 
00105   template <class T, class Prop, class Storage, class Allocator>
00106   inline Matrix_HermPacked<T, Prop, Storage, Allocator>::~Matrix_HermPacked()
00107   {
00108 
00109 #ifdef SELDON_CHECK_MEMORY
00110     try
00111       {
00112 #endif
00113 
00114         if (this->data_ != NULL)
00115           {
00116             this->allocator_.deallocate(this->data_,
00117                                         (this->m_ * (this->m_ + 1)) / 2);
00118             this->data_ = NULL;
00119           }
00120 
00121 #ifdef SELDON_CHECK_MEMORY
00122       }
00123     catch (...)
00124       {
00125         this->m_ = 0;
00126         this->n_ = 0;
00127         this->data_ = NULL;
00128       }
00129 #endif
00130 
00131   }
00132 
00133 
00135 
00139   template <class T, class Prop, class Storage, class Allocator>
00140   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>::Clear()
00141   {
00142     this->~Matrix_HermPacked();
00143     this->m_ = 0;
00144     this->n_ = 0;
00145   }
00146 
00147 
00148   /*******************
00149    * BASIC FUNCTIONS *
00150    *******************/
00151 
00152 
00154 
00157   template <class T, class Prop, class Storage, class Allocator>
00158   int Matrix_HermPacked<T, Prop, Storage, Allocator>::GetDataSize() const
00159   {
00160     return (this->m_ * (this->m_ + 1)) / 2;
00161   }
00162 
00163 
00164   /*********************
00165    * MEMORY MANAGEMENT *
00166    *********************/
00167 
00168 
00170 
00176   template <class T, class Prop, class Storage, class Allocator>
00177   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
00178   ::Reallocate(int i, int j)
00179   {
00180 
00181     if (i != this->m_)
00182       {
00183         this->m_ = i;
00184         this->n_ = i;
00185 
00186 #ifdef SELDON_CHECK_MEMORY
00187         try
00188           {
00189 #endif
00190 
00191             this->data_ =
00192               reinterpret_cast<pointer>(this->allocator_.reallocate(this->data_,
00193                                                                     (i*(i + 1)) / 2,
00194                                                                     this));
00195 
00196 #ifdef SELDON_CHECK_MEMORY
00197           }
00198         catch (...)
00199           {
00200             this->m_ = 0;
00201             this->n_ = 0;
00202             this->data_ = NULL;
00203             throw NoMemory("Matrix_HermPacked::Reallocate(int, int)",
00204                            "Unable to reallocate memory for data_.");
00205           }
00206         if (this->data_ == NULL)
00207           {
00208             this->m_ = 0;
00209             this->n_ = 0;
00210             throw NoMemory("Matrix_HermPacked::Reallocate(int, int)",
00211                            "Unable to reallocate memory for data_.");
00212           }
00213 #endif
00214 
00215       }
00216   }
00217 
00218 
00221 
00235   template <class T, class Prop, class Storage, class Allocator>
00236   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
00237   ::SetData(int i, int j,
00238             typename Matrix_HermPacked<T, Prop, Storage, Allocator>
00239             ::pointer data)
00240   {
00241     this->Clear();
00242 
00243     this->m_ = i;
00244     this->n_ = i;
00245 
00246     this->data_ = data;
00247   }
00248 
00249 
00251 
00255   template <class T, class Prop, class Storage, class Allocator>
00256   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>::Nullify()
00257   {
00258     this->data_ = NULL;
00259     this->m_ = 0;
00260     this->n_ = 0;
00261   }
00262 
00263 
00264   /**********************************
00265    * ELEMENT ACCESS AND AFFECTATION *
00266    **********************************/
00267 
00268 
00270 
00276   template <class T, class Prop, class Storage, class Allocator>
00277   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::value_type
00278   Matrix_HermPacked<T, Prop, Storage, Allocator>
00279   ::operator() (int i, int j) const
00280   {
00281 
00282 #ifdef SELDON_CHECK_BOUNDS
00283     if (i < 0 || i >= this->m_)
00284       throw WrongRow("Matrix_HermPacked::operator()",
00285                      string("Index should be in [0, ") + to_str(this->m_-1)
00286                      + "], but is equal to " + to_str(i) + ".");
00287     if (j < 0 || j >= this->n_)
00288       throw WrongCol("Matrix_HermPacked::operator()",
00289                      string("Index should be in [0, ") + to_str(this->n_-1)
00290                      + "], but is equal to " + to_str(j) + ".");
00291 #endif
00292 
00293     if (i > j)
00294       return conj(this->data_[Storage::GetFirst(j * this->m_
00295                                                 - (j*(j+1)) / 2 + i,
00296                                                 (i*(i+1)) / 2 + j)]);
00297     else
00298       return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
00299                                            (j*(j+1)) / 2 + i)];
00300   }
00301 
00302 
00304 
00311   template <class T, class Prop, class Storage, class Allocator>
00312   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
00313   Matrix_HermPacked<T, Prop, Storage, Allocator>::Val(int i, int j)
00314   {
00315 
00316 #ifdef SELDON_CHECK_BOUNDS
00317     if (i < 0 || i >= this->m_)
00318       throw WrongRow("Matrix_HermPacked::Val(int, int)",
00319                      string("Index should be in [0, ") + to_str(this->m_-1)
00320                      + "], but is equal to " + to_str(i) + ".");
00321     if (j < 0 || j >= this->n_)
00322       throw WrongCol("Matrix_HermPacked::Val(int, int)",
00323                      string("Index should be in [0, ") + to_str(this->n_-1)
00324                      + "], but is equal to " + to_str(j) + ".");
00325     if (i > j)
00326       throw WrongRow("Matrix_HermPacked::Val(int, int)",
00327                      string("Attempted to access to element (")
00328                      + to_str(i) + ", " + to_str(j)
00329                      + ") but row index should not be strictly"
00330                      + " greater than column index.");
00331 #endif
00332 
00333     return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
00334                                          (j*(j+1)) / 2 + i)];
00335   }
00336 
00337 
00339 
00346   template <class T, class Prop, class Storage, class Allocator>
00347   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>
00348   ::const_reference
00349   Matrix_HermPacked<T, Prop, Storage, Allocator>::Val(int i, int j) const
00350   {
00351 
00352 #ifdef SELDON_CHECK_BOUNDS
00353     if (i < 0 || i >= this->m_)
00354       throw WrongRow("Matrix_HermPacked::Val(int, int) const",
00355                      string("Index should be in [0, ") + to_str(this->m_-1)
00356                      + "], but is equal to " + to_str(i) + ".");
00357     if (j < 0 || j >= this->n_)
00358       throw WrongCol("Matrix_HermPacked::Val(int, int) cont",
00359                      string("Index should be in [0, ") + to_str(this->n_-1)
00360                      + "], but is equal to " + to_str(j) + ".");
00361     if (i > j)
00362       throw WrongRow("Matrix_HermPacked::Val(int, int) const",
00363                      string("Attempted to access to element (")
00364                      + to_str(i) + ", " + to_str(j)
00365                      + string(") but row index should not be strictly")
00366                      + " greater than column index.");
00367 #endif
00368 
00369     return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
00370                                          (j*(j+1)) / 2 + i)];
00371   }
00372 
00373 
00375 
00380   template <class T, class Prop, class Storage, class Allocator>
00381   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
00382   Matrix_HermPacked<T, Prop, Storage, Allocator>::Get(int i, int j)
00383   {
00384     return this->Val(i, j);
00385   }
00386 
00387 
00389 
00394   template <class T, class Prop, class Storage, class Allocator>
00395   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>
00396   ::const_reference
00397   Matrix_HermPacked<T, Prop, Storage, Allocator>::Get(int i, int j) const
00398   {
00399     return this->Val(i, j);
00400   }
00401 
00402 
00404 
00409   template <class T, class Prop, class Storage, class Allocator>
00410   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
00411   Matrix_HermPacked<T, Prop, Storage, Allocator>::operator[] (int i)
00412   {
00413 
00414 #ifdef SELDON_CHECK_BOUNDS
00415     if (i < 0 || i >= this->GetDataSize())
00416       throw WrongIndex("Matrix_HermPacked::operator[] (int)",
00417                        string("Index should be in [0, ")
00418                        + to_str(this->GetDataSize()-1) + "], but is equal to "
00419                        + to_str(i) + ".");
00420 #endif
00421 
00422     return this->data_[i];
00423   }
00424 
00425 
00427 
00432   template <class T, class Prop, class Storage, class Allocator>
00433   inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>
00434   ::const_reference
00435   Matrix_HermPacked<T, Prop, Storage, Allocator>::operator[] (int i) const
00436   {
00437 
00438 #ifdef SELDON_CHECK_BOUNDS
00439     if (i < 0 || i >= this->GetDataSize())
00440       throw WrongIndex("Matrix_HermPacked::operator[] (int) const",
00441                        string("Index should be in [0, ")
00442                        + to_str(this->GetDataSize()-1) + "], but is equal to "
00443                        + to_str(i) + ".");
00444 #endif
00445 
00446     return this->data_[i];
00447   }
00448 
00449 
00451 
00456   template <class T, class Prop, class Storage, class Allocator>
00457   inline Matrix_HermPacked<T, Prop, Storage, Allocator>&
00458   Matrix_HermPacked<T, Prop, Storage, Allocator>
00459   ::operator= (const Matrix_HermPacked<T, Prop, Storage, Allocator>& A)
00460   {
00461     this->Copy(A);
00462 
00463     return *this;
00464   }
00465 
00466 
00468 
00473   template <class T, class Prop, class Storage, class Allocator>
00474   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
00475   ::Set(int i, int j, const T& x)
00476   {
00477     if (i > j)
00478       this->Val(j, i) = conj(x);
00479     else
00480       this->Val(i, j) = x;
00481   }
00482 
00483 
00485 
00490   template <class T, class Prop, class Storage, class Allocator>
00491   inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
00492   ::Copy(const Matrix_HermPacked<T, Prop, Storage, Allocator>& A)
00493   {
00494     this->Reallocate(A.GetM(), A.GetN());
00495 
00496     this->allocator_.memorycpy(this->data_, A.GetData(), this->GetDataSize());
00497   }
00498 
00499 
00500   /************************
00501    * CONVENIENT FUNCTIONS *
00502    ************************/
00503 
00504 
00506 
00510   template <class T, class Prop, class Storage, class Allocator>
00511   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Zero()
00512   {
00513     this->allocator_.memoryset(this->data_, char(0),
00514                                this->GetDataSize() * sizeof(value_type));
00515   }
00516 
00517 
00519   template <class T, class Prop, class Storage, class Allocator>
00520   void Matrix_HermPacked<T, Prop, Storage, Allocator>::SetIdentity()
00521   {
00522     this->Fill(T(0));
00523 
00524     T one;
00525     SetComplexOne(one);
00526     for (int i = 0; i < min(this->m_, this->n_); i++)
00527       this->Val(i,i) = one;
00528   }
00529 
00530 
00532 
00536   template <class T, class Prop, class Storage, class Allocator>
00537   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Fill()
00538   {
00539     for (int i = 0; i < this->GetDataSize(); i++)
00540       this->data_[i] = i;
00541   }
00542 
00543 
00545 
00550   template <class T, class Prop, class Storage, class Allocator>
00551   template <class T0>
00552   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Fill(const T0& x)
00553   {
00554     for (int i = 0; i < this->GetDataSize(); i++)
00555       this->data_[i] = x;
00556   }
00557 
00558 
00560 
00565   template <class T, class Prop, class Storage, class Allocator>
00566   template <class T0>
00567   Matrix_HermPacked<T, Prop, Storage, Allocator>&
00568   Matrix_HermPacked<T, Prop, Storage, Allocator>::operator= (const T0& x)
00569   {
00570     this->Fill(x);
00571 
00572     return *this;
00573   }
00574 
00575 
00577 
00580   template <class T, class Prop, class Storage, class Allocator>
00581   void Matrix_HermPacked<T, Prop, Storage, Allocator>::FillRand()
00582   {
00583     srand(time(NULL));
00584     for (int i = 0; i < this->GetDataSize(); i++)
00585       this->data_[i] = rand();
00586   }
00587 
00588 
00590 
00595   template <class T, class Prop, class Storage, class Allocator>
00596   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Print() const
00597   {
00598     for (int i = 0; i < this->m_; i++)
00599       {
00600         for (int j = 0; j < this->n_; j++)
00601           cout << (*this)(i, j) << "\t";
00602         cout << endl;
00603       }
00604   }
00605 
00606 
00608 
00619   template <class T, class Prop, class Storage, class Allocator>
00620   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00621   ::Print(int a, int b, int m, int n) const
00622   {
00623     for (int i = a; i < min(this->m_, a+m); i++)
00624       {
00625         for (int j = b; j < min(this->n_, b+n); j++)
00626           cout << (*this)(i, j) << "\t";
00627         cout << endl;
00628       }
00629   }
00630 
00631 
00633 
00641   template <class T, class Prop, class Storage, class Allocator>
00642   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Print(int l) const
00643   {
00644     Print(0, 0, l, l);
00645   }
00646 
00647 
00648   /**************************
00649    * INPUT/OUTPUT FUNCTIONS *
00650    **************************/
00651 
00652 
00654 
00661   template <class T, class Prop, class Storage, class Allocator>
00662   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00663   ::Write(string FileName) const
00664   {
00665 
00666     ofstream FileStream;
00667     FileStream.open(FileName.c_str(), ofstream::binary);
00668 
00669 #ifdef SELDON_CHECK_IO
00670     // Checks if the file was opened.
00671     if (!FileStream.is_open())
00672       throw IOError("Matrix_HermPacked::Write(string FileName)",
00673                     string("Unable to open file \"") + FileName + "\".");
00674 #endif
00675 
00676     this->Write(FileStream);
00677 
00678     FileStream.close();
00679 
00680   }
00681 
00682 
00684 
00691   template <class T, class Prop, class Storage, class Allocator>
00692   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00693   ::Write(ostream& FileStream) const
00694   {
00695 
00696 #ifdef SELDON_CHECK_IO
00697     // Checks if the file is ready.
00698     if (!FileStream.good())
00699       throw IOError("Matrix_HermPacked::Write(ofstream& FileStream)",
00700                     "Stream is not ready.");
00701 #endif
00702 
00703     FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->m_)),
00704                      sizeof(int));
00705     FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&this->n_)),
00706                      sizeof(int));
00707 
00708     FileStream.write(reinterpret_cast<char*>(this->data_),
00709                      this->GetDataSize() * sizeof(value_type));
00710 
00711 #ifdef SELDON_CHECK_IO
00712     // Checks if data was written.
00713     if (!FileStream.good())
00714       throw IOError("Matrix_HermPacked::Write(ofstream& FileStream)",
00715                     string("Output operation failed.")
00716                     + string(" The output file may have been removed")
00717                     + " or there is no space left on device.");
00718 #endif
00719 
00720   }
00721 
00722 
00724 
00731   template <class T, class Prop, class Storage, class Allocator>
00732   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00733   ::WriteText(string FileName) const
00734   {
00735     ofstream FileStream;
00736     FileStream.precision(cout.precision());
00737     FileStream.flags(cout.flags());
00738     FileStream.open(FileName.c_str());
00739 
00740 #ifdef SELDON_CHECK_IO
00741     // Checks if the file was opened.
00742     if (!FileStream.is_open())
00743       throw IOError("Matrix_HermPacked::WriteText(string FileName)",
00744                     string("Unable to open file \"") + FileName + "\".");
00745 #endif
00746 
00747     this->WriteText(FileStream);
00748 
00749     FileStream.close();
00750   }
00751 
00752 
00754 
00761   template <class T, class Prop, class Storage, class Allocator>
00762   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00763   ::WriteText(ostream& FileStream) const
00764   {
00765 
00766 #ifdef SELDON_CHECK_IO
00767     // Checks if the stream is ready.
00768     if (!FileStream.good())
00769       throw IOError("Matrix_HermPacked::WriteText(ofstream& FileStream)",
00770                     "Stream is not ready.");
00771 #endif
00772 
00773     int i, j;
00774     for (i = 0; i < this->GetM(); i++)
00775       {
00776         for (j = 0; j < this->GetN(); j++)
00777           FileStream << (*this)(i, j) << '\t';
00778         FileStream << endl;
00779       }
00780 
00781 #ifdef SELDON_CHECK_IO
00782     // Checks if data was written.
00783     if (!FileStream.good())
00784       throw IOError("Matrix_HermPacked::WriteText(ofstream& FileStream)",
00785                     string("Output operation failed.")
00786                     + string(" The output file may have been removed")
00787                     + " or there is no space left on device.");
00788 #endif
00789 
00790   }
00791 
00792 
00794 
00801   template <class T, class Prop, class Storage, class Allocator>
00802   void Matrix_HermPacked<T, Prop, Storage, Allocator>::Read(string FileName)
00803   {
00804     ifstream FileStream;
00805     FileStream.open(FileName.c_str(), ifstream::binary);
00806 
00807 #ifdef SELDON_CHECK_IO
00808     // Checks if the file was opened.
00809     if (!FileStream.good())
00810       throw IOError("Matrix_HermPacked::Read(string FileName)",
00811                     string("Unable to open file \"") + FileName + "\".");
00812 #endif
00813 
00814     this->Read(FileStream);
00815 
00816     FileStream.close();
00817   }
00818 
00819 
00821 
00828   template <class T, class Prop, class Storage, class Allocator>
00829   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00830   ::Read(istream& FileStream)
00831   {
00832 
00833 #ifdef SELDON_CHECK_IO
00834     // Checks if the stream is ready.
00835     if (!FileStream.good())
00836       throw IOError("Matrix_HermPacked::Read(ifstream& FileStream)",
00837                     "Stream is not ready.");
00838 #endif
00839 
00840     int new_m, new_n;
00841     FileStream.read(reinterpret_cast<char*>(&new_m), sizeof(int));
00842     FileStream.read(reinterpret_cast<char*>(&new_n), sizeof(int));
00843     this->Reallocate(new_m, new_n);
00844 
00845     FileStream.read(reinterpret_cast<char*>(this->data_),
00846                     this->GetDataSize() * sizeof(value_type));
00847 
00848 #ifdef SELDON_CHECK_IO
00849     // Checks if data was read.
00850     if (!FileStream.good())
00851       throw IOError("Matrix_HermPacked::Read(ifstream& FileStream)",
00852                     string("Input operation failed.")
00853                     + string(" The input file may have been removed")
00854                     + " or may not contain enough data.");
00855 #endif
00856 
00857   }
00858 
00859 
00861 
00865   template <class T, class Prop, class Storage, class Allocator>
00866   void Matrix_HermPacked<T, Prop, Storage, Allocator>::ReadText(string FileName)
00867   {
00868     ifstream FileStream;
00869     FileStream.open(FileName.c_str());
00870 
00871 #ifdef SELDON_CHECK_IO
00872     // Checks if the file was opened.
00873     if (!FileStream.is_open())
00874       throw IOError("Matrix_Pointers::ReadText(string FileName)",
00875                     string("Unable to open file \"") + FileName + "\".");
00876 #endif
00877 
00878     this->ReadText(FileStream);
00879 
00880     FileStream.close();
00881   }
00882 
00883 
00885 
00889   template <class T, class Prop, class Storage, class Allocator>
00890   void Matrix_HermPacked<T, Prop, Storage, Allocator>
00891   ::ReadText(istream& FileStream)
00892   {
00893     // clears previous matrix
00894     Clear();
00895 
00896 #ifdef SELDON_CHECK_IO
00897     // Checks if the stream is ready.
00898     if (!FileStream.good())
00899       throw IOError("Matrix_Pointers::ReadText(ifstream& FileStream)",
00900                     "Stream is not ready.");
00901 #endif
00902 
00903     // we read first line
00904     string line;
00905     getline(FileStream, line);
00906 
00907     if (FileStream.fail())
00908       {
00909         // empty file ?
00910         return;
00911       }
00912 
00913     // converting first line into a vector
00914     istringstream line_stream(line);
00915     Vector<T> first_row;
00916     first_row.ReadText(line_stream);
00917 
00918     // and now the other rows
00919     Vector<T> other_rows;
00920     other_rows.ReadText(FileStream);
00921 
00922     // number of rows and columns
00923     int n = first_row.GetM();
00924     int m = 1 + other_rows.GetM()/n;
00925 
00926 #ifdef SELDON_CHECK_IO
00927     // Checking number of elements
00928     if (other_rows.GetM() != (m-1)*n)
00929       throw IOError("Matrix_Pointers::ReadText(ifstream& FileStream)",
00930                     "The file should contain same number of columns.");
00931 #endif
00932 
00933     this->Reallocate(m,n);
00934     // filling matrix
00935     for (int j = 0; j < n; j++)
00936       this->Val(0, j) = first_row(j);
00937 
00938     int nb = 0;
00939     for (int i = 1; i < m; i++)
00940       {
00941         for (int j = 0; j < i; j++)
00942           nb++;
00943 
00944         for (int j = i; j < n; j++)
00945           this->Val(i, j) = other_rows(nb++);
00946       }
00947   }
00948 
00949 
00950 
00952   // MATRIX<COLHERMPACKED> //
00954 
00955 
00956   /****************
00957    * CONSTRUCTORS *
00958    ****************/
00959 
00960 
00962 
00965   template <class T, class Prop, class Allocator>
00966   Matrix<T, Prop, ColHermPacked, Allocator>::Matrix():
00967     Matrix_HermPacked<T, Prop, ColHermPacked, Allocator>()
00968   {
00969   }
00970 
00971 
00973 
00978   template <class T, class Prop, class Allocator>
00979   Matrix<T, Prop, ColHermPacked, Allocator>::Matrix(int i, int j):
00980     Matrix_HermPacked<T, Prop, ColHermPacked, Allocator>(i, j)
00981   {
00982   }
00983 
00984 
00985   /*******************
00986    * OTHER FUNCTIONS *
00987    *******************/
00988 
00989 
00991 
00994   template <class T, class Prop, class Allocator>
00995   template <class T0>
00996   inline Matrix<T, Prop, ColHermPacked, Allocator>&
00997   Matrix<T, Prop, ColHermPacked, Allocator>
00998   ::operator= (const T0& x)
00999   {
01000     this->Fill(x);
01001 
01002     return *this;
01003   }
01004 
01005 
01007 
01012   template <class T, class Prop, class Allocator>
01013   inline Matrix<T, Prop, ColHermPacked, Allocator>&
01014   Matrix<T, Prop, ColHermPacked, Allocator>::operator= (const Matrix<T, Prop,
01015                                                        ColHermPacked,
01016                                                        Allocator>& A)
01017   {
01018     this->Copy(A);
01019     return *this;
01020   }
01021 
01022 
01024 
01027   template <class T, class Prop, class Allocator>
01028   template <class T0>
01029   Matrix<T, Prop, ColHermPacked, Allocator>&
01030   Matrix<T, Prop, ColHermPacked, Allocator>::operator*= (const T0& x)
01031   {
01032     for (int i = 0; i < this->GetDataSize();i++)
01033       this->data_[i] *= x;
01034 
01035     return *this;
01036   }
01037 
01038 
01040 
01047   template <class T, class Prop, class Allocator>
01048   inline void Matrix<T, Prop, ColHermPacked, Allocator>
01049   ::Resize(int i, int j)
01050   {
01051 
01052     // Storing the old values of the matrix.
01053     int nold = this->GetDataSize();
01054     Vector<T, VectFull, Allocator> xold(nold);
01055     for (int k = 0; k < nold; k++)
01056       xold(k) = this->data_[k];
01057 
01058     // Reallocation.
01059     this->Reallocate(i, j);
01060 
01061     // Filling the matrix with its old values.
01062     int nmin = min(nold, this->GetDataSize());
01063     for (int k = 0; k < nmin; k++)
01064       this->data_[k] = xold(k);
01065   }
01066 
01067 
01069   // MATRIX<ROWHERMPACKED> //
01071 
01072 
01073   /****************
01074    * CONSTRUCTORS *
01075    ****************/
01076 
01077 
01079 
01082   template <class T, class Prop, class Allocator>
01083   Matrix<T, Prop, RowHermPacked, Allocator>::Matrix():
01084     Matrix_HermPacked<T, Prop, RowHermPacked, Allocator>()
01085   {
01086   }
01087 
01088 
01090 
01095   template <class T, class Prop, class Allocator>
01096   Matrix<T, Prop, RowHermPacked, Allocator>::Matrix(int i, int j):
01097     Matrix_HermPacked<T, Prop, RowHermPacked, Allocator>(i, j)
01098   {
01099   }
01100 
01101 
01102   /*******************
01103    * OTHER FUNCTIONS *
01104    *******************/
01105 
01106 
01108 
01111   template <class T, class Prop, class Allocator>
01112   template <class T0>
01113   inline Matrix<T, Prop, RowHermPacked, Allocator>&
01114   Matrix<T, Prop, RowHermPacked, Allocator>
01115   ::operator= (const T0& x)
01116   {
01117     this->Fill(x);
01118 
01119     return *this;
01120   }
01121 
01122 
01124 
01129   template <class T, class Prop, class Allocator>
01130   inline Matrix<T, Prop, RowHermPacked, Allocator>&
01131   Matrix<T, Prop, RowHermPacked, Allocator>::operator= (const Matrix<T, Prop,
01132                                                        RowHermPacked,
01133                                                        Allocator>& A)
01134   {
01135     this->Copy(A);
01136     return *this;
01137   }
01138 
01139 
01141 
01144   template <class T, class Prop, class Allocator>
01145   template <class T0>
01146   Matrix<T, Prop, RowHermPacked, Allocator>&
01147   Matrix<T, Prop, RowHermPacked, Allocator>::operator*= (const T0& x)
01148   {
01149     for (int i = 0; i < this->GetDataSize();i++)
01150       this->data_[i] *= x;
01151 
01152     return *this;
01153   }
01154 
01155 
01157 
01164   template <class T, class Prop, class Allocator>
01165   inline void Matrix<T, Prop, RowHermPacked, Allocator>
01166   ::Resize(int i, int j)
01167   {
01168     // Storing the old values of the matrix.
01169     int nold = this->GetDataSize(), iold = this->m_;
01170     Vector<T, VectFull, Allocator> xold(nold);
01171     for (int k = 0; k < nold; k++)
01172       xold(k) = this->data_[k];
01173 
01174     // Reallocation.
01175     this->Reallocate(i, j);
01176 
01177     // Filling the matrix with its old values.
01178     int imin = min(iold, i);
01179     nold = 0;
01180     int n = 0;
01181     for (int k = 0; k < imin; k++)
01182       {
01183         for (int l = k; l < imin; l++)
01184           this->data_[n+l-k] = xold(nold+l-k);
01185 
01186         n += i - k;
01187         nold += iold - k;
01188       }
01189   }
01190 
01191 
01192 } // namespace Seldon.
01193 
01194 #define SELDON_FILE_MATRIX_HERMPACKED_CXX
01195 #endif