SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2013 Soumyajit De 00008 */ 00009 00010 #ifndef DENSE_MATRIX_OPERATOR_H_ 00011 #define DENSE_MATRIX_OPERATOR_H_ 00012 00013 #include <shogun/lib/config.h> 00014 00015 #ifdef HAVE_EIGEN3 00016 #include <shogun/mathematics/linalg/linop/MatrixOperator.h> 00017 00018 namespace shogun 00019 { 00020 template<class T> class SGVector; 00021 template<class T> class SGMatrix; 00022 00029 template<class T> class CDenseMatrixOperator : public CMatrixOperator<T> 00030 { 00032 typedef bool supports_complex128_t; 00033 00034 public: 00036 CDenseMatrixOperator(); 00037 00043 explicit CDenseMatrixOperator(SGMatrix<T> op); 00044 00050 CDenseMatrixOperator(const CDenseMatrixOperator<T>& orig); 00051 00053 ~CDenseMatrixOperator(); 00054 00061 virtual SGVector<T> apply(SGVector<T> b) const; 00062 00068 virtual void set_diagonal(SGVector<T> diag); 00069 00075 virtual SGVector<T> get_diagonal() const; 00076 00078 SGMatrix<T> get_matrix_operator() const; 00079 00083 template<class Scalar> 00084 inline operator CDenseMatrixOperator<Scalar>*() const 00085 { 00086 REQUIRE(m_operator.matrix, "Matrix is not initialized!\n"); 00087 00088 SGMatrix<Scalar> casted_m(m_operator.num_rows, m_operator.num_cols); 00089 for (index_t i=0; i<m_operator.num_cols; ++i) 00090 { 00091 for (index_t j=0; j<m_operator.num_rows; ++j) 00092 casted_m(j,i)=static_cast<Scalar>(m_operator(j,i)); 00093 } 00094 SG_SDEBUG("DenseMatrixOperator::static_cast(): Creating casted operator!\n"); 00095 00096 return new CDenseMatrixOperator<Scalar>(casted_m); 00097 } 00098 00100 virtual const char* get_name() const 00101 { 00102 return "DenseMatrixOperator"; 00103 } 00104 00105 private: 00107 SGMatrix<T> m_operator; 00108 00110 void init(); 00111 00112 }; 00113 00114 } 00115 00116 #endif // HAVE_EIGEN3 00117 #endif // DENSE_MATRIX_OPERATOR_H_