aligator  0.10.0
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
6#include <proxsuite-nlp/math.hpp>
7
8#define ALIGATOR_DYNAMIC_TYPEDEFS(Scalar) PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
9
10#define ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar) \
11 ALIGATOR_DYNAMIC_TYPEDEFS(Scalar); \
12 using RowMatrixXs = typename Eigen::Transpose<MatrixXs>::PlainObject; \
13 using RowMatrixRef = Eigen::Ref<RowMatrixXs>; \
14 using ConstRowMatrixRef = Eigen::Ref<const RowMatrixXs>
15
16namespace aligator {
17
18// NOLINTBEGIN(misc-unused-using-decls)
19using proxsuite::nlp::math_types;
20// NOLINTEND(misc-unused-using-decls)
21
25template <typename D>
26auto eigenPrintWithPreamble(const Eigen::EigenBase<D> &mat,
27 const std::string &text) {
28 Eigen::IOFormat ft = EIGEN_DEFAULT_IO_FORMAT;
29 ft.matPrefix = text;
30 ft.rowSpacer = "";
31 int i = int(text.length()) - 1;
32 while (i >= 0) {
33 if (text[size_t(i)] != '\n')
34 ft.rowSpacer += ' ';
35 i--;
36 }
37 return mat.derived().format(ft);
38}
39
41namespace math {
42
43// NOLINTBEGIN(misc-unused-using-decls)
44using proxsuite::nlp::math::check_scalar;
45using proxsuite::nlp::math::check_value;
46using proxsuite::nlp::math::infty_norm;
47using proxsuite::nlp::math::scalar_close;
48// NOLINTEND(misc-unused-using-decls)
49
51template <typename T> bool check_value(const std::vector<T> &xs) {
52 const std::size_t n = xs.size();
53 for (std::size_t i = 0; i < n; i++) {
54 if (check_value<T>(xs[i]))
55 return true;
56 }
57 return false;
58}
59
60template <typename T> void setZero(std::vector<T> &mats) {
61 for (std::size_t i = 0; i < mats.size(); i++) {
62 mats[i].setZero();
63 }
64}
65
67template <typename A, typename B, typename OutType, typename Scalar>
68void vectorMultiplyAdd(const std::vector<A> &a, const std::vector<B> &b,
69 std::vector<OutType> &c, const Scalar alpha) {
70 assert(a.size() == b.size());
71 assert(a.size() == c.size());
72 const std::size_t N = a.size();
73 for (std::size_t i = 0; i < N; i++) {
74 c[i] = a[i] + alpha * b[i];
75 }
76}
77
78} // namespace math
79} // namespace aligator
void setZero(std::vector< T > &mats)
Definition math.hpp:60
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:68
bool check_value(const std::vector< T > &xs)
Check if a std::vector of numerical objects has invalid values.
Definition math.hpp:51
Main package namespace.
auto eigenPrintWithPreamble(const Eigen::EigenBase< D > &mat, const std::string &text)
Definition math.hpp:26