OrthonormalSequence.h
Go to the documentation of this file.
1 /* Copyright 2020-2021 CNRS-AIST JRL */
2 
3 #pragma once
4 
5 #include <vector>
6 
7 #include <Eigen/Householder>
8 #include <Eigen/Jacobi>
9 
10 #include <jrl-qp/api.h>
11 #include <jrl-qp/defs.h>
14 
15 namespace jrl::qp::internal
16 {
17 enum class OSeqType
18 {
20  Givens,
22 };
23 
28 {
29 public:
30  ElemOrthonormalSequence(OSeqType type, int n, int size);
31 
33  template<typename VectorType, typename CoeffType>
34  void add(const Eigen::HouseholderSequence<VectorType, CoeffType> & Q);
36  void add(const Givens & Q);
38  void add(const VectorConstRef & essential, double tau);
39 
40  void applyToTheLeft(VectorRef v, int start, int size) const;
41  void applyTransposeToTheLeft(VectorRef v, int start, int size) const;
42 
43  OSeqType type() const
44  {
45  return type_;
46  }
47 
48  int n() const
49  {
50  return n_;
51  }
52 
53  int size() const
54  {
55  return size_;
56  }
57 
58  bool full() const
59  {
60  return size_ >= n_ - 1;
61  }
62 
63  // For debug purpose
64  Eigen::MatrixXd toDense() const;
65 
66 private:
67  OSeqType type_;
68  int n_; // Size of the matrix represented by the sequence
69  int size_; // Number of elementary transformation
70  Workspace<> work1_;
71  Workspace<> work2_;
72  Workspace<> tmp_;
73 };
74 
76 {
77 public:
78  OrthonormalSequence(int n = 0);
79 
81  void add(int start, const Givens & Q);
83  void add(int start, const VectorConstRef & essential, double tau);
84 
85  void prepare(OSeqType type, int n, int seqSize);
86 
87  void clear();
88  void resize(int n);
89 
90  int size() const;
91 
92  void applyToTheLeft(VectorRef v) const;
93  void applyTransposeToTheLeft(VectorRef v) const;
94 
95  void applyToTheLeft(VectorRef v, const SingleNZSegmentVector & in) const;
96  void applyTransposeToTheLeft(VectorRef out, const SingleNZSegmentVector & in) const;
97 
98 private:
99  struct EmbeddedSeq
100  {
101  EmbeddedSeq(int start, OSeqType type, int n, int size) : start(start), H(type, n, size) {}
102  int start;
104  };
105 
106  int n_; // Size of the matrix represented by the sequence.
107  std::vector<EmbeddedSeq> seq_;
108 };
109 
112 {
113 public:
114  PartitionnedQ() = default;
115  PartitionnedQ(const OrthonormalSequence & Q, const int & m1) : Q_(&Q), m1_(&m1) {}
116 
117  const OrthonormalSequence & Q() const
118  {
119  return *Q_;
120  }
121 
122  int m1() const
123  {
124  return *m1_;
125  }
126 
127  int m2() const
128  {
129  return Q_->size() - *m1_;
130  }
131 
132  void reset()
133  {
134  Q_ = nullptr;
135  m1_ = nullptr;
136  }
137 
138 private:
139  const OrthonormalSequence * Q_ = nullptr;
140  const int * m1_ = nullptr;
141 };
142 
143 template<typename VectorType, typename CoeffType>
144 inline void ElemOrthonormalSequence::add(const Eigen::HouseholderSequence<VectorType, CoeffType> & Q)
145 {
146 }
147 } // namespace jrl::qp::internal
Workspace.h
jrl::qp::internal::ElemOrthonormalSequence::full
bool full() const
Definition: OrthonormalSequence.h:58
jrl::qp::internal::Workspace
Definition: Workspace.h:18
jrl::qp::internal::OSeqType
OSeqType
Definition: OrthonormalSequence.h:17
jrl::qp::internal::ElemOrthonormalSequence::size
int size() const
Definition: OrthonormalSequence.h:53
jrl::qp::internal::ElemOrthonormalSequence
Definition: OrthonormalSequence.h:27
jrl::qp::internal::OSeqType::Householder
@ Householder
jrl::qp::internal::ElemOrthonormalSequence::type
OSeqType type() const
Definition: OrthonormalSequence.h:43
jrl::qp::internal::OSeqType::Givens
@ Givens
jrl::qp::VectorConstRef
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
Definition: defs.h:13
jrl::qp::internal::PartitionnedQ::m1
int m1() const
Definition: OrthonormalSequence.h:122
jrl::qp::internal::PartitionnedQ::reset
void reset()
Definition: OrthonormalSequence.h:132
SingleNZSegmentVector.h
jrl::qp::internal
Definition: ActiveSet.h:11
jrl::qp::internal::PartitionnedQ
Definition: OrthonormalSequence.h:111
jrl::qp::internal::OrthonormalSequence
Definition: OrthonormalSequence.h:75
jrl::qp::internal::PartitionnedQ::Q
const OrthonormalSequence & Q() const
Definition: OrthonormalSequence.h:117
jrl::qp::internal::OSeqType::Permutation
@ Permutation
jrl::qp::internal::ElemOrthonormalSequence::add
void add(const Eigen::HouseholderSequence< VectorType, CoeffType > &Q)
Definition: OrthonormalSequence.h:144
JRLQP_DLLAPI
#define JRLQP_DLLAPI
Definition: api.h:35
jrl::qp::internal::PartitionnedQ::m2
int m2() const
Definition: OrthonormalSequence.h:127
jrl::qp::internal::SingleNZSegmentVector
Definition: SingleNZSegmentVector.h:10
defs.h
jrl::qp::Givens
Eigen::JacobiRotation< double > Givens
Definition: defs.h:18
jrl::qp::VectorRef
Eigen::Ref< Eigen::VectorXd > VectorRef
Definition: defs.h:14
jrl::qp::internal::PartitionnedQ::PartitionnedQ
PartitionnedQ(const OrthonormalSequence &Q, const int &m1)
Definition: OrthonormalSequence.h:115
jrl::qp::internal::ElemOrthonormalSequence::n
int n() const
Definition: OrthonormalSequence.h:48
api.h