proxsuite 0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2022 INRIA
3//
8#ifndef PROXSUITE_HELPERS_COMMON_HPP
9#define PROXSUITE_HELPERS_COMMON_HPP
10
11#include "proxsuite/config.hpp"
12#include <limits>
13
14namespace proxsuite {
15namespace helpers {
16
17template<typename Scalar>
19{
20 static Scalar value()
21 {
22 using namespace std;
23 return sqrt(std::numeric_limits<Scalar>::max());
24 }
25};
26
27#define PROXSUITE_DEDUCE_RET(...) \
28 noexcept(noexcept(__VA_ARGS__)) \
29 ->typename std::remove_const<decltype(__VA_ARGS__)>::type \
30 { \
31 return __VA_ARGS__; \
32 } \
33 static_assert(true, ".")
34
36template<typename T, typename Scalar>
37auto
38at_most(T const& expr, const Scalar value) PROXSUITE_DEDUCE_RET(
39 (expr.array() < value).select(expr, T::Constant(expr.rows(), value)));
40
42template<typename T, typename Scalar>
43auto
44at_least(T const& expr, const Scalar value) PROXSUITE_DEDUCE_RET(
45 (expr.array() > value).select(expr, T::Constant(expr.rows(), value)));
46
48template<typename T>
49auto
50positive_part(T const& expr)
51 PROXSUITE_DEDUCE_RET((expr.array() > 0).select(expr, T::Zero(expr.rows())));
52
54template<typename T>
55auto
56negative_part(T const& expr)
57 PROXSUITE_DEDUCE_RET((expr.array() < 0).select(expr, T::Zero(expr.rows())));
58
61template<typename Condition, typename T, typename Scalar>
62auto
63select(Condition const& condition, T const& expr, const Scalar value)
64 PROXSUITE_DEDUCE_RET((condition).select(expr,
65 T::Constant(expr.rows(), value)));
66
67} // helpers
68} // proxsuite
69
70#endif // ifndef PROXSUITE_HELPERS_COMMON_HPP
#define PROXSUITE_DEDUCE_RET(...)
Definition common.hpp:27
auto select(Condition const &condition, T const &expr, const Scalar value) PROXSUITE_DEDUCE_RET((condition).select(expr
Select the components of the expression if the condition is fullfiled. Otherwise, set the component t...
auto positive_part(T const &expr) PROXSUITE_DEDUCE_RET((expr.array() > 0).select(expr
Returns the positive part of an expression.
auto at_least(T const &expr, const Scalar value) PROXSUITE_DEDUCE_RET((expr.array() > value).select(expr
Returns the part of the expression which is greater than value.
auto at_most(T const &expr, const Scalar value) PROXSUITE_DEDUCE_RET((expr.array()< value).select(expr
Returns the part of the expression which is lower than value.
auto negative_part(T const &expr) PROXSUITE_DEDUCE_RET((expr.array()< 0).select(expr
Returns the negative part of an expression.
STL namespace.