00001 //=========================================================================== 00002 // GoTools - SINTEF Geometry Tools version 1.1 00003 // 00004 // GoTools module: parametrization 00005 // 00006 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation version 2 of the License. 00011 // 00012 // This program 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 for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 00020 // 59 Temple Place - Suite 330, 00021 // Boston, MA 02111-1307, USA. 00022 // 00023 // Contact information: E-mail: tor.dokken@sintef.no 00024 // SINTEF ICT, Department of Applied Mathematics, 00025 // P.O. Box 124 Blindern, 00026 // 0314 Oslo, Norway. 00027 // 00028 // Other licenses are also available for this software, notably licenses 00029 // for: 00030 // - Building commercial software. 00031 // - Building software whose source code you wish to keep private. 00032 //=========================================================================== 00033 #ifndef PRMATSPARSE_H 00034 #define PRMATSPARSE_H 00035 00036 #include "PrMatrix.h" 00037 #include "errormacros.h" 00038 #include <vector> 00039 00040 /*<PrMatSparse-syntax: */ 00041 00042 class PrMatSparse : public PrMatrix 00043 { 00044 private: 00045 int m_, n_; // matrix dimensions 00046 int p_; // number of non-zeros 00047 std::vector<int> irow_; // the indexes in a_ and jcol_ of the 00048 // first non-zeros of the m rows 00049 std::vector<int> jcol_; // the p indexes j of the non-zero elements 00050 std::vector<double> a_; // the p non-zero elements 00051 00052 00053 public: 00054 00057 virtual int rows() const; 00058 virtual int colmns() const; 00059 virtual double operator () (int i, int j) const; 00061 virtual void prod(const PrVec& x, PrVec& y) const; 00062 virtual void print(std::ostream& os); 00063 virtual void read(std::istream& is); 00065 virtual ~PrMatSparse(); 00067 00070 00071 00072 00073 void matProd(PrMatSparse& B, PrMatSparse& C) const; 00075 void scalProd(double d); 00077 void printFull(std::ostream& os); 00078 00080 PrMatSparse() : m_(0), n_(0), p_(0) {} 00082 PrMatSparse(int m, int n, int num_nonzero); 00084 PrMatSparse(int m, int n, int num_nonzero, 00085 const int* irow, const int* jcol, const double* data); 00087 void redim(int m, int n, int num_nonzero); 00089 void setToMatrix(const PrMatrix& m, double tol = 0.0); 00090 00092 int& irow(int k); 00094 const int& irow(int k) const; 00096 int& jcol(int k); 00098 const int& jcol(int k) const; 00100 double& operator () (int k); 00102 const double& operator () (int k) const; 00104 }; 00105 00106 00107 /*>PrMatSparse-syntax: */ 00108 00109 //----------------------------------------------------------------------------- 00110 inline void PrMatSparse::scalProd(double d) 00111 //----------------------------------------------------------------------------- 00112 { 00113 for (std::vector<double>::iterator it = a_.begin(); it != a_.end(); ++it) { 00114 (*it) *= d; 00115 } 00116 } 00117 00118 00119 //----------------------------------------------------------------------------- 00120 inline const int& PrMatSparse::irow(int k) const 00121 //----------------------------------------------------------------------------- 00122 { 00123 return irow_[k]; 00124 } 00125 00126 //----------------------------------------------------------------------------- 00127 inline int& PrMatSparse::irow(int k) 00128 //----------------------------------------------------------------------------- 00129 { 00130 return irow_[k]; 00131 } 00132 00133 //----------------------------------------------------------------------------- 00134 inline const int& PrMatSparse::jcol(int k) const 00135 //----------------------------------------------------------------------------- 00136 { 00137 return jcol_[k]; 00138 } 00139 00140 //----------------------------------------------------------------------------- 00141 inline int& PrMatSparse::jcol(int k) 00142 //----------------------------------------------------------------------------- 00143 { 00144 return jcol_[k]; 00145 } 00146 00147 //----------------------------------------------------------------------------- 00148 inline const double& PrMatSparse::operator() (int k) const 00149 //----------------------------------------------------------------------------- 00150 { 00151 return a_[k]; 00152 } 00153 00154 //----------------------------------------------------------------------------- 00155 inline double& PrMatSparse::operator() (int k) 00156 //----------------------------------------------------------------------------- 00157 { 00158 return a_[k]; 00159 } 00160 00161 /*Class:PrMatSparse 00162 00163 Name: PrMatSparse 00164 Syntax: @PrMatSparse-syntax 00165 Keywords: 00166 Description: This class implements a matrix 00167 Member functions: 00168 00169 Constructors: 00170 Files: 00171 Example: 00172 00173 See also: 00174 Developed by: SINTEF Applied Mathematics, Oslo, Norway 00175 Author: Michael Floater, SINTEF 00176 Date: Dec. 98 00177 */ 00178 00179 #endif // PRMATSPARSE_H 00180 00181 00182 00183 00184