matrix/Matrix_Triangular.hxx

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 // To be included by Seldon.hxx
00022 
00023 #ifndef SELDON_FILE_MATRIX_TRIANGULAR_HXX
00024 
00025 #include "../share/Common.hxx"
00026 #include "../share/Properties.hxx"
00027 #include "../share/Storage.hxx"
00028 #include "../share/Errors.hxx"
00029 #include "../share/Allocator.hxx"
00030 
00031 namespace Seldon
00032 {
00033 
00034 
00036   template <class T, class Prop, class Storage,
00037             class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00038   class Matrix_Triangular: public Matrix_Base<T, Allocator>
00039   {
00040     // typedef declaration.
00041   public:
00042     typedef typename Allocator::value_type value_type;
00043     typedef typename Allocator::pointer pointer;
00044     typedef typename Allocator::const_pointer const_pointer;
00045     typedef typename Allocator::reference reference;
00046     typedef typename Allocator::const_reference const_reference;
00047     typedef typename Allocator::value_type entry_type;
00048     typedef typename Allocator::value_type access_type;
00049     typedef typename Allocator::value_type const_access_type;
00050 
00051     // Attributes.
00052   protected:
00053     pointer* me_;
00054 
00055     // Methods.
00056   public:
00057     // Constructor.
00058     Matrix_Triangular();
00059     Matrix_Triangular(int i, int j);
00060     Matrix_Triangular(const Matrix_Triangular<T, Prop,
00061                       Storage, Allocator>& A);
00062 
00063     // Destructor.
00064     ~Matrix_Triangular();
00065     void Clear();
00066 
00067     // Basic methods.
00068     int GetDataSize() const;
00069 
00070     // Memory management.
00071     void Reallocate(int i, int j);
00072     void Resize(int i, int j);
00073     void SetData(int i, int j, pointer data);
00074     void Nullify();
00075 
00076     // Element access and affectation.
00077     value_type operator() (int i, int j) const;
00078     const_reference Val(int i, int j) const;
00079     reference Val(int i, int j);
00080     const_reference Get(int i, int j) const;
00081     reference Get(int i, int j);
00082     reference operator[] (int i);
00083     const_reference operator[] (int i) const;
00084     Matrix_Triangular<T, Prop, Storage, Allocator>&
00085     operator= (const Matrix_Triangular<T, Prop, Storage, Allocator>& A);
00086     void Set(int i, int j, const T& x);
00087     void Copy(const Matrix_Triangular<T, Prop, Storage, Allocator>& A);
00088 
00089     // Convenient functions.
00090     void Zero();
00091     void SetIdentity();
00092     void Fill();
00093     template <class T0>
00094     void Fill(const T0& x);
00095     template <class T0>
00096     Matrix_Triangular<T, Prop, Storage, Allocator>& operator= (const T0& x);
00097     void FillRand();
00098     void Print() const;
00099     void Print(int a, int b, int m, int n) const;
00100     void Print(int l) const;
00101 
00102     // Input/output functions.
00103     void Write(string FileName) const;
00104     void Write(ostream& FileStream) const;
00105     void WriteText(string FileName) const;
00106     void WriteText(ostream& FileStream) const;
00107     void Read(string FileName);
00108     void Read(istream& FileStream);
00109     void ReadText(string FileName);
00110     void ReadText(istream& FileStream);
00111 
00112   };
00113 
00114 
00116   template <class T, class Prop, class Allocator>
00117   class Matrix<T, Prop, ColUpTriang, Allocator>:
00118     public Matrix_Triangular<T, Prop, ColUpTriang, Allocator>
00119   {
00120     // typedef declaration.
00121   public:
00122     typedef typename Allocator::value_type value_type;
00123     typedef Prop property;
00124     typedef ColUpTriang storage;
00125     typedef Allocator allocator;
00126 
00127   public:
00128     Matrix();
00129     Matrix(int i, int j);
00130 
00131     template <class T0>
00132     Matrix<T, Prop, ColUpTriang, Allocator>& operator= (const T0& x);
00133     Matrix<T, Prop, ColUpTriang, Allocator>&
00134     operator= (const Matrix<T, Prop, ColUpTriang, Allocator>& A);
00135     template<class T0>
00136     Matrix<T, Prop, ColUpTriang, Allocator>& operator*= (const T0& x);
00137 
00138   };
00139 
00140 
00142   template <class T, class Prop, class Allocator>
00143   class Matrix<T, Prop, ColLoTriang, Allocator>:
00144     public Matrix_Triangular<T, Prop, ColLoTriang, Allocator>
00145   {
00146     // typedef declaration.
00147   public:
00148     typedef typename Allocator::value_type value_type;
00149     typedef Prop property;
00150     typedef ColLoTriang storage;
00151     typedef Allocator allocator;
00152 
00153   public:
00154     Matrix();
00155     Matrix(int i, int j);
00156 
00157     template <class T0>
00158     Matrix<T, Prop, ColLoTriang, Allocator>& operator= (const T0& x);
00159     Matrix<T, Prop, ColLoTriang, Allocator>&
00160     operator= (const Matrix<T, Prop, ColLoTriang, Allocator>& A);
00161     template<class T0>
00162     Matrix<T, Prop, ColLoTriang, Allocator>& operator*= (const T0& x);
00163 
00164   };
00165 
00166 
00168   template <class T, class Prop, class Allocator>
00169   class Matrix<T, Prop, RowUpTriang, Allocator>:
00170     public Matrix_Triangular<T, Prop, RowUpTriang, Allocator>
00171   {
00172     // typedef declaration.
00173   public:
00174     typedef typename Allocator::value_type value_type;
00175     typedef Prop property;
00176     typedef RowUpTriang storage;
00177     typedef Allocator allocator;
00178 
00179   public:
00180     Matrix();
00181     Matrix(int i, int j);
00182 
00183     template <class T0>
00184     Matrix<T, Prop, RowUpTriang, Allocator>& operator= (const T0& x);
00185     Matrix<T, Prop, RowUpTriang, Allocator>&
00186     operator= (const Matrix<T, Prop, RowUpTriang, Allocator>& A);
00187     template<class T0>
00188     Matrix<T, Prop, RowUpTriang, Allocator>& operator*= (const T0& x);
00189 
00190   };
00191 
00192 
00194   template <class T, class Prop, class Allocator>
00195   class Matrix<T, Prop, RowLoTriang, Allocator>:
00196     public Matrix_Triangular<T, Prop, RowLoTriang, Allocator>
00197   {
00198     // typedef declaration.
00199   public:
00200     typedef typename Allocator::value_type value_type;
00201     typedef Prop property;
00202     typedef RowLoTriang storage;
00203     typedef Allocator allocator;
00204 
00205   public:
00206     Matrix();
00207     Matrix(int i, int j);
00208 
00209     template <class T0>
00210     Matrix<T, Prop, RowLoTriang, Allocator>& operator= (const T0& x);
00211     Matrix<T, Prop, RowLoTriang, Allocator>&
00212     operator= (const Matrix<T, Prop, RowLoTriang, Allocator>& A);
00213     template<class T0>
00214     Matrix<T, Prop, RowLoTriang, Allocator>& operator*= (const T0& x);
00215   };
00216 
00217 
00218 } // namespace Seldon.
00219 
00220 #define SELDON_FILE_MATRIX_TRIANGULAR_HXX
00221 #endif