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

/home/vivien/public_html/.src_seldon/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 Get(int i, int j);
00078     const_reference Get(int i, int j) const;
00079     reference operator[] (int i);
00080     const_reference operator[] (int i) const;
00081     Matrix_SymPacked<T, Prop, Storage, Allocator>&
00082     operator= (const Matrix_SymPacked<T, Prop, Storage, Allocator>& A);
00083     void Set(int i, int j, const T& x);
00084     void Copy(const Matrix_SymPacked<T, Prop, Storage, Allocator>& A);
00085 
00086     // Convenient functions.
00087     void Zero();
00088     void SetIdentity();
00089     void Fill();
00090     template <class T0>
00091     void Fill(const T0& x);
00092     template <class T0>
00093     Matrix_SymPacked<T, Prop, Storage, Allocator>& operator= (const T0& x);
00094     void FillRand();
00095     void Print() const;
00096     void Print(int a, int b, int m, int n) const;
00097     void Print(int l) const;
00098 
00099     // Input/output functions.
00100     void Write(string FileName) const;
00101     void Write(ostream& FileStream) const;
00102     void WriteText(string FileName) const;
00103     void WriteText(ostream& FileStream) const;
00104     void Read(string FileName);
00105     void Read(istream& FileStream);
00106     void ReadText(string FileName);
00107     void ReadText(istream& FileStream);
00108   };
00109 
00110 
00112   template <class T, class Prop, class Allocator>
00113   class Matrix<T, Prop, ColSymPacked, Allocator>:
00114     public Matrix_SymPacked<T, Prop, ColSymPacked, Allocator>
00115   {
00116     // typedef declaration.
00117   public:
00118     typedef typename Allocator::value_type value_type;
00119     typedef Prop property;
00120     typedef ColSymPacked storage;
00121     typedef Allocator allocator;
00122 
00123   public:
00124     Matrix();
00125     Matrix(int i, int j = 0);
00126 
00127     template <class T0>
00128     Matrix<T, Prop, ColSymPacked, Allocator>& operator= (const T0& x);
00129     Matrix<T, Prop, ColSymPacked, Allocator>& operator= (const Matrix<T, Prop,
00130                                                          ColSymPacked,
00131                                                          Allocator>& A);
00132     template<class T0>
00133     Matrix<T, Prop, ColSymPacked, Allocator>& operator*= (const T0& x);
00134     void Resize(int i, int j);
00135   };
00136 
00137 
00139   template <class T, class Prop, class Allocator>
00140   class Matrix<T, Prop, RowSymPacked, Allocator>:
00141     public Matrix_SymPacked<T, Prop, RowSymPacked, Allocator>
00142   {
00143     // typedef declaration.
00144   public:
00145     typedef typename Allocator::value_type value_type;
00146     typedef Prop property;
00147     typedef RowSymPacked storage;
00148     typedef Allocator allocator;
00149 
00150   public:
00151     Matrix();
00152     Matrix(int i, int j = 0);
00153 
00154     template <class T0>
00155     Matrix<T, Prop, RowSymPacked, Allocator>& operator= (const T0& x);
00156     Matrix<T, Prop, RowSymPacked, Allocator>& operator= (const Matrix<T, Prop,
00157                                                          RowSymPacked,
00158                                                          Allocator>& A);
00159     template<class T0>
00160     Matrix<T, Prop, RowSymPacked, Allocator>& operator*= (const T0& x);
00161     void Resize(int i, int j);
00162   };
00163 
00164 
00165 } // namespace Seldon.
00166 
00167 #define SELDON_FILE_MATRIX_SYMPACKED_HXX
00168 #endif