GMSparse2.h 3.3 KB

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