smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
scalar.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
10#include <random>
11
12#include "../concepts/lie_group.hpp"
13#include "../detail/traits.hpp"
14
15SMOOTH_BEGIN_NAMESPACE
16
17namespace traits {
21template<ScalarType G>
22struct lie<G>
23{
24 // \cond
25 using Scalar = G;
26 using PlainObject = G;
27 template<typename NewScalar>
28 using CastT = NewScalar;
29
30 static constexpr int Dof = 1;
31 static constexpr bool IsCommutative = true;
32
33 // group interface
34
35 static inline PlainObject Identity(Eigen::Index) { return G(0); }
36 static inline PlainObject Random(Eigen::Index)
37 {
38 std::minstd_rand gen;
39 std::uniform_real_distribution<Scalar> dist(-1., 1.);
40 return G(dist(gen));
41 }
42 static inline Eigen::Matrix<Scalar, 1, 1> Ad(G) { return Eigen::Matrix<Scalar, 1, 1>{1}; }
43 static inline PlainObject composition(G g1, G g2) { return g1 + g2; }
44 static inline Eigen::Index dof(G) { return 1; }
45 static inline PlainObject inverse(G g) { return -g; }
46 static inline bool isApprox(G g1, G g2, Scalar eps)
47 {
48 using std::abs;
49 return abs<G>(g1 - g2) <= eps * abs<G>(g1);
50 }
51 static inline Eigen::Matrix<Scalar, 1, 1> log(G g) { return Eigen::Matrix<Scalar, 1, 1>{g}; }
52 template<typename NewScalar>
53 static inline NewScalar cast(G g)
54 {
55 return static_cast<NewScalar>(g);
56 }
57
58 // tangent interface
59
60 template<typename Derived>
61 static inline Eigen::Matrix<Scalar, 1, 1> ad(const Eigen::MatrixBase<Derived> &)
62 {
63 return Eigen::Matrix<Scalar, 1, 1>::Zero();
64 }
65 template<typename Derived>
66 static inline PlainObject exp(const Eigen::MatrixBase<Derived> & a)
67 {
68 return a(0);
69 }
70 template<typename Derived>
71 static inline Eigen::Matrix<Scalar, 1, 1> dr_exp(const Eigen::MatrixBase<Derived> &)
72 {
73 return Eigen::Matrix<Scalar, 1, 1>::Identity();
74 }
75 template<typename Derived>
76 static inline Eigen::Matrix<Scalar, 1, 1> dr_expinv(const Eigen::MatrixBase<Derived> &)
77 {
78 return Eigen::Matrix<Scalar, 1, 1>::Identity();
79 }
80 template<typename Derived>
81 static inline Eigen::Matrix<Scalar, 1, 1> d2r_exp(const Eigen::MatrixBase<Derived> &)
82 {
83 return Eigen::Matrix<Scalar, 1, 1>::Zero();
84 }
85 template<typename Derived>
86 static inline Eigen::Matrix<Scalar, 1, 1> d2r_expinv(const Eigen::MatrixBase<Derived> &)
87 {
88 return Eigen::Matrix<Scalar, 1, 1>::Zero();
89 }
90 // \endcond
91};
92
93} // namespace traits
94
95SMOOTH_END_NAMESPACE
TangentMap< G > Ad(const G &g)
Group adjoint .
PlainObject< G > Random()
Random element in Lie group with static Dof.
Hessian< G > d2r_exp(Arg &&a)
Right Hessian of exponential map.
bool isApprox(const G &g, Arg &&a, typename traits::lie< G >::Scalar eps=Eigen::NumTraits< typename traits::lie< G >::Scalar >::dummy_precision())
Check if two group elements are approximately equal.
Tangent< G > log(const G &g)
Group logarithm.
TangentMap< G > dr_exp(Arg &&a)
Right Jacobian of exponential map.
PlainObject< G > composition(const G &g, Arg &&a)
Group binary composition.
PlainObject< G > exp(Arg &&a)
Lie algebra exponential.
Hessian< G > d2r_expinv(Arg &&a)
Right Hessian of exponential map inverse.
PlainObject< G > Identity()
Identity in Lie group with static Dof.
TangentMap< G > ad(Arg &&a)
Lie algebra adjoint .
PlainObject< G > inverse(const G &g)
Group inverse.
TangentMap< G > dr_expinv(Arg &&a)
Right Jacobian of exponential map inverse.
typename traits::man< M >::Scalar Scalar
Manifold scalar type.
Definition manifold.hpp:88
Eigen::Index dof(const M &m)
Manifold degrees of freedom (tangent space dimension)
Definition manifold.hpp:145
typename traits::man< M >::template CastT< NewScalar > CastT
Cast'ed type.
Definition manifold.hpp:100
CastT< NewScalar, M > cast(const M &m)
Cast to different scalar type.
Definition manifold.hpp:154
typename traits::man< M >::PlainObject PlainObject
Manifold default type.
Definition manifold.hpp:94