tinyopt 700
Tinyopt, a lightweight, header only optimization library
Loading...
Searching...
No Matches
types.h
1// Copyright 2026 Julien Michot.
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include <Eigen/Core>
7#include <Eigen/Dense>
8#include <Eigen/Sparse>
9
10#include <Eigen/src/Core/util/Constants.h>
11#include <Eigen/src/SparseCore/SparseSelfAdjointView.h>
12#include <Eigen/SparseCholesky>
13
14namespace tinyopt {
15
16static constexpr int Dynamic = Eigen::Dynamic;
17static constexpr int Lower = Eigen::Lower;
18static constexpr int Upper = Eigen::Upper;
19static constexpr int Infinity = Eigen::Infinity;
20
21using Index = Eigen::Index;
22
23template <typename Scalar, int Rows = Dynamic, int Cols = Dynamic, int Options = 0,
24 int MaxRows = Rows, int MaxCols = Cols>
25using Matrix =
26 std::conditional_t<Rows != 1 || (Rows == 1 && Cols == 1),
27 Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>,
28 Eigen::Matrix<Scalar, Rows, Cols, Eigen::RowMajor, MaxRows, MaxCols>>;
29
30template <typename Scalar, int Rows = Dynamic>
31using Vector = Matrix<Scalar, Rows, 1>;
32
33template <typename T, int Cols>
34using RowVector = Matrix<T, 1, Cols, Eigen::RowMajor>;
35
36template <typename Scalar = double, int Options = 0, typename StorageIndex = int>
37using SparseMatrix = Eigen::SparseMatrix<Scalar, Options, StorageIndex>;
38
39using SparseMat = SparseMatrix<double>;
40using SparseMatf = SparseMatrix<float>;
41
42template <typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
43using Block = Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>;
44template <typename T>
45using MatrixBase = Eigen::MatrixBase<T>;
46template <typename T>
47using DenseBase = Eigen::DenseBase<T>;
48template <typename T>
49using ArrayBase = Eigen::ArrayBase<T>;
50
51// Let's define some common matrix and vectors
52using MatX = Matrix<double, Dynamic, Dynamic>;
53using MatXf = Matrix<float, Dynamic, Dynamic>;
54
55using Mat1 = Matrix<double, 1, 1>;
56using Mat2 = Matrix<double, 2, 2>;
57using Mat3 = Matrix<double, 3, 3>;
58using Mat4 = Matrix<double, 4, 4>;
59using Mat5 = Matrix<double, 5, 5>;
60using Mat6 = Matrix<double, 6, 6>;
61
62using Mat1f = Matrix<float, 1, 1>;
63using Mat2f = Matrix<float, 2, 2>;
64using Mat3f = Matrix<float, 3, 3>;
65using Mat4f = Matrix<float, 4, 4>;
66using Mat5f = Matrix<float, 5, 5>;
67using Mat6f = Matrix<float, 6, 6>;
68
69using VecX = Vector<double, Dynamic>;
70using Vec1 = Vector<double, 1>;
71using Vec2 = Vector<double, 2>;
72using Vec3 = Vector<double, 3>;
73using Vec4 = Vector<double, 4>;
74using Vec5 = Vector<double, 5>;
75using Vec6 = Vector<double, 6>;
76using Vec12 = Vector<double, 12>;
77using Vec21 = Vector<double, 21>;
78
79using VecXf = Vector<float, Dynamic>;
80using Vec1f = Vector<float, 1>;
81using Vec2f = Vector<float, 2>;
82using Vec3f = Vector<float, 3>;
83using Vec4f = Vector<float, 4>;
84using Vec5f = Vector<float, 5>;
85using Vec6f = Vector<float, 6>;
86using Vec12f = Vector<float, 12>;
87using Vec21f = Vector<float, 21>;
88
89using Mat2X = Matrix<double, 2, Dynamic>;
90using Mat3X = Matrix<double, 3, Dynamic>;
91
92using Mat2Xf = Matrix<float, 2, Dynamic>;
93using Mat3Xf = Matrix<float, 3, Dynamic>;
94
95using Mat23 = Matrix<double, 2, 3>;
96using Mat32 = Matrix<double, 3, 2>;
97
98using Mat23f = Matrix<float, 2, 3>;
99using Mat32f = Matrix<float, 3, 2>;
100
101} // namespace tinyopt
Definition options.h:18