/** * @file GenericMatrix.h * @brief matrix interface for indirect matrix multiplications * @author Erik Rodner * @date 05/14/2009 */ #ifndef GENERICMATRIXINCLUDE #define GENERICMATRIXINCLUDE #include "core/basics/triplet.h" #include "AlgebraTools.h" #include "core/vector/SparseVector.h" namespace OBJREC { /** matrix interface for indirect matrix multiplications */ class GenericMatrix { protected: public: /** multiply with a vector: A*x = y */ virtual void multiply ( NICE::Vector & y, const NICE::Vector & x ) const = 0; /** get the number of rows in A */ virtual uint rows() const = 0; /** get the number of columns in A */ virtual uint cols() const = 0; /** simple destructor */ virtual ~GenericMatrix() {}; }; class GMSlowICE : public GenericMatrix { protected: NICE::Matrix A; public: GMSlowICE ( const NICE::Matrix & _A ) : A(_A) {}; /** get the number of rows in A */ uint rows() const { return A.rows(); }; /** get the number of columns in A */ uint cols() const { return A.cols(); }; /** multiply with a vector: A*x = y */ void multiply ( NICE::Vector & y, const NICE::Vector & x ) const { y.multiply ( A, x ); }; }; class GMSparse : public GenericMatrix { protected: std::vector< NICE::triplet > A; uint m_rows; uint m_cols; public: GMSparse ( uint _rows, uint _cols ) : m_rows(_rows), m_cols(_cols) {} GMSparse ( const NICE::Matrix & A, double epsilon = 1e-9 ); /** get the number of rows in A */ uint rows() const { return m_rows; }; /** get the number of columns in A */ uint cols() const { return m_cols; }; /** multiply with a vector: A*x = y */ void multiply ( NICE::Vector & y, const NICE::Vector & x ) const; }; class GMCovariance : public GenericMatrix { protected: const NICE::Matrix *data; uint m_rows; uint m_cols; public: GMCovariance ( const NICE::Matrix *data ); /** get the number of rows in A */ uint rows() const { return m_rows; }; /** get the number of columns in A */ uint cols() const { return m_cols; }; /** multiply with a vector: A*x = y */ void multiply ( NICE::Vector & y, const NICE::Vector & x ) const; }; } // namespace #endif