/usr/include/sopt/positive_quadrant.h is in libsopt-dev 2.0.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #ifndef SOPT_PROJECTED_ALGORITHM_H
#define SOPT_PROJECTED_ALGORITHM_H
#include "sopt/linear_transform.h"
#include "sopt/types.h"
namespace sopt {
namespace algorithm {
//! \brief Computes according to given algorithm and then projects it to the positive quadrant
//! \details C implementation of the reweighted algorithms uses this, even-though the solutions are
//! already constrained to the positive quadrant.
template <class ALGORITHM> class PositiveQuadrant {
public:
//! Underlying algorithm
typedef ALGORITHM Algorithm;
//! Underlying scalar
typedef typename Algorithm::Scalar Scalar;
//! Underlying vector
typedef typename Algorithm::t_Vector t_Vector;
//! Underlying convergence functions
typedef typename Algorithm::t_IsConverged t_IsConverged;
//! Underlying result type
typedef typename ALGORITHM::Diagnostic Diagnostic;
//! Underlying result type
typedef typename ALGORITHM::DiagnosticAndResult DiagnosticAndResult;
PositiveQuadrant(Algorithm const &algo) : algorithm_(algo) {}
PositiveQuadrant(Algorithm &&algo) : algorithm_(std::move(algo)) {}
Algorithm &algorithm() { return algorithm_; }
Algorithm const &algorithm() const { return algorithm_; }
//! Performs algorithm and project results onto positive quadrant
template <class... T> Diagnostic operator()(t_Vector &out, T const &... args) const {
auto const diagnostic = algorithm()(out, std::forward<T const &>(args)...);
out = positive_quadrant(out);
return diagnostic;
};
//! Performs algorithm and project results onto positive quadrant
template <class... T> DiagnosticAndResult operator()(T const &... args) const {
auto result = algorithm()(std::forward<T const &>(args)...);
result.x = positive_quadrant(result.x);
return result;
};
protected:
//! Underlying algorithm
Algorithm algorithm_;
};
//! Extended algorithm where the solution is projected on the positive quadrant
template <class ALGORITHM> PositiveQuadrant<ALGORITHM> positive_quadrant(ALGORITHM const &algo) {
return {algo};
}
}
}
#endif
|