SingleNZSegmentVector.h
Go to the documentation of this file.
1 /* Copyright 2020-2021 CNRS-AIST JRL */
2 
3 #pragma once
4 
5 #include <jrl-qp/defs.h>
6 
7 namespace jrl::qp::internal
8 {
11 {
12 public:
17  SingleNZSegmentVector(const VectorConstRef & v, int start, int size) : start_(start), size_(size), v_(v)
18  {
19  assert(start >= 0);
20  assert(start + v.size() <= size);
21  }
22 
23  int start() const
24  {
25  return start_;
26  }
27 
28  int end() const
29  {
30  return start_ + static_cast<int>(v_.size());
31  }
32 
33  int size() const
34  {
35  return size_;
36  }
37 
38  const VectorConstRef & nzSegment() const
39  {
40  return v_;
41  }
42 
43  void toFullVector(VectorRef u) const
44  {
45  assert(u.size() == size_);
46  u.head(start_).setZero();
47  u.segment(start_, v_.size()) = v_;
48  u.tail(size_ - v_.size() - start_).setZero();
49  }
50 
51  double dot(const VectorConstRef & u) const
52  {
53  assert(u.size() == size_);
54  return v_.dot(u.segment(start_, v_.size()));
55  }
56 
57 private:
58  int start_;
59  int size_;
60  VectorConstRef v_;
61 };
62 } // namespace jrl::qp::internal
jrl::qp::internal::SingleNZSegmentVector::toFullVector
void toFullVector(VectorRef u) const
Definition: SingleNZSegmentVector.h:43
jrl::qp::internal::SingleNZSegmentVector::nzSegment
const VectorConstRef & nzSegment() const
Definition: SingleNZSegmentVector.h:38
jrl::qp::internal::SingleNZSegmentVector::SingleNZSegmentVector
SingleNZSegmentVector(const VectorConstRef &v, int start, int size)
Definition: SingleNZSegmentVector.h:17
jrl::qp::VectorConstRef
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
Definition: defs.h:13
jrl::qp::internal
Definition: ActiveSet.h:11
jrl::qp::internal::SingleNZSegmentVector::end
int end() const
Definition: SingleNZSegmentVector.h:28
jrl::qp::internal::SingleNZSegmentVector::start
int start() const
Definition: SingleNZSegmentVector.h:23
jrl::qp::internal::SingleNZSegmentVector
Definition: SingleNZSegmentVector.h:10
jrl::qp::internal::SingleNZSegmentVector::dot
double dot(const VectorConstRef &u) const
Definition: SingleNZSegmentVector.h:51
defs.h
jrl::qp::internal::SingleNZSegmentVector::size
int size() const
Definition: SingleNZSegmentVector.h:33
jrl::qp::VectorRef
Eigen::Ref< Eigen::VectorXd > VectorRef
Definition: defs.h:14