SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseMatrixOperator.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Soumyajit De
8  */
9 
10 #ifndef DENSE_MATRIX_OPERATOR_H_
11 #define DENSE_MATRIX_OPERATOR_H_
12 
13 #include <shogun/lib/config.h>
14 
15 #ifdef HAVE_EIGEN3
17 
18 namespace shogun
19 {
20 template<class T> class SGVector;
21 template<class T> class SGMatrix;
22 
29 template<class T> class CDenseMatrixOperator : public CMatrixOperator<T>
30 {
32 typedef bool supports_complex128_t;
33 
34 public:
37 
43  explicit CDenseMatrixOperator(SGMatrix<T> op);
44 
51 
54 
61  virtual SGVector<T> apply(SGVector<T> b) const;
62 
68  virtual void set_diagonal(SGVector<T> diag);
69 
75  virtual SGVector<T> get_diagonal() const;
76 
79 
83  template<class Scalar>
84  inline operator CDenseMatrixOperator<Scalar>*() const
85  {
86  REQUIRE(m_operator.matrix, "Matrix is not initialized!\n");
87 
88  SGMatrix<Scalar> casted_m(m_operator.num_rows, m_operator.num_cols);
89  for (index_t i=0; i<m_operator.num_cols; ++i)
90  {
91  for (index_t j=0; j<m_operator.num_rows; ++j)
92  casted_m(j,i)=static_cast<Scalar>(m_operator(j,i));
93  }
94  SG_SDEBUG("DenseMatrixOperator::static_cast(): Creating casted operator!\n");
95 
96  return new CDenseMatrixOperator<Scalar>(casted_m);
97  }
98 
100  virtual const char* get_name() const
101  {
102  return "DenseMatrixOperator";
103  }
104 
105 private:
107  SGMatrix<T> m_operator;
108 
110  void init();
111 
112 };
113 
114 }
115 
116 #endif // HAVE_EIGEN3
117 #endif // DENSE_MATRIX_OPERATOR_H_

SHOGUN Machine Learning Toolbox - Documentation