SOPT
Sparse OPTimisation
positive_quadrant.h
Go to the documentation of this file.
1 #ifndef SOPT_PROJECTED_ALGORITHM_H
2 #define SOPT_PROJECTED_ALGORITHM_H
3 
5 #include "sopt/types.h"
6 
7 #include <utility> // for std::forward
8 
9 namespace sopt::algorithm {
10 
14 template <typename ALGORITHM>
16  public:
18  using Algorithm = ALGORITHM;
20  using Scalar = typename Algorithm::Scalar;
22  using t_Vector = typename Algorithm::t_Vector;
24  using t_IsConverged = typename Algorithm::t_IsConverged;
26  using Diagnostic = typename ALGORITHM::Diagnostic;
28  using DiagnosticAndResult = typename ALGORITHM::DiagnosticAndResult;
29 
30  PositiveQuadrant(Algorithm const &algo) : algorithm_(algo) {}
31  PositiveQuadrant(Algorithm &&algo) : algorithm_(std::move(algo)) {}
32 
33  Algorithm &algorithm() { return algorithm_; }
34  Algorithm const &algorithm() const { return algorithm_; }
35 
37  template <typename... T>
38  Diagnostic operator()(t_Vector &out, T const &... args) const {
39  auto const diagnostic = algorithm()(out, std::forward<T const &>(args)...);
40  out = positive_quadrant(out);
41  return diagnostic;
42  };
43 
45  template <typename... T>
46  DiagnosticAndResult operator()(T const &... args) const {
47  auto result = algorithm()(std::forward<T const &>(args)...);
48  result.x = positive_quadrant(result.x);
49  return result;
50  };
51 
52  protected:
54  Algorithm algorithm_;
55 };
56 
58 template <typename ALGORITHM>
60  return {algo};
61 }
62 } // namespace sopt::algorithm
63 
64 #endif
sopt::Vector< Scalar > t_Vector
sopt::t_real Scalar
Computes according to given algorithm and then projects it to the positive quadrant.
typename Algorithm::Scalar Scalar
Underlying scalar.
PositiveQuadrant(Algorithm const &algo)
ALGORITHM Algorithm
Underlying algorithm.
Diagnostic operator()(t_Vector &out, T const &... args) const
Performs algorithm and project results onto positive quadrant.
DiagnosticAndResult operator()(T const &... args) const
Performs algorithm and project results onto positive quadrant.
typename ALGORITHM::Diagnostic Diagnostic
Underlying result type.
typename Algorithm::t_Vector t_Vector
Underlying vector.
typename ALGORITHM::DiagnosticAndResult DiagnosticAndResult
Underlying result type.
Algorithm const & algorithm() const
typename Algorithm::t_IsConverged t_IsConverged
Underlying convergence functions.
PositiveQuadrant< ALGORITHM > positive_quadrant(ALGORITHM const &algo)
Extended algorithm where the solution is projected on the positive quadrant.