SOPT
Sparse OPTimisation
proximal_expression.h
Go to the documentation of this file.
1 #ifndef SOPT_PROXIMAL_EXPRESSION_H
2 #define SOPT_PROXIMAL_EXPRESSION_H
3 
4 #include "sopt/config.h"
5 #include <type_traits>
6 #include <utility> // for std::move<>
7 #include <Eigen/Core>
8 #include "sopt/maths.h"
9 
11 namespace sopt::proximal {
12 
13 namespace details {
18 template <typename FUNCTION, typename DERIVED>
20  : public Eigen::ReturnByValue<DelayedProximalFunction<FUNCTION, DERIVED>> {
21  public:
22  using PlainObject = typename DERIVED::PlainObject;
23  using Index = typename DERIVED::Index;
25 
26  DelayedProximalFunction(FUNCTION const &func, Real const &gamma, DERIVED const &x)
27  : func(func), gamma(gamma), x(x) {}
29  : func(c.func), gamma(c.gamma), x(c.x) {}
31  : func(std::move(c.func)), gamma(c.gamma), x(c.x) {}
32 
33  template <typename DESTINATION>
34  void evalTo(DESTINATION &destination) const {
35  destination.resizeLike(x);
36  func(destination, gamma, x);
37  }
38 
39  Index rows() const { return x.rows(); }
40  Index cols() const { return x.cols(); }
41 
42  private:
43  FUNCTION const func;
44  Real const gamma;
45  DERIVED const &x;
46 };
47 
52 template <typename FUNCTION, typename DERIVED>
54  : public Eigen::ReturnByValue<DelayedProximalEnveloppeFunction<FUNCTION, DERIVED>> {
55  public:
56  using PlainObject = typename DERIVED::PlainObject;
57  using Index = typename DERIVED::Index;
59 
60  DelayedProximalEnveloppeFunction(FUNCTION const &func, DERIVED const &x) : func(func), x(x) {}
62  : func(c.func), x(c.x) {}
64  : func(std::move(c.func)), x(c.x) {}
65 
66  template <typename DESTINATION>
67  void evalTo(DESTINATION &destination) const {
68  destination.resizeLike(x);
69  func(destination, x);
70  }
71 
72  Index rows() const { return x.rows(); }
73  Index cols() const { return x.cols(); }
74 
75  private:
76  FUNCTION const func;
77  DERIVED const &x;
78 };
79 
80 } // namespace details
81 
83 template <typename FUNC, typename T0>
86 template <typename FUNC, typename T0>
88 } // namespace sopt::proximal
89 
90 namespace Eigen::internal {
91 template <typename FUNCTION, typename VECTOR>
92 struct traits<sopt::proximal::details::DelayedProximalFunction<FUNCTION, VECTOR>> {
93  using ReturnType = typename VECTOR::PlainObject;
94 };
95 template <typename FUNCTION, typename VECTOR>
96 struct traits<sopt::proximal::details::DelayedProximalEnveloppeFunction<FUNCTION, VECTOR>> {
97  using ReturnType = typename VECTOR::PlainObject;
98 };
99 } // namespace Eigen::internal
100 
101 #endif
Computes inner-most element type.
Definition: real_type.h:42
Expression referencing a lazy function call to envelope proximal.
DelayedProximalEnveloppeFunction(FUNCTION const &func, DERIVED const &x)
typename real_type< typename DERIVED::Scalar >::type Real
DelayedProximalEnveloppeFunction(DelayedProximalEnveloppeFunction &&c)
DelayedProximalEnveloppeFunction(DelayedProximalEnveloppeFunction const &c)
Expression referencing a lazy proximal function call.
void evalTo(DESTINATION &destination) const
DelayedProximalFunction(DelayedProximalFunction const &c)
typename real_type< typename DERIVED::Scalar >::type Real
DelayedProximalFunction(FUNCTION const &func, Real const &gamma, DERIVED const &x)
Holds some standard proximals.
Definition: l1_proximal.h:17