00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SPARSEMATRIX_H_
00015 #define SPARSEMATRIX_H_
00016
00021 template <class T>
00022 class SparseMatrix {
00023 public:
00024 SparseMatrix();
00029 SparseMatrix(int rows, int cols);
00030
00039 SparseMatrix(int *nzRows, int *nzCols, T *nz, int rows, int cols, int nnz);
00040 virtual ~SparseMatrix();
00041
00046 int* getRows();
00047
00052 int* getCols();
00053
00058 int getRowCount();
00059
00064 int getColCount();
00065
00070 int getNNz();
00071
00076 T * getVals();
00077
00078 private:
00079 int * nzrows;
00080 int * nzcols;
00081 int rows;
00082 int cols;
00083 int nnz;
00084 T * nonzeros;
00085 };
00086
00087
00088 template<class T> SparseMatrix<T>::SparseMatrix() {
00089 }
00090
00091
00092
00093 template<class T> SparseMatrix<T>::SparseMatrix(int r, int c) {
00094 rows = r;
00095 cols = c;
00096 }
00097
00098 template<class T> SparseMatrix<T>::SparseMatrix(int *nzRows, int *nzCols, T *nz, int r, int c, int n) {
00099 nzrows = nzRows;
00100 nzcols = nzCols;
00101 nonzeros = nz;
00102 rows = r;
00103 cols = c;
00104 nnz = n;
00105 }
00106
00107
00108
00109 template<class T> SparseMatrix<T>::~SparseMatrix() {
00110 delete[](nzrows);
00111 delete[](nzcols);
00112 delete[](nonzeros);
00113 }
00114
00115 template<class T> int SparseMatrix<T>::getRowCount() {
00116 return rows;
00117 }
00118
00119 template<class T> int SparseMatrix<T>::getColCount() {
00120 return cols;
00121 }
00122
00123 template<class T> int SparseMatrix<T>::getNNz() {
00124 return nnz;
00125 }
00126
00127
00128 template<class T> int *SparseMatrix<T>::getRows() {
00129 return nzrows;
00130 }
00131
00132
00133
00134 template<class T> int *SparseMatrix<T>::getCols() {
00135 return nzcols;
00136 }
00137
00138
00139 template<class T> T *SparseMatrix<T>::getVals() {
00140 return nonzeros;
00141 }
00142
00143 #endif