GMSparse2.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * @file GMSparse2.h
  3. * @brief Sparse Matrix depends on SparseVectors
  4. * @author Björn Fröhlich
  5. * @date 05/14/2009
  6. */
  7. #ifndef GMSPARSE2INCLUDE
  8. #define GMSPARSE2INCLUDE
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "vislearning/math/algebra/GenericMatrix.h"
  12. namespace OBJREC {
  13. class GMSparse2 : public GenericMatrix
  14. {
  15. protected:
  16. //! the sparse matrix
  17. std::vector<NICE::SparseVector*> A;
  18. //! count of rows
  19. uint m_rows;
  20. //! count of columns
  21. uint m_cols;
  22. //! are the vectors new ones or came they from somewhere else
  23. bool newvectors;
  24. public:
  25. /**
  26. * simple constructor -> does nothing
  27. */
  28. GMSparse2(){resize(0,0);};
  29. /**
  30. * constructor which set the rows and cols of the SparseMatrix
  31. * @param _rows
  32. * @param _cols
  33. */
  34. GMSparse2 ( uint _rows, uint _cols );
  35. /**
  36. * converts an ICE::Matrix to a sparse matrix
  37. * @param A input ICE::Matrix
  38. * @param epsilon tolerance value
  39. */
  40. GMSparse2 ( const NICE::Matrix & iceA, double epsilon = 1e-9 );
  41. /**
  42. * simple destructor
  43. */
  44. ~GMSparse2();
  45. /**
  46. * resize the matrix
  47. * @param _rows new count of rows
  48. * @param _cols new count of cols
  49. */
  50. void resize( int _rows, int _cols);
  51. /**
  52. * clean up
  53. */
  54. void clear();
  55. /** get the number of rows in A */
  56. uint rows() const { return m_rows; };
  57. /** get the number of columns in A */
  58. uint cols() const { return m_cols; };
  59. /** multiply with a vector: A*x = y */
  60. void multiply ( NICE::Vector & y, const NICE::Vector & x ) const;
  61. /**
  62. * return the i-th row
  63. * @param i
  64. * @return SparseVector at row i
  65. */
  66. NICE::SparseVector & operator[](int i) const;
  67. /**
  68. * restore the information of the sparse matrix
  69. * @param is inputstream
  70. * @param format
  71. */
  72. void restore (std::istream & is, int format = 0);
  73. /**
  74. * store the information of the sparse matrix
  75. * @param os outputstream
  76. * @param format
  77. */
  78. void store (std::ostream & os, int format = 0) const;
  79. /**
  80. * Should the data be deleted when the destructor is called
  81. * @param del
  82. */
  83. void setDel(bool del = true);
  84. /**
  85. * add a new row
  86. * @param x ICE::Vector
  87. */
  88. void addRow(const NICE::Vector &x);
  89. /**
  90. * add a new row
  91. * @param x SparseVector
  92. */
  93. void addRow(NICE::SparseVector *x);
  94. /**
  95. * matrixmultiplication x*y = out
  96. * @param y input
  97. * @param out output
  98. * @param transpx use the transpose of x
  99. * @param transpy use the transpose of y
  100. * @return z
  101. */
  102. void mult(GMSparse2 &y, GMSparse2 & out, bool transpx = false, bool transpy = false);
  103. /**
  104. * matrixmultiplication x*y = out
  105. * @param y input Sparse Vector
  106. * @param out output
  107. * @param transpx use the transpose of x
  108. * @param transpy use the transpose of y
  109. * @return z
  110. */
  111. void mult(NICE::SparseVector &y, GMSparse2 & out, bool transpx = false, bool transpy = false);
  112. /**
  113. * same like mult, but faster when y ist very sparse and slower if not
  114. * @param y input
  115. * @param out output
  116. * @param transpx use the transpose of x
  117. * @param transpy use the transpose of y
  118. * @return z
  119. */
  120. void mult2(GMSparse2 &y, GMSparse2 & out, bool transpx = false, bool transpy = false);
  121. };
  122. } // namespace
  123. #endif