aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1
4#pragma once
5
7#include <proxsuite-nlp/math.hpp>
8
9#define ALIGATOR_RAISE_IF_NAN(value) \
10 if (::aligator::math::check_value(value)) \
11 ALIGATOR_RUNTIME_ERROR("Encountered NaN.\n")
12
13#define ALIGATOR_RAISE_IF_NAN_NAME(value, name) \
14 if (::aligator::math::check_value(value)) \
15 ALIGATOR_RUNTIME_ERROR( \
16 fmt::format("Encountered NaN for variable {:s}\n", name))
17
18#define ALIGATOR_DYNAMIC_TYPEDEFS(Scalar) PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
19
20#define ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar) \
21 ALIGATOR_DYNAMIC_TYPEDEFS(Scalar); \
22 using RowMatrixXs = typename Eigen::Transpose<MatrixXs>::PlainObject; \
23 using RowMatrixRef = Eigen::Ref<RowMatrixXs>; \
24 using ConstRowMatrixRef = Eigen::Ref<const RowMatrixXs>
25
26namespace aligator {
27
28// NOLINTBEGIN(misc-unused-using-decls)
29using proxsuite::nlp::math_types;
30// NOLINTEND(misc-unused-using-decls)
31
35template <typename D>
36auto eigenPrintWithPreamble(const Eigen::EigenBase<D> &mat,
37 const std::string &text) {
38 Eigen::IOFormat ft = EIGEN_DEFAULT_IO_FORMAT;
39 ft.matPrefix = text;
40 ft.rowSpacer = "";
41 int i = int(text.length()) - 1;
42 while (i >= 0) {
43 if (text[size_t(i)] != '\n')
44 ft.rowSpacer += ' ';
45 i--;
46 }
47 return mat.derived().format(ft);
48}
49
51namespace math {
52
53// NOLINTBEGIN(misc-unused-using-decls)
54using proxsuite::nlp::math::check_scalar;
55using proxsuite::nlp::math::check_value;
56using proxsuite::nlp::math::infty_norm;
57using proxsuite::nlp::math::scalar_close;
58// NOLINTEND(misc-unused-using-decls)
59
61template <typename T> bool check_value(const std::vector<T> &xs) {
62 const std::size_t n = xs.size();
63 for (std::size_t i = 0; i < n; i++) {
64 if (check_value<T>(xs[i]))
65 return true;
66 }
67 return false;
68}
69
70template <typename T> void setZero(std::vector<T> &mats) {
71 for (std::size_t i = 0; i < mats.size(); i++) {
72 mats[i].setZero();
73 }
74}
75
77template <typename A, typename B, typename OutType, typename Scalar>
78void vectorMultiplyAdd(const std::vector<A> &a, const std::vector<B> &b,
79 std::vector<OutType> &c, const Scalar alpha) {
80 assert(a.size() == b.size());
81 assert(a.size() == c.size());
82 const std::size_t N = a.size();
83 for (std::size_t i = 0; i < N; i++) {
84 c[i] = a[i] + alpha * b[i];
85 }
86}
87
88} // namespace math
89} // namespace aligator
void setZero(std::vector< T > &mats)
Definition math.hpp:70
void vectorMultiplyAdd(const std::vector< A > &a, const std::vector< B > &b, std::vector< OutType > &c, const Scalar alpha)
Compute zi = xi + alpha * yi for all i.
Definition math.hpp:78
bool check_value(const std::vector< T > &xs)
Check if a std::vector of numerical objects has invalid values.
Definition math.hpp:61
Main package namespace.
auto eigenPrintWithPreamble(const Eigen::EigenBase< D > &mat, const std::string &text)
Definition math.hpp:36