GenericMatrix.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file GenericMatrix.h
  3. * @brief matrix interface for indirect matrix multiplications
  4. * @author Erik Rodner
  5. * @date 05/14/2009
  6. */
  7. #ifndef GENERICMATRIXINCLUDE
  8. #define GENERICMATRIXINCLUDE
  9. #include "core/basics/triplet.h"
  10. #include "AlgebraTools.h"
  11. #include "core/vector/SparseVector.h"
  12. namespace OBJREC {
  13. /** matrix interface for indirect matrix multiplications */
  14. class GenericMatrix
  15. {
  16. protected:
  17. public:
  18. /** multiply with a vector: A*x = y */
  19. virtual void multiply ( NICE::Vector & y, const NICE::Vector & x ) const = 0;
  20. /** get the number of rows in A */
  21. virtual uint rows() const = 0;
  22. /** get the number of columns in A */
  23. virtual uint cols() const = 0;
  24. /** simple destructor */
  25. virtual ~GenericMatrix() {};
  26. };
  27. class GMSlowICE : public GenericMatrix
  28. {
  29. protected:
  30. NICE::Matrix A;
  31. public:
  32. GMSlowICE ( const NICE::Matrix & _A ) : A(_A) {};
  33. /** get the number of rows in A */
  34. uint rows() const { return A.rows(); };
  35. /** get the number of columns in A */
  36. uint cols() const { return A.cols(); };
  37. /** multiply with a vector: A*x = y */
  38. void multiply ( NICE::Vector & y, const NICE::Vector & x ) const
  39. { y.multiply ( A, x ); };
  40. };
  41. class GMSparse : public GenericMatrix
  42. {
  43. protected:
  44. std::vector< NICE::triplet<int, int, double> > A;
  45. uint m_rows;
  46. uint m_cols;
  47. public:
  48. GMSparse ( uint _rows, uint _cols ) : m_rows(_rows), m_cols(_cols) {}
  49. GMSparse ( const NICE::Matrix & A, double epsilon = 1e-9 );
  50. /** get the number of rows in A */
  51. uint rows() const { return m_rows; };
  52. /** get the number of columns in A */
  53. uint cols() const { return m_cols; };
  54. /** multiply with a vector: A*x = y */
  55. void multiply ( NICE::Vector & y, const NICE::Vector & x ) const;
  56. };
  57. class GMCovariance : public GenericMatrix
  58. {
  59. protected:
  60. const NICE::Matrix *data;
  61. uint m_rows;
  62. uint m_cols;
  63. public:
  64. GMCovariance ( const NICE::Matrix *data );
  65. /** get the number of rows in A */
  66. uint rows() const { return m_rows; };
  67. /** get the number of columns in A */
  68. uint cols() const { return m_cols; };
  69. /** multiply with a vector: A*x = y */
  70. void multiply ( NICE::Vector & y, const NICE::Vector & x ) const;
  71. };
  72. } // namespace
  73. #endif