Advertisement
miki_brill

Untitled

Jan 4th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. #ifndef SPARSE_H_
  2. #define SPARSE_H_
  3. #include <iostream>
  4. #include <cmath>
  5. #include <vector>
  6. using std::vector;
  7.  
  8. namespace mtm{
  9. typedef double T;
  10.  
  11. //template <class T>
  12. class rowVecItem{
  13. int index;
  14. T val;
  15. public:
  16. T& get();
  17. friend class rowVec;
  18. };
  19.  
  20. //////////////////funcs of class rowVecItem/////////////////////////////////////
  21. T& rowVecItem::get(){
  22. return val;
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////
  25.  
  26. //template <class T>
  27. class rowVec{
  28. int index;
  29. vector <rowVecItem> all_row_items;
  30. public:
  31. vector <rowVecItem>::iterator begin();
  32. vector <rowVecItem>::iterator end();
  33. rowVecItem& at(int index);
  34. const rowVecItem& at(int index) const;
  35. vector <rowVecItem>& get();
  36. friend class SparseMatrix;
  37. };
  38.  
  39. ///////////////////////funcs of class rowVec////////////////////////////////////
  40. vector <rowVecItem>& rowVec::get(){
  41. return all_row_items;
  42. }
  43.  
  44. vector <rowVecItem>::iterator rowVec::begin(){
  45. return all_row_items.begin();
  46. }
  47.  
  48. vector <rowVecItem>::iterator rowVec::end(){
  49. return all_row_items.end();
  50. }
  51.  
  52. rowVecItem& rowVec::at(int index){
  53. return all_row_items.at(index);
  54. }
  55.  
  56. const rowVecItem& rowVec::at(int index) const{
  57. return all_row_items.at(index);
  58. }
  59. ////////////////////////////////////////////////////////////////////////////////
  60.  
  61. //template <class T>
  62. class SparseMatrix{
  63. int max_rows;
  64. int max_cols;
  65. vector <rowVec> sparse_mat_vec;
  66. public:
  67. typedef vector <rowVec>::const_iterator row_const_iterator;
  68. SparseMatrix(int rows, int cols);
  69. SparseMatrix(const SparseMatrix& sm);
  70. ~SparseMatrix();
  71. int get_row_count() const;
  72. int get_col_count() const;
  73. int get_non_zero_cells();
  74. void iterate_non_zero_row_vals();
  75. //T& operator()(int row, int col); // reading+writing.
  76. //const T operator()(int row, int col) const; // reading only.
  77. SparseMatrix& operator+=(const SparseMatrix& sm);
  78. vector <rowVec>::iterator begin();
  79. vector <rowVec>::iterator end();
  80. rowVec& at(int index);
  81. const rowVec& at(int index) const;
  82.  
  83. };
  84.  
  85. SparseMatrix operator+(const SparseMatrix& sm1, const SparseMatrix& sm2);
  86. SparseMatrix operator*(const SparseMatrix& sm1, const SparseMatrix& sm2);
  87.  
  88. ///////////////////////funcs of class rowVec////////////////////////////////////
  89. //NOT COMPLETED
  90. SparseMatrix::~SparseMatrix(){
  91.  
  92. }
  93.  
  94. vector <rowVec>::iterator SparseMatrix::begin(){
  95. return sparse_mat_vec.begin();
  96. }
  97.  
  98. vector <rowVec>::iterator SparseMatrix::end(){
  99. return sparse_mat_vec.end();
  100. }
  101.  
  102. rowVec& SparseMatrix::at(int index){
  103. return sparse_mat_vec.at(index);
  104. }
  105.  
  106. const rowVec& SparseMatrix::at(int index) const{
  107. return sparse_mat_vec.at(index);
  108. }
  109.  
  110. //NOT COMPLETED
  111. SparseMatrix::SparseMatrix(const SparseMatrix& sm){
  112. max_rows = sm.get_row_count();
  113. max_cols = sm.get_col_count();
  114. }
  115.  
  116. int SparseMatrix::get_row_count() const{
  117. return max_rows;
  118. }
  119.  
  120. int SparseMatrix::get_col_count() const{
  121. return max_cols;
  122. }
  123.  
  124. SparseMatrix::SparseMatrix(int rows, int cols): max_rows(rows), max_cols(cols){
  125. vector<rowVec> sparseMatVec();
  126. }
  127.  
  128. /*int sparseMatrix::get_non_zero_cells(){
  129. int count=0;
  130. int row=0;
  131. for(vector<rowVec>::iterator i = sparseMatVec.begin();
  132. i != sparseMatVec.end(); ++i) {
  133. for(vector<rowVecItem>::iterator i = rowVec::allRowItems.begin();
  134. i != rowVec::allRowItems.end(); ++i) {
  135. }
  136. row=0;
  137. }
  138. return count;
  139. }*/
  140. ////////////////////////////////////////////////////////////////////////////////
  141. }
  142. /*
  143. template <class T>
  144. class rowVecItem{
  145. int col;
  146. T val;
  147. };
  148. template <class T>
  149. class rowVec{
  150. //typedef ___ iterator; - public/private
  151. int row;
  152. vector <rowVecItem<T> > allRowItems;
  153. };
  154. template <class T>
  155. class sparseMatrix{
  156. // iterator - public/private
  157. vector <rowVec<T> > sparseMatVec;
  158. };
  159. */
  160. #endif /* SPARSE_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement