matrix/Matrix_SymPacked.hxx

00001 // Copyright (C) 2001-2009 Vivien Mallet
00002 //
00003 // This file is part of the linear-algebra library Seldon,
00004 // http://seldon.sourceforge.net/.
00005 //
00006 // Seldon is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the Free
00008 // Software Foundation; either version 2.1 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00018 
00019 
00020 // To be included by Seldon.hxx
00021 
00022 #ifndef SELDON_FILE_MATRIX_SYMPACKED_HXX
00023 
00024 #include "../share/Common.hxx"
00025 #include "../share/Properties.hxx"
00026 #include "../share/Storage.hxx"
00027 #include "../share/Errors.hxx"
00028 #include "../share/Allocator.hxx"
00029 
00030 namespace Seldon
00031 {
00032 
00033 
00035   template <class T, class Prop, class Storage,
00036             class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00037   class Matrix_SymPacked: public Matrix_Base<T, Allocator>
00038   {
00039     // typedef declaration.
00040   public:
00041     typedef typename Allocator::value_type value_type;
00042     typedef typename Allocator::pointer pointer;
00043     typedef typename Allocator::const_pointer const_pointer;
00044     typedef typename Allocator::reference reference;
00045     typedef typename Allocator::const_reference const_reference;
00046     typedef typename Allocator::value_type entry_type;
00047     typedef typename Allocator::reference access_type;
00048     typedef typename Allocator::const_reference const_access_type;
00049 
00050     // Attributes.
00051   protected:
00052 
00053     // Methods.
00054   public:
00055     // Constructor.
00056     Matrix_SymPacked();
00057     Matrix_SymPacked(int i, int j = 0);
00058     Matrix_SymPacked(const Matrix_SymPacked<T, Prop, Storage, Allocator>& A);
00059 
00060     // Destructor.
00061     ~Matrix_SymPacked();
00062     void Clear();
00063 
00064     // Basic methods.
00065     int GetDataSize() const;
00066 
00067     // Memory management.
00068     void Reallocate(int i, int j);
00069     void SetData(int i, int j, pointer data);
00070     void Nullify();
00071 
00072     // Element access and affectation.
00073     reference operator() (int i, int j);
00074     const_reference operator() (int i, int j) const;
00075     reference Val(int i, int j);
00076     const_reference Val(int i, int j) const;
00077     reference operator[] (int i);
00078     const_reference operator[] (int i) const;
00079     Matrix_SymPacked<T, Prop, Storage, Allocator>&
00080     operator= (const Matrix_SymPacked<T, Prop, Storage, Allocator>& A);
00081     void Copy(const Matrix_SymPacked<T, Prop, Storage, Allocator>& A);
00082 
00083     // Convenient functions.
00084     void Zero();
00085     void SetIdentity();
00086     void Fill();
00087     template <class T0>
00088     void Fill(const T0& x);
00089     template <class T0>
00090     Matrix_SymPacked<T, Prop, Storage, Allocator>& operator= (const T0& x);
00091     void FillRand();
00092     void Print() const;
00093     void Print(int a, int b, int m, int n) const;
00094     void Print(int l) const;
00095 
00096     // Input/output functions.
00097     void Write(string FileName) const;
00098     void Write(ostream& FileStream) const;
00099     void WriteText(string FileName) const;
00100     void WriteText(ostream& FileStream) const;
00101     void Read(string FileName);
00102     void Read(istream& FileStream);
00103     void ReadText(string FileName);
00104     void ReadText(istream& FileStream);
00105   };
00106 
00107 
00109   template <class T, class Prop, class Allocator>
00110   class Matrix<T, Prop, ColSymPacked, Allocator>:
00111     public Matrix_SymPacked<T, Prop, ColSymPacked, Allocator>
00112   {
00113     // typedef declaration.
00114   public:
00115     typedef typename Allocator::value_type value_type;
00116     typedef Prop property;
00117     typedef ColSymPacked storage;
00118     typedef Allocator allocator;
00119 
00120   public:
00121     Matrix();
00122     Matrix(int i, int j = 0);
00123 
00124     template <class T0>
00125     Matrix<T, Prop, ColSymPacked, Allocator>& operator= (const T0& x);
00126     template<class T0>
00127     Matrix<T, Prop, ColSymPacked, Allocator>& operator*= (const T0& x);
00128     void Resize(int i, int j);
00129   };
00130 
00131 
00133   template <class T, class Prop, class Allocator>
00134   class Matrix<T, Prop, RowSymPacked, Allocator>:
00135     public Matrix_SymPacked<T, Prop, RowSymPacked, Allocator>
00136   {
00137     // typedef declaration.
00138   public:
00139     typedef typename Allocator::value_type value_type;
00140     typedef Prop property;
00141     typedef RowSymPacked storage;
00142     typedef Allocator allocator;
00143 
00144   public:
00145     Matrix();
00146     Matrix(int i, int j = 0);
00147 
00148     template <class T0>
00149     Matrix<T, Prop, RowSymPacked, Allocator>& operator= (const T0& x);
00150     template<class T0>
00151     Matrix<T, Prop, RowSymPacked, Allocator>& operator*= (const T0& x);
00152     void Resize(int i, int j);
00153   };
00154 
00155 
00156 } // namespace Seldon.
00157 
00158 #define SELDON_FILE_MATRIX_SYMPACKED_HXX
00159 #endif