alpaqa 0.0.1
Nonconvex constrained optimization
vec.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4
5namespace alpaqa {
6
7/// Default floating point type
8using real_t = double; // TODO: make template?
9/// Default type for floating point vectors.
10using realvec = Eigen::Matrix<real_t, Eigen::Dynamic, 1>;
11/// Default type for floating point matrices.
12using realmat = Eigen::Matrix<real_t, Eigen::Dynamic, Eigen::Dynamic>;
13/// Default type for vectors.
14using vec = realvec;
15/// Default type for mutable references to vectors.
16using rvec = Eigen::Ref<vec>;
17/// Default type for immutable references to vectors.
18using crvec = Eigen::Ref<const vec>;
19/// Default type for matrices.
20using mat = realmat;
21/// Default type for mutable references to matrices.
22using rmat = Eigen::Ref<mat>;
23/// Default type for immutable references to matrices.
24using crmat = Eigen::Ref<const mat>;
25/// @f$ \infty @f$
26constexpr real_t inf = std::numeric_limits<real_t>::infinity();
27/// Not a number.
28constexpr real_t NaN = std::numeric_limits<real_t>::quiet_NaN();
29
30namespace vec_util {
31
32/// Get the Σ norm squared of a given vector, with Σ a diagonal matrix.
33/// @returns @f$ \langle v, \Sigma v \rangle @f$
34template <class V, class M>
35auto norm_squared_weighted(V &&v, M &&Σ) {
36 return v.dot(Σ.asDiagonal() * v);
37}
38
39/// Get the maximum or infinity-norm of the given vector.
40/// @returns @f$ \left\|v\right\|_\infty @f$
41template <class Vec>
42real_t norm_inf(const Vec &v) {
43 return v.template lpNorm<Eigen::Infinity>();
44}
45
46/// Get the 1-norm of the given vector.
47/// @returns @f$ \left\|v\right\|_1 @f$
48template <class Vec>
49real_t norm_1(const Vec &v) {
50 return v.template lpNorm<1>();
51}
52
53} // namespace vec_util
54
55} // namespace alpaqa
int Σ
Definition: test.py:72
real_t norm_1(const Vec &v)
Get the 1-norm of the given vector.
Definition: vec.hpp:49
auto norm_squared_weighted(V &&v, M &&Σ)
Get the Σ norm squared of a given vector, with Σ a diagonal matrix.
Definition: vec.hpp:35
real_t norm_inf(const Vec &v)
Get the maximum or infinity-norm of the given vector.
Definition: vec.hpp:42
Eigen::Matrix< real_t, Eigen::Dynamic, Eigen::Dynamic > realmat
Default type for floating point matrices.
Definition: vec.hpp:12
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
Eigen::Ref< const mat > crmat
Default type for immutable references to matrices.
Definition: vec.hpp:24
constexpr real_t NaN
Not a number.
Definition: vec.hpp:28
constexpr real_t inf
Definition: vec.hpp:26
realmat mat
Default type for matrices.
Definition: vec.hpp:20
realvec vec
Default type for vectors.
Definition: vec.hpp:14
Eigen::Ref< mat > rmat
Default type for mutable references to matrices.
Definition: vec.hpp:22
double real_t
Default floating point type.
Definition: vec.hpp:8
Eigen::Matrix< real_t, Eigen::Dynamic, 1 > realvec
Default type for floating point vectors.
Definition: vec.hpp:10
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Definition: vec.hpp:16