Main Page | User's Guide | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

Matrix_Sparse.hxx

00001 // Copyright (C) 2001-2004 Vivien Mallet
00002 //
00003 // This file is part of Seldon library.
00004 // Seldon library provides matrices and vectors structures for
00005 // linear algebra.
00006 // 
00007 // Seldon is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 // 
00012 // Seldon is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License (file "license") for more details.
00016 //
00017 // For more information, please see the Seldon home page:
00018 //     http://spacetown.free.fr/lib/seldon/
00019 
00020 // To be included by Seldon.hxx
00021 
00022 #ifndef SELDON_FILE_MATRIX_SPARSE_HXX
00023 
00024 #include "../Common/Common.hxx"
00025 #include "../Common/Properties.hxx"
00026 #include "../Common/Storage.hxx"
00027 #include "../Common/Errors.cxx"
00028 #include "../Common/Allocator.hxx"
00029 
00030 namespace Seldon
00031 {
00032   
00033 
00035 
00042   template <class T, class Prop, class Storage,
00043             class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00044   class Matrix_Sparse: public Spacetown, public Matrix_Base<T, Allocator>
00045   {
00046     // typedef declaration.
00047   public:
00048     typedef typename Allocator::value_type value_type;
00049     typedef typename Allocator::pointer pointer;
00050     typedef typename Allocator::const_pointer const_pointer;
00051     typedef typename Allocator::reference reference;
00052     typedef typename Allocator::const_reference const_reference;
00053 
00054     // Attributes.
00055   protected:
00056     // Number of non-zero elements.
00057     int nz_;
00058     // Index (in data_) of first element stored for each row or column.
00059     int* ptr_;
00060     // Column or row index (in the matrix) each element.
00061     int* ind_;
00062 
00063     // Methods.
00064   public:
00065     // Constructors.
00066     Matrix_Sparse();
00067     Matrix_Sparse(int i, int j);
00068     Matrix_Sparse(int i, int j, int nz);
00069     template <class Storage0, class Allocator0,
00070               class Storage1, class Allocator1,
00071               class Storage2, class Allocator2>
00072     Matrix_Sparse(int i, int j, Vector<T, Storage0, Allocator0>& values,
00073                   Vector<int, Storage1, Allocator1>& ptr,
00074                   Vector<int, Storage2, Allocator2>& ind);
00075     
00076     // Destructor.
00077     ~Matrix_Sparse();
00078     void Clear();
00079 
00080     // Memory management.
00081     template <class Storage0, class Allocator0,
00082               class Storage1, class Allocator1,
00083               class Storage2, class Allocator2>
00084     void SetData(int i, int j,
00085                  Vector<T, Storage0, Allocator0>& values,
00086                  Vector<int, Storage1, Allocator1>& ptr,
00087                  Vector<int, Storage2, Allocator2>& ind);
00088     void SetData(int i, int j, int nz, pointer values, int* ptr, int* ind);
00089 
00090     // Basic methods.
00091     int GetNonZeros() const;
00092     int GetDataSize() const;
00093     int* GetPtr() const;
00094     int* GetInd() const;
00095     int GetPtrSize() const;
00096     int GetIndSize() const;
00097 
00098     // Element acess and affectation.
00099     value_type operator() (int i, int j) const;
00100     
00101     // Convenient functions.
00102     void Print() const;
00103     void SetDiags();
00104   };
00105 
00106 
00108   template <class T, class Prop, class Allocator>
00109   class Matrix<T, Prop, ColSparse, Allocator>:
00110     public Matrix_Sparse<T, Prop, ColSparse, Allocator>
00111   {
00112   public:
00113     Matrix()  throw();
00114     Matrix(int i, int j);
00115     Matrix(int i, int j, int nz);
00116     template <class Storage0, class Allocator0,
00117               class Storage1, class Allocator1,
00118               class Storage2, class Allocator2>
00119     Matrix(int i, int j,
00120            Vector<T, Storage0, Allocator0>& values,
00121            Vector<int, Storage1, Allocator1>& ptr,
00122            Vector<int, Storage2, Allocator2>& ind);
00123   };
00124 
00125 
00127   template <class T, class Prop, class Allocator>
00128   class Matrix<T, Prop, RowSparse, Allocator>:
00129     public Matrix_Sparse<T, Prop, RowSparse, Allocator>
00130   {
00131   public:
00132     Matrix()  throw();
00133     Matrix(int i, int j);
00134     Matrix(int i, int j, int nz);
00135     template <class Storage0, class Allocator0,
00136               class Storage1, class Allocator1,
00137               class Storage2, class Allocator2>
00138     Matrix(int i, int j,
00139            Vector<T, Storage0, Allocator0>& values,
00140            Vector<int, Storage1, Allocator1>& ptr,
00141            Vector<int, Storage2, Allocator2>& ind);
00142   };
00143 
00144 
00145 } // namespace Seldon.
00146 
00147 #define SELDON_FILE_MATRIX_SPARSE_HXX
00148 #endif

Generated on Sun Jan 16 23:37:58 2005 for Multivac by  doxygen 1.4.0