# shogun-toolbox/shogun

added sparse-matrix linear operator in log-det framework

 @@ -66,6 +66,20 @@ template class SGSparseMatrix : public SGReferencedData return *this; } /* compute sparse-matrix dense-vector multiplication * @param v the dense-vector to be multiplied with * @return the result vector \f$Q*v\f$, Q being this sparse matrix */ const SGVector operator*(SGVector v) const { SGVector result(num_vectors); ASSERT(v.vlen==num_features); for (index_t i=0; i
 @@ -0,0 +1,87 @@ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Written (W) 2013 Soumyajit De */ #ifndef SPARSE_MATRIX_OPERATOR_H_ #define SPARSE_MATRIX_OPERATOR_H_ #include #include namespace shogun { template class SGVector; template class SGSparseMatrix; /** @brief Class that represents a sparse-matrix linear operator. * It computes matrix-vector product \f$Ax\f$ in its apply method, * \f$A\in\mathbb{C}^{m\times n},A:\mathbb{C}^{n}\rightarrow \mathbb{C}^{m}\f$ * being the matrix operator and \f$x\in\mathbb{C}^{n}\f$ being the vector. * The result is a vector \f$y\in\mathbb{C}^{m}\f$. */ template class CSparseMatrixOperator : public CMatrixOperator { /** this class has support for complex64_t */ typedef bool supports_complex64_t; public: /** default constructor */ CSparseMatrixOperator(); /** * constructor * * @param op the sparse matrix to be used as the linear operator */ CSparseMatrixOperator(SGSparseMatrix op); /** destructor */ ~CSparseMatrixOperator(); /** * method that applies the sparse-matrix linear operator to a vector * * @param b the vector to which the linear operator applies * @return the result vector */ virtual SGVector apply(SGVector b) const; /** * method that sets the main diagonal of the matrix * * @param diag the diagonal to be set */ virtual void set_diagonal(SGVector diag); /** * method that returns the main diagonal of the matrix * * @return the diagonal */ virtual SGVector get_diagonal() const; /** @return the sparse matrix operator */ SGSparseMatrix get_matrix_operator() const; /** @return object name */ virtual const char* get_name() const { return "SparseMatrixOperator"; } private: /** the sparse matrix operator */ SGSparseMatrix m_operator; /** initialize with default values and register params */ void init(); }; } #endif // SPARSE_MATRIX_OPERATOR_H_