Kernel Quantum Probability Library
The KQP library aims at providing tools for working with quantums probabilities
generic.hpp
1 /*
2  This file is part of the Kernel Quantum Probability library (KQP).
3 
4  KQP is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  KQP is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with KQP. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __KQP_GENERIC_FEATURE_MATRIX_H__
19 #define __KQP_GENERIC_FEATURE_MATRIX_H__
20 
21 #include <kqp/feature_matrix.hpp>
22 
23 namespace kqp {
24 
25 
31  template <class FVector>
32  class FeatureList : public FeatureMatrix< FeatureList<FVector> > {
33  public:
34  KQP_FMATRIX_COMMON_DEFS(FeatureMatrix<FVector>);
35 
36  FeatureList(Index dimension) : m_dimension(dimension) {}
37 
38 
39 
40  protected:
41  Index _size() const { return this->list.size(); }
42 
43  void _add(const Self &other, std::vector<bool> *which = NULL) {
44  this->list.push_back(f);
45  }
46 
47  const ScalarMatrix &_inner() const {
48  }
49 
50  template<class DerivedMatrix>
51  void _inner(const Self &other, const Eigen::MatrixBase<DerivedMatrix> &result) const {
52  if (result.rows() != _size() || result.cols() != other.size())
53  result.derived().resize(result.rows(), result.cols());
54  }
55 
56  // Computes alpha * X * A + beta * Y * B (X = *this)
57  Self _linear_combination(const ScalarAltMatrix &mA, Scalar alpha, const Self *mY, const ScalarAltMatrix *mB, Scalar beta) const {
58  }
59 
60  void _subset(const std::vector<bool>::const_iterator &begin, const std::vector<bool>::const_iterator &end, Self &into) const {
61  }
62 
63  private:
65  mutable ScalarMatrix m_gramMatrix;
66 
68  std::vector<FVector> m_list;
69 
71  Index m_dimension;
72  };
73 
74 
75  // Informations about the generic feature matrix
76  template <typename FVector> struct FeatureMatrixTypes<FVector> {
77  typedef FVector::Scalar Scalar;
78  enum {
79  can_linearly_combine = FVector::can_linearly_combine
80  };
81  };
82 
83 
85  template<typename _Scalar, bool _can_linearly_combine>
86  struct GenericVector<Scalar> {
87  typedef _Scalar Scalar;
88  enum {
89  can_linearly_combine = _can_linearly_combine;
90  }
91 
92  virtual Scalar inner() = 0;
93  virtual Scalar inner(const GenericVector<Scalar> &other) = 0;
94  };
95 
96  template<Scalar>
97  inline Scalar inner(const GenericVector<Scalar> &a, const GenericVector<Scalar> &b) {
98  return a.inner(b);
99  }
100 
101  template<Scalar>
102  inline Scalar inner(GenericVector<Scalar> &a) {
103  return a.inner();
104  }
105 
106 } // end namespace kqp
107 
108 #endif