00001 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 00002 /* ******** *** SparseLib++ */ 00003 /* ******* ** *** *** *** */ 00004 /* ***** *** ******** ******** */ 00005 /* ***** *** ******** ******** R. Pozo */ 00006 /* ** ******* *** ** *** *** K. Remington */ 00007 /* ******** ******** A. Lumsdaine */ 00008 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 00009 /* */ 00010 /* */ 00011 /* SparseLib++ : Sparse Matrix Library */ 00012 /* */ 00013 /* National Institute of Standards and Technology */ 00014 /* University of Notre Dame */ 00015 /* Authors: R. Pozo, K. Remington, A. Lumsdaine */ 00016 /* */ 00017 /* NOTICE */ 00018 /* */ 00019 /* Permission to use, copy, modify, and distribute this software and */ 00020 /* its documentation for any purpose and without fee is hereby granted */ 00021 /* provided that the above notice appear in all copies and supporting */ 00022 /* documentation. */ 00023 /* */ 00024 /* Neither the Institutions (National Institute of Standards and Technology, */ 00025 /* University of Notre Dame) nor the Authors make any representations about */ 00026 /* the suitability of this software for any purpose. This software is */ 00027 /* provided ``as is'' without expressed or implied warranty. */ 00028 /* */ 00029 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 00030 00031 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 00032 /* Coordinate Sparse Matrix (0-based, Fortran) */ 00033 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 00034 00035 // Note A.(i,j) will return 0.0 if not in A, but A.set(i,j) will throw 00036 // an exception, because A's size cannot grow... 00037 00038 00039 #ifndef Coord_Mat_double_H 00040 #define Coord_Mat_double_H 00041 00042 #include "vecdefs.h" 00043 #include VECTOR_H 00044 00045 class CompCol_Mat_double; 00046 class CompRow_Mat_double; 00047 00048 class Coord_Mat_double { 00049 00050 private: 00051 VECTOR_double val_; // data values (nz_ elements) 00052 VECTOR_int rowind_; // row_ind (nz_ elements) 00053 VECTOR_int colind_; // col_ind (nz_ elements) 00054 00055 int base_; // index base: not used.... 00056 int nz_; // number of nonzeros 00057 int dim_[2]; // number of rows, cols 00058 00059 public: 00060 Coord_Mat_double(void); 00061 Coord_Mat_double(const Coord_Mat_double &S); 00062 Coord_Mat_double(int M, int N, int nz, double *val, int *r, 00063 int *c, int base=0); 00064 Coord_Mat_double(const CompCol_Mat_double &C); 00065 Coord_Mat_double(const CompRow_Mat_double &R); 00066 ~Coord_Mat_double() {}; 00067 00068 /*******************************/ 00069 /* Access and info functions */ 00070 /*******************************/ 00071 00072 double& val(int i) { return val_(i); } 00073 int& row_ind(int i) { return rowind_(i); } 00074 int& col_ind(int i) { return colind_(i);} 00075 00076 const double& val(int i) const { return val_(i); } 00077 const int& row_ind(int i) const { return rowind_(i); } 00078 const int& col_ind(int i) const { return colind_(i);} 00079 00080 int dim(int i) const {return dim_[i];}; 00081 int size(int i) const {return dim_[i];}; 00082 int NumNonzeros() const {return nz_;}; 00083 int base() const {return base_;} 00084 00085 /*******************************/ 00086 /* Assignment operator */ 00087 /*******************************/ 00088 00089 Coord_Mat_double& operator=(const Coord_Mat_double &C); 00090 Coord_Mat_double& newsize(int M, int N, int nz); 00091 00092 /***********************************/ 00093 /* General access function (slow) */ 00094 /***********************************/ 00095 00096 double operator() (int i, int j) const; 00097 double& set(int i, int j); 00098 00099 /***********************************/ 00100 /* Matrix/Vector multiply */ 00101 /***********************************/ 00102 00103 VECTOR_double operator*(const VECTOR_double &x) const; 00104 VECTOR_double trans_mult(const VECTOR_double &x) const; 00105 00106 00107 }; 00108 00109 #endif 00110 /* Coord_Mat_double_H */ 00111 00112 std::ostream& operator << (std::ostream & os, const Coord_Mat_double & mat);