PANOC-ALM main
Nonconvex constrained optimization
box.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "vec.hpp"
4
5namespace pa {
6
7struct Box {
10};
11
14template <class Vec>
15inline auto project(const Vec &v,
16 const Box &box
17) {
18 using binary_real_f = real_t (*)(real_t, real_t);
19 return v.binaryExpr(box.lowerbound, binary_real_f(std::fmax))
20 .binaryExpr(box.upperbound, binary_real_f(std::fmin));
21}
22
26template <class Vec>
27inline auto
29 const Box &box
30) {
31 return v - project(v, box);
32}
33
38 const Box &box
39) {
40 return projecting_difference(v, box).squaredNorm();
41}
42
49 const Box &box,
50 crvec Σ
51) {
52 // TODO: Does this allocate?
53 // Does it have dangling references to temporaries?
54 auto d = v - project(v, box);
55 return d.dot(Σ.asDiagonal() * d);
56}
57
58} // namespace pa
Definition: alm.hpp:9
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
auto project(const Vec &v, const Box &box)
Project a vector onto a box.
Definition: box.hpp:15
vec upperbound
Definition: box.hpp:8
realvec vec
Default type for vectors.
Definition: vec.hpp:14
real_t dist_squared(crvec v, const Box &box)
Get the distance squared between the given vector and its projection.
Definition: box.hpp:37
vec lowerbound
Definition: box.hpp:9
double real_t
Default floating point type.
Definition: vec.hpp:8
auto projecting_difference(const Vec &v, const Box &box)
Get the difference between the given vector and its projection.
Definition: box.hpp:28
Definition: box.hpp:7
int Σ
Definition: test.py:72